1 From aa7f6b1162807f867524ec38a56a32107b493ed7 Mon Sep 17 00:00:00 2001
2 From: Dennis Groenen <tj.groenen@gmail.com>
3 Date: Sat, 22 Sep 2012 11:22:11 +0200
4 Subject: [PATCH 1/2] pgrep: check whether we're pkill at runtime
6 If we want to call pgrep_main() from other applets, pkill or pgrep will be left
7 undefined. Check whether we're called as pkill or pgrep at runtime instead of
8 using the preprocessor.
10 procps/pgrep.c | 15 +++++++++------
11 1 file changed, 9 insertions(+), 6 deletions(-)
13 diff --git a/procps/pgrep.c b/procps/pgrep.c
14 index dc7ffff..2d5b221 100644
21 -/* Idea taken from kill.c */
22 -#define pgrep (ENABLE_PGREP && applet_name[1] == 'g')
23 -#define pkill (ENABLE_PKILL && applet_name[1] == 'k')
24 +/* Are we pgrep or pkill? */
25 +unsigned short pkill;
29 @@ -63,13 +62,14 @@ enum {
31 static void act(unsigned pid, char *cmd, int signo)
37 if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */
38 printf("%d %s\n", pid, cmd);
46 int pgrep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47 @@ -93,6 +93,9 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
49 memset(&Z, 0, sizeof(Z));
51 + /* Are we called as pkill? */
52 + pkill = argv[0][1] == 'k' ? 1 : 0;
54 /* Parse -SIGNAL for pkill. Must be first option, if present */
56 if (pkill && argv[1] && argv[1][0] == '-') {