diff options
author | Denis Vlasenko | 2006-11-01 09:16:49 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-11-01 09:16:49 +0000 |
commit | 35fb51272863c8723a40e59d2024c7f4c9ec8946 (patch) | |
tree | a97deb26bca43e394a603840039846cd9d89cae9 /libbb | |
parent | d3ada3228551e2556afb9de6d3126fd016df1fb1 (diff) | |
download | busybox-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 'libbb')
-rw-r--r-- | libbb/find_pid_by_name.c | 25 | ||||
-rw-r--r-- | libbb/procps.c | 3 |
2 files changed, 13 insertions, 15 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index 247d79f..05f7f96 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c @@ -7,10 +7,6 @@ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */ -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> #include "libbb.h" /* find_pid_by_name() @@ -23,30 +19,31 @@ * Returns a list of all matching PIDs * It is the caller's duty to free the returned pidlist. */ -long* find_pid_by_name(const char* pidName) +pid_t* find_pid_by_name(const char* procName) { - long* pidList; + pid_t* pidList; int i = 0; procps_status_t* p; - pidList = xmalloc(sizeof(long)); + pidList = xmalloc(sizeof(*pidList)); while ((p = procps_scan(0)) != 0) { - if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) { - pidList = xrealloc( pidList, sizeof(long) * (i+2)); + if (strncmp(p->short_cmd, procName, COMM_LEN-1) == 0) { + pidList = xrealloc(pidList, sizeof(*pidList) * (i+2)); pidList[i++] = p->pid; } } - pidList[i] = i==0 ? -1 : 0; + pidList[i] = 0; return pidList; } -long *pidlist_reverse(long *pidList) +pid_t *pidlist_reverse(pid_t *pidList) { int i = 0; - while (pidList[i] > 0 && ++i); - if (i-- > 0) { - long k; + while (pidList[i]) + i++; + if (--i >= 0) { + pid_t k; int j; for (j = 0; i > j; i--, j++) { k = pidList[i]; diff --git a/libbb/procps.c b/libbb/procps.c index eba9070..15a1cf7 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -32,8 +32,9 @@ static int read_to_buf(const char *filename, void *buf) procps_status_t * procps_scan(int save_user_arg0) { static DIR *dir; - struct dirent *entry; static procps_status_t ret_status; + + struct dirent *entry; char *name; int n; char status[32]; |