Added poweroff (and adjusted init to use it). Inlined function

calls to code only called once in tee.  Made BB_KLOGD and option.
 -Erik
This commit is contained in:
Eric Andersen 1999-12-10 08:25:07 +00:00
parent c5ff0165ad
commit 2cb55077e2
16 changed files with 193 additions and 99 deletions

View File

@ -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

5
TODO
View File

@ -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).

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 $ */

17
init.c
View File

@ -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) {

View File

@ -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) {

31
init/poweroff.c Normal file
View File

@ -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));
}

View File

@ -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));
}

View File

@ -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);

31
poweroff.c Normal file
View File

@ -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));
}

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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);
}

60
tee.c
View File

@ -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 $ */