update busybox power against BusyBox 1.21.1 release
[busybox-power] / debian / patches / 0001-pgrep-check-whether-we-re-pkill-at-runtime.patch
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
5
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.
9 ---
10  procps/pgrep.c | 15 +++++++++------
11  1 file changed, 9 insertions(+), 6 deletions(-)
12
13 diff --git a/procps/pgrep.c b/procps/pgrep.c
14 index dc7ffff..2d5b221 100644
15 --- a/procps/pgrep.c
16 +++ b/procps/pgrep.c
17 @@ -36,9 +36,8 @@
18  #include "libbb.h"
19  #include "xregex.h"
20  
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;
26  
27  enum {
28         /* "vlfxons:P:" */
29 @@ -63,13 +62,14 @@ enum {
30  
31  static void act(unsigned pid, char *cmd, int signo)
32  {
33 -       if (pgrep) {
34 +       if (pkill) {
35 +               kill(pid, signo);
36 +       } else {
37                 if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */
38                         printf("%d %s\n", pid, cmd);
39                 else
40                         printf("%d\n", pid);
41 -       } else
42 -               kill(pid, signo);
43 +       }
44  }
45  
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)
48  
49         memset(&Z, 0, sizeof(Z));
50  
51 +       /* Are we called as pkill? */
52 +       pkill = argv[0][1] == 'k' ? 1 : 0;
53 +
54         /* Parse -SIGNAL for pkill. Must be first option, if present */
55         signo = SIGTERM;
56         if (pkill && argv[1] && argv[1][0] == '-') {
57 -- 
58 1.7.12
59