integ/base/bash/files/bash-history-exit-child-on-parent-death.patch
slin14 3975ba05c7 de-fuzz bash patches
When do Centos 7.5 upgraded, some patches didn't resolve and cause
the fuzzy in the line numbers of the patches. And it may cause
.orig file is created when do patch. And this .orig file will lead
to rpm packaging failure due to the unexpected and unpackaged .orig
file.

Please visit below link to get more detail info:
https://bugs.launchpad.net/starlingx/+bug/1794611

Solution:
  Safest solution is to de-fuzz our patches.

Story: 2003389
Task: 26755

Change-Id: I13298239f6a49298b800aa07adeeadab0ef33729
Signed-off-by: slin14 <shuicheng.lin@intel.com>
2018-09-28 07:22:13 +08:00

106 lines
2.7 KiB
Diff

From 31e35dced8a76f9bec4ed2be86d0cca234751d09 Mon Sep 17 00:00:00 2001
From: Scott Little <scott.little@windriver.com>
Date: Fri, 26 Aug 2016 16:04:48 -0400
Subject: [PATCH 2/2] WRS: Patch501:
bash-history-exit-child-on-parent-death.patch
---
shell.c | 16 +++++++++++++++-
sig.c | 13 +++++++++++++
sig.h | 2 ++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/shell.c b/shell.c
index 7eca4e3..dcba61a 100644
--- a/shell.c
+++ b/shell.c
@@ -75,6 +75,7 @@
#if defined (SYSLOG_HISTORY)
# include <syslog.h>
# include <sys/socket.h>
+# include <sys/prctl.h>
# include "error.h"
#endif
@@ -338,6 +339,7 @@ static void shell_reinitialize __P((void));
static void show_shell_usage __P((FILE *, int));
#if defined (SYSLOG_HISTORY)
+int logger_terminated = 0;
static pid_t make_consumer_process __P(());
#endif
@@ -1687,6 +1689,16 @@ make_consumer_process ()
default_tty_job_signals ();
+ /* handle parent process deaths */
+ set_signal_handler(SIGTERM, sigterm_logger_sighandler);
+ prctl(PR_SET_PDEATHSIG, SIGTERM);
+
+ if (getppid() == 1)
+ {
+ /* parent has already died */
+ exit (0);
+ }
+
close(cmdline_hist_sock[0]);
ret = getsockopt(cmdline_hist_sock[1], SOL_SOCKET, SO_RCVBUF, &rcvbuf_size, &optlen);
@@ -1718,7 +1730,9 @@ make_consumer_process ()
/*syslog this bash command line*/
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s",
getpid(), current_user.uid, buffer);
- } while (1);
+ } while (!logger_terminated);
+
+ exit(0);
}
else
diff --git a/sig.c b/sig.c
index 6bd1319..94864fa 100644
--- a/sig.c
+++ b/sig.c
@@ -556,6 +556,19 @@ termsig_handler (sig)
kill (getpid (), sig);
}
+sighandler
+sigterm_logger_sighandler (sig)
+ int sig;
+{
+#if defined (MUST_REINSTALL_SIGHANDLERS)
+ signal (sig, sigterm_logger_sighandler);
+#endif
+
+ logger_terminated = 1;
+
+ SIGRETURN (0);
+}
+
/* What we really do when SIGINT occurs. */
sighandler
sigint_sighandler (sig)
diff --git a/sig.h b/sig.h
index 540aa3e..8f47c56 100644
--- a/sig.h
+++ b/sig.h
@@ -115,11 +115,13 @@ extern volatile int sigwinch_received;
extern int interrupt_immediately;
extern int terminate_immediately;
+extern int logger_terminated;
/* Functions from sig.c. */
extern sighandler termsig_sighandler __P((int));
extern void termsig_handler __P((int));
extern sighandler sigint_sighandler __P((int));
+extern sighandler sigterm_logger_sighandler __P((int));
extern void initialize_signals __P((int));
extern void initialize_terminating_signals __P((void));
extern void reset_terminating_signals __P((void));
--
2.7.4