--- /dev/null
+From aa7f6b1162807f867524ec38a56a32107b493ed7 Mon Sep 17 00:00:00 2001
+From: Dennis Groenen <tj.groenen@gmail.com>
+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
+
--- /dev/null
+From c96672c9c603498d7c4775b2a372cbe9b0ba6dbf Mon Sep 17 00:00:00 2001
+From: Dennis Groenen <tj.groenen@gmail.com>
+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
+