aboutsummaryrefslogtreecommitdiff
path: root/libbb
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 /libbb
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 'libbb')
-rw-r--r--libbb/find_pid_by_name.c25
-rw-r--r--libbb/procps.c3
2 files changed, 13 insertions, 15 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 */
26long* find_pid_by_name(const char* pidName) 22pid_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
44long *pidlist_reverse(long *pidList) 40pid_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];
diff --git a/libbb/procps.c b/libbb/procps.c
index eba90705c..15a1cf74b 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -32,8 +32,9 @@ static int read_to_buf(const char *filename, void *buf)
32procps_status_t * procps_scan(int save_user_arg0) 32procps_status_t * procps_scan(int save_user_arg0)
33{ 33{
34 static DIR *dir; 34 static DIR *dir;
35 struct dirent *entry;
36 static procps_status_t ret_status; 35 static procps_status_t ret_status;
36
37 struct dirent *entry;
37 char *name; 38 char *name;
38 int n; 39 int n;
39 char status[32]; 40 char status[32];