aboutsummaryrefslogtreecommitdiff
path: root/procps/pidof.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-01 09:16:49 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-01 09:16:49 +0000
commit9929fc484855149072edb217da1b801f00c0fe15 (patch)
treea97deb26bca43e394a603840039846cd9d89cae9 /procps/pidof.c
parent7a695ef456cfdfcd5d460681a8016ad9a1cf0833 (diff)
downloadbusybox-w32-9929fc484855149072edb217da1b801f00c0fe15.tar.gz
busybox-w32-9929fc484855149072edb217da1b801f00c0fe15.tar.bz2
busybox-w32-9929fc484855149072edb217da1b801f00c0fe15.zip
PID should be stored in pid_t, not int or long.
find_pid_by_name() was returning 0 or -1 in last array element, but -1 was never checked. We can use just 0 intead. git-svn-id: svn://busybox.net/trunk/busybox@16485 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r--procps/pidof.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/procps/pidof.c b/procps/pidof.c
index 62c590fd8..28c5c04e2 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -18,18 +18,18 @@
18#endif 18#endif
19 19
20#if ENABLE_FEATURE_PIDOF_OMIT 20#if ENABLE_FEATURE_PIDOF_OMIT
21#define _OMIT_COMPL(a) a 21# define _OMIT_COMPL(a) a
22#define _OMIT(a) ,a 22# define _OMIT(a) ,a
23#if ENABLE_FEATURE_PIDOF_SINGLE 23# if ENABLE_FEATURE_PIDOF_SINGLE
24#define OMIT (1<<1) 24# define OMIT (1<<1)
25#else 25# else
26#define OMIT (1<<0) 26# define OMIT (1<<0)
27#endif 27# endif
28#else 28#else
29#define _OMIT_COMPL(a) "" 29# define _OMIT_COMPL(a) ""
30#define _OMIT(a) 30# define _OMIT(a)
31#define OMIT (0) 31# define OMIT (0)
32#define omitted (0) 32# define omitted (0)
33#endif 33#endif
34 34
35int pidof_main(int argc, char **argv) 35int pidof_main(int argc, char **argv)
@@ -65,21 +65,23 @@ int pidof_main(int argc, char **argv)
65#endif 65#endif
66 /* Looks like everything is set to go. */ 66 /* Looks like everything is set to go. */
67 while (optind < argc) { 67 while (optind < argc) {
68 long *pidList; 68 pid_t *pidList;
69 long *pl; 69 pid_t *pl;
70 70
71 /* reverse the pidlist like GNU pidof does. */ 71 /* reverse the pidlist like GNU pidof does. */
72 pidList = pidlist_reverse(find_pid_by_name(argv[optind])); 72 pidList = pidlist_reverse(find_pid_by_name(argv[optind]));
73 for (pl = pidList; *pl > 0; pl++) { 73 for (pl = pidList; *pl; pl++) {
74#if ENABLE_FEATURE_PIDOF_OMIT 74#if ENABLE_FEATURE_PIDOF_OMIT
75 unsigned omitted = 0; 75 unsigned omitted = 0;
76 if (opt & OMIT) { 76 if (opt & OMIT) {
77 llist_t *omits_p = omits; 77 llist_t *omits_p = omits;
78 while (omits_p) 78 while (omits_p) {
79 if (xatoul(omits_p->data) == *pl) { 79 if (xatoul(omits_p->data) == *pl) {
80 omitted = 1; break; 80 omitted = 1;
81 break;
81 } else 82 } else
82 omits_p = omits_p->link; 83 omits_p = omits_p->link;
84 }
83 } 85 }
84#endif 86#endif
85 if (!omitted) { 87 if (!omitted) {
@@ -88,7 +90,7 @@ int pidof_main(int argc, char **argv)
88 } else { 90 } else {
89 n = 1; 91 n = 1;
90 } 92 }
91 printf("%ld", *pl); 93 printf("%u", (unsigned)*pl);
92 } 94 }
93 fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted); 95 fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted);
94 96