calls to code only called once in tee. Made BB_KLOGD and option.
-Erik
* 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
* 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
* 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).
#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
#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
#define BB_HOSTNAME
#define BB_INIT
#define BB_KILL
+#define BB_KLOGD
//#define BB_LENGTH
#define BB_LN
#define BB_LOADFONT
//#define BB_MTAB
#define BB_MV
#define BB_PING
+#define BB_POWEROFF
//#define BB_PRINTF
#define BB_PS
#define BB_PWD
#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 _______________________________________________________________ */
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
}
}
-/* ________________________________________________________________________ */
-
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
fclose(file);
}
+/* ________________________________________________________________________ */
+
/* BusyBoxed tee(1) */
int
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++) {
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 {
}
/* 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 */
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 $ */
}
/* 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. */
"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);
}
} 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") ||
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) {
/* 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) {
}
/* 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. */
"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);
}
} 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") ||
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) {
/* 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) {
--- /dev/null
+/*
+ * 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));
+}
reboot_main(int argc, char ** argv)
{
/* don't assume init's pid == 1 */
- exit( kill(findInitPid(), SIGUSR2));
+ exit( kill(findInitPid(), SIGINT));
}
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);
--- /dev/null
+/*
+ * 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));
+}
reboot_main(int argc, char ** argv)
{
/* don't assume init's pid == 1 */
- exit( kill(findInitPid(), SIGUSR2));
+ exit( kill(findInitPid(), SIGINT));
}
"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";
close(fd);
}
+#ifdef BB_KLOGD
+
static void klogd_signal(int sig)
{
ksyslog(7, NULL, 0);
exit( TRUE);
}
-
static void doKlogd(void)
{
int priority=LOG_INFO;
}
+#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;
case 'n':
doFork = FALSE;
break;
+#ifdef BB_KLOGD
+ case 'K':
+ startKlogd = FALSE;
+ break;
+#endif
case 'O':
if (--argc == 0) {
usage(syslogd_usage);
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);
}
"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";
close(fd);
}
+#ifdef BB_KLOGD
+
static void klogd_signal(int sig)
{
ksyslog(7, NULL, 0);
exit( TRUE);
}
-
static void doKlogd(void)
{
int priority=LOG_INFO;
}
+#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;
case 'n':
doFork = FALSE;
break;
+#ifdef BB_KLOGD
+ case 'K':
+ startKlogd = FALSE;
+ break;
+#endif
case 'O':
if (--argc == 0) {
usage(syslogd_usage);
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);
}
#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 _______________________________________________________________ */
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
}
}
-/* ________________________________________________________________________ */
-
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
fclose(file);
}
+/* ________________________________________________________________________ */
+
/* BusyBoxed tee(1) */
int
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++) {
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 {
}
/* 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 */
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 $ */