aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-07 23:32:17 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-07 23:32:17 +0000
commit2ac2fae728cca8a535b29bdd2fa6899e6f4992f2 (patch)
tree76eb5871ac3cde7d58048aadba75c7f40fab93b7
parentcbd0d625c7466af80f141e0ae24186e15987bf3e (diff)
downloadbusybox-w32-2ac2fae728cca8a535b29bdd2fa6899e6f4992f2.tar.gz
busybox-w32-2ac2fae728cca8a535b29bdd2fa6899e6f4992f2.tar.bz2
busybox-w32-2ac2fae728cca8a535b29bdd2fa6899e6f4992f2.zip
Fix bugs related to finding PIDs.
-Erik
-rw-r--r--Changelog8
-rw-r--r--halt.c4
-rw-r--r--init.c6
-rw-r--r--init/halt.c4
-rw-r--r--init/init.c6
-rw-r--r--init/poweroff.c4
-rw-r--r--init/reboot.c4
-rw-r--r--lsmod.c6
-rw-r--r--modutils/lsmod.c6
-rw-r--r--poweroff.c4
-rw-r--r--procps/ps.c53
-rw-r--r--ps.c53
-rw-r--r--reboot.c4
-rw-r--r--utility.c28
14 files changed, 144 insertions, 46 deletions
diff --git a/Changelog b/Changelog
index fd560a82a..ebc69bd37 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,9 @@
10.43 10.43
2 * Busybox can now work perfectly when /proc is disabled, thereby
3 saving a bunch of memory (kernel /proc support is not thin).
4 This is done by making use of some nice kernel patches I
5 wrote up to support the features that busybox requires and
6 that /proc usually provides.
2 * Wrote basename, killall, and uptime. 7 * Wrote basename, killall, and uptime.
3 * Added freeramdisk, which will free up all memory associated 8 * Added freeramdisk, which will free up all memory associated
4 with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it> 9 with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
@@ -36,7 +41,8 @@
36 * An initial telnet implementation was added by 41 * An initial telnet implementation was added by
37 Randolph Chung <tausq@debian.org>. 42 Randolph Chung <tausq@debian.org>.
38 * Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e") 43 * Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
39 would go into an infinite loop. 44 * ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
45 to match the terminal (defaults to width=79 when this is off).
40 46
41 47
42 -Erik Andersen 48 -Erik Andersen
diff --git a/halt.c b/halt.c
index f2c9828d4..81d24cf2d 100644
--- a/halt.c
+++ b/halt.c
@@ -26,6 +26,10 @@
26 26
27extern int halt_main(int argc, char **argv) 27extern int halt_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGUSR1)); 31 exit(kill(findPidByName("init"), SIGUSR1));
32#else
33 exit(kill(1, SIGUSR1));
34#endif
31} 35}
diff --git a/init.c b/init.c
index 8e28f076f..c6052f8cf 100644
--- a/init.c
+++ b/init.c
@@ -336,10 +336,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
336 336
337 337
338 if ((pid = fork()) == 0) { 338 if ((pid = fork()) == 0) {
339#ifdef DEBUG_INIT
340 pid_t shell_pgid = getpid();
341#endif
342
343 /* Clean up */ 339 /* Clean up */
344 close(0); 340 close(0);
345 close(1); 341 close(1);
@@ -373,8 +369,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
373 * specifies. 369 * specifies.
374 */ 370 */
375 char c; 371 char c;
376
377#ifdef DEBUG_INIT 372#ifdef DEBUG_INIT
373 pid_t shell_pgid = getpid();
378 message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n", 374 message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
379 command, shell_pgid, terminal); 375 command, shell_pgid, terminal);
380#endif 376#endif
diff --git a/init/halt.c b/init/halt.c
index f2c9828d4..81d24cf2d 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -26,6 +26,10 @@
26 26
27extern int halt_main(int argc, char **argv) 27extern int halt_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGUSR1)); 31 exit(kill(findPidByName("init"), SIGUSR1));
32#else
33 exit(kill(1, SIGUSR1));
34#endif
31} 35}
diff --git a/init/init.c b/init/init.c
index 8e28f076f..c6052f8cf 100644
--- a/init/init.c
+++ b/init/init.c
@@ -336,10 +336,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
336 336
337 337
338 if ((pid = fork()) == 0) { 338 if ((pid = fork()) == 0) {
339#ifdef DEBUG_INIT
340 pid_t shell_pgid = getpid();
341#endif
342
343 /* Clean up */ 339 /* Clean up */
344 close(0); 340 close(0);
345 close(1); 341 close(1);
@@ -373,8 +369,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
373 * specifies. 369 * specifies.
374 */ 370 */
375 char c; 371 char c;
376
377#ifdef DEBUG_INIT 372#ifdef DEBUG_INIT
373 pid_t shell_pgid = getpid();
378 message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n", 374 message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
379 command, shell_pgid, terminal); 375 command, shell_pgid, terminal);
380#endif 376#endif
diff --git a/init/poweroff.c b/init/poweroff.c
index 14dc2f5b9..0f23b9562 100644
--- a/init/poweroff.c
+++ b/init/poweroff.c
@@ -26,6 +26,10 @@
26 26
27extern int poweroff_main(int argc, char **argv) 27extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGUSR2)); 31 exit(kill(findPidByName("init"), SIGUSR2));
32#else
33 exit(kill(1, SIGUSR2));
34#endif
31} 35}
diff --git a/init/reboot.c b/init/reboot.c
index fc01ea004..2f8b2b4a5 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -26,8 +26,12 @@
26 26
27extern int reboot_main(int argc, char **argv) 27extern int reboot_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGINT)); 31 exit(kill(findPidByName("init"), SIGINT));
32#else
33 exit(kill(1, SIGINT));
34#endif
31} 35}
32 36
33/* 37/*
diff --git a/lsmod.c b/lsmod.c
index d9c40eaaf..b0b37bdd7 100644
--- a/lsmod.c
+++ b/lsmod.c
@@ -25,9 +25,9 @@
25#include <stdio.h> 25#include <stdio.h>
26 26
27 27
28#if ! defined BB_FEATURE_USE_PROCFS 28//#if ! defined BB_FEATURE_USE_PROCFS
29#error Sorry, I depend on the /proc filesystem right now. 29//#error Sorry, I depend on the /proc filesystem right now.
30#endif 30//#endif
31 31
32extern int lsmod_main(int argc, char **argv) 32extern int lsmod_main(int argc, char **argv)
33{ 33{
diff --git a/modutils/lsmod.c b/modutils/lsmod.c
index d9c40eaaf..b0b37bdd7 100644
--- a/modutils/lsmod.c
+++ b/modutils/lsmod.c
@@ -25,9 +25,9 @@
25#include <stdio.h> 25#include <stdio.h>
26 26
27 27
28#if ! defined BB_FEATURE_USE_PROCFS 28//#if ! defined BB_FEATURE_USE_PROCFS
29#error Sorry, I depend on the /proc filesystem right now. 29//#error Sorry, I depend on the /proc filesystem right now.
30#endif 30//#endif
31 31
32extern int lsmod_main(int argc, char **argv) 32extern int lsmod_main(int argc, char **argv)
33{ 33{
diff --git a/poweroff.c b/poweroff.c
index 14dc2f5b9..0f23b9562 100644
--- a/poweroff.c
+++ b/poweroff.c
@@ -26,6 +26,10 @@
26 26
27extern int poweroff_main(int argc, char **argv) 27extern int poweroff_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGUSR2)); 31 exit(kill(findPidByName("init"), SIGUSR2));
32#else
33 exit(kill(1, SIGUSR2));
34#endif
31} 35}
diff --git a/procps/ps.c b/procps/ps.c
index b0933ab51..b9ff5bd0b 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -35,6 +35,8 @@
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <ctype.h> 37#include <ctype.h>
38#include <sys/ioctl.h>
39
38 40
39#if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB 41#if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB
40 42
@@ -116,7 +118,15 @@ extern int ps_main(int argc, char **argv)
116 char path[32], sbuf[512]; 118 char path[32], sbuf[512];
117 char uidName[10] = ""; 119 char uidName[10] = "";
118 char groupName[10] = ""; 120 char groupName[10] = "";
119 int i, c; 121 int len, i, c;
122#ifdef BB_FEATURE_AUTOWIDTH
123 struct winsize win = { 0, 0 };
124 int terminal_width = 0;
125#else
126#define terminal_width 79
127#endif
128
129
120 130
121 if (argc > 1 && **(argv + 1) == '-') 131 if (argc > 1 && **(argv + 1) == '-')
122 usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); 132 usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
@@ -125,6 +135,12 @@ extern int ps_main(int argc, char **argv)
125 if (!dir) 135 if (!dir)
126 fatalError("Can't open /proc"); 136 fatalError("Can't open /proc");
127 137
138#ifdef BB_FEATURE_AUTOWIDTH
139 ioctl(fileno(stdout), TIOCGWINSZ, &win);
140 if (win.ws_col > 0)
141 terminal_width = win.ws_col - 1;
142#endif
143
128 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 144 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
129 "State", "Command"); 145 "State", "Command");
130 while ((entry = readdir(dir)) != NULL) { 146 while ((entry = readdir(dir)) != NULL) {
@@ -146,21 +162,21 @@ extern int ps_main(int argc, char **argv)
146 if (*groupName == '\0') 162 if (*groupName == '\0')
147 sprintf(groupName, "%d", p.rgid); 163 sprintf(groupName, "%d", p.rgid);
148 164
149 fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName, 165 len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
150 p.state); 166 p.state);
151 sprintf(path, "/proc/%s/cmdline", entry->d_name); 167 sprintf(path, "/proc/%s/cmdline", entry->d_name);
152 file = fopen(path, "r"); 168 file = fopen(path, "r");
153 if (file == NULL) 169 if (file == NULL)
154 fatalError("Can't open %s: %s\n", path, strerror(errno)); 170 fatalError("Can't open %s: %s\n", path, strerror(errno));
155 i = 0; 171 i = 0;
156 while (((c = getc(file)) != EOF) && (i < 53)) { 172 while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
157 i++; 173 i++;
158 if (c == '\0') 174 if (c == '\0')
159 c = ' '; 175 c = ' ';
160 putc(c, stdout); 176 putc(c, stdout);
161 } 177 }
162 if (i == 0) 178 if (i == 0)
163 fprintf(stdout, "%s", p.cmd); 179 fprintf(stdout, "[%s]", p.cmd);
164 fprintf(stdout, "\n"); 180 fprintf(stdout, "\n");
165 } 181 }
166 closedir(dir); 182 closedir(dir);
@@ -175,19 +191,24 @@ extern int ps_main(int argc, char **argv)
175 * this one uses the nifty new devps kernel device. 191 * this one uses the nifty new devps kernel device.
176 */ 192 */
177 193
178#include <sys/ioctl.h>
179#include <linux/devps.h> 194#include <linux/devps.h>
180 195
181 196
182extern int ps_main(int argc, char **argv) 197extern int ps_main(int argc, char **argv)
183{ 198{
184 char device[] = "/dev/ps"; 199 char device[] = "/dev/ps";
185 int i, fd; 200 int i, j, len, fd;
186 pid_t num_pids; 201 pid_t num_pids;
187 pid_t* pid_array = NULL; 202 pid_t* pid_array = NULL;
188 struct pid_info info; 203 struct pid_info info;
189 char uidName[10] = ""; 204 char uidName[10] = "";
190 char groupName[10] = ""; 205 char groupName[10] = "";
206#ifdef BB_FEATURE_AUTOWIDTH
207 struct winsize win = { 0, 0 };
208 int terminal_width = 0;
209#else
210#define terminal_width 79
211#endif
191 212
192 if (argc > 1 && **(argv + 1) == '-') 213 if (argc > 1 && **(argv + 1) == '-')
193 usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n"); 214 usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
@@ -212,6 +233,12 @@ extern int ps_main(int argc, char **argv)
212 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) 233 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
213 fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); 234 fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
214 235
236#ifdef BB_FEATURE_AUTOWIDTH
237 ioctl(fileno(stdout), TIOCGWINSZ, &win);
238 if (win.ws_col > 0)
239 terminal_width = win.ws_col - 1;
240#endif
241
215 /* Print up a ps listing */ 242 /* Print up a ps listing */
216 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 243 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
217 "State", "Command"); 244 "State", "Command");
@@ -232,13 +259,19 @@ extern int ps_main(int argc, char **argv)
232 if (*groupName == '\0') 259 if (*groupName == '\0')
233 sprintf(groupName, "%ld", info.egid); 260 sprintf(groupName, "%ld", info.egid);
234 261
235 fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); 262 len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
236 263
237 if (strlen(info.command_line) > 1) 264 if (strlen(info.command_line) > 1) {
265 for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
266 if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
267 *(info.command_line+j) = ' ';
268 }
269 }
270 *(info.command_line+j) = '\0';
238 fprintf(stdout, "%s\n", info.command_line); 271 fprintf(stdout, "%s\n", info.command_line);
239 else 272 } else {
240 fprintf(stdout, "[%s]\n", info.name); 273 fprintf(stdout, "[%s]\n", info.name);
241 274 }
242 } 275 }
243 276
244 /* Free memory */ 277 /* Free memory */
diff --git a/ps.c b/ps.c
index b0933ab51..b9ff5bd0b 100644
--- a/ps.c
+++ b/ps.c
@@ -35,6 +35,8 @@
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <ctype.h> 37#include <ctype.h>
38#include <sys/ioctl.h>
39
38 40
39#if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB 41#if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB
40 42
@@ -116,7 +118,15 @@ extern int ps_main(int argc, char **argv)
116 char path[32], sbuf[512]; 118 char path[32], sbuf[512];
117 char uidName[10] = ""; 119 char uidName[10] = "";
118 char groupName[10] = ""; 120 char groupName[10] = "";
119 int i, c; 121 int len, i, c;
122#ifdef BB_FEATURE_AUTOWIDTH
123 struct winsize win = { 0, 0 };
124 int terminal_width = 0;
125#else
126#define terminal_width 79
127#endif
128
129
120 130
121 if (argc > 1 && **(argv + 1) == '-') 131 if (argc > 1 && **(argv + 1) == '-')
122 usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); 132 usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
@@ -125,6 +135,12 @@ extern int ps_main(int argc, char **argv)
125 if (!dir) 135 if (!dir)
126 fatalError("Can't open /proc"); 136 fatalError("Can't open /proc");
127 137
138#ifdef BB_FEATURE_AUTOWIDTH
139 ioctl(fileno(stdout), TIOCGWINSZ, &win);
140 if (win.ws_col > 0)
141 terminal_width = win.ws_col - 1;
142#endif
143
128 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 144 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
129 "State", "Command"); 145 "State", "Command");
130 while ((entry = readdir(dir)) != NULL) { 146 while ((entry = readdir(dir)) != NULL) {
@@ -146,21 +162,21 @@ extern int ps_main(int argc, char **argv)
146 if (*groupName == '\0') 162 if (*groupName == '\0')
147 sprintf(groupName, "%d", p.rgid); 163 sprintf(groupName, "%d", p.rgid);
148 164
149 fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName, 165 len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
150 p.state); 166 p.state);
151 sprintf(path, "/proc/%s/cmdline", entry->d_name); 167 sprintf(path, "/proc/%s/cmdline", entry->d_name);
152 file = fopen(path, "r"); 168 file = fopen(path, "r");
153 if (file == NULL) 169 if (file == NULL)
154 fatalError("Can't open %s: %s\n", path, strerror(errno)); 170 fatalError("Can't open %s: %s\n", path, strerror(errno));
155 i = 0; 171 i = 0;
156 while (((c = getc(file)) != EOF) && (i < 53)) { 172 while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
157 i++; 173 i++;
158 if (c == '\0') 174 if (c == '\0')
159 c = ' '; 175 c = ' ';
160 putc(c, stdout); 176 putc(c, stdout);
161 } 177 }
162 if (i == 0) 178 if (i == 0)
163 fprintf(stdout, "%s", p.cmd); 179 fprintf(stdout, "[%s]", p.cmd);
164 fprintf(stdout, "\n"); 180 fprintf(stdout, "\n");
165 } 181 }
166 closedir(dir); 182 closedir(dir);
@@ -175,19 +191,24 @@ extern int ps_main(int argc, char **argv)
175 * this one uses the nifty new devps kernel device. 191 * this one uses the nifty new devps kernel device.
176 */ 192 */
177 193
178#include <sys/ioctl.h>
179#include <linux/devps.h> 194#include <linux/devps.h>
180 195
181 196
182extern int ps_main(int argc, char **argv) 197extern int ps_main(int argc, char **argv)
183{ 198{
184 char device[] = "/dev/ps"; 199 char device[] = "/dev/ps";
185 int i, fd; 200 int i, j, len, fd;
186 pid_t num_pids; 201 pid_t num_pids;
187 pid_t* pid_array = NULL; 202 pid_t* pid_array = NULL;
188 struct pid_info info; 203 struct pid_info info;
189 char uidName[10] = ""; 204 char uidName[10] = "";
190 char groupName[10] = ""; 205 char groupName[10] = "";
206#ifdef BB_FEATURE_AUTOWIDTH
207 struct winsize win = { 0, 0 };
208 int terminal_width = 0;
209#else
210#define terminal_width 79
211#endif
191 212
192 if (argc > 1 && **(argv + 1) == '-') 213 if (argc > 1 && **(argv + 1) == '-')
193 usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n"); 214 usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
@@ -212,6 +233,12 @@ extern int ps_main(int argc, char **argv)
212 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) 233 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
213 fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); 234 fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
214 235
236#ifdef BB_FEATURE_AUTOWIDTH
237 ioctl(fileno(stdout), TIOCGWINSZ, &win);
238 if (win.ws_col > 0)
239 terminal_width = win.ws_col - 1;
240#endif
241
215 /* Print up a ps listing */ 242 /* Print up a ps listing */
216 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", 243 fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
217 "State", "Command"); 244 "State", "Command");
@@ -232,13 +259,19 @@ extern int ps_main(int argc, char **argv)
232 if (*groupName == '\0') 259 if (*groupName == '\0')
233 sprintf(groupName, "%ld", info.egid); 260 sprintf(groupName, "%ld", info.egid);
234 261
235 fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); 262 len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
236 263
237 if (strlen(info.command_line) > 1) 264 if (strlen(info.command_line) > 1) {
265 for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
266 if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
267 *(info.command_line+j) = ' ';
268 }
269 }
270 *(info.command_line+j) = '\0';
238 fprintf(stdout, "%s\n", info.command_line); 271 fprintf(stdout, "%s\n", info.command_line);
239 else 272 } else {
240 fprintf(stdout, "[%s]\n", info.name); 273 fprintf(stdout, "[%s]\n", info.name);
241 274 }
242 } 275 }
243 276
244 /* Free memory */ 277 /* Free memory */
diff --git a/reboot.c b/reboot.c
index fc01ea004..2f8b2b4a5 100644
--- a/reboot.c
+++ b/reboot.c
@@ -26,8 +26,12 @@
26 26
27extern int reboot_main(int argc, char **argv) 27extern int reboot_main(int argc, char **argv)
28{ 28{
29#ifdef BB_FEATURE_LINUXRC
29 /* don't assume init's pid == 1 */ 30 /* don't assume init's pid == 1 */
30 exit(kill(findPidByName("init"), SIGINT)); 31 exit(kill(findPidByName("init"), SIGINT));
32#else
33 exit(kill(1, SIGINT));
34#endif
31} 35}
32 36
33/* 37/*
diff --git a/utility.c b/utility.c
index 789c6f228..c3f9947c5 100644
--- a/utility.c
+++ b/utility.c
@@ -1247,7 +1247,7 @@ extern int device_open(char *device, int mode)
1247#endif /* BB_INIT BB_SYSLOGD */ 1247#endif /* BB_INIT BB_SYSLOGD */
1248 1248
1249 1249
1250#if defined BB_INIT || defined BB_HALT || defined BB_REBOOT || defined BB_KILLALL 1250#if defined BB_KILLALL || defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )
1251 1251
1252#ifdef BB_FEATURE_USE_DEVPS_N_DEVMTAB 1252#ifdef BB_FEATURE_USE_DEVPS_N_DEVMTAB
1253#include <linux/devps.h> 1253#include <linux/devps.h>
@@ -1318,6 +1318,7 @@ extern pid_t findPidByName( char* pidName)
1318#if ! defined BB_FEATURE_USE_PROCFS 1318#if ! defined BB_FEATURE_USE_PROCFS
1319#error Sorry, I depend on the /proc filesystem right now. 1319#error Sorry, I depend on the /proc filesystem right now.
1320#endif 1320#endif
1321
1321/* findPidByName() 1322/* findPidByName()
1322 * 1323 *
1323 * This finds the pid of the specified process. 1324 * This finds the pid of the specified process.
@@ -1330,15 +1331,24 @@ extern pid_t findPidByName( char* pidName)
1330 */ 1331 */
1331extern pid_t findPidByName( char* pidName) 1332extern pid_t findPidByName( char* pidName)
1332{ 1333{
1333 pid_t thePid; 1334 DIR *dir;
1334 char filename[256]; 1335 struct dirent *next;
1335 char buffer[256];
1336 1336
1337 /* no need to opendir ;) */ 1337 dir = opendir("/proc");
1338 for (thePid = 1; thePid < 65536; thePid++) { 1338 if (!dir)
1339 fatalError( "Cannot open /proc: %s\n", strerror (errno));
1340
1341 while ((next = readdir(dir)) != NULL) {
1339 FILE *status; 1342 FILE *status;
1343 char filename[256];
1344 char buffer[256];
1345
1346 /* If it isn't a number, we don't want it */
1347 if (!isdigit(*next->d_name))
1348 continue;
1340 1349
1341 sprintf(filename, "/proc/%d/cmdline", thePid); 1350 /* Now open the command line file */
1351 sprintf(filename, "/proc/%s/status", next->d_name);
1342 status = fopen(filename, "r"); 1352 status = fopen(filename, "r");
1343 if (!status) { 1353 if (!status) {
1344 continue; 1354 continue;
@@ -1347,13 +1357,13 @@ extern pid_t findPidByName( char* pidName)
1347 fclose(status); 1357 fclose(status);
1348 1358
1349 if ((strstr(buffer, pidName) != NULL)) { 1359 if ((strstr(buffer, pidName) != NULL)) {
1350 return thePid; 1360 return strtol(next->d_name, NULL, 0);
1351 } 1361 }
1352 } 1362 }
1353 return 0; 1363 return 0;
1354} 1364}
1355#endif /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ 1365#endif /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */
1356#endif /* BB_INIT || BB_HALT || BB_REBOOT || KILLALL */ 1366#endif /* BB_INIT || BB_HALT || BB_REBOOT || BB_KILLALL || BB_POWEROFF */
1357 1367
1358#if defined BB_GUNZIP \ 1368#if defined BB_GUNZIP \
1359 || defined BB_GZIP \ 1369 || defined BB_GZIP \