aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog4
-rw-r--r--TODO5
-rw-r--r--applets/busybox.c3
-rw-r--r--busybox.c3
-rw-r--r--busybox.def.h2
-rw-r--r--coreutils/tee.c60
-rw-r--r--init.c17
-rw-r--r--init/init.c17
-rw-r--r--init/poweroff.c31
-rw-r--r--init/reboot.c2
-rw-r--r--internal.h1
-rw-r--r--poweroff.c31
-rw-r--r--reboot.c2
-rw-r--r--sysklogd/syslogd.c27
-rw-r--r--syslogd.c27
-rw-r--r--tee.c60
16 files changed, 193 insertions, 99 deletions
diff --git a/Changelog b/Changelog
index 3f2efba74..4f8fb0902 100644
--- a/Changelog
+++ b/Changelog
@@ -12,8 +12,10 @@
* kill now behaves itself properly, added 'kill -l' to list signals
* 'ls -l' was failing on long directories, since my_getid was leaking
one file descriptor per file. Oops.
- * Fixed rebooting from init. I'd left some debugging code in
+ * Fixed rebooting from init. I'd accidently left some debugging code in
which blocked reboots.
+ * Fixed reboot, halt (and added poweroff) such that they handle it when
+ init is not at PID 1 (like when running in an initrd).
* Added a prelinary du implementation. Some parameter parsing
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>)
* Implemented tee. -beppu
diff --git a/TODO b/TODO
index 5daa67a64..4cc82d57e 100644
--- a/TODO
+++ b/TODO
@@ -9,9 +9,6 @@ around to it some time. If you have any good ideas, please let me know.
* Allow tar to create archives with sockets, devices, and other special files
* Add in a mini insmod, rmmod, lsmod
-* Change init so halt, reboot (and poweroff) work with an initrd
- when init is not PID 1
-* poweroff
* mkfifo
* dnsdomainname
* traceroute/nslookup/netstat
@@ -22,7 +19,7 @@ around to it some time. If you have any good ideas, please let me know.
* sort/uniq
* wc
* tr
-* expr (maybe)? (ash builtin?)
+* expr (maybe?) (ash builtin?)
* login/sulogin/passwd/getty (These are actully now part of tinylogin, which
I've just started to maintain).
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[] = {
#ifdef BB_PING //bin
{"ping", ping_main},
#endif
+#ifdef BB_POWEROFF //sbin
+ {"poweroff", poweroff_main},
+#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#endif
diff --git a/busybox.c b/busybox.c
index f4573019b..d1eb38a0b 100644
--- a/busybox.c
+++ b/busybox.c
@@ -138,6 +138,9 @@ static const struct Applet applets[] = {
#ifdef BB_PING //bin
{"ping", ping_main},
#endif
+#ifdef BB_POWEROFF //sbin
+ {"poweroff", poweroff_main},
+#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#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 @@
#define BB_HOSTNAME
#define BB_INIT
#define BB_KILL
+#define BB_KLOGD
//#define BB_LENGTH
#define BB_LN
#define BB_LOADFONT
@@ -47,6 +48,7 @@
//#define BB_MTAB
#define BB_MV
#define BB_PING
+#define BB_POWEROFF
//#define BB_PRINTF
#define BB_PS
#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 @@
#include <stdio.h>
static const char tee_usage[] =
-"Usage: tee [OPTION]... [FILE]...\n"
-"Copy standard input to each FILE, and also to standard output.\n\n"
-" -a, append to the given FILEs, do not overwrite\n"
-" -i, ignore interrupt signals\n"
-" -h, this help message\n";
+ "tee [OPTION]... [FILE]...\n\n"
+ "Copy standard input to each FILE, and also to standard output.\n\n"
+ "Options:\n"
+ "\t-a\tappend to the given FILEs, do not overwrite\n"
+#if 0
+ "\t-i\tignore interrupt signals\n"
+#endif
+ ;
+
/* FileList _______________________________________________________________ */
@@ -39,27 +43,6 @@ static int FL_end;
typedef void (FL_Function)(FILE *file, char c);
-/* initialize FileList */
-static void
-FL_init()
-{
- FL_end = 0;
- FileList[0] = stdout;
-}
-
-/* add a file to FileList */
-static int
-FL_add(const char *filename, char *opt_open)
-{
- FILE *file;
-
- file = fopen(filename, opt_open);
- if (!file) { return 0; };
- if (FL_end < FL_MAX) {
- FileList[++FL_end] = file;
- }
- return 1;
-}
/* apply a function to everything in FileList */
static void
@@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c)
}
}
-/* ________________________________________________________________________ */
-
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
@@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c)
fclose(file);
}
+/* ________________________________________________________________________ */
+
/* BusyBoxed tee(1) */
int
tee_main(int argc, char **argv)
@@ -95,6 +78,7 @@ tee_main(int argc, char **argv)
char c;
char opt;
char opt_fopen[2] = "w";
+ FILE *file;
/* parse argv[] */
for (i = 1; i < argc; i++) {
@@ -104,14 +88,12 @@ tee_main(int argc, char **argv)
case 'a':
opt_fopen[0] = 'a';
break;
+#if 0
case 'i':
- fprintf(stderr, "ingore interrupt not implemented\n");
- break;
- case 'h':
- usage(tee_usage);
+ fprintf(stderr, "ignore interrupt not implemented\n");
break;
+#endif
default:
- fprintf(stderr, "tee: invalid option -- %c\n", opt);
usage(tee_usage);
}
} else {
@@ -120,9 +102,15 @@ tee_main(int argc, char **argv)
}
/* init FILE pointers */
- FL_init();
+ FL_end = 0;
+ FileList[0] = stdout;
for ( ; i < argc; i++) {
- FL_add(argv[i], opt_fopen);
+ /* add a file to FileList */
+ file = fopen(argv[i], opt_fopen);
+ if (!file) { continue; }
+ if (FL_end < FL_MAX) {
+ FileList[++FL_end] = file;
+ }
}
/* read and redirect */
@@ -135,4 +123,4 @@ tee_main(int argc, char **argv)
exit(0);
}
-/* $Id: tee.c,v 1.3 1999/12/10 07:41:03 beppu Exp $ */
+/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
diff --git a/init.c b/init.c
index d2e9a7e97..3c800b9b2 100644
--- a/init.c
+++ b/init.c
@@ -336,9 +336,9 @@ static pid_t run(const char * const* command,
}
/* Log the process name and args */
- message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
- while ( *cmd) message(LOG, "%s ", *cmd++);
- message(LOG, "'\r\n");
+ message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
+ while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
+ message(LOG|CONSOLE, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
@@ -418,8 +418,10 @@ static void halt_signal(int sig)
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync();
#ifndef DEBUG_INIT
- reboot(RB_HALT_SYSTEM);
- //reboot(RB_POWER_OFF);
+ if (sig == SIGUSR2)
+ reboot(RB_POWER_OFF);
+ else
+ reboot(RB_HALT_SYSTEM);
#endif
exit(0);
}
@@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv)
} else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
+fprintf(stderr, "got proc\n");
+
/* Make sure there is enough memory to do something useful. */
check_memory();
+fprintf(stderr, "got check_memory\n");
/* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") ||
@@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv)
tty1_command = shell_command;
tty2_command = shell_command;
}
+fprintf(stderr, "got single\n");
/* Make sure an init script exists before trying to run it */
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
@@ -535,6 +541,7 @@ extern int init_main(int argc, char **argv)
/* Make sure /sbin/getty exists before trying to run it */
if (stat(GETTY, &statbuf)==0) {
char* where;
+fprintf(stderr, "\n");
wait_for_enter_tty2 = FALSE;
where = strrchr( console, '/');
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,
}
/* Log the process name and args */
- message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
- while ( *cmd) message(LOG, "%s ", *cmd++);
- message(LOG, "'\r\n");
+ message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
+ while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
+ message(LOG|CONSOLE, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
@@ -418,8 +418,10 @@ static void halt_signal(int sig)
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync();
#ifndef DEBUG_INIT
- reboot(RB_HALT_SYSTEM);
- //reboot(RB_POWER_OFF);
+ if (sig == SIGUSR2)
+ reboot(RB_POWER_OFF);
+ else
+ reboot(RB_HALT_SYSTEM);
#endif
exit(0);
}
@@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv)
} else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
+fprintf(stderr, "got proc\n");
+
/* Make sure there is enough memory to do something useful. */
check_memory();
+fprintf(stderr, "got check_memory\n");
/* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") ||
@@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv)
tty1_command = shell_command;
tty2_command = shell_command;
}
+fprintf(stderr, "got single\n");
/* Make sure an init script exists before trying to run it */
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
@@ -535,6 +541,7 @@ extern int init_main(int argc, char **argv)
/* Make sure /sbin/getty exists before trying to run it */
if (stat(GETTY, &statbuf)==0) {
char* where;
+fprintf(stderr, "\n");
wait_for_enter_tty2 = FALSE;
where = strrchr( console, '/');
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 @@
+/*
+ * Mini poweroff implementation for busybox
+ *
+ *
+ * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <signal.h>
+
+extern int
+poweroff_main(int argc, char ** argv)
+{
+ /* don't assume init's pid == 1 */
+ exit( kill(findInitPid(), SIGUSR2));
+}
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
reboot_main(int argc, char ** argv)
{
/* don't assume init's pid == 1 */
- exit( kill(findInitPid(), SIGUSR2));
+ exit( kill(findInitPid(), SIGINT));
}
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);
extern int mt_main(int argc, char** argv);
extern int mv_main(int argc, char** argv);
extern int ping_main(int argc, char **argv);
+extern int poweroff_main(int argc, char **argv);
extern int printf_main(int argc, char** argv);
extern int ps_main(int argc, char** argv);
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 @@
+/*
+ * Mini poweroff implementation for busybox
+ *
+ *
+ * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <signal.h>
+
+extern int
+poweroff_main(int argc, char ** argv)
+{
+ /* don't assume init's pid == 1 */
+ exit( kill(findInitPid(), SIGUSR2));
+}
diff --git a/reboot.c b/reboot.c
index ff2c6ad18..1339a60f4 100644
--- a/reboot.c
+++ b/reboot.c
@@ -27,5 +27,5 @@ extern int
reboot_main(int argc, char ** argv)
{
/* don't assume init's pid == 1 */
- exit( kill(findInitPid(), SIGUSR2));
+ exit( kill(findInitPid(), SIGINT));
}
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[] =
"Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
"\t-n\tDo not fork into the background (for when run by init)\n"
+#ifdef BB_KLOGD
+ "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n"
+#endif
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
@@ -251,6 +254,8 @@ static void doSyslogd(void)
close(fd);
}
+#ifdef BB_KLOGD
+
static void klogd_signal(int sig)
{
ksyslog(7, NULL, 0);
@@ -259,7 +264,6 @@ static void klogd_signal(int sig)
exit( TRUE);
}
-
static void doKlogd(void)
{
int priority=LOG_INFO;
@@ -325,11 +329,15 @@ static void doKlogd(void)
}
+#endif
extern int syslogd_main(int argc, char **argv)
{
int pid, klogd_pid;
int doFork = TRUE;
+#ifdef BB_KLOGD
+ int startKlogd = TRUE;
+#endif
char *p;
char **argv1=argv;
@@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv)
case 'n':
doFork = FALSE;
break;
+#ifdef BB_KLOGD
+ case 'K':
+ startKlogd = FALSE;
+ break;
+#endif
case 'O':
if (--argc == 0) {
usage(syslogd_usage);
@@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd();
}
+#ifdef BB_KLOGD
/* Start up the klogd process */
- klogd_pid = fork();
- if (klogd_pid == 0 ) {
- strncpy(argv[0], "klogd", strlen(argv[0]));
- doKlogd();
+ if (startKlogd == TRUE) {
+ klogd_pid = fork();
+ if (klogd_pid == 0 ) {
+ strncpy(argv[0], "klogd", strlen(argv[0]));
+ doKlogd();
+ }
}
+#endif
exit( TRUE);
}
diff --git a/syslogd.c b/syslogd.c
index 1f3e31225..24c721f8e 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -62,6 +62,9 @@ static const char syslogd_usage[] =
"Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
"\t-n\tDo not fork into the background (for when run by init)\n"
+#ifdef BB_KLOGD
+ "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n"
+#endif
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
@@ -251,6 +254,8 @@ static void doSyslogd(void)
close(fd);
}
+#ifdef BB_KLOGD
+
static void klogd_signal(int sig)
{
ksyslog(7, NULL, 0);
@@ -259,7 +264,6 @@ static void klogd_signal(int sig)
exit( TRUE);
}
-
static void doKlogd(void)
{
int priority=LOG_INFO;
@@ -325,11 +329,15 @@ static void doKlogd(void)
}
+#endif
extern int syslogd_main(int argc, char **argv)
{
int pid, klogd_pid;
int doFork = TRUE;
+#ifdef BB_KLOGD
+ int startKlogd = TRUE;
+#endif
char *p;
char **argv1=argv;
@@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv)
case 'n':
doFork = FALSE;
break;
+#ifdef BB_KLOGD
+ case 'K':
+ startKlogd = FALSE;
+ break;
+#endif
case 'O':
if (--argc == 0) {
usage(syslogd_usage);
@@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd();
}
+#ifdef BB_KLOGD
/* Start up the klogd process */
- klogd_pid = fork();
- if (klogd_pid == 0 ) {
- strncpy(argv[0], "klogd", strlen(argv[0]));
- doKlogd();
+ if (startKlogd == TRUE) {
+ klogd_pid = fork();
+ if (klogd_pid == 0 ) {
+ strncpy(argv[0], "klogd", strlen(argv[0]));
+ doKlogd();
+ }
}
+#endif
exit( TRUE);
}
diff --git a/tee.c b/tee.c
index 45128b568..8d1ca6efd 100644
--- a/tee.c
+++ b/tee.c
@@ -25,11 +25,15 @@
#include <stdio.h>
static const char tee_usage[] =
-"Usage: tee [OPTION]... [FILE]...\n"
-"Copy standard input to each FILE, and also to standard output.\n\n"
-" -a, append to the given FILEs, do not overwrite\n"
-" -i, ignore interrupt signals\n"
-" -h, this help message\n";
+ "tee [OPTION]... [FILE]...\n\n"
+ "Copy standard input to each FILE, and also to standard output.\n\n"
+ "Options:\n"
+ "\t-a\tappend to the given FILEs, do not overwrite\n"
+#if 0
+ "\t-i\tignore interrupt signals\n"
+#endif
+ ;
+
/* FileList _______________________________________________________________ */
@@ -39,27 +43,6 @@ static int FL_end;
typedef void (FL_Function)(FILE *file, char c);
-/* initialize FileList */
-static void
-FL_init()
-{
- FL_end = 0;
- FileList[0] = stdout;
-}
-
-/* add a file to FileList */
-static int
-FL_add(const char *filename, char *opt_open)
-{
- FILE *file;
-
- file = fopen(filename, opt_open);
- if (!file) { return 0; };
- if (FL_end < FL_MAX) {
- FileList[++FL_end] = file;
- }
- return 1;
-}
/* apply a function to everything in FileList */
static void
@@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c)
}
}
-/* ________________________________________________________________________ */
-
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
@@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c)
fclose(file);
}
+/* ________________________________________________________________________ */
+
/* BusyBoxed tee(1) */
int
tee_main(int argc, char **argv)
@@ -95,6 +78,7 @@ tee_main(int argc, char **argv)
char c;
char opt;
char opt_fopen[2] = "w";
+ FILE *file;
/* parse argv[] */
for (i = 1; i < argc; i++) {
@@ -104,14 +88,12 @@ tee_main(int argc, char **argv)
case 'a':
opt_fopen[0] = 'a';
break;
+#if 0
case 'i':
- fprintf(stderr, "ingore interrupt not implemented\n");
- break;
- case 'h':
- usage(tee_usage);
+ fprintf(stderr, "ignore interrupt not implemented\n");
break;
+#endif
default:
- fprintf(stderr, "tee: invalid option -- %c\n", opt);
usage(tee_usage);
}
} else {
@@ -120,9 +102,15 @@ tee_main(int argc, char **argv)
}
/* init FILE pointers */
- FL_init();
+ FL_end = 0;
+ FileList[0] = stdout;
for ( ; i < argc; i++) {
- FL_add(argv[i], opt_fopen);
+ /* add a file to FileList */
+ file = fopen(argv[i], opt_fopen);
+ if (!file) { continue; }
+ if (FL_end < FL_MAX) {
+ FileList[++FL_end] = file;
+ }
}
/* read and redirect */
@@ -135,4 +123,4 @@ tee_main(int argc, char **argv)
exit(0);
}
-/* $Id: tee.c,v 1.3 1999/12/10 07:41:03 beppu Exp $ */
+/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */