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 * kill now behaves itself properly, added 'kill -l' to list signals
* 'ls -l' was failing on long directories, since my_getid was leaking * 'ls -l' was failing on long directories, since my_getid was leaking
one file descriptor per file. Oops. 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. 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 * Added a prelinary du implementation. Some parameter parsing
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>) stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>)
* Implemented tee. -beppu * 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 * Allow tar to create archives with sockets, devices, and other special files
* Add in a mini insmod, rmmod, lsmod * 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 * mkfifo
* dnsdomainname * dnsdomainname
* traceroute/nslookup/netstat * traceroute/nslookup/netstat
@ -22,7 +19,7 @@ around to it some time. If you have any good ideas, please let me know.
* sort/uniq * sort/uniq
* wc * wc
* tr * tr
* expr (maybe)? (ash builtin?) * expr (maybe?) (ash builtin?)
* login/sulogin/passwd/getty (These are actully now part of tinylogin, which * login/sulogin/passwd/getty (These are actully now part of tinylogin, which
I've just started to maintain). I've just started to maintain).

View File

@ -138,6 +138,9 @@ static const struct Applet applets[] = {
#ifdef BB_PING //bin #ifdef BB_PING //bin
{"ping", ping_main}, {"ping", ping_main},
#endif #endif
#ifdef BB_POWEROFF //sbin
{"poweroff", poweroff_main},
#endif
#ifdef BB_PRINTF //usr/bin #ifdef BB_PRINTF //usr/bin
{"printf", printf_main}, {"printf", printf_main},
#endif #endif

View File

@ -138,6 +138,9 @@ static const struct Applet applets[] = {
#ifdef BB_PING //bin #ifdef BB_PING //bin
{"ping", ping_main}, {"ping", ping_main},
#endif #endif
#ifdef BB_POWEROFF //sbin
{"poweroff", poweroff_main},
#endif
#ifdef BB_PRINTF //usr/bin #ifdef BB_PRINTF //usr/bin
{"printf", printf_main}, {"printf", printf_main},
#endif #endif

View File

@ -28,6 +28,7 @@
#define BB_HOSTNAME #define BB_HOSTNAME
#define BB_INIT #define BB_INIT
#define BB_KILL #define BB_KILL
#define BB_KLOGD
//#define BB_LENGTH //#define BB_LENGTH
#define BB_LN #define BB_LN
#define BB_LOADFONT #define BB_LOADFONT
@ -47,6 +48,7 @@
//#define BB_MTAB //#define BB_MTAB
#define BB_MV #define BB_MV
#define BB_PING #define BB_PING
#define BB_POWEROFF
//#define BB_PRINTF //#define BB_PRINTF
#define BB_PS #define BB_PS
#define BB_PWD #define BB_PWD

View File

@ -25,11 +25,15 @@
#include <stdio.h> #include <stdio.h>
static const char tee_usage[] = static const char tee_usage[] =
"Usage: tee [OPTION]... [FILE]...\n" "tee [OPTION]... [FILE]...\n\n"
"Copy standard input to each FILE, and also to standard output.\n\n" "Copy standard input to each FILE, and also to standard output.\n\n"
" -a, append to the given FILEs, do not overwrite\n" "Options:\n"
" -i, ignore interrupt signals\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
" -h, this help message\n"; #if 0
"\t-i\tignore interrupt signals\n"
#endif
;
/* FileList _______________________________________________________________ */ /* FileList _______________________________________________________________ */
@ -39,27 +43,6 @@ static int FL_end;
typedef void (FL_Function)(FILE *file, char c); 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 */ /* apply a function to everything in FileList */
static void static void
@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c)
} }
} }
/* ________________________________________________________________________ */
/* FL_Function for writing to files*/ /* FL_Function for writing to files*/
static void static void
tee_fwrite(FILE *file, char c) tee_fwrite(FILE *file, char c)
@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c)
fclose(file); fclose(file);
} }
/* ________________________________________________________________________ */
/* BusyBoxed tee(1) */ /* BusyBoxed tee(1) */
int int
tee_main(int argc, char **argv) tee_main(int argc, char **argv)
@ -95,6 +78,7 @@ tee_main(int argc, char **argv)
char c; char c;
char opt; char opt;
char opt_fopen[2] = "w"; char opt_fopen[2] = "w";
FILE *file;
/* parse argv[] */ /* parse argv[] */
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
@ -104,14 +88,12 @@ tee_main(int argc, char **argv)
case 'a': case 'a':
opt_fopen[0] = 'a'; opt_fopen[0] = 'a';
break; break;
#if 0
case 'i': case 'i':
fprintf(stderr, "ingore interrupt not implemented\n"); fprintf(stderr, "ignore interrupt not implemented\n");
break;
case 'h':
usage(tee_usage);
break; break;
#endif
default: default:
fprintf(stderr, "tee: invalid option -- %c\n", opt);
usage(tee_usage); usage(tee_usage);
} }
} else { } else {
@ -120,9 +102,15 @@ tee_main(int argc, char **argv)
} }
/* init FILE pointers */ /* init FILE pointers */
FL_init(); FL_end = 0;
FileList[0] = stdout;
for ( ; i < argc; i++) { 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 */ /* read and redirect */
@ -135,4 +123,4 @@ tee_main(int argc, char **argv)
exit(0); 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 */ /* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal); message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
while ( *cmd) message(LOG, "%s ", *cmd++); while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
message(LOG, "'\r\n"); message(LOG|CONSOLE, "'\r\n");
/* Now run it. The new program will take over this PID, /* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */ * 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"); "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync(); sync();
#ifndef DEBUG_INIT #ifndef DEBUG_INIT
reboot(RB_HALT_SYSTEM); if (sig == SIGUSR2)
//reboot(RB_POWER_OFF); reboot(RB_POWER_OFF);
else
reboot(RB_HALT_SYSTEM);
#endif #endif
exit(0); exit(0);
} }
@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv)
} else } else
message(CONSOLE|LOG, "Mounting /proc: failed!\n"); message(CONSOLE|LOG, "Mounting /proc: failed!\n");
fprintf(stderr, "got proc\n");
/* Make sure there is enough memory to do something useful. */ /* Make sure there is enough memory to do something useful. */
check_memory(); check_memory();
fprintf(stderr, "got check_memory\n");
/* Check if we are supposed to be in single user mode */ /* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") || if ( argc > 1 && (!strcmp(argv[1], "single") ||
@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv)
tty1_command = shell_command; tty1_command = shell_command;
tty2_command = shell_command; tty2_command = shell_command;
} }
fprintf(stderr, "got single\n");
/* Make sure an init script exists before trying to run it */ /* Make sure an init script exists before trying to run it */
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { 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 */ /* Make sure /sbin/getty exists before trying to run it */
if (stat(GETTY, &statbuf)==0) { if (stat(GETTY, &statbuf)==0) {
char* where; char* where;
fprintf(stderr, "\n");
wait_for_enter_tty2 = FALSE; wait_for_enter_tty2 = FALSE;
where = strrchr( console, '/'); where = strrchr( console, '/');
if ( where != NULL) { if ( where != NULL) {

View File

@ -336,9 +336,9 @@ static pid_t run(const char * const* command,
} }
/* Log the process name and args */ /* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal); message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
while ( *cmd) message(LOG, "%s ", *cmd++); while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
message(LOG, "'\r\n"); message(LOG|CONSOLE, "'\r\n");
/* Now run it. The new program will take over this PID, /* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */ * 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"); "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync(); sync();
#ifndef DEBUG_INIT #ifndef DEBUG_INIT
reboot(RB_HALT_SYSTEM); if (sig == SIGUSR2)
//reboot(RB_POWER_OFF); reboot(RB_POWER_OFF);
else
reboot(RB_HALT_SYSTEM);
#endif #endif
exit(0); exit(0);
} }
@ -514,8 +516,11 @@ extern int init_main(int argc, char **argv)
} else } else
message(CONSOLE|LOG, "Mounting /proc: failed!\n"); message(CONSOLE|LOG, "Mounting /proc: failed!\n");
fprintf(stderr, "got proc\n");
/* Make sure there is enough memory to do something useful. */ /* Make sure there is enough memory to do something useful. */
check_memory(); check_memory();
fprintf(stderr, "got check_memory\n");
/* Check if we are supposed to be in single user mode */ /* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") || if ( argc > 1 && (!strcmp(argv[1], "single") ||
@ -524,6 +529,7 @@ extern int init_main(int argc, char **argv)
tty1_command = shell_command; tty1_command = shell_command;
tty2_command = shell_command; tty2_command = shell_command;
} }
fprintf(stderr, "got single\n");
/* Make sure an init script exists before trying to run it */ /* Make sure an init script exists before trying to run it */
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) { 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 */ /* Make sure /sbin/getty exists before trying to run it */
if (stat(GETTY, &statbuf)==0) { if (stat(GETTY, &statbuf)==0) {
char* where; char* where;
fprintf(stderr, "\n");
wait_for_enter_tty2 = FALSE; wait_for_enter_tty2 = FALSE;
where = strrchr( console, '/'); where = strrchr( console, '/');
if ( where != NULL) { 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) reboot_main(int argc, char ** argv)
{ {
/* don't assume init's pid == 1 */ /* 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 mt_main(int argc, char** argv);
extern int mv_main(int argc, char** argv); extern int mv_main(int argc, char** argv);
extern int ping_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 printf_main(int argc, char** argv);
extern int ps_main(int argc, char** argv); extern int ps_main(int argc, char** argv);
extern int pwd_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) reboot_main(int argc, char ** argv)
{ {
/* don't assume init's pid == 1 */ /* 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" "Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\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" "\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"; "\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
@ -251,6 +254,8 @@ static void doSyslogd(void)
close(fd); close(fd);
} }
#ifdef BB_KLOGD
static void klogd_signal(int sig) static void klogd_signal(int sig)
{ {
ksyslog(7, NULL, 0); ksyslog(7, NULL, 0);
@ -259,7 +264,6 @@ static void klogd_signal(int sig)
exit( TRUE); exit( TRUE);
} }
static void doKlogd(void) static void doKlogd(void)
{ {
int priority=LOG_INFO; int priority=LOG_INFO;
@ -325,11 +329,15 @@ static void doKlogd(void)
} }
#endif
extern int syslogd_main(int argc, char **argv) extern int syslogd_main(int argc, char **argv)
{ {
int pid, klogd_pid; int pid, klogd_pid;
int doFork = TRUE; int doFork = TRUE;
#ifdef BB_KLOGD
int startKlogd = TRUE;
#endif
char *p; char *p;
char **argv1=argv; char **argv1=argv;
@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv)
case 'n': case 'n':
doFork = FALSE; doFork = FALSE;
break; break;
#ifdef BB_KLOGD
case 'K':
startKlogd = FALSE;
break;
#endif
case 'O': case 'O':
if (--argc == 0) { if (--argc == 0) {
usage(syslogd_usage); usage(syslogd_usage);
@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd(); doSyslogd();
} }
#ifdef BB_KLOGD
/* Start up the klogd process */ /* Start up the klogd process */
klogd_pid = fork(); if (startKlogd == TRUE) {
if (klogd_pid == 0 ) { klogd_pid = fork();
strncpy(argv[0], "klogd", strlen(argv[0])); if (klogd_pid == 0 ) {
doKlogd(); strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
} }
#endif
exit( TRUE); exit( TRUE);
} }

View File

@ -62,6 +62,9 @@ static const char syslogd_usage[] =
"Options:\n" "Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\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" "\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"; "\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
@ -251,6 +254,8 @@ static void doSyslogd(void)
close(fd); close(fd);
} }
#ifdef BB_KLOGD
static void klogd_signal(int sig) static void klogd_signal(int sig)
{ {
ksyslog(7, NULL, 0); ksyslog(7, NULL, 0);
@ -259,7 +264,6 @@ static void klogd_signal(int sig)
exit( TRUE); exit( TRUE);
} }
static void doKlogd(void) static void doKlogd(void)
{ {
int priority=LOG_INFO; int priority=LOG_INFO;
@ -325,11 +329,15 @@ static void doKlogd(void)
} }
#endif
extern int syslogd_main(int argc, char **argv) extern int syslogd_main(int argc, char **argv)
{ {
int pid, klogd_pid; int pid, klogd_pid;
int doFork = TRUE; int doFork = TRUE;
#ifdef BB_KLOGD
int startKlogd = TRUE;
#endif
char *p; char *p;
char **argv1=argv; char **argv1=argv;
@ -345,6 +353,11 @@ extern int syslogd_main(int argc, char **argv)
case 'n': case 'n':
doFork = FALSE; doFork = FALSE;
break; break;
#ifdef BB_KLOGD
case 'K':
startKlogd = FALSE;
break;
#endif
case 'O': case 'O':
if (--argc == 0) { if (--argc == 0) {
usage(syslogd_usage); usage(syslogd_usage);
@ -375,12 +388,16 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd(); doSyslogd();
} }
#ifdef BB_KLOGD
/* Start up the klogd process */ /* Start up the klogd process */
klogd_pid = fork(); if (startKlogd == TRUE) {
if (klogd_pid == 0 ) { klogd_pid = fork();
strncpy(argv[0], "klogd", strlen(argv[0])); if (klogd_pid == 0 ) {
doKlogd(); strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
} }
#endif
exit( TRUE); exit( TRUE);
} }

60
tee.c
View File

@ -25,11 +25,15 @@
#include <stdio.h> #include <stdio.h>
static const char tee_usage[] = static const char tee_usage[] =
"Usage: tee [OPTION]... [FILE]...\n" "tee [OPTION]... [FILE]...\n\n"
"Copy standard input to each FILE, and also to standard output.\n\n" "Copy standard input to each FILE, and also to standard output.\n\n"
" -a, append to the given FILEs, do not overwrite\n" "Options:\n"
" -i, ignore interrupt signals\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
" -h, this help message\n"; #if 0
"\t-i\tignore interrupt signals\n"
#endif
;
/* FileList _______________________________________________________________ */ /* FileList _______________________________________________________________ */
@ -39,27 +43,6 @@ static int FL_end;
typedef void (FL_Function)(FILE *file, char c); 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 */ /* apply a function to everything in FileList */
static void static void
@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c)
} }
} }
/* ________________________________________________________________________ */
/* FL_Function for writing to files*/ /* FL_Function for writing to files*/
static void static void
tee_fwrite(FILE *file, char c) tee_fwrite(FILE *file, char c)
@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c)
fclose(file); fclose(file);
} }
/* ________________________________________________________________________ */
/* BusyBoxed tee(1) */ /* BusyBoxed tee(1) */
int int
tee_main(int argc, char **argv) tee_main(int argc, char **argv)
@ -95,6 +78,7 @@ tee_main(int argc, char **argv)
char c; char c;
char opt; char opt;
char opt_fopen[2] = "w"; char opt_fopen[2] = "w";
FILE *file;
/* parse argv[] */ /* parse argv[] */
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
@ -104,14 +88,12 @@ tee_main(int argc, char **argv)
case 'a': case 'a':
opt_fopen[0] = 'a'; opt_fopen[0] = 'a';
break; break;
#if 0
case 'i': case 'i':
fprintf(stderr, "ingore interrupt not implemented\n"); fprintf(stderr, "ignore interrupt not implemented\n");
break;
case 'h':
usage(tee_usage);
break; break;
#endif
default: default:
fprintf(stderr, "tee: invalid option -- %c\n", opt);
usage(tee_usage); usage(tee_usage);
} }
} else { } else {
@ -120,9 +102,15 @@ tee_main(int argc, char **argv)
} }
/* init FILE pointers */ /* init FILE pointers */
FL_init(); FL_end = 0;
FileList[0] = stdout;
for ( ; i < argc; i++) { 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 */ /* read and redirect */
@ -135,4 +123,4 @@ tee_main(int argc, char **argv)
exit(0); 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 $ */