summaryrefslogtreecommitdiff
path: root/procps/pidof.c
diff options
context:
space:
mode:
authorDenis Vlasenko2006-11-01 09:16:49 +0000
committerDenis Vlasenko2006-11-01 09:16:49 +0000
commit35fb51272863c8723a40e59d2024c7f4c9ec8946 (patch)
treea97deb26bca43e394a603840039846cd9d89cae9 /procps/pidof.c
parentd3ada3228551e2556afb9de6d3126fd016df1fb1 (diff)
downloadbusybox-35fb51272863c8723a40e59d2024c7f4c9ec8946.zip
busybox-35fb51272863c8723a40e59d2024c7f4c9ec8946.tar.gz
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 62c590f..28c5c04 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -18,18 +18,18 @@
#endif
#if ENABLE_FEATURE_PIDOF_OMIT
-#define _OMIT_COMPL(a) a
-#define _OMIT(a) ,a
-#if ENABLE_FEATURE_PIDOF_SINGLE
-#define OMIT (1<<1)
-#else
-#define OMIT (1<<0)
-#endif
+# define _OMIT_COMPL(a) a
+# define _OMIT(a) ,a
+# if ENABLE_FEATURE_PIDOF_SINGLE
+# define OMIT (1<<1)
+# else
+# define OMIT (1<<0)
+# endif
#else
-#define _OMIT_COMPL(a) ""
-#define _OMIT(a)
-#define OMIT (0)
-#define omitted (0)
+# define _OMIT_COMPL(a) ""
+# define _OMIT(a)
+# define OMIT (0)
+# define omitted (0)
#endif
int pidof_main(int argc, char **argv)
@@ -65,21 +65,23 @@ int pidof_main(int argc, char **argv)
#endif
/* Looks like everything is set to go. */
while (optind < argc) {
- long *pidList;
- long *pl;
+ pid_t *pidList;
+ pid_t *pl;
/* reverse the pidlist like GNU pidof does. */
pidList = pidlist_reverse(find_pid_by_name(argv[optind]));
- for (pl = pidList; *pl > 0; pl++) {
+ for (pl = pidList; *pl; pl++) {
#if ENABLE_FEATURE_PIDOF_OMIT
unsigned omitted = 0;
if (opt & OMIT) {
llist_t *omits_p = omits;
- while (omits_p)
+ while (omits_p) {
if (xatoul(omits_p->data) == *pl) {
- omitted = 1; break;
+ omitted = 1;
+ break;
} else
omits_p = omits_p->link;
+ }
}
#endif
if (!omitted) {
@@ -88,7 +90,7 @@ int pidof_main(int argc, char **argv)
} else {
n = 1;
}
- printf("%ld", *pl);
+ printf("%u", (unsigned)*pl);
}
fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted);