aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2005-10-07 15:44:37 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2005-10-07 15:44:37 +0000
commitab52db8d5ec63b037a85a609646ba93f96308138 (patch)
tree2733d2f072f4ff69cee6d2424f0451acc0b3a16a
parent6c0642d772c6661186e2191174fa83182fdc443e (diff)
downloadbusybox-w32-ab52db8d5ec63b037a85a609646ba93f96308138.tar.gz
busybox-w32-ab52db8d5ec63b037a85a609646ba93f96308138.tar.bz2
busybox-w32-ab52db8d5ec63b037a85a609646ba93f96308138.zip
- size reduction of pidof
- fix typo in reverse_pidlist
-rw-r--r--libbb/find_pid_by_name.c2
-rw-r--r--procps/pidof.c72
2 files changed, 31 insertions, 43 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index 966595ddb..24084a34f 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -45,7 +45,7 @@ extern long* find_pid_by_name( const char* pidName)
45extern long *pidlist_reverse(long *pidList) 45extern long *pidlist_reverse(long *pidList)
46{ 46{
47 int i=0; 47 int i=0;
48 while (pidList[i] > 0 && i++); 48 while (pidList[i] > 0 && ++i);
49 if ( i-- > 0) { 49 if ( i-- > 0) {
50 long k; 50 long k;
51 int j; 51 int j;
diff --git a/procps/pidof.c b/procps/pidof.c
index 6f959e4ad..76c58df85 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -15,6 +15,7 @@
15#include <signal.h> 15#include <signal.h>
16#include <ctype.h> 16#include <ctype.h>
17#include <string.h> 17#include <string.h>
18#include <sys/types.h>
18#include <unistd.h> 19#include <unistd.h>
19#include "busybox.h" 20#include "busybox.h"
20 21
@@ -29,7 +30,6 @@
29#if ENABLE_FEATURE_PIDOF_OMIT 30#if ENABLE_FEATURE_PIDOF_OMIT
30#define _OMIT_COMPL(a) a 31#define _OMIT_COMPL(a) a
31#define _OMIT(a) ,a 32#define _OMIT(a) ,a
32static llist_t *omits; /* list of pids to omit */
33#if ENABLE_FEATURE_PIDOF_SINGLE 33#if ENABLE_FEATURE_PIDOF_SINGLE
34#define OMIT (1<<1) 34#define OMIT (1<<1)
35#else 35#else
@@ -39,58 +39,45 @@ static llist_t *omits; /* list of pids to omit */
39#define _OMIT_COMPL(a) "" 39#define _OMIT_COMPL(a) ""
40#define _OMIT(a) 40#define _OMIT(a)
41#define OMIT (0) 41#define OMIT (0)
42#define omitted (0)
42#endif 43#endif
43 44
44extern int pidof_main(int argc, char **argv) 45extern int pidof_main(int argc, char **argv)
45{ 46{
46 int n = 0; 47 unsigned n = 0;
47 int fail = 1; 48 unsigned fail = 1;
48 unsigned long int opt; 49 unsigned long int opt;
49#if ENABLE_FEATURE_PIDOF_OMIT 50#if ENABLE_FEATURE_PIDOF_OMIT
51 llist_t *omits = NULL; /* list of pids to omit */
50 bb_opt_complementally = _OMIT_COMPL("o*"); 52 bb_opt_complementally = _OMIT_COMPL("o*");
51#endif 53#endif
52 54
53 /* do option parsing */ 55 /* do unconditional option parsing */
54 if ((opt = bb_getopt_ulflags(argc, argv, 56 opt = bb_getopt_ulflags(argc, argv,
55 _SINGLE_COMPL("s") _OMIT_COMPL("o:") 57 _SINGLE_COMPL("s") _OMIT_COMPL("o:")
56 _OMIT(&omits))) 58 _OMIT(&omits));
57 > 0) {
58#if ENABLE_FEATURE_PIDOF_SINGLE
59 if (!(opt & SINGLE))
60#endif
61#if ENABLE_FEATURE_PIDOF_OMIT
62 if (!(opt & OMIT))
63#endif
64 bb_show_usage();
65 }
66 59
67#if ENABLE_FEATURE_PIDOF_OMIT 60#if ENABLE_FEATURE_PIDOF_OMIT
68 /* fill omit list. */ 61 /* fill omit list. */
69 { 62 {
70 RESERVE_CONFIG_BUFFER(getppid_str, 32); 63 RESERVE_CONFIG_BUFFER(getppid_str, 32);
71 llist_t * omits_p = omits; 64 llist_t * omits_p = omits;
72 while (omits_p) { 65 while (omits_p) {
73 /* are we asked to exclude the parent's process ID? */ 66 /* are we asked to exclude the parent's process ID? */
74 if (omits_p->data[0] == '%') {
75 if (!strncmp(omits_p->data, "%PPID", 5)) { 67 if (!strncmp(omits_p->data, "%PPID", 5)) {
76 /* yes, exclude ppid */ 68 omits_p = llist_free_one(omits_p);
77 snprintf(getppid_str, sizeof(getppid_str), "%ld", getppid()); 69 snprintf(getppid_str, sizeof(getppid_str), "%d", getppid());
78// omits_p->data = getppid_str; 70 omits_p = llist_add_to(omits_p, getppid_str);
79#if 0 71#if 0
80 } else { 72 } else {
81 bb_error_msg_and_die("illegal omit pid value (%s)!\n", 73 bb_error_msg_and_die("illegal omit pid value (%s)!\n",
82 omits_p->data); 74 omits_p->data);
83#endif 75#endif
84 } 76 }
85 } else { 77 omits_p = omits_p->link;
86 /* no, not talking about ppid but deal with usual case (pid). */
87 snprintf(getppid_str, sizeof(getppid_str), "%ld",
88 strtol(omits_p->data, NULL, 10));
89 } 78 }
90 omits_p->data = getppid_str; 79 if (ENABLE_FEATURE_CLEAN_UP)
91 omits_p = omits_p->link; 80 RELEASE_CONFIG_BUFFER(getppid_str);
92 }
93 RELEASE_CONFIG_BUFFER(getppid_str);
94 } 81 }
95#endif 82#endif
96 /* Looks like everything is set to go. */ 83 /* Looks like everything is set to go. */
@@ -102,7 +89,7 @@ extern int pidof_main(int argc, char **argv)
102 pidList = pidlist_reverse(find_pid_by_name(argv[optind])); 89 pidList = pidlist_reverse(find_pid_by_name(argv[optind]));
103 for(pl = pidList; *pl > 0; pl++) { 90 for(pl = pidList; *pl > 0; pl++) {
104#if ENABLE_FEATURE_PIDOF_OMIT 91#if ENABLE_FEATURE_PIDOF_OMIT
105 unsigned short omitted = 0; 92 unsigned omitted = 0;
106 if (opt & OMIT) { 93 if (opt & OMIT) {
107 llist_t *omits_p = omits; 94 llist_t *omits_p = omits;
108 while (omits_p) 95 while (omits_p)
@@ -111,18 +98,19 @@ extern int pidof_main(int argc, char **argv)
111 } else 98 } else
112 omits_p = omits_p->link; 99 omits_p = omits_p->link;
113 } 100 }
114 if (!omitted)
115#endif 101#endif
116 printf("%s%ld", (n++ ? " " : ""), *pl); 102 if (!omitted) {
117#if ENABLE_FEATURE_PIDOF_OMIT 103 if (n) {
118 fail = omitted; 104 putchar(' ');
119#else 105 } else {
120 fail = 0; 106 n = 1;
121#endif 107 }
122#if ENABLE_FEATURE_PIDOF_SINGLE 108 printf("%ld", *pl);
123 if (opt & SINGLE) 109 }
110 fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted);
111
112 if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & SINGLE))
124 break; 113 break;
125#endif
126 } 114 }
127 free(pidList); 115 free(pidList);
128 optind++; 116 optind++;