diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-03-07 07:41:42 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-03-07 07:41:42 +0000 |
commit | 246cc6dddd3df2164e8a925ebd8e9a7bba379253 (patch) | |
tree | 0b9f317c6b6fdebad4f90fbfde5565e195076ea4 | |
parent | e916d24805b4a191bc08d2ee31c9247a30f9bc1e (diff) | |
download | busybox-w32-246cc6dddd3df2164e8a925ebd8e9a7bba379253.tar.gz busybox-w32-246cc6dddd3df2164e8a925ebd8e9a7bba379253.tar.bz2 busybox-w32-246cc6dddd3df2164e8a925ebd8e9a7bba379253.zip |
Wrote killall.
Adjusted mount, ps, utility.c, etc to handle my nifty new kernel
patches the allow busybox to run perfectly without /proc.
-Erik
-rw-r--r-- | Changelog | 6 | ||||
-rw-r--r-- | applets/busybox.c | 3 | ||||
-rw-r--r-- | busybox.c | 3 | ||||
-rw-r--r-- | busybox.def.h | 12 | ||||
-rw-r--r-- | chmod_chown_chgrp.c | 6 | ||||
-rw-r--r-- | halt.c | 2 | ||||
-rw-r--r-- | init/halt.c | 2 | ||||
-rw-r--r-- | init/poweroff.c | 2 | ||||
-rw-r--r-- | init/reboot.c | 2 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | kill.c | 63 | ||||
-rw-r--r-- | mount.c | 86 | ||||
-rw-r--r-- | poweroff.c | 2 | ||||
-rw-r--r-- | procps/kill.c | 63 | ||||
-rw-r--r-- | procps/ps.c | 150 | ||||
-rw-r--r-- | ps.c | 150 | ||||
-rw-r--r-- | reboot.c | 2 | ||||
-rw-r--r-- | util-linux/mount.c | 86 | ||||
-rw-r--r-- | utility.c | 101 |
19 files changed, 601 insertions, 142 deletions
@@ -1,5 +1,5 @@ | |||
1 | 0.43 | 1 | 0.43 |
2 | * Wrote basename, and uptime. | 2 | * Wrote basename, killall, and uptime. |
3 | * Added freeramdisk, which will free up all memory associated | 3 | * Added freeramdisk, which will free up all memory associated |
4 | with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it> | 4 | with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it> |
5 | and then adjusted a bit by me. | 5 | and then adjusted a bit by me. |
@@ -35,8 +35,8 @@ | |||
35 | - Fixes to the makefile for handling "strip" | 35 | - Fixes to the makefile for handling "strip" |
36 | * An initial telnet implementation was added by | 36 | * An initial telnet implementation was added by |
37 | Randolph Chung <tausq@debian.org>. | 37 | Randolph Chung <tausq@debian.org>. |
38 | * Fixed a bug where "sed 's/foo/bar/g'" would go into an | 38 | * Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e") |
39 | infinite loop. | 39 | would go into an infinite loop. |
40 | 40 | ||
41 | 41 | ||
42 | -Erik Andersen | 42 | -Erik Andersen |
diff --git a/applets/busybox.c b/applets/busybox.c index 36cf0a05c..cea191cb3 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -139,6 +139,9 @@ static const struct Applet applets[] = { | |||
139 | #ifdef BB_KILL //bin | 139 | #ifdef BB_KILL //bin |
140 | {"kill", kill_main}, | 140 | {"kill", kill_main}, |
141 | #endif | 141 | #endif |
142 | #ifdef BB_KILLALL //usr/bin | ||
143 | {"killall", kill_main}, | ||
144 | #endif | ||
142 | #ifdef BB_LENGTH //usr/bin | 145 | #ifdef BB_LENGTH //usr/bin |
143 | {"length", length_main}, | 146 | {"length", length_main}, |
144 | #endif | 147 | #endif |
@@ -139,6 +139,9 @@ static const struct Applet applets[] = { | |||
139 | #ifdef BB_KILL //bin | 139 | #ifdef BB_KILL //bin |
140 | {"kill", kill_main}, | 140 | {"kill", kill_main}, |
141 | #endif | 141 | #endif |
142 | #ifdef BB_KILLALL //usr/bin | ||
143 | {"killall", kill_main}, | ||
144 | #endif | ||
142 | #ifdef BB_LENGTH //usr/bin | 145 | #ifdef BB_LENGTH //usr/bin |
143 | {"length", length_main}, | 146 | {"length", length_main}, |
144 | #endif | 147 | #endif |
diff --git a/busybox.def.h b/busybox.def.h index 306133ba8..da34055ee 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
@@ -39,6 +39,7 @@ | |||
39 | // Don't turn BB_INSMOD on. It doesn't work. | 39 | // Don't turn BB_INSMOD on. It doesn't work. |
40 | //#define BB_INSMOD | 40 | //#define BB_INSMOD |
41 | #define BB_KILL | 41 | #define BB_KILL |
42 | #define BB_KILLALL | ||
42 | #define BB_KLOGD | 43 | #define BB_KLOGD |
43 | //#define BB_LENGTH | 44 | //#define BB_LENGTH |
44 | #define BB_LN | 45 | #define BB_LN |
@@ -106,8 +107,17 @@ | |||
106 | // pretty/useful). | 107 | // pretty/useful). |
107 | // | 108 | // |
108 | // | 109 | // |
110 | // Turn this on to use Erik's very cool devps, devmtab, | ||
111 | // etc. kernel drivers, thereby eliminating the need for | ||
112 | // the /proc filesystem and thereby saving lots and lots | ||
113 | // memory for more important things. | ||
114 | // You can't use this and USE_PROCFS at the same time... | ||
115 | //#define BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
116 | // | ||
117 | // | ||
109 | // enable features that use the /proc filesystem (apps that | 118 | // enable features that use the /proc filesystem (apps that |
110 | // break without this will tell you on compile)... | 119 | // break without this will tell you on compile)... |
120 | // You can't use this and DEVPS_N_DEVMTAB at the same time... | ||
111 | #define BB_FEATURE_USE_PROCFS | 121 | #define BB_FEATURE_USE_PROCFS |
112 | // | 122 | // |
113 | // Use termios to manipulate the screen ('more' is prettier with this on) | 123 | // Use termios to manipulate the screen ('more' is prettier with this on) |
@@ -161,6 +171,6 @@ | |||
161 | // just like an initrd does. Requires a kernel patch by Werner Almesberger. | 171 | // just like an initrd does. Requires a kernel patch by Werner Almesberger. |
162 | // ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz | 172 | // ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz |
163 | #ifdef BB_MOUNT | 173 | #ifdef BB_MOUNT |
164 | #define BB_FEATURE_INIT_CHROOT | 174 | //#define BB_FEATURE_INIT_CHROOT |
165 | #endif | 175 | #endif |
166 | // | 176 | // |
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c index 4e5e9b08e..e197ee3e8 100644 --- a/chmod_chown_chgrp.c +++ b/chmod_chown_chgrp.c | |||
@@ -98,13 +98,11 @@ int chmod_chown_chgrp_main(int argc, char **argv) | |||
98 | char *p; | 98 | char *p; |
99 | const char *appUsage; | 99 | const char *appUsage; |
100 | 100 | ||
101 | whichApp = | 101 | whichApp = (strcmp(*argv, "chown") == 0)? |
102 | (strcmp(*argv, "chown") == 0)? | ||
103 | CHOWN_APP : (strcmp(*argv, "chmod") == 0)? | 102 | CHOWN_APP : (strcmp(*argv, "chmod") == 0)? |
104 | CHMOD_APP : CHGRP_APP; | 103 | CHMOD_APP : CHGRP_APP; |
105 | 104 | ||
106 | appUsage = | 105 | appUsage = (whichApp == CHOWN_APP)? |
107 | (whichApp == CHOWN_APP)? | ||
108 | chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage; | 106 | chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage; |
109 | 107 | ||
110 | if (argc < 2) | 108 | if (argc < 2) |
@@ -27,5 +27,5 @@ | |||
27 | extern int halt_main(int argc, char **argv) | 27 | extern int halt_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGUSR1)); | 30 | exit(kill(findPidByName("init"), SIGUSR1)); |
31 | } | 31 | } |
diff --git a/init/halt.c b/init/halt.c index d61c38760..f2c9828d4 100644 --- a/init/halt.c +++ b/init/halt.c | |||
@@ -27,5 +27,5 @@ | |||
27 | extern int halt_main(int argc, char **argv) | 27 | extern int halt_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGUSR1)); | 30 | exit(kill(findPidByName("init"), SIGUSR1)); |
31 | } | 31 | } |
diff --git a/init/poweroff.c b/init/poweroff.c index 7f9abf14a..14dc2f5b9 100644 --- a/init/poweroff.c +++ b/init/poweroff.c | |||
@@ -27,5 +27,5 @@ | |||
27 | extern int poweroff_main(int argc, char **argv) | 27 | extern int poweroff_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGUSR2)); | 30 | exit(kill(findPidByName("init"), SIGUSR2)); |
31 | } | 31 | } |
diff --git a/init/reboot.c b/init/reboot.c index f782fa1e6..fc01ea004 100644 --- a/init/reboot.c +++ b/init/reboot.c | |||
@@ -27,7 +27,7 @@ | |||
27 | extern int reboot_main(int argc, char **argv) | 27 | extern int reboot_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGINT)); | 30 | exit(kill(findPidByName("init"), SIGINT)); |
31 | } | 31 | } |
32 | 32 | ||
33 | /* | 33 | /* |
diff --git a/internal.h b/internal.h index fcb24dc14..2e2556d81 100644 --- a/internal.h +++ b/internal.h | |||
@@ -203,7 +203,7 @@ extern char *mtab_next(void **iter); | |||
203 | extern char *mtab_getinfo(const char *match, const char which); | 203 | extern char *mtab_getinfo(const char *match, const char which); |
204 | extern int check_wildcard_match(const char* text, const char* pattern); | 204 | extern int check_wildcard_match(const char* text, const char* pattern); |
205 | extern long getNum (const char *cp); | 205 | extern long getNum (const char *cp); |
206 | extern pid_t findInitPid(); | 206 | extern pid_t findPidByName( char* pidName); |
207 | extern void *xmalloc (size_t size); | 207 | extern void *xmalloc (size_t size); |
208 | #if defined BB_INIT || defined BB_SYSLOGD | 208 | #if defined BB_INIT || defined BB_SYSLOGD |
209 | extern int device_open(char *device, int mode); | 209 | extern int device_open(char *device, int mode); |
@@ -24,6 +24,7 @@ | |||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include <errno.h> | ||
27 | #include <unistd.h> | 28 | #include <unistd.h> |
28 | #include <signal.h> | 29 | #include <signal.h> |
29 | #include <ctype.h> | 30 | #include <ctype.h> |
@@ -35,6 +36,14 @@ static const char *kill_usage = | |||
35 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" | 36 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" |
36 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; | 37 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; |
37 | 38 | ||
39 | static const char *killall_usage = | ||
40 | "killall [-signal] process-name [process-name ...]\n\n" | ||
41 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" | ||
42 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; | ||
43 | |||
44 | |||
45 | #define KILL 0 | ||
46 | #define KILLALL 1 | ||
38 | 47 | ||
39 | struct signal_name { | 48 | struct signal_name { |
40 | const char *name; | 49 | const char *name; |
@@ -120,13 +129,19 @@ const struct signal_name signames[] = { | |||
120 | 129 | ||
121 | extern int kill_main(int argc, char **argv) | 130 | extern int kill_main(int argc, char **argv) |
122 | { | 131 | { |
123 | int sig = SIGTERM; | 132 | int whichApp, sig = SIGTERM; |
133 | const char *appUsage; | ||
134 | |||
135 | /* Figure out what we are trying to do here */ | ||
136 | whichApp = (strcmp(*argv, "killall") == 0)? | ||
137 | KILLALL : KILL; | ||
138 | appUsage = (whichApp == KILLALL)? killall_usage : kill_usage; | ||
124 | 139 | ||
125 | argc--; | 140 | argc--; |
126 | argv++; | 141 | argv++; |
127 | /* Parse any options */ | 142 | /* Parse any options */ |
128 | if (argc < 1) | 143 | if (argc < 1) |
129 | usage(kill_usage); | 144 | usage(appUsage); |
130 | 145 | ||
131 | while (argc > 0 && **argv == '-') { | 146 | while (argc > 0 && **argv == '-') { |
132 | while (*++(*argv)) { | 147 | while (*++(*argv)) { |
@@ -150,7 +165,7 @@ extern int kill_main(int argc, char **argv) | |||
150 | } | 165 | } |
151 | break; | 166 | break; |
152 | case '-': | 167 | case '-': |
153 | usage(kill_usage); | 168 | usage(appUsage); |
154 | default: | 169 | default: |
155 | { | 170 | { |
156 | if (isdigit(**argv)) { | 171 | if (isdigit(**argv)) { |
@@ -186,32 +201,34 @@ extern int kill_main(int argc, char **argv) | |||
186 | 201 | ||
187 | do_it_now: | 202 | do_it_now: |
188 | 203 | ||
189 | while (--argc >= 0) { | 204 | if (whichApp == KILL) { |
190 | int pid; | 205 | /* Looks like they want to do a kill. Do that */ |
191 | struct stat statbuf; | 206 | while (--argc >= 0) { |
192 | char pidpath[20] = "/proc/"; | 207 | int pid; |
193 | 208 | ||
194 | if (!isdigit(**argv)) { | 209 | if (!isdigit(**argv)) |
195 | fprintf(stderr, "bad PID: %s\n", *argv); | 210 | fatalError( "Bad PID: %s\n", strerror(errno)); |
196 | exit(FALSE); | 211 | pid = strtol(*argv, NULL, 0); |
197 | } | 212 | if (kill(pid, sig) != 0) |
198 | pid = atoi(*argv); | 213 | fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); |
199 | snprintf(pidpath, 20, "/proc/%s/stat", *argv); | 214 | argv++; |
200 | if (stat(pidpath, &statbuf) != 0) { | ||
201 | fprintf(stderr, "kill: (%d) - No such pid\n", pid); | ||
202 | exit(FALSE); | ||
203 | } | 215 | } |
204 | fprintf(stderr, "sig = %d\n", sig); | 216 | } else { |
205 | if (kill(pid, sig) != 0) { | 217 | /* Looks like they want to do a killall. Do that */ |
206 | perror(*argv); | 218 | while (--argc >= 0) { |
207 | exit(FALSE); | 219 | int pid; |
220 | |||
221 | while((pid = findPidByName( *argv))) { | ||
222 | if (kill(pid, sig) != 0) | ||
223 | fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); | ||
224 | } | ||
225 | argv++; | ||
208 | } | 226 | } |
209 | argv++; | ||
210 | } | 227 | } |
228 | |||
211 | exit(TRUE); | 229 | exit(TRUE); |
212 | 230 | ||
213 | 231 | ||
214 | end: | 232 | end: |
215 | fprintf(stderr, "bad signal name: %s\n", *argv); | 233 | fatalError( "bad signal name: %s\n", *argv); |
216 | exit(TRUE); | ||
217 | } | 234 | } |
@@ -46,6 +46,10 @@ | |||
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> |
47 | #include <ctype.h> | 47 | #include <ctype.h> |
48 | #include <fstab.h> | 48 | #include <fstab.h> |
49 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
50 | #include <linux/devmtab.h> | ||
51 | #endif | ||
52 | |||
49 | 53 | ||
50 | #if defined BB_FEATURE_MOUNT_LOOP | 54 | #if defined BB_FEATURE_MOUNT_LOOP |
51 | #include <fcntl.h> | 55 | #include <fcntl.h> |
@@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
221 | { | 225 | { |
222 | int status = 0; | 226 | int status = 0; |
223 | 227 | ||
224 | char buf[255]; | ||
225 | |||
226 | #if defined BB_FEATURE_USE_PROCFS | 228 | #if defined BB_FEATURE_USE_PROCFS |
229 | char buf[255]; | ||
227 | if (strcmp(filesystemType, "auto") == 0) { | 230 | if (strcmp(filesystemType, "auto") == 0) { |
228 | FILE *f = fopen("/proc/filesystems", "r"); | 231 | FILE *f = fopen("/proc/filesystems", "r"); |
229 | 232 | ||
@@ -252,6 +255,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
252 | fclose(f); | 255 | fclose(f); |
253 | } else | 256 | } else |
254 | #endif | 257 | #endif |
258 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
259 | if (strcmp(filesystemType, "auto") == 0) { | ||
260 | int fd, i, numfilesystems; | ||
261 | char device[] = "/dev/mtab"; | ||
262 | struct k_fstype *fslist; | ||
263 | |||
264 | /* open device */ | ||
265 | fd = open(device, O_RDONLY); | ||
266 | if (fd < 0) | ||
267 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
268 | |||
269 | /* How many filesystems? We need to know to allocate enough space */ | ||
270 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); | ||
271 | if (numfilesystems<0) | ||
272 | fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); | ||
273 | fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); | ||
274 | |||
275 | /* Grab the list of available filesystems */ | ||
276 | status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); | ||
277 | if (status<0) | ||
278 | fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno)); | ||
279 | |||
280 | /* Walk the list trying to mount filesystems | ||
281 | * that do not claim to be nodev filesystems */ | ||
282 | for( i = 0 ; i < numfilesystems ; i++) { | ||
283 | if (fslist[i].mnt_nodev) | ||
284 | continue; | ||
285 | status = do_mount(blockDevice, directory, fslist[i].mnt_type, | ||
286 | flags | MS_MGC_VAL, string_flags, | ||
287 | useMtab, fakeIt, mtab_opts); | ||
288 | if (status == TRUE) | ||
289 | break; | ||
290 | } | ||
291 | free( fslist); | ||
292 | close(fd); | ||
293 | } else | ||
294 | #endif | ||
255 | { | 295 | { |
256 | status = do_mount(blockDevice, directory, filesystemType, | 296 | status = do_mount(blockDevice, directory, filesystemType, |
257 | flags | MS_MGC_VAL, string_flags, useMtab, | 297 | flags | MS_MGC_VAL, string_flags, useMtab, |
@@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv) | |||
285 | /* Only compiled in if BB_MTAB is not defined */ | 325 | /* Only compiled in if BB_MTAB is not defined */ |
286 | whine_if_fstab_is_missing(); | 326 | whine_if_fstab_is_missing(); |
287 | 327 | ||
328 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
329 | if (argc == 1) { | ||
330 | int fd, i, numfilesystems; | ||
331 | char device[] = "/dev/mtab"; | ||
332 | struct k_mntent *mntentlist; | ||
333 | |||
334 | /* open device */ | ||
335 | fd = open(device, O_RDONLY); | ||
336 | if (fd < 0) | ||
337 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
338 | |||
339 | /* How many mounted filesystems? We need to know to | ||
340 | * allocate enough space for later... */ | ||
341 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); | ||
342 | if (numfilesystems<0) | ||
343 | fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); | ||
344 | mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); | ||
345 | |||
346 | /* Grab the list of mounted filesystems */ | ||
347 | if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) | ||
348 | fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno)); | ||
349 | |||
350 | for( i = 0 ; i < numfilesystems ; i++) { | ||
351 | fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname, | ||
352 | mntentlist[i].mnt_dir, mntentlist[i].mnt_type, | ||
353 | mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, | ||
354 | mntentlist[i].mnt_passno); | ||
355 | } | ||
356 | free( mntentlist); | ||
357 | close(fd); | ||
358 | exit(TRUE); | ||
359 | } | ||
360 | #else | ||
288 | if (argc == 1) { | 361 | if (argc == 1) { |
289 | FILE *mountTable = setmntent(mtab_file, "r"); | 362 | FILE *mountTable = setmntent(mtab_file, "r"); |
290 | 363 | ||
@@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv) | |||
310 | } | 383 | } |
311 | exit(TRUE); | 384 | exit(TRUE); |
312 | } | 385 | } |
313 | 386 | #endif | |
314 | 387 | ||
315 | /* Parse options */ | 388 | /* Parse options */ |
316 | i = --argc; | 389 | i = --argc; |
@@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv) | |||
372 | struct mntent *m; | 445 | struct mntent *m; |
373 | FILE *f = setmntent("/etc/fstab", "r"); | 446 | FILE *f = setmntent("/etc/fstab", "r"); |
374 | 447 | ||
375 | if (f == NULL) { | 448 | if (f == NULL) |
376 | perror("/etc/fstab"); | 449 | fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); |
377 | exit(FALSE); | 450 | |
378 | } | ||
379 | while ((m = getmntent(f)) != NULL) { | 451 | while ((m = getmntent(f)) != NULL) { |
380 | // If the file system isn't noauto, | 452 | // If the file system isn't noauto, |
381 | // and isn't swap or nfs, then mount it | 453 | // and isn't swap or nfs, then mount it |
diff --git a/poweroff.c b/poweroff.c index 7f9abf14a..14dc2f5b9 100644 --- a/poweroff.c +++ b/poweroff.c | |||
@@ -27,5 +27,5 @@ | |||
27 | extern int poweroff_main(int argc, char **argv) | 27 | extern int poweroff_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGUSR2)); | 30 | exit(kill(findPidByName("init"), SIGUSR2)); |
31 | } | 31 | } |
diff --git a/procps/kill.c b/procps/kill.c index 516621232..8a99e0f9e 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include <errno.h> | ||
27 | #include <unistd.h> | 28 | #include <unistd.h> |
28 | #include <signal.h> | 29 | #include <signal.h> |
29 | #include <ctype.h> | 30 | #include <ctype.h> |
@@ -35,6 +36,14 @@ static const char *kill_usage = | |||
35 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" | 36 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" |
36 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; | 37 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; |
37 | 38 | ||
39 | static const char *killall_usage = | ||
40 | "killall [-signal] process-name [process-name ...]\n\n" | ||
41 | "Send a signal (default is SIGTERM) to the specified process(es).\n\n" | ||
42 | "Options:\n" "\t-l\tList all signal names and numbers.\n\n"; | ||
43 | |||
44 | |||
45 | #define KILL 0 | ||
46 | #define KILLALL 1 | ||
38 | 47 | ||
39 | struct signal_name { | 48 | struct signal_name { |
40 | const char *name; | 49 | const char *name; |
@@ -120,13 +129,19 @@ const struct signal_name signames[] = { | |||
120 | 129 | ||
121 | extern int kill_main(int argc, char **argv) | 130 | extern int kill_main(int argc, char **argv) |
122 | { | 131 | { |
123 | int sig = SIGTERM; | 132 | int whichApp, sig = SIGTERM; |
133 | const char *appUsage; | ||
134 | |||
135 | /* Figure out what we are trying to do here */ | ||
136 | whichApp = (strcmp(*argv, "killall") == 0)? | ||
137 | KILLALL : KILL; | ||
138 | appUsage = (whichApp == KILLALL)? killall_usage : kill_usage; | ||
124 | 139 | ||
125 | argc--; | 140 | argc--; |
126 | argv++; | 141 | argv++; |
127 | /* Parse any options */ | 142 | /* Parse any options */ |
128 | if (argc < 1) | 143 | if (argc < 1) |
129 | usage(kill_usage); | 144 | usage(appUsage); |
130 | 145 | ||
131 | while (argc > 0 && **argv == '-') { | 146 | while (argc > 0 && **argv == '-') { |
132 | while (*++(*argv)) { | 147 | while (*++(*argv)) { |
@@ -150,7 +165,7 @@ extern int kill_main(int argc, char **argv) | |||
150 | } | 165 | } |
151 | break; | 166 | break; |
152 | case '-': | 167 | case '-': |
153 | usage(kill_usage); | 168 | usage(appUsage); |
154 | default: | 169 | default: |
155 | { | 170 | { |
156 | if (isdigit(**argv)) { | 171 | if (isdigit(**argv)) { |
@@ -186,32 +201,34 @@ extern int kill_main(int argc, char **argv) | |||
186 | 201 | ||
187 | do_it_now: | 202 | do_it_now: |
188 | 203 | ||
189 | while (--argc >= 0) { | 204 | if (whichApp == KILL) { |
190 | int pid; | 205 | /* Looks like they want to do a kill. Do that */ |
191 | struct stat statbuf; | 206 | while (--argc >= 0) { |
192 | char pidpath[20] = "/proc/"; | 207 | int pid; |
193 | 208 | ||
194 | if (!isdigit(**argv)) { | 209 | if (!isdigit(**argv)) |
195 | fprintf(stderr, "bad PID: %s\n", *argv); | 210 | fatalError( "Bad PID: %s\n", strerror(errno)); |
196 | exit(FALSE); | 211 | pid = strtol(*argv, NULL, 0); |
197 | } | 212 | if (kill(pid, sig) != 0) |
198 | pid = atoi(*argv); | 213 | fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); |
199 | snprintf(pidpath, 20, "/proc/%s/stat", *argv); | 214 | argv++; |
200 | if (stat(pidpath, &statbuf) != 0) { | ||
201 | fprintf(stderr, "kill: (%d) - No such pid\n", pid); | ||
202 | exit(FALSE); | ||
203 | } | 215 | } |
204 | fprintf(stderr, "sig = %d\n", sig); | 216 | } else { |
205 | if (kill(pid, sig) != 0) { | 217 | /* Looks like they want to do a killall. Do that */ |
206 | perror(*argv); | 218 | while (--argc >= 0) { |
207 | exit(FALSE); | 219 | int pid; |
220 | |||
221 | while((pid = findPidByName( *argv))) { | ||
222 | if (kill(pid, sig) != 0) | ||
223 | fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno)); | ||
224 | } | ||
225 | argv++; | ||
208 | } | 226 | } |
209 | argv++; | ||
210 | } | 227 | } |
228 | |||
211 | exit(TRUE); | 229 | exit(TRUE); |
212 | 230 | ||
213 | 231 | ||
214 | end: | 232 | end: |
215 | fprintf(stderr, "bad signal name: %s\n", *argv); | 233 | fatalError( "bad signal name: %s\n", *argv); |
216 | exit(TRUE); | ||
217 | } | 234 | } |
diff --git a/procps/ps.c b/procps/ps.c index 207cdaa02..b0933ab51 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -1,34 +1,47 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini ps implementation for busybox | 3 | * Mini ps implementation(s) for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen | ||
6 | * <andersen@lineo.com>, <andersee@debian.org> | ||
5 | * | 7 | * |
6 | * Copyright (C) 1999 by Lineo, inc. | ||
7 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This contains _two_ implementations of ps for Linux. One uses the |
10 | * it under the terms of the GNU General Public License as published by | 10 | * traditional /proc virtual filesystem, and the other use the devps kernel |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * driver (written by Erik Andersen to avoid using /proc thereby saving 100k+). |
12 | * (at your option) any later version. | ||
13 | * | 12 | * |
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | 13 | * |
19 | * You should have received a copy of the GNU General Public License | 14 | * |
20 | * along with this program; if not, write to the Free Software | 15 | * This program is free software; you can redistribute it and/or modify it |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | * under the terms of the GNU General Public License as published by the Free |
17 | * Software Foundation; either version 2 of the License, or (at your option) | ||
18 | * any later version. | ||
19 | * | ||
20 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
21 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
22 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
23 | * more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License along with | ||
26 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
27 | * Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | 28 | * |
23 | */ | 29 | */ |
24 | 30 | ||
25 | #include "internal.h" | 31 | #include "internal.h" |
32 | #include <stdio.h> | ||
26 | #include <unistd.h> | 33 | #include <unistd.h> |
27 | #include <dirent.h> | 34 | #include <dirent.h> |
28 | #include <stdio.h> | 35 | #include <errno.h> |
29 | #include <fcntl.h> | 36 | #include <fcntl.h> |
30 | #include <ctype.h> | 37 | #include <ctype.h> |
31 | 38 | ||
39 | #if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
40 | |||
41 | /* The following is the first ps implementation -- | ||
42 | * the one using the /proc virtual filesystem. | ||
43 | */ | ||
44 | |||
32 | #if ! defined BB_FEATURE_USE_PROCFS | 45 | #if ! defined BB_FEATURE_USE_PROCFS |
33 | #error Sorry, I depend on the /proc filesystem right now. | 46 | #error Sorry, I depend on the /proc filesystem right now. |
34 | #endif | 47 | #endif |
@@ -105,16 +118,12 @@ extern int ps_main(int argc, char **argv) | |||
105 | char groupName[10] = ""; | 118 | char groupName[10] = ""; |
106 | int i, c; | 119 | int i, c; |
107 | 120 | ||
108 | if (argc > 1 && **(argv + 1) == '-') { | 121 | if (argc > 1 && **(argv + 1) == '-') |
109 | usage | 122 | usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); |
110 | ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); | ||
111 | } | ||
112 | 123 | ||
113 | dir = opendir("/proc"); | 124 | dir = opendir("/proc"); |
114 | if (!dir) { | 125 | if (!dir) |
115 | perror("Can't open /proc"); | 126 | fatalError("Can't open /proc"); |
116 | exit(FALSE); | ||
117 | } | ||
118 | 127 | ||
119 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", | 128 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", |
120 | "State", "Command"); | 129 | "State", "Command"); |
@@ -131,9 +140,9 @@ extern int ps_main(int argc, char **argv) | |||
131 | 140 | ||
132 | /* Make some adjustments as needed */ | 141 | /* Make some adjustments as needed */ |
133 | my_getpwuid(uidName, p.ruid); | 142 | my_getpwuid(uidName, p.ruid); |
134 | my_getgrgid(groupName, p.rgid); | ||
135 | if (*uidName == '\0') | 143 | if (*uidName == '\0') |
136 | sprintf(uidName, "%d", p.ruid); | 144 | sprintf(uidName, "%d", p.ruid); |
145 | my_getgrgid(groupName, p.rgid); | ||
137 | if (*groupName == '\0') | 146 | if (*groupName == '\0') |
138 | sprintf(groupName, "%d", p.rgid); | 147 | sprintf(groupName, "%d", p.rgid); |
139 | 148 | ||
@@ -141,10 +150,8 @@ extern int ps_main(int argc, char **argv) | |||
141 | p.state); | 150 | p.state); |
142 | sprintf(path, "/proc/%s/cmdline", entry->d_name); | 151 | sprintf(path, "/proc/%s/cmdline", entry->d_name); |
143 | file = fopen(path, "r"); | 152 | file = fopen(path, "r"); |
144 | if (file == NULL) { | 153 | if (file == NULL) |
145 | perror(path); | 154 | fatalError("Can't open %s: %s\n", path, strerror(errno)); |
146 | exit(FALSE); | ||
147 | } | ||
148 | i = 0; | 155 | i = 0; |
149 | while (((c = getc(file)) != EOF) && (i < 53)) { | 156 | while (((c = getc(file)) != EOF) && (i < 53)) { |
150 | i++; | 157 | i++; |
@@ -159,3 +166,90 @@ extern int ps_main(int argc, char **argv) | |||
159 | closedir(dir); | 166 | closedir(dir); |
160 | exit(TRUE); | 167 | exit(TRUE); |
161 | } | 168 | } |
169 | |||
170 | |||
171 | #else /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
172 | |||
173 | |||
174 | /* The following is the second ps implementation -- | ||
175 | * this one uses the nifty new devps kernel device. | ||
176 | */ | ||
177 | |||
178 | #include <sys/ioctl.h> | ||
179 | #include <linux/devps.h> | ||
180 | |||
181 | |||
182 | extern int ps_main(int argc, char **argv) | ||
183 | { | ||
184 | char device[] = "/dev/ps"; | ||
185 | int i, fd; | ||
186 | pid_t num_pids; | ||
187 | pid_t* pid_array = NULL; | ||
188 | struct pid_info info; | ||
189 | char uidName[10] = ""; | ||
190 | char groupName[10] = ""; | ||
191 | |||
192 | if (argc > 1 && **(argv + 1) == '-') | ||
193 | usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n"); | ||
194 | |||
195 | /* open device */ | ||
196 | fd = open(device, O_RDONLY); | ||
197 | if (fd < 0) | ||
198 | fatalError( "open failed for `%s': %s\n", device, strerror (errno)); | ||
199 | |||
200 | /* Find out how many processes there are */ | ||
201 | if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0) | ||
202 | fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
203 | |||
204 | /* Allocate some memory -- grab a few extras just in case | ||
205 | * some new processes start up while we wait. The kernel will | ||
206 | * just ignore any extras if we give it too many, and will trunc. | ||
207 | * the list if we give it too few. */ | ||
208 | pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); | ||
209 | pid_array[0] = num_pids+10; | ||
210 | |||
211 | /* Now grab the pid list */ | ||
212 | if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) | ||
213 | fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
214 | |||
215 | /* Print up a ps listing */ | ||
216 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", | ||
217 | "State", "Command"); | ||
218 | |||
219 | for (i=1; i<pid_array[0] ; i++) { | ||
220 | uidName[0] = '\0'; | ||
221 | groupName[0] = '\0'; | ||
222 | info.pid = pid_array[i]; | ||
223 | |||
224 | if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) | ||
225 | fatalError("\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); | ||
226 | |||
227 | /* Make some adjustments as needed */ | ||
228 | my_getpwuid(uidName, info.euid); | ||
229 | if (*uidName == '\0') | ||
230 | sprintf(uidName, "%ld", info.euid); | ||
231 | my_getgrgid(groupName, info.egid); | ||
232 | if (*groupName == '\0') | ||
233 | sprintf(groupName, "%ld", info.egid); | ||
234 | |||
235 | fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); | ||
236 | |||
237 | if (strlen(info.command_line) > 1) | ||
238 | fprintf(stdout, "%s\n", info.command_line); | ||
239 | else | ||
240 | fprintf(stdout, "[%s]\n", info.name); | ||
241 | |||
242 | } | ||
243 | |||
244 | /* Free memory */ | ||
245 | free( pid_array); | ||
246 | |||
247 | /* close device */ | ||
248 | if (close (fd) != 0) | ||
249 | fatalError("close failed for `%s': %s\n", device, strerror (errno)); | ||
250 | |||
251 | exit (0); | ||
252 | } | ||
253 | |||
254 | #endif /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
255 | |||
@@ -1,34 +1,47 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini ps implementation for busybox | 3 | * Mini ps implementation(s) for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen | ||
6 | * <andersen@lineo.com>, <andersee@debian.org> | ||
5 | * | 7 | * |
6 | * Copyright (C) 1999 by Lineo, inc. | ||
7 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This contains _two_ implementations of ps for Linux. One uses the |
10 | * it under the terms of the GNU General Public License as published by | 10 | * traditional /proc virtual filesystem, and the other use the devps kernel |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * driver (written by Erik Andersen to avoid using /proc thereby saving 100k+). |
12 | * (at your option) any later version. | ||
13 | * | 12 | * |
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | 13 | * |
19 | * You should have received a copy of the GNU General Public License | 14 | * |
20 | * along with this program; if not, write to the Free Software | 15 | * This program is free software; you can redistribute it and/or modify it |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | * under the terms of the GNU General Public License as published by the Free |
17 | * Software Foundation; either version 2 of the License, or (at your option) | ||
18 | * any later version. | ||
19 | * | ||
20 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
21 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
22 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
23 | * more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License along with | ||
26 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
27 | * Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | 28 | * |
23 | */ | 29 | */ |
24 | 30 | ||
25 | #include "internal.h" | 31 | #include "internal.h" |
32 | #include <stdio.h> | ||
26 | #include <unistd.h> | 33 | #include <unistd.h> |
27 | #include <dirent.h> | 34 | #include <dirent.h> |
28 | #include <stdio.h> | 35 | #include <errno.h> |
29 | #include <fcntl.h> | 36 | #include <fcntl.h> |
30 | #include <ctype.h> | 37 | #include <ctype.h> |
31 | 38 | ||
39 | #if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
40 | |||
41 | /* The following is the first ps implementation -- | ||
42 | * the one using the /proc virtual filesystem. | ||
43 | */ | ||
44 | |||
32 | #if ! defined BB_FEATURE_USE_PROCFS | 45 | #if ! defined BB_FEATURE_USE_PROCFS |
33 | #error Sorry, I depend on the /proc filesystem right now. | 46 | #error Sorry, I depend on the /proc filesystem right now. |
34 | #endif | 47 | #endif |
@@ -105,16 +118,12 @@ extern int ps_main(int argc, char **argv) | |||
105 | char groupName[10] = ""; | 118 | char groupName[10] = ""; |
106 | int i, c; | 119 | int i, c; |
107 | 120 | ||
108 | if (argc > 1 && **(argv + 1) == '-') { | 121 | if (argc > 1 && **(argv + 1) == '-') |
109 | usage | 122 | usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); |
110 | ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n"); | ||
111 | } | ||
112 | 123 | ||
113 | dir = opendir("/proc"); | 124 | dir = opendir("/proc"); |
114 | if (!dir) { | 125 | if (!dir) |
115 | perror("Can't open /proc"); | 126 | fatalError("Can't open /proc"); |
116 | exit(FALSE); | ||
117 | } | ||
118 | 127 | ||
119 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", | 128 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", |
120 | "State", "Command"); | 129 | "State", "Command"); |
@@ -131,9 +140,9 @@ extern int ps_main(int argc, char **argv) | |||
131 | 140 | ||
132 | /* Make some adjustments as needed */ | 141 | /* Make some adjustments as needed */ |
133 | my_getpwuid(uidName, p.ruid); | 142 | my_getpwuid(uidName, p.ruid); |
134 | my_getgrgid(groupName, p.rgid); | ||
135 | if (*uidName == '\0') | 143 | if (*uidName == '\0') |
136 | sprintf(uidName, "%d", p.ruid); | 144 | sprintf(uidName, "%d", p.ruid); |
145 | my_getgrgid(groupName, p.rgid); | ||
137 | if (*groupName == '\0') | 146 | if (*groupName == '\0') |
138 | sprintf(groupName, "%d", p.rgid); | 147 | sprintf(groupName, "%d", p.rgid); |
139 | 148 | ||
@@ -141,10 +150,8 @@ extern int ps_main(int argc, char **argv) | |||
141 | p.state); | 150 | p.state); |
142 | sprintf(path, "/proc/%s/cmdline", entry->d_name); | 151 | sprintf(path, "/proc/%s/cmdline", entry->d_name); |
143 | file = fopen(path, "r"); | 152 | file = fopen(path, "r"); |
144 | if (file == NULL) { | 153 | if (file == NULL) |
145 | perror(path); | 154 | fatalError("Can't open %s: %s\n", path, strerror(errno)); |
146 | exit(FALSE); | ||
147 | } | ||
148 | i = 0; | 155 | i = 0; |
149 | while (((c = getc(file)) != EOF) && (i < 53)) { | 156 | while (((c = getc(file)) != EOF) && (i < 53)) { |
150 | i++; | 157 | i++; |
@@ -159,3 +166,90 @@ extern int ps_main(int argc, char **argv) | |||
159 | closedir(dir); | 166 | closedir(dir); |
160 | exit(TRUE); | 167 | exit(TRUE); |
161 | } | 168 | } |
169 | |||
170 | |||
171 | #else /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
172 | |||
173 | |||
174 | /* The following is the second ps implementation -- | ||
175 | * this one uses the nifty new devps kernel device. | ||
176 | */ | ||
177 | |||
178 | #include <sys/ioctl.h> | ||
179 | #include <linux/devps.h> | ||
180 | |||
181 | |||
182 | extern int ps_main(int argc, char **argv) | ||
183 | { | ||
184 | char device[] = "/dev/ps"; | ||
185 | int i, fd; | ||
186 | pid_t num_pids; | ||
187 | pid_t* pid_array = NULL; | ||
188 | struct pid_info info; | ||
189 | char uidName[10] = ""; | ||
190 | char groupName[10] = ""; | ||
191 | |||
192 | if (argc > 1 && **(argv + 1) == '-') | ||
193 | usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n"); | ||
194 | |||
195 | /* open device */ | ||
196 | fd = open(device, O_RDONLY); | ||
197 | if (fd < 0) | ||
198 | fatalError( "open failed for `%s': %s\n", device, strerror (errno)); | ||
199 | |||
200 | /* Find out how many processes there are */ | ||
201 | if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0) | ||
202 | fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
203 | |||
204 | /* Allocate some memory -- grab a few extras just in case | ||
205 | * some new processes start up while we wait. The kernel will | ||
206 | * just ignore any extras if we give it too many, and will trunc. | ||
207 | * the list if we give it too few. */ | ||
208 | pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); | ||
209 | pid_array[0] = num_pids+10; | ||
210 | |||
211 | /* Now grab the pid list */ | ||
212 | if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) | ||
213 | fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
214 | |||
215 | /* Print up a ps listing */ | ||
216 | fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", | ||
217 | "State", "Command"); | ||
218 | |||
219 | for (i=1; i<pid_array[0] ; i++) { | ||
220 | uidName[0] = '\0'; | ||
221 | groupName[0] = '\0'; | ||
222 | info.pid = pid_array[i]; | ||
223 | |||
224 | if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) | ||
225 | fatalError("\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); | ||
226 | |||
227 | /* Make some adjustments as needed */ | ||
228 | my_getpwuid(uidName, info.euid); | ||
229 | if (*uidName == '\0') | ||
230 | sprintf(uidName, "%ld", info.euid); | ||
231 | my_getgrgid(groupName, info.egid); | ||
232 | if (*groupName == '\0') | ||
233 | sprintf(groupName, "%ld", info.egid); | ||
234 | |||
235 | fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state); | ||
236 | |||
237 | if (strlen(info.command_line) > 1) | ||
238 | fprintf(stdout, "%s\n", info.command_line); | ||
239 | else | ||
240 | fprintf(stdout, "[%s]\n", info.name); | ||
241 | |||
242 | } | ||
243 | |||
244 | /* Free memory */ | ||
245 | free( pid_array); | ||
246 | |||
247 | /* close device */ | ||
248 | if (close (fd) != 0) | ||
249 | fatalError("close failed for `%s': %s\n", device, strerror (errno)); | ||
250 | |||
251 | exit (0); | ||
252 | } | ||
253 | |||
254 | #endif /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
255 | |||
@@ -27,7 +27,7 @@ | |||
27 | extern int reboot_main(int argc, char **argv) | 27 | extern int reboot_main(int argc, char **argv) |
28 | { | 28 | { |
29 | /* don't assume init's pid == 1 */ | 29 | /* don't assume init's pid == 1 */ |
30 | exit(kill(findInitPid(), SIGINT)); | 30 | exit(kill(findPidByName("init"), SIGINT)); |
31 | } | 31 | } |
32 | 32 | ||
33 | /* | 33 | /* |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 37f789d3c..f46664bf4 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -46,6 +46,10 @@ | |||
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> |
47 | #include <ctype.h> | 47 | #include <ctype.h> |
48 | #include <fstab.h> | 48 | #include <fstab.h> |
49 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
50 | #include <linux/devmtab.h> | ||
51 | #endif | ||
52 | |||
49 | 53 | ||
50 | #if defined BB_FEATURE_MOUNT_LOOP | 54 | #if defined BB_FEATURE_MOUNT_LOOP |
51 | #include <fcntl.h> | 55 | #include <fcntl.h> |
@@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
221 | { | 225 | { |
222 | int status = 0; | 226 | int status = 0; |
223 | 227 | ||
224 | char buf[255]; | ||
225 | |||
226 | #if defined BB_FEATURE_USE_PROCFS | 228 | #if defined BB_FEATURE_USE_PROCFS |
229 | char buf[255]; | ||
227 | if (strcmp(filesystemType, "auto") == 0) { | 230 | if (strcmp(filesystemType, "auto") == 0) { |
228 | FILE *f = fopen("/proc/filesystems", "r"); | 231 | FILE *f = fopen("/proc/filesystems", "r"); |
229 | 232 | ||
@@ -252,6 +255,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
252 | fclose(f); | 255 | fclose(f); |
253 | } else | 256 | } else |
254 | #endif | 257 | #endif |
258 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
259 | if (strcmp(filesystemType, "auto") == 0) { | ||
260 | int fd, i, numfilesystems; | ||
261 | char device[] = "/dev/mtab"; | ||
262 | struct k_fstype *fslist; | ||
263 | |||
264 | /* open device */ | ||
265 | fd = open(device, O_RDONLY); | ||
266 | if (fd < 0) | ||
267 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
268 | |||
269 | /* How many filesystems? We need to know to allocate enough space */ | ||
270 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); | ||
271 | if (numfilesystems<0) | ||
272 | fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); | ||
273 | fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); | ||
274 | |||
275 | /* Grab the list of available filesystems */ | ||
276 | status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); | ||
277 | if (status<0) | ||
278 | fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno)); | ||
279 | |||
280 | /* Walk the list trying to mount filesystems | ||
281 | * that do not claim to be nodev filesystems */ | ||
282 | for( i = 0 ; i < numfilesystems ; i++) { | ||
283 | if (fslist[i].mnt_nodev) | ||
284 | continue; | ||
285 | status = do_mount(blockDevice, directory, fslist[i].mnt_type, | ||
286 | flags | MS_MGC_VAL, string_flags, | ||
287 | useMtab, fakeIt, mtab_opts); | ||
288 | if (status == TRUE) | ||
289 | break; | ||
290 | } | ||
291 | free( fslist); | ||
292 | close(fd); | ||
293 | } else | ||
294 | #endif | ||
255 | { | 295 | { |
256 | status = do_mount(blockDevice, directory, filesystemType, | 296 | status = do_mount(blockDevice, directory, filesystemType, |
257 | flags | MS_MGC_VAL, string_flags, useMtab, | 297 | flags | MS_MGC_VAL, string_flags, useMtab, |
@@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv) | |||
285 | /* Only compiled in if BB_MTAB is not defined */ | 325 | /* Only compiled in if BB_MTAB is not defined */ |
286 | whine_if_fstab_is_missing(); | 326 | whine_if_fstab_is_missing(); |
287 | 327 | ||
328 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
329 | if (argc == 1) { | ||
330 | int fd, i, numfilesystems; | ||
331 | char device[] = "/dev/mtab"; | ||
332 | struct k_mntent *mntentlist; | ||
333 | |||
334 | /* open device */ | ||
335 | fd = open(device, O_RDONLY); | ||
336 | if (fd < 0) | ||
337 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
338 | |||
339 | /* How many mounted filesystems? We need to know to | ||
340 | * allocate enough space for later... */ | ||
341 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); | ||
342 | if (numfilesystems<0) | ||
343 | fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); | ||
344 | mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); | ||
345 | |||
346 | /* Grab the list of mounted filesystems */ | ||
347 | if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) | ||
348 | fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno)); | ||
349 | |||
350 | for( i = 0 ; i < numfilesystems ; i++) { | ||
351 | fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname, | ||
352 | mntentlist[i].mnt_dir, mntentlist[i].mnt_type, | ||
353 | mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, | ||
354 | mntentlist[i].mnt_passno); | ||
355 | } | ||
356 | free( mntentlist); | ||
357 | close(fd); | ||
358 | exit(TRUE); | ||
359 | } | ||
360 | #else | ||
288 | if (argc == 1) { | 361 | if (argc == 1) { |
289 | FILE *mountTable = setmntent(mtab_file, "r"); | 362 | FILE *mountTable = setmntent(mtab_file, "r"); |
290 | 363 | ||
@@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv) | |||
310 | } | 383 | } |
311 | exit(TRUE); | 384 | exit(TRUE); |
312 | } | 385 | } |
313 | 386 | #endif | |
314 | 387 | ||
315 | /* Parse options */ | 388 | /* Parse options */ |
316 | i = --argc; | 389 | i = --argc; |
@@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv) | |||
372 | struct mntent *m; | 445 | struct mntent *m; |
373 | FILE *f = setmntent("/etc/fstab", "r"); | 446 | FILE *f = setmntent("/etc/fstab", "r"); |
374 | 447 | ||
375 | if (f == NULL) { | 448 | if (f == NULL) |
376 | perror("/etc/fstab"); | 449 | fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); |
377 | exit(FALSE); | 450 | |
378 | } | ||
379 | while ((m = getmntent(f)) != NULL) { | 451 | while ((m = getmntent(f)) != NULL) { |
380 | // If the file system isn't noauto, | 452 | // If the file system isn't noauto, |
381 | // and isn't swap or nfs, then mount it | 453 | // and isn't swap or nfs, then mount it |
@@ -56,6 +56,13 @@ | |||
56 | #include <linux/loop.h> | 56 | #include <linux/loop.h> |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | /* Busybox mount uses either /proc/filesystems or /dev/mtab to get the | ||
60 | * list of available filesystems used for the -t auto option */ | ||
61 | #if defined BB_FEATURE_USE_PROCFS && defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
62 | //#error Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again. | ||
63 | #error "Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again." | ||
64 | #endif | ||
65 | |||
59 | 66 | ||
60 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF | 67 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF |
61 | # if defined BB_FEATURE_USE_PROCFS | 68 | # if defined BB_FEATURE_USE_PROCFS |
@@ -64,9 +71,13 @@ const char mtab_file[] = "/proc/mounts"; | |||
64 | # if defined BB_MTAB | 71 | # if defined BB_MTAB |
65 | const char mtab_file[] = "/etc/mtab"; | 72 | const char mtab_file[] = "/etc/mtab"; |
66 | # else | 73 | # else |
67 | # error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or BB_FEATURE_USE_PROCFS | 74 | # if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB |
75 | const char mtab_file[] = "/dev/mtab"; | ||
76 | # else | ||
77 | # error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or ( BB_FEATURE_USE_PROCFS | BB_FEATURE_USE_DEVPS_N_DEVMTAB) | ||
68 | # endif | 78 | # endif |
69 | # endif | 79 | # endif |
80 | # endif | ||
70 | #endif | 81 | #endif |
71 | 82 | ||
72 | 83 | ||
@@ -1238,29 +1249,96 @@ extern int device_open(char *device, int mode) | |||
1238 | 1249 | ||
1239 | #if defined BB_INIT || defined BB_HALT || defined BB_REBOOT | 1250 | #if defined BB_INIT || defined BB_HALT || defined BB_REBOOT |
1240 | 1251 | ||
1252 | #ifdef BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
1253 | #include <linux/devps.h> | ||
1254 | #endif | ||
1255 | |||
1256 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
1257 | /* findPidByName() | ||
1258 | * | ||
1259 | * This finds the pid of the specified process, | ||
1260 | * by using the /dev/ps device driver. | ||
1261 | * | ||
1262 | * [return] | ||
1263 | * 0 failure | ||
1264 | * pid when the pid is found. | ||
1265 | */ | ||
1266 | extern pid_t findPidByName( char* pidName) | ||
1267 | { | ||
1268 | int fd, i; | ||
1269 | char device[] = "/dev/ps"; | ||
1270 | pid_t thePid = 0; | ||
1271 | pid_t num_pids; | ||
1272 | pid_t* pid_array = NULL; | ||
1273 | |||
1274 | /* open device */ | ||
1275 | fd = open(device, O_RDONLY); | ||
1276 | if (fd < 0) | ||
1277 | fatalError( "open failed for `%s': %s\n", device, strerror (errno)); | ||
1278 | |||
1279 | /* Find out how many processes there are */ | ||
1280 | if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0) | ||
1281 | fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
1282 | |||
1283 | /* Allocate some memory -- grab a few extras just in case | ||
1284 | * some new processes start up while we wait. The kernel will | ||
1285 | * just ignore any extras if we give it too many, and will trunc. | ||
1286 | * the list if we give it too few. */ | ||
1287 | pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); | ||
1288 | pid_array[0] = num_pids+10; | ||
1289 | |||
1290 | /* Now grab the pid list */ | ||
1291 | if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) | ||
1292 | fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); | ||
1293 | |||
1294 | /* Now search for a match */ | ||
1295 | for (i=1; i<pid_array[0] ; i++) { | ||
1296 | struct pid_info info; | ||
1297 | |||
1298 | info.pid = pid_array[i]; | ||
1299 | if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) | ||
1300 | fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); | ||
1301 | |||
1302 | if ((strstr(info.command_line, pidName) != NULL)) { | ||
1303 | thePid = info.pid; | ||
1304 | break; | ||
1305 | } | ||
1306 | } | ||
1307 | |||
1308 | /* Free memory */ | ||
1309 | free( pid_array); | ||
1310 | |||
1311 | /* close device */ | ||
1312 | if (close (fd) != 0) | ||
1313 | fatalError( "close failed for `%s': %s\n",device, strerror (errno)); | ||
1314 | |||
1315 | return thePid; | ||
1316 | } | ||
1317 | #else /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
1241 | #if ! defined BB_FEATURE_USE_PROCFS | 1318 | #if ! defined BB_FEATURE_USE_PROCFS |
1242 | #error Sorry, I depend on the /proc filesystem right now. | 1319 | #error Sorry, I depend on the /proc filesystem right now. |
1243 | #endif | 1320 | #endif |
1244 | /* findInitPid() | 1321 | /* findPidByName() |
1245 | * | 1322 | * |
1246 | * This finds the pid of init (which is not always 1). | 1323 | * This finds the pid of the specified process. |
1247 | * Currently, it's implemented by rummaging through the proc filesystem. | 1324 | * Currently, it's implemented by rummaging through |
1325 | * the proc filesystem. | ||
1248 | * | 1326 | * |
1249 | * [return] | 1327 | * [return] |
1250 | * 0 failure | 1328 | * 0 failure |
1251 | * pid when init's pid is found. | 1329 | * pid when the pid is found. |
1252 | */ | 1330 | */ |
1253 | extern pid_t findInitPid() | 1331 | extern pid_t findPidByName( char* pidName) |
1254 | { | 1332 | { |
1255 | pid_t init_pid; | 1333 | pid_t thePid; |
1256 | char filename[256]; | 1334 | char filename[256]; |
1257 | char buffer[256]; | 1335 | char buffer[256]; |
1258 | 1336 | ||
1259 | /* no need to opendir ;) */ | 1337 | /* no need to opendir ;) */ |
1260 | for (init_pid = 1; init_pid < 65536; init_pid++) { | 1338 | for (thePid = 1; thePid < 65536; thePid++) { |
1261 | FILE *status; | 1339 | FILE *status; |
1262 | 1340 | ||
1263 | sprintf(filename, "/proc/%d/cmdline", init_pid); | 1341 | sprintf(filename, "/proc/%d/cmdline", thePid); |
1264 | status = fopen(filename, "r"); | 1342 | status = fopen(filename, "r"); |
1265 | if (!status) { | 1343 | if (!status) { |
1266 | continue; | 1344 | continue; |
@@ -1268,12 +1346,13 @@ extern pid_t findInitPid() | |||
1268 | fgets(buffer, 256, status); | 1346 | fgets(buffer, 256, status); |
1269 | fclose(status); | 1347 | fclose(status); |
1270 | 1348 | ||
1271 | if ((strstr(buffer, "init") != NULL)) { | 1349 | if ((strstr(buffer, pidName) != NULL)) { |
1272 | return init_pid; | 1350 | return thePid; |
1273 | } | 1351 | } |
1274 | } | 1352 | } |
1275 | return 0; | 1353 | return 0; |
1276 | } | 1354 | } |
1355 | #endif /* BB_FEATURE_USE_DEVPS_N_DEVMTAB */ | ||
1277 | #endif /* BB_INIT || BB_HALT || BB_REBOOT */ | 1356 | #endif /* BB_INIT || BB_HALT || BB_REBOOT */ |
1278 | 1357 | ||
1279 | #if defined BB_GUNZIP \ | 1358 | #if defined BB_GUNZIP \ |