diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-12-10 08:25:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-12-10 08:25:07 +0000 |
commit | 2cb55077e2f65f17dbc8933eec47760bcc2a6ba1 (patch) | |
tree | a788718415ded192938d7c7a3661d0cab8cd8afe | |
parent | c5ff0165adac767d37103baa875c2f86bb43c0e1 (diff) | |
download | busybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.tar.gz busybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.tar.bz2 busybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.zip |
Added poweroff (and adjusted init to use it). Inlined function
calls to code only called once in tee. Made BB_KLOGD and option.
-Erik
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | applets/busybox.c | 3 | ||||
-rw-r--r-- | busybox.c | 3 | ||||
-rw-r--r-- | busybox.def.h | 2 | ||||
-rw-r--r-- | coreutils/tee.c | 60 | ||||
-rw-r--r-- | init.c | 17 | ||||
-rw-r--r-- | init/init.c | 17 | ||||
-rw-r--r-- | init/poweroff.c | 31 | ||||
-rw-r--r-- | init/reboot.c | 2 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | poweroff.c | 31 | ||||
-rw-r--r-- | reboot.c | 2 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 27 | ||||
-rw-r--r-- | syslogd.c | 27 | ||||
-rw-r--r-- | tee.c | 60 |
16 files changed, 193 insertions, 99 deletions
@@ -12,8 +12,10 @@ | |||
12 | * kill now behaves itself properly, added 'kill -l' to list signals | 12 | * kill now behaves itself properly, added 'kill -l' to list signals |
13 | * 'ls -l' was failing on long directories, since my_getid was leaking | 13 | * 'ls -l' was failing on long directories, since my_getid was leaking |
14 | one file descriptor per file. Oops. | 14 | one file descriptor per file. Oops. |
15 | * Fixed rebooting from init. I'd left some debugging code in | 15 | * Fixed rebooting from init. I'd accidently left some debugging code in |
16 | which blocked reboots. | 16 | which blocked reboots. |
17 | * Fixed reboot, halt (and added poweroff) such that they handle it when | ||
18 | init is not at PID 1 (like when running in an initrd). | ||
17 | * Added a prelinary du implementation. Some parameter parsing | 19 | * Added a prelinary du implementation. Some parameter parsing |
18 | stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>) | 20 | stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>) |
19 | * Implemented tee. -beppu | 21 | * Implemented tee. -beppu |
@@ -9,9 +9,6 @@ around to it some time. If you have any good ideas, please let me know. | |||
9 | 9 | ||
10 | * Allow tar to create archives with sockets, devices, and other special files | 10 | * Allow tar to create archives with sockets, devices, and other special files |
11 | * Add in a mini insmod, rmmod, lsmod | 11 | * Add in a mini insmod, rmmod, lsmod |
12 | * Change init so halt, reboot (and poweroff) work with an initrd | ||
13 | when init is not PID 1 | ||
14 | * poweroff | ||
15 | * mkfifo | 12 | * mkfifo |
16 | * dnsdomainname | 13 | * dnsdomainname |
17 | * traceroute/nslookup/netstat | 14 | * traceroute/nslookup/netstat |
@@ -22,7 +19,7 @@ around to it some time. If you have any good ideas, please let me know. | |||
22 | * sort/uniq | 19 | * sort/uniq |
23 | * wc | 20 | * wc |
24 | * tr | 21 | * tr |
25 | * expr (maybe)? (ash builtin?) | 22 | * expr (maybe?) (ash builtin?) |
26 | * login/sulogin/passwd/getty (These are actully now part of tinylogin, which | 23 | * login/sulogin/passwd/getty (These are actully now part of tinylogin, which |
27 | I've just started to maintain). | 24 | I've just started to maintain). |
28 | 25 | ||
diff --git a/applets/busybox.c b/applets/busybox.c index f4573019b..d1eb38a0b 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -138,6 +138,9 @@ static const struct Applet applets[] = { | |||
138 | #ifdef BB_PING //bin | 138 | #ifdef BB_PING //bin |
139 | {"ping", ping_main}, | 139 | {"ping", ping_main}, |
140 | #endif | 140 | #endif |
141 | #ifdef BB_POWEROFF //sbin | ||
142 | {"poweroff", poweroff_main}, | ||
143 | #endif | ||
141 | #ifdef BB_PRINTF //usr/bin | 144 | #ifdef BB_PRINTF //usr/bin |
142 | {"printf", printf_main}, | 145 | {"printf", printf_main}, |
143 | #endif | 146 | #endif |
@@ -138,6 +138,9 @@ static const struct Applet applets[] = { | |||
138 | #ifdef BB_PING //bin | 138 | #ifdef BB_PING //bin |
139 | {"ping", ping_main}, | 139 | {"ping", ping_main}, |
140 | #endif | 140 | #endif |
141 | #ifdef BB_POWEROFF //sbin | ||
142 | {"poweroff", poweroff_main}, | ||
143 | #endif | ||
141 | #ifdef BB_PRINTF //usr/bin | 144 | #ifdef BB_PRINTF //usr/bin |
142 | {"printf", printf_main}, | 145 | {"printf", printf_main}, |
143 | #endif | 146 | #endif |
diff --git a/busybox.def.h b/busybox.def.h index 1bdb9a429..30533616a 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #define BB_HOSTNAME | 28 | #define BB_HOSTNAME |
29 | #define BB_INIT | 29 | #define BB_INIT |
30 | #define BB_KILL | 30 | #define BB_KILL |
31 | #define BB_KLOGD | ||
31 | //#define BB_LENGTH | 32 | //#define BB_LENGTH |
32 | #define BB_LN | 33 | #define BB_LN |
33 | #define BB_LOADFONT | 34 | #define BB_LOADFONT |
@@ -47,6 +48,7 @@ | |||
47 | //#define BB_MTAB | 48 | //#define BB_MTAB |
48 | #define BB_MV | 49 | #define BB_MV |
49 | #define BB_PING | 50 | #define BB_PING |
51 | #define BB_POWEROFF | ||
50 | //#define BB_PRINTF | 52 | //#define BB_PRINTF |
51 | #define BB_PS | 53 | #define BB_PS |
52 | #define BB_PWD | 54 | #define BB_PWD |
diff --git a/coreutils/tee.c b/coreutils/tee.c index 45128b568..8d1ca6efd 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c | |||
@@ -25,11 +25,15 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | 26 | ||
27 | static const char tee_usage[] = | 27 | static const char tee_usage[] = |
28 | "Usage: tee [OPTION]... [FILE]...\n" | 28 | "tee [OPTION]... [FILE]...\n\n" |
29 | "Copy standard input to each FILE, and also to standard output.\n\n" | 29 | "Copy standard input to each FILE, and also to standard output.\n\n" |
30 | " -a, append to the given FILEs, do not overwrite\n" | 30 | "Options:\n" |
31 | " -i, ignore interrupt signals\n" | 31 | "\t-a\tappend to the given FILEs, do not overwrite\n" |
32 | " -h, this help message\n"; | 32 | #if 0 |
33 | "\t-i\tignore interrupt signals\n" | ||
34 | #endif | ||
35 | ; | ||
36 | |||
33 | 37 | ||
34 | /* FileList _______________________________________________________________ */ | 38 | /* FileList _______________________________________________________________ */ |
35 | 39 | ||
@@ -39,27 +43,6 @@ static int FL_end; | |||
39 | 43 | ||
40 | typedef void (FL_Function)(FILE *file, char c); | 44 | typedef void (FL_Function)(FILE *file, char c); |
41 | 45 | ||
42 | /* initialize FileList */ | ||
43 | static void | ||
44 | FL_init() | ||
45 | { | ||
46 | FL_end = 0; | ||
47 | FileList[0] = stdout; | ||
48 | } | ||
49 | |||
50 | /* add a file to FileList */ | ||
51 | static int | ||
52 | FL_add(const char *filename, char *opt_open) | ||
53 | { | ||
54 | FILE *file; | ||
55 | |||
56 | file = fopen(filename, opt_open); | ||
57 | if (!file) { return 0; }; | ||
58 | if (FL_end < FL_MAX) { | ||
59 | FileList[++FL_end] = file; | ||
60 | } | ||
61 | return 1; | ||
62 | } | ||
63 | 46 | ||
64 | /* apply a function to everything in FileList */ | 47 | /* apply a function to everything in FileList */ |
65 | static void | 48 | static void |
@@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c) | |||
71 | } | 54 | } |
72 | } | 55 | } |
73 | 56 | ||
74 | /* ________________________________________________________________________ */ | ||
75 | |||
76 | /* FL_Function for writing to files*/ | 57 | /* FL_Function for writing to files*/ |
77 | static void | 58 | static void |
78 | tee_fwrite(FILE *file, char c) | 59 | tee_fwrite(FILE *file, char c) |
@@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c) | |||
87 | fclose(file); | 68 | fclose(file); |
88 | } | 69 | } |
89 | 70 | ||
71 | /* ________________________________________________________________________ */ | ||
72 | |||
90 | /* BusyBoxed tee(1) */ | 73 | /* BusyBoxed tee(1) */ |
91 | int | 74 | int |
92 | tee_main(int argc, char **argv) | 75 | tee_main(int argc, char **argv) |
@@ -95,6 +78,7 @@ tee_main(int argc, char **argv) | |||
95 | char c; | 78 | char c; |
96 | char opt; | 79 | char opt; |
97 | char opt_fopen[2] = "w"; | 80 | char opt_fopen[2] = "w"; |
81 | FILE *file; | ||
98 | 82 | ||
99 | /* parse argv[] */ | 83 | /* parse argv[] */ |
100 | for (i = 1; i < argc; i++) { | 84 | for (i = 1; i < argc; i++) { |
@@ -104,14 +88,12 @@ tee_main(int argc, char **argv) | |||
104 | case 'a': | 88 | case 'a': |
105 | opt_fopen[0] = 'a'; | 89 | opt_fopen[0] = 'a'; |
106 | break; | 90 | break; |
91 | #if 0 | ||
107 | case 'i': | 92 | case 'i': |
108 | fprintf(stderr, "ingore interrupt not implemented\n"); | 93 | fprintf(stderr, "ignore interrupt not implemented\n"); |
109 | break; | ||
110 | case 'h': | ||
111 | usage(tee_usage); | ||
112 | break; | 94 | break; |
95 | #endif | ||
113 | default: | 96 | default: |
114 | fprintf(stderr, "tee: invalid option -- %c\n", opt); | ||
115 | usage(tee_usage); | 97 | usage(tee_usage); |
116 | } | 98 | } |
117 | } else { | 99 | } else { |
@@ -120,9 +102,15 @@ tee_main(int argc, char **argv) | |||
120 | } | 102 | } |
121 | 103 | ||
122 | /* init FILE pointers */ | 104 | /* init FILE pointers */ |
123 | FL_init(); | 105 | FL_end = 0; |
106 | FileList[0] = stdout; | ||
124 | for ( ; i < argc; i++) { | 107 | for ( ; i < argc; i++) { |
125 | FL_add(argv[i], opt_fopen); | 108 | /* add a file to FileList */ |
109 | file = fopen(argv[i], opt_fopen); | ||
110 | if (!file) { continue; } | ||
111 | if (FL_end < FL_MAX) { | ||
112 | FileList[++FL_end] = file; | ||
113 | } | ||
126 | } | 114 | } |
127 | 115 | ||
128 | /* read and redirect */ | 116 | /* read and redirect */ |
@@ -135,4 +123,4 @@ tee_main(int argc, char **argv) | |||
135 | exit(0); | 123 | exit(0); |
136 | } | 124 | } |
137 | 125 | ||
138 | /* $Id: tee.c,v 1.3 1999/12/10 07:41:03 beppu Exp $ */ | 126 | /* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */ |
@@ -336,9 +336,9 @@ static pid_t run(const char * const* command, | |||
336 | } | 336 | } |
337 | 337 | ||
338 | /* Log the process name and args */ | 338 | /* Log the process name and args */ |
339 | message(LOG, "Starting pid %d, console %s: '", getpid(), terminal); | 339 | message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal); |
340 | while ( *cmd) message(LOG, "%s ", *cmd++); | 340 | while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++); |
341 | message(LOG, "'\r\n"); | 341 | message(LOG|CONSOLE, "'\r\n"); |
342 | 342 | ||
343 | /* Now run it. The new program will take over this PID, | 343 | /* Now run it. The new program will take over this PID, |
344 | * so nothing further in init.c should be run. */ | 344 | * so nothing further in init.c should be run. */ |
@@ -418,8 +418,10 @@ static void halt_signal(int sig) | |||
418 | "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); | 418 | "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); |
419 | sync(); | 419 | sync(); |
420 | #ifndef DEBUG_INIT | 420 | #ifndef DEBUG_INIT |
421 | reboot(RB_HALT_SYSTEM); | 421 | if (sig == SIGUSR2) |
422 | //reboot(RB_POWER_OFF); | 422 | reboot(RB_POWER_OFF); |
423 | else | ||
424 | reboot(RB_HALT_SYSTEM); | ||
423 | #endif | 425 | #endif |
424 | exit(0); | 426 | exit(0); |
425 | } | 427 | } |
@@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv) | |||
514 | } else | 516 | } else |
515 | message(CONSOLE|LOG, "Mounting /proc: failed!\n"); | 517 | message(CONSOLE|LOG, "Mounting /proc: failed!\n"); |
516 | 518 | ||
519 | fprintf(stderr, "got proc\n"); | ||
520 | |||
517 | /* Make sure there is enough memory to do something useful. */ | 521 | /* Make sure there is enough memory to do something useful. */ |
518 | check_memory(); | 522 | check_memory(); |
523 | fprintf(stderr, "got check_memory\n"); | ||
519 | 524 | ||
520 | /* Check if we are supposed to be in single user mode */ | 525 | /* Check if we are supposed to be in single user mode */ |
521 | if ( argc > 1 && (!strcmp(argv[1], "single") || | 526 | if ( argc > 1 && (!strcmp(argv[1], "single") || |
@@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv) | |||
524 | tty1_command = shell_command; | 529 | tty1_command = shell_command; |
525 | tty2_command = shell_command; | 530 | tty2_command = shell_command; |
526 | } | 531 | } |
532 | fprintf(stderr, "got single\n"); | ||
527 | 533 | ||
528 | /* Make sure an init script exists before trying to run it */ | 534 | /* Make sure an init script exists before trying to run it */ |
529 | if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { | 535 | if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { |
@@ -535,6 +541,7 @@ extern int init_main(int argc, char **argv) | |||
535 | /* Make sure /sbin/getty exists before trying to run it */ | 541 | /* Make sure /sbin/getty exists before trying to run it */ |
536 | if (stat(GETTY, &statbuf)==0) { | 542 | if (stat(GETTY, &statbuf)==0) { |
537 | char* where; | 543 | char* where; |
544 | fprintf(stderr, "\n"); | ||
538 | wait_for_enter_tty2 = FALSE; | 545 | wait_for_enter_tty2 = FALSE; |
539 | where = strrchr( console, '/'); | 546 | where = strrchr( console, '/'); |
540 | if ( where != NULL) { | 547 | if ( where != NULL) { |
diff --git a/init/init.c b/init/init.c index d2e9a7e97..3c800b9b2 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -336,9 +336,9 @@ static pid_t run(const char * const* command, | |||
336 | } | 336 | } |
337 | 337 | ||
338 | /* Log the process name and args */ | 338 | /* Log the process name and args */ |
339 | message(LOG, "Starting pid %d, console %s: '", getpid(), terminal); | 339 | message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal); |
340 | while ( *cmd) message(LOG, "%s ", *cmd++); | 340 | while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++); |
341 | message(LOG, "'\r\n"); | 341 | message(LOG|CONSOLE, "'\r\n"); |
342 | 342 | ||
343 | /* Now run it. The new program will take over this PID, | 343 | /* Now run it. The new program will take over this PID, |
344 | * so nothing further in init.c should be run. */ | 344 | * so nothing further in init.c should be run. */ |
@@ -418,8 +418,10 @@ static void halt_signal(int sig) | |||
418 | "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); | 418 | "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); |
419 | sync(); | 419 | sync(); |
420 | #ifndef DEBUG_INIT | 420 | #ifndef DEBUG_INIT |
421 | reboot(RB_HALT_SYSTEM); | 421 | if (sig == SIGUSR2) |
422 | //reboot(RB_POWER_OFF); | 422 | reboot(RB_POWER_OFF); |
423 | else | ||
424 | reboot(RB_HALT_SYSTEM); | ||
423 | #endif | 425 | #endif |
424 | exit(0); | 426 | exit(0); |
425 | } | 427 | } |
@@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv) | |||
514 | } else | 516 | } else |
515 | message(CONSOLE|LOG, "Mounting /proc: failed!\n"); | 517 | message(CONSOLE|LOG, "Mounting /proc: failed!\n"); |
516 | 518 | ||
519 | fprintf(stderr, "got proc\n"); | ||
520 | |||
517 | /* Make sure there is enough memory to do something useful. */ | 521 | /* Make sure there is enough memory to do something useful. */ |
518 | check_memory(); | 522 | check_memory(); |
523 | fprintf(stderr, "got check_memory\n"); | ||
519 | 524 | ||
520 | /* Check if we are supposed to be in single user mode */ | 525 | /* Check if we are supposed to be in single user mode */ |
521 | if ( argc > 1 && (!strcmp(argv[1], "single") || | 526 | if ( argc > 1 && (!strcmp(argv[1], "single") || |
@@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv) | |||
524 | tty1_command = shell_command; | 529 | tty1_command = shell_command; |
525 | tty2_command = shell_command; | 530 | tty2_command = shell_command; |
526 | } | 531 | } |
532 | fprintf(stderr, "got single\n"); | ||
527 | 533 | ||
528 | /* Make sure an init script exists before trying to run it */ | 534 | /* Make sure an init script exists before trying to run it */ |
529 | if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { | 535 | if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { |
@@ -535,6 +541,7 @@ extern int init_main(int argc, char **argv) | |||
535 | /* Make sure /sbin/getty exists before trying to run it */ | 541 | /* Make sure /sbin/getty exists before trying to run it */ |
536 | if (stat(GETTY, &statbuf)==0) { | 542 | if (stat(GETTY, &statbuf)==0) { |
537 | char* where; | 543 | char* where; |
544 | fprintf(stderr, "\n"); | ||
538 | wait_for_enter_tty2 = FALSE; | 545 | wait_for_enter_tty2 = FALSE; |
539 | where = strrchr( console, '/'); | 546 | where = strrchr( console, '/'); |
540 | if ( where != NULL) { | 547 | if ( where != NULL) { |
diff --git a/init/poweroff.c b/init/poweroff.c new file mode 100644 index 000000000..405ca3fe2 --- /dev/null +++ b/init/poweroff.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Mini poweroff implementation for busybox | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include "internal.h" | ||
24 | #include <signal.h> | ||
25 | |||
26 | extern int | ||
27 | poweroff_main(int argc, char ** argv) | ||
28 | { | ||
29 | /* don't assume init's pid == 1 */ | ||
30 | exit( kill(findInitPid(), SIGUSR2)); | ||
31 | } | ||
diff --git a/init/reboot.c b/init/reboot.c index ff2c6ad18..1339a60f4 100644 --- a/init/reboot.c +++ b/init/reboot.c | |||
@@ -27,5 +27,5 @@ extern int | |||
27 | reboot_main(int argc, char ** argv) | 27 | 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(), SIGUSR2)); | 30 | exit( kill(findInitPid(), SIGINT)); |
31 | } | 31 | } |
diff --git a/internal.h b/internal.h index 39b07b952..95df64c63 100644 --- a/internal.h +++ b/internal.h | |||
@@ -96,6 +96,7 @@ extern int mount_main(int argc, char** argv); | |||
96 | extern int mt_main(int argc, char** argv); | 96 | extern int mt_main(int argc, char** argv); |
97 | extern int mv_main(int argc, char** argv); | 97 | extern int mv_main(int argc, char** argv); |
98 | extern int ping_main(int argc, char **argv); | 98 | extern int ping_main(int argc, char **argv); |
99 | extern int poweroff_main(int argc, char **argv); | ||
99 | extern int printf_main(int argc, char** argv); | 100 | extern int printf_main(int argc, char** argv); |
100 | extern int ps_main(int argc, char** argv); | 101 | extern int ps_main(int argc, char** argv); |
101 | extern int pwd_main(int argc, char** argv); | 102 | extern int pwd_main(int argc, char** argv); |
diff --git a/poweroff.c b/poweroff.c new file mode 100644 index 000000000..405ca3fe2 --- /dev/null +++ b/poweroff.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Mini poweroff implementation for busybox | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include "internal.h" | ||
24 | #include <signal.h> | ||
25 | |||
26 | extern int | ||
27 | poweroff_main(int argc, char ** argv) | ||
28 | { | ||
29 | /* don't assume init's pid == 1 */ | ||
30 | exit( kill(findInitPid(), SIGUSR2)); | ||
31 | } | ||
@@ -27,5 +27,5 @@ extern int | |||
27 | reboot_main(int argc, char ** argv) | 27 | 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(), SIGUSR2)); | 30 | exit( kill(findInitPid(), SIGINT)); |
31 | } | 31 | } |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 1f3e31225..24c721f8e 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -62,6 +62,9 @@ static const char syslogd_usage[] = | |||
62 | "Options:\n" | 62 | "Options:\n" |
63 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" | 63 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" |
64 | "\t-n\tDo not fork into the background (for when run by init)\n" | 64 | "\t-n\tDo not fork into the background (for when run by init)\n" |
65 | #ifdef BB_KLOGD | ||
66 | "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n" | ||
67 | #endif | ||
65 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; | 68 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; |
66 | 69 | ||
67 | 70 | ||
@@ -251,6 +254,8 @@ static void doSyslogd(void) | |||
251 | close(fd); | 254 | close(fd); |
252 | } | 255 | } |
253 | 256 | ||
257 | #ifdef BB_KLOGD | ||
258 | |||
254 | static void klogd_signal(int sig) | 259 | static void klogd_signal(int sig) |
255 | { | 260 | { |
256 | ksyslog(7, NULL, 0); | 261 | ksyslog(7, NULL, 0); |
@@ -259,7 +264,6 @@ static void klogd_signal(int sig) | |||
259 | exit( TRUE); | 264 | exit( TRUE); |
260 | } | 265 | } |
261 | 266 | ||
262 | |||
263 | static void doKlogd(void) | 267 | static void doKlogd(void) |
264 | { | 268 | { |
265 | int priority=LOG_INFO; | 269 | int priority=LOG_INFO; |
@@ -325,11 +329,15 @@ static void doKlogd(void) | |||
325 | 329 | ||
326 | } | 330 | } |
327 | 331 | ||
332 | #endif | ||
328 | 333 | ||
329 | extern int syslogd_main(int argc, char **argv) | 334 | extern int syslogd_main(int argc, char **argv) |
330 | { | 335 | { |
331 | int pid, klogd_pid; | 336 | int pid, klogd_pid; |
332 | int doFork = TRUE; | 337 | int doFork = TRUE; |
338 | #ifdef BB_KLOGD | ||
339 | int startKlogd = TRUE; | ||
340 | #endif | ||
333 | char *p; | 341 | char *p; |
334 | char **argv1=argv; | 342 | char **argv1=argv; |
335 | 343 | ||
@@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv) | |||
345 | case 'n': | 353 | case 'n': |
346 | doFork = FALSE; | 354 | doFork = FALSE; |
347 | break; | 355 | break; |
356 | #ifdef BB_KLOGD | ||
357 | case 'K': | ||
358 | startKlogd = FALSE; | ||
359 | break; | ||
360 | #endif | ||
348 | case 'O': | 361 | case 'O': |
349 | if (--argc == 0) { | 362 | if (--argc == 0) { |
350 | usage(syslogd_usage); | 363 | usage(syslogd_usage); |
@@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv) | |||
375 | doSyslogd(); | 388 | doSyslogd(); |
376 | } | 389 | } |
377 | 390 | ||
391 | #ifdef BB_KLOGD | ||
378 | /* Start up the klogd process */ | 392 | /* Start up the klogd process */ |
379 | klogd_pid = fork(); | 393 | if (startKlogd == TRUE) { |
380 | if (klogd_pid == 0 ) { | 394 | klogd_pid = fork(); |
381 | strncpy(argv[0], "klogd", strlen(argv[0])); | 395 | if (klogd_pid == 0 ) { |
382 | doKlogd(); | 396 | strncpy(argv[0], "klogd", strlen(argv[0])); |
397 | doKlogd(); | ||
398 | } | ||
383 | } | 399 | } |
400 | #endif | ||
384 | 401 | ||
385 | exit( TRUE); | 402 | exit( TRUE); |
386 | } | 403 | } |
@@ -62,6 +62,9 @@ static const char syslogd_usage[] = | |||
62 | "Options:\n" | 62 | "Options:\n" |
63 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" | 63 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" |
64 | "\t-n\tDo not fork into the background (for when run by init)\n" | 64 | "\t-n\tDo not fork into the background (for when run by init)\n" |
65 | #ifdef BB_KLOGD | ||
66 | "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n" | ||
67 | #endif | ||
65 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; | 68 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; |
66 | 69 | ||
67 | 70 | ||
@@ -251,6 +254,8 @@ static void doSyslogd(void) | |||
251 | close(fd); | 254 | close(fd); |
252 | } | 255 | } |
253 | 256 | ||
257 | #ifdef BB_KLOGD | ||
258 | |||
254 | static void klogd_signal(int sig) | 259 | static void klogd_signal(int sig) |
255 | { | 260 | { |
256 | ksyslog(7, NULL, 0); | 261 | ksyslog(7, NULL, 0); |
@@ -259,7 +264,6 @@ static void klogd_signal(int sig) | |||
259 | exit( TRUE); | 264 | exit( TRUE); |
260 | } | 265 | } |
261 | 266 | ||
262 | |||
263 | static void doKlogd(void) | 267 | static void doKlogd(void) |
264 | { | 268 | { |
265 | int priority=LOG_INFO; | 269 | int priority=LOG_INFO; |
@@ -325,11 +329,15 @@ static void doKlogd(void) | |||
325 | 329 | ||
326 | } | 330 | } |
327 | 331 | ||
332 | #endif | ||
328 | 333 | ||
329 | extern int syslogd_main(int argc, char **argv) | 334 | extern int syslogd_main(int argc, char **argv) |
330 | { | 335 | { |
331 | int pid, klogd_pid; | 336 | int pid, klogd_pid; |
332 | int doFork = TRUE; | 337 | int doFork = TRUE; |
338 | #ifdef BB_KLOGD | ||
339 | int startKlogd = TRUE; | ||
340 | #endif | ||
333 | char *p; | 341 | char *p; |
334 | char **argv1=argv; | 342 | char **argv1=argv; |
335 | 343 | ||
@@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv) | |||
345 | case 'n': | 353 | case 'n': |
346 | doFork = FALSE; | 354 | doFork = FALSE; |
347 | break; | 355 | break; |
356 | #ifdef BB_KLOGD | ||
357 | case 'K': | ||
358 | startKlogd = FALSE; | ||
359 | break; | ||
360 | #endif | ||
348 | case 'O': | 361 | case 'O': |
349 | if (--argc == 0) { | 362 | if (--argc == 0) { |
350 | usage(syslogd_usage); | 363 | usage(syslogd_usage); |
@@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv) | |||
375 | doSyslogd(); | 388 | doSyslogd(); |
376 | } | 389 | } |
377 | 390 | ||
391 | #ifdef BB_KLOGD | ||
378 | /* Start up the klogd process */ | 392 | /* Start up the klogd process */ |
379 | klogd_pid = fork(); | 393 | if (startKlogd == TRUE) { |
380 | if (klogd_pid == 0 ) { | 394 | klogd_pid = fork(); |
381 | strncpy(argv[0], "klogd", strlen(argv[0])); | 395 | if (klogd_pid == 0 ) { |
382 | doKlogd(); | 396 | strncpy(argv[0], "klogd", strlen(argv[0])); |
397 | doKlogd(); | ||
398 | } | ||
383 | } | 399 | } |
400 | #endif | ||
384 | 401 | ||
385 | exit( TRUE); | 402 | exit( TRUE); |
386 | } | 403 | } |
@@ -25,11 +25,15 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | 26 | ||
27 | static const char tee_usage[] = | 27 | static const char tee_usage[] = |
28 | "Usage: tee [OPTION]... [FILE]...\n" | 28 | "tee [OPTION]... [FILE]...\n\n" |
29 | "Copy standard input to each FILE, and also to standard output.\n\n" | 29 | "Copy standard input to each FILE, and also to standard output.\n\n" |
30 | " -a, append to the given FILEs, do not overwrite\n" | 30 | "Options:\n" |
31 | " -i, ignore interrupt signals\n" | 31 | "\t-a\tappend to the given FILEs, do not overwrite\n" |
32 | " -h, this help message\n"; | 32 | #if 0 |
33 | "\t-i\tignore interrupt signals\n" | ||
34 | #endif | ||
35 | ; | ||
36 | |||
33 | 37 | ||
34 | /* FileList _______________________________________________________________ */ | 38 | /* FileList _______________________________________________________________ */ |
35 | 39 | ||
@@ -39,27 +43,6 @@ static int FL_end; | |||
39 | 43 | ||
40 | typedef void (FL_Function)(FILE *file, char c); | 44 | typedef void (FL_Function)(FILE *file, char c); |
41 | 45 | ||
42 | /* initialize FileList */ | ||
43 | static void | ||
44 | FL_init() | ||
45 | { | ||
46 | FL_end = 0; | ||
47 | FileList[0] = stdout; | ||
48 | } | ||
49 | |||
50 | /* add a file to FileList */ | ||
51 | static int | ||
52 | FL_add(const char *filename, char *opt_open) | ||
53 | { | ||
54 | FILE *file; | ||
55 | |||
56 | file = fopen(filename, opt_open); | ||
57 | if (!file) { return 0; }; | ||
58 | if (FL_end < FL_MAX) { | ||
59 | FileList[++FL_end] = file; | ||
60 | } | ||
61 | return 1; | ||
62 | } | ||
63 | 46 | ||
64 | /* apply a function to everything in FileList */ | 47 | /* apply a function to everything in FileList */ |
65 | static void | 48 | static void |
@@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c) | |||
71 | } | 54 | } |
72 | } | 55 | } |
73 | 56 | ||
74 | /* ________________________________________________________________________ */ | ||
75 | |||
76 | /* FL_Function for writing to files*/ | 57 | /* FL_Function for writing to files*/ |
77 | static void | 58 | static void |
78 | tee_fwrite(FILE *file, char c) | 59 | tee_fwrite(FILE *file, char c) |
@@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c) | |||
87 | fclose(file); | 68 | fclose(file); |
88 | } | 69 | } |
89 | 70 | ||
71 | /* ________________________________________________________________________ */ | ||
72 | |||
90 | /* BusyBoxed tee(1) */ | 73 | /* BusyBoxed tee(1) */ |
91 | int | 74 | int |
92 | tee_main(int argc, char **argv) | 75 | tee_main(int argc, char **argv) |
@@ -95,6 +78,7 @@ tee_main(int argc, char **argv) | |||
95 | char c; | 78 | char c; |
96 | char opt; | 79 | char opt; |
97 | char opt_fopen[2] = "w"; | 80 | char opt_fopen[2] = "w"; |
81 | FILE *file; | ||
98 | 82 | ||
99 | /* parse argv[] */ | 83 | /* parse argv[] */ |
100 | for (i = 1; i < argc; i++) { | 84 | for (i = 1; i < argc; i++) { |
@@ -104,14 +88,12 @@ tee_main(int argc, char **argv) | |||
104 | case 'a': | 88 | case 'a': |
105 | opt_fopen[0] = 'a'; | 89 | opt_fopen[0] = 'a'; |
106 | break; | 90 | break; |
91 | #if 0 | ||
107 | case 'i': | 92 | case 'i': |
108 | fprintf(stderr, "ingore interrupt not implemented\n"); | 93 | fprintf(stderr, "ignore interrupt not implemented\n"); |
109 | break; | ||
110 | case 'h': | ||
111 | usage(tee_usage); | ||
112 | break; | 94 | break; |
95 | #endif | ||
113 | default: | 96 | default: |
114 | fprintf(stderr, "tee: invalid option -- %c\n", opt); | ||
115 | usage(tee_usage); | 97 | usage(tee_usage); |
116 | } | 98 | } |
117 | } else { | 99 | } else { |
@@ -120,9 +102,15 @@ tee_main(int argc, char **argv) | |||
120 | } | 102 | } |
121 | 103 | ||
122 | /* init FILE pointers */ | 104 | /* init FILE pointers */ |
123 | FL_init(); | 105 | FL_end = 0; |
106 | FileList[0] = stdout; | ||
124 | for ( ; i < argc; i++) { | 107 | for ( ; i < argc; i++) { |
125 | FL_add(argv[i], opt_fopen); | 108 | /* add a file to FileList */ |
109 | file = fopen(argv[i], opt_fopen); | ||
110 | if (!file) { continue; } | ||
111 | if (FL_end < FL_MAX) { | ||
112 | FileList[++FL_end] = file; | ||
113 | } | ||
126 | } | 114 | } |
127 | 115 | ||
128 | /* read and redirect */ | 116 | /* read and redirect */ |
@@ -135,4 +123,4 @@ tee_main(int argc, char **argv) | |||
135 | exit(0); | 123 | exit(0); |
136 | } | 124 | } |
137 | 125 | ||
138 | /* $Id: tee.c,v 1.3 1999/12/10 07:41:03 beppu Exp $ */ | 126 | /* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */ |