diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-01 09:16:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-01 09:16:49 +0000 |
commit | 35fb51272863c8723a40e59d2024c7f4c9ec8946 (patch) | |
tree | a97deb26bca43e394a603840039846cd9d89cae9 /libbb/find_pid_by_name.c | |
parent | d3ada3228551e2556afb9de6d3126fd016df1fb1 (diff) | |
download | busybox-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 'libbb/find_pid_by_name.c')
-rw-r--r-- | libbb/find_pid_by_name.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index 247d79f9f..05f7f968f 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
@@ -7,10 +7,6 @@ | |||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <ctype.h> | ||
12 | #include <string.h> | ||
13 | #include <stdlib.h> | ||
14 | #include "libbb.h" | 10 | #include "libbb.h" |
15 | 11 | ||
16 | /* find_pid_by_name() | 12 | /* find_pid_by_name() |
@@ -23,30 +19,31 @@ | |||
23 | * Returns a list of all matching PIDs | 19 | * Returns a list of all matching PIDs |
24 | * It is the caller's duty to free the returned pidlist. | 20 | * It is the caller's duty to free the returned pidlist. |
25 | */ | 21 | */ |
26 | long* find_pid_by_name(const char* pidName) | 22 | pid_t* find_pid_by_name(const char* procName) |
27 | { | 23 | { |
28 | long* pidList; | 24 | pid_t* pidList; |
29 | int i = 0; | 25 | int i = 0; |
30 | procps_status_t* p; | 26 | procps_status_t* p; |
31 | 27 | ||
32 | pidList = xmalloc(sizeof(long)); | 28 | pidList = xmalloc(sizeof(*pidList)); |
33 | while ((p = procps_scan(0)) != 0) { | 29 | while ((p = procps_scan(0)) != 0) { |
34 | if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) { | 30 | if (strncmp(p->short_cmd, procName, COMM_LEN-1) == 0) { |
35 | pidList = xrealloc( pidList, sizeof(long) * (i+2)); | 31 | pidList = xrealloc(pidList, sizeof(*pidList) * (i+2)); |
36 | pidList[i++] = p->pid; | 32 | pidList[i++] = p->pid; |
37 | } | 33 | } |
38 | } | 34 | } |
39 | 35 | ||
40 | pidList[i] = i==0 ? -1 : 0; | 36 | pidList[i] = 0; |
41 | return pidList; | 37 | return pidList; |
42 | } | 38 | } |
43 | 39 | ||
44 | long *pidlist_reverse(long *pidList) | 40 | pid_t *pidlist_reverse(pid_t *pidList) |
45 | { | 41 | { |
46 | int i = 0; | 42 | int i = 0; |
47 | while (pidList[i] > 0 && ++i); | 43 | while (pidList[i]) |
48 | if (i-- > 0) { | 44 | i++; |
49 | long k; | 45 | if (--i >= 0) { |
46 | pid_t k; | ||
50 | int j; | 47 | int j; |
51 | for (j = 0; i > j; i--, j++) { | 48 | for (j = 0; i > j; i--, j++) { |
52 | k = pidList[i]; | 49 | k = pidList[i]; |