summaryrefslogtreecommitdiff
path: root/procps/pidof.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-01 09:16:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-01 09:16:49 +0000
commit35fb51272863c8723a40e59d2024c7f4c9ec8946 (patch)
treea97deb26bca43e394a603840039846cd9d89cae9 /procps/pidof.c
parentd3ada3228551e2556afb9de6d3126fd016df1fb1 (diff)
downloadbusybox-w32-35fb51272863c8723a40e59d2024c7f4c9ec8946.tar.gz
busybox-w32-35fb51272863c8723a40e59d2024c7f4c9ec8946.tar.bz2
busybox-w32-35fb51272863c8723a40e59d2024c7f4c9ec8946.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.
Diffstat (limited to 'procps/pidof.c')
-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