From: Dennis Groenen Date: Sat, 13 Oct 2012 13:02:04 +0000 (+0200) Subject: exit shell cleanly upon receiving SIGHUP X-Git-Tag: 1.20.2power3~2 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=d371257e3d8b4614619d55d192f87d7c43f3e5bc;hp=b99092b1af34a3b6a8efb9a26384c8ca54b21d2e;p=busybox-power exit shell cleanly upon receiving SIGHUP --- diff --git a/debian/patches/0001-pgrep-check-whether-we-re-pkill-at-runtime.patch b/debian/patches/0001-pgrep-check-whether-we-re-pkill-at-runtime.patch new file mode 100644 index 0000000..d72d831 --- /dev/null +++ b/debian/patches/0001-pgrep-check-whether-we-re-pkill-at-runtime.patch @@ -0,0 +1,59 @@ +From aa7f6b1162807f867524ec38a56a32107b493ed7 Mon Sep 17 00:00:00 2001 +From: Dennis Groenen +Date: Sat, 22 Sep 2012 11:22:11 +0200 +Subject: [PATCH 1/2] pgrep: check whether we're pkill at runtime + +If we want to call pgrep_main() from other applets, pkill or pgrep will be left +undefined. Check whether we're called as pkill or pgrep at runtime instead of +using the preprocessor. +--- + procps/pgrep.c | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +diff --git a/procps/pgrep.c b/procps/pgrep.c +index dc7ffff..2d5b221 100644 +--- a/procps/pgrep.c ++++ b/procps/pgrep.c +@@ -36,9 +36,8 @@ + #include "libbb.h" + #include "xregex.h" + +-/* Idea taken from kill.c */ +-#define pgrep (ENABLE_PGREP && applet_name[1] == 'g') +-#define pkill (ENABLE_PKILL && applet_name[1] == 'k') ++/* Are we pgrep or pkill? */ ++unsigned short pkill; + + enum { + /* "vlfxons:P:" */ +@@ -63,13 +62,14 @@ enum { + + static void act(unsigned pid, char *cmd, int signo) + { +- if (pgrep) { ++ if (pkill) { ++ kill(pid, signo); ++ } else { + if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */ + printf("%d %s\n", pid, cmd); + else + printf("%d\n", pid); +- } else +- kill(pid, signo); ++ } + } + + int pgrep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +@@ -93,6 +93,9 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) + + memset(&Z, 0, sizeof(Z)); + ++ /* Are we called as pkill? */ ++ pkill = argv[0][1] == 'k' ? 1 : 0; ++ + /* Parse -SIGNAL for pkill. Must be first option, if present */ + signo = SIGTERM; + if (pkill && argv[1] && argv[1][0] == '-') { +-- +1.7.12 + diff --git a/debian/patches/0002-ash-install-SIGHUP-signal-handler-when-interactive.patch b/debian/patches/0002-ash-install-SIGHUP-signal-handler-when-interactive.patch new file mode 100644 index 0000000..4c8808f --- /dev/null +++ b/debian/patches/0002-ash-install-SIGHUP-signal-handler-when-interactive.patch @@ -0,0 +1,80 @@ +From c96672c9c603498d7c4775b2a372cbe9b0ba6dbf Mon Sep 17 00:00:00 2001 +From: Dennis Groenen +Date: Sat, 22 Sep 2012 11:38:11 +0200 +Subject: [PATCH 2/2] ash: install SIGHUP signal handler when interactive + +--- + include/libbb.h | 2 ++ + procps/Kbuild.src | 1 + + shell/ash.c | 23 +++++++++++++++++++++++ + 3 files changed, 26 insertions(+) + +diff --git a/include/libbb.h b/include/libbb.h +index 2cc1466..8694d52 100644 +--- a/include/libbb.h ++++ b/include/libbb.h +@@ -1097,6 +1097,8 @@ int kill_main(int argc, char **argv) IF_KILL(MAIN_EXTERNALLY_VISIBLE); + int chown_main(int argc, char **argv) IF_CHOWN(MAIN_EXTERNALLY_VISIBLE); + /* Used by ftpd */ + int ls_main(int argc, char **argv) IF_LS(MAIN_EXTERNALLY_VISIBLE); ++/* Used by ash */ ++int pgrep_main(int argc, char **argv) IF_PKILL(MAIN_EXTERNALLY_VISIBLE); + /* Don't need IF_xxx() guard for these */ + int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; + int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +diff --git a/procps/Kbuild.src b/procps/Kbuild.src +index 89b1cc0..0718d32 100644 +--- a/procps/Kbuild.src ++++ b/procps/Kbuild.src +@@ -11,6 +11,7 @@ lib-$(CONFIG_FREE) += free.o + lib-$(CONFIG_FUSER) += fuser.o + lib-$(CONFIG_KILL) += kill.o + lib-$(CONFIG_ASH) += kill.o # used for built-in kill by ash ++lib-$(CONFIG_ASH) += pgrep.o # used by ash to signal its process group + lib-$(CONFIG_PGREP) += pgrep.o + lib-$(CONFIG_PKILL) += pgrep.o + lib-$(CONFIG_PIDOF) += pidof.o +diff --git a/shell/ash.c b/shell/ash.c +index d025da4..5885b04 100644 +--- a/shell/ash.c ++++ b/shell/ash.c +@@ -3378,6 +3378,26 @@ static void setjobctl(int); + #endif + + /* ++ * Hangup all children and exit cleany. ++ */ ++static void ++signal_pgrp_exit(int signo) ++{ ++ const char *args[] = { ++ "pkill", ++ xasprintf("-%d", SIGHUP), ++ "-P", ++ xasprintf("%d", getpid()), ++ NULL ++ }; ++ ++ pgrep_main(4, (char**)args); ++ ++ exitstatus = 128 + signo; ++ exitshell(); // exit shell cleanly ++} ++ ++/* + * Ignore a signal. + */ + static void +@@ -13160,6 +13180,9 @@ int ash_main(int argc UNUSED_PARAM, char **argv) + setstackmark(&smark); + procargs(argv); + ++ if (iflag) ++ signal(SIGHUP, signal_pgrp_exit); ++ + #if ENABLE_FEATURE_EDITING_SAVEHISTORY + if (iflag) { + const char *hp = lookupvar("HISTFILE"); +-- +1.7.12 + diff --git a/debian/patches/series b/debian/patches/series index 6a8b4d7..718bad1 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -20,6 +20,8 @@ ps-accept-and-ignore-missing-options.patch # New patches as per reported issues by users showkey-default-option.patch +0001-pgrep-check-whether-we-re-pkill-at-runtime.patch +0002-ash-install-SIGHUP-signal-handler-when-interactive.patch # Hotfixes hotfixes/busybox-1.20.2-kernel_ver.patch