aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-12-06 14:52:32 +0000
committerEric Andersen <andersen@codepoet.org>2001-12-06 14:52:32 +0000
commitb24d65659f193cd7497dfdae4d8aa1bc91dbf343 (patch)
tree430b543e3b98a9028f5c0435b1363b2256d26a24
parent06656f363de87846086f03c5e12541a66637858e (diff)
downloadbusybox-w32-b24d65659f193cd7497dfdae4d8aa1bc91dbf343.tar.gz
busybox-w32-b24d65659f193cd7497dfdae4d8aa1bc91dbf343.tar.bz2
busybox-w32-b24d65659f193cd7497dfdae4d8aa1bc91dbf343.zip
If find_pid_by_name() had an error, it was returning -1, but storing
that into a pid_t, which is unsigned on a number archs. Furthermore, find_pid_by_name() would _never_ return an error if the intended proces was "init", but instead would return 1, meaning we would fail to work on 2.4.x kernels running an initrd... -Erik
-rw-r--r--include/libbb.h2
-rw-r--r--init/halt.c2
-rw-r--r--init/poweroff.c2
-rw-r--r--init/reboot.c2
-rw-r--r--libbb/find_pid_by_name.c30
-rw-r--r--procps/kill.c2
-rw-r--r--procps/pidof.c2
7 files changed, 15 insertions, 27 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 2dcfa1f4d..a953b3cb0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -116,7 +116,7 @@ extern void write_mtab(char* blockDevice, char* directory,
116 char* filesystemType, long flags, char* string_flags); 116 char* filesystemType, long flags, char* string_flags);
117extern void erase_mtab(const char * name); 117extern void erase_mtab(const char * name);
118extern long atoi_w_units (const char *cp); 118extern long atoi_w_units (const char *cp);
119extern pid_t* find_pid_by_name( char* pidName); 119extern long* find_pid_by_name( char* pidName);
120extern char *find_real_root_device_name(const char* name); 120extern char *find_real_root_device_name(const char* name);
121extern char *get_line_from_file(FILE *file); 121extern char *get_line_from_file(FILE *file);
122extern void print_file(FILE *file); 122extern void print_file(FILE *file);
diff --git a/init/halt.c b/init/halt.c
index 307c1022d..917de8b5a 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -28,7 +28,7 @@ extern int halt_main(int argc, char **argv)
28{ 28{
29#ifdef CONFIG_FEATURE_INITRD 29#ifdef CONFIG_FEATURE_INITRD
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 pid_t *pid = find_pid_by_name("init"); 31 long *pid = find_pid_by_name("init");
32 if (!pid || *pid<=0) { 32 if (!pid || *pid<=0) {
33 pid = find_pid_by_name("linuxrc"); 33 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0) 34 if (!pid || *pid<=0)
diff --git a/init/poweroff.c b/init/poweroff.c
index cec2d6ddd..d99b5562d 100644
--- a/init/poweroff.c
+++ b/init/poweroff.c
@@ -28,7 +28,7 @@ extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef CONFIG_FEATURE_INITRD 29#ifdef CONFIG_FEATURE_INITRD
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 pid_t *pid = find_pid_by_name("init"); 31 long *pid = find_pid_by_name("init");
32 if (!pid || *pid<=0) { 32 if (!pid || *pid<=0) {
33 pid = find_pid_by_name("linuxrc"); 33 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0) 34 if (!pid || *pid<=0)
diff --git a/init/reboot.c b/init/reboot.c
index a13d42492..6f71536d8 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -28,7 +28,7 @@ extern int reboot_main(int argc, char **argv)
28{ 28{
29#ifdef CONFIG_FEATURE_INITRD 29#ifdef CONFIG_FEATURE_INITRD
30 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
31 pid_t *pid = find_pid_by_name("init"); 31 long *pid = find_pid_by_name("init");
32 if (!pid || *pid<=0) { 32 if (!pid || *pid<=0) {
33 pid = find_pid_by_name("linuxrc"); 33 pid = find_pid_by_name("linuxrc");
34 if (!pid || *pid<=0) 34 if (!pid || *pid<=0)
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index f183cc0bd..4eaee03e3 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -40,13 +40,13 @@
40 * 40 *
41 * Returns a list of all matching PIDs 41 * Returns a list of all matching PIDs
42 */ 42 */
43extern pid_t* find_pid_by_name( char* pidName) 43extern long* find_pid_by_name( char* pidName)
44{ 44{
45 int fd, i, j; 45 int fd, i, j;
46 char device[] = "/dev/ps"; 46 char device[] = "/dev/ps";
47 pid_t num_pids; 47 pid_t num_pids;
48 pid_t* pid_array = NULL; 48 pid_t* pid_array = NULL;
49 pid_t* pidList=NULL; 49 long* pidList=NULL;
50 50
51 /* open device */ 51 /* open device */
52 fd = open(device, O_RDONLY); 52 fd = open(device, O_RDONLY);
@@ -87,20 +87,14 @@ extern pid_t* find_pid_by_name( char* pidName)
87 87
88 if ((strstr(info.command_line, pidName) != NULL) 88 if ((strstr(info.command_line, pidName) != NULL)
89 && (strlen(pidName) == strlen(info.command_line))) { 89 && (strlen(pidName) == strlen(info.command_line))) {
90 pidList=xrealloc( pidList, sizeof(pid_t) * (j+2)); 90 pidList=xrealloc( pidList, sizeof(long) * (j+2));
91 pidList[j++]=info.pid; 91 pidList[j++]=info.pid;
92 } 92 }
93 } 93 }
94 if (pidList) { 94 if (pidList) {
95 pidList[j]=0; 95 pidList[j]=0;
96 } else if ( strcmp(pidName, "init")==0) {
97 /* If we found nothing and they were trying to kill "init",
98 * guess PID 1 and call it good... Perhaps we should simply
99 * exit if /proc isn't mounted, but this will do for now. */
100 pidList=xrealloc( pidList, sizeof(pid_t));
101 pidList[0]=1;
102 } else { 96 } else {
103 pidList=xrealloc( pidList, sizeof(pid_t)); 97 pidList=xrealloc( pidList, sizeof(long));
104 pidList[0]=-1; 98 pidList[0]=-1;
105 } 99 }
106 100
@@ -124,11 +118,11 @@ extern pid_t* find_pid_by_name( char* pidName)
124 * 118 *
125 * Returns a list of all matching PIDs 119 * Returns a list of all matching PIDs
126 */ 120 */
127extern pid_t* find_pid_by_name( char* pidName) 121extern long* find_pid_by_name( char* pidName)
128{ 122{
129 DIR *dir; 123 DIR *dir;
130 struct dirent *next; 124 struct dirent *next;
131 pid_t* pidList=NULL; 125 long* pidList=NULL;
132 int i=0; 126 int i=0;
133 127
134 dir = opendir("/proc"); 128 dir = opendir("/proc");
@@ -162,21 +156,15 @@ extern pid_t* find_pid_by_name( char* pidName)
162 /* Buffer should contain a string like "Name: binary_name" */ 156 /* Buffer should contain a string like "Name: binary_name" */
163 sscanf(buffer, "%*s %s", name); 157 sscanf(buffer, "%*s %s", name);
164 if (strcmp(name, pidName) == 0) { 158 if (strcmp(name, pidName) == 0) {
165 pidList=xrealloc( pidList, sizeof(pid_t) * (i+2)); 159 pidList=xrealloc( pidList, sizeof(long) * (i+2));
166 pidList[i++]=strtol(next->d_name, NULL, 0); 160 pidList[i++]=strtol(next->d_name, NULL, 0);
167 } 161 }
168 } 162 }
169 163
170 if (pidList) 164 if (pidList) {
171 pidList[i]=0; 165 pidList[i]=0;
172 else if ( strcmp(pidName, "init")==0) {
173 /* If we found nothing and they were trying to kill "init",
174 * guess PID 1 and call it good... Perhaps we should simply
175 * exit if /proc isn't mounted, but this will do for now. */
176 pidList=xrealloc( pidList, sizeof(pid_t));
177 pidList[0]=1;
178 } else { 166 } else {
179 pidList=xrealloc( pidList, sizeof(pid_t)); 167 pidList=xrealloc( pidList, sizeof(long));
180 pidList[0]=-1; 168 pidList[0]=-1;
181 } 169 }
182 return pidList; 170 return pidList;
diff --git a/procps/kill.c b/procps/kill.c
index 8b8a9922c..7147b5727 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -114,7 +114,7 @@ extern int kill_main(int argc, char **argv)
114 pid_t myPid=getpid(); 114 pid_t myPid=getpid();
115 /* Looks like they want to do a killall. Do that */ 115 /* Looks like they want to do a killall. Do that */
116 while (--argc >= 0) { 116 while (--argc >= 0) {
117 pid_t* pidList; 117 long* pidList;
118 118
119 pidList = find_pid_by_name( *argv); 119 pidList = find_pid_by_name( *argv);
120 if (!pidList || *pidList<=0) { 120 if (!pidList || *pidList<=0) {
diff --git a/procps/pidof.c b/procps/pidof.c
index 5a40288dc..941582704 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -58,7 +58,7 @@ extern int pidof_main(int argc, char **argv)
58 58
59 /* Looks like everything is set to go. */ 59 /* Looks like everything is set to go. */
60 while(optind < argc) { 60 while(optind < argc) {
61 pid_t* pidList; 61 long* pidList;
62 62
63 pidList = find_pid_by_name( argv[optind]); 63 pidList = find_pid_by_name( argv[optind]);
64 if (!pidList || *pidList<=0) { 64 if (!pidList || *pidList<=0) {