aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-15 22:28:50 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-15 22:28:50 +0000
commit3163821967821518cfa4c4315f775ec5301bb023 (patch)
treefe0c764cb41cc3ea86c3dcd270e48fa6a1abebcd
parentb7cc49d992ed9a5a59261096012e0b4a811bb7f4 (diff)
downloadbusybox-w32-3163821967821518cfa4c4315f775ec5301bb023.tar.gz
busybox-w32-3163821967821518cfa4c4315f775ec5301bb023.tar.bz2
busybox-w32-3163821967821518cfa4c4315f775ec5301bb023.zip
Sync up busybox with the latest and greatest. This is not stuff for
the Embedix release. -Erik
-rw-r--r--Changelog15
-rw-r--r--Makefile22
-rw-r--r--TODO5
-rw-r--r--applets/busybox.c29
-rw-r--r--busybox.c29
-rw-r--r--busybox.def.h21
-rw-r--r--coreutils/hostid.c28
-rw-r--r--coreutils/logname.c40
-rw-r--r--coreutils/tty.c42
-rw-r--r--coreutils/wc.c162
-rw-r--r--coreutils/whoami.c44
-rw-r--r--coreutils/yes.c41
-rw-r--r--docs/CommandList9
-rw-r--r--hostid.c28
-rw-r--r--init.c57
-rw-r--r--init/init.c57
-rw-r--r--internal.h32
-rw-r--r--logname.c40
-rw-r--r--mount.c4
-rw-r--r--tty.c42
-rw-r--r--util-linux/mount.c4
-rw-r--r--utility.c2
-rw-r--r--wc.c162
-rw-r--r--whoami.c44
-rw-r--r--yes.c41
25 files changed, 907 insertions, 93 deletions
diff --git a/Changelog b/Changelog
index 6c68d844d..878b9c698 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,6 @@
10.41 10.41
2 * New App: wc -- contributed by Edward Betts <edward@debian.org> 2 * New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
3 by Edward Betts <edward@debian.org>
3 * Fixed a bug in both cp and mv preventing 'cp foo/README bar' 4 * Fixed a bug in both cp and mv preventing 'cp foo/README bar'
4 type commands (file in a directory to another directory) 5 type commands (file in a directory to another directory)
5 from working. 6 from working.
@@ -13,6 +14,18 @@
13 * Added -o loop option for mount, and support in umount for loop 14 * Added -o loop option for mount, and support in umount for loop
14 devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins 15 devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
15 <bcollins@debian.org> 16 <bcollins@debian.org>
17 * Several fixes from Marco Pantaleoni <panta@prosa.it>
18 * compile in fullWrite() not only if BB_TAR is defined, but also
19 if BB_CP or BB_MV are (fullWrite() is referenced by copyFile())
20 * add some compiler optimizations to further reduce executable size
21 (as a side note, on my machines the largest code is generated by
22 gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with -O2
23 -m386 ...)
24 * Compile no longer fails if busybox.def.h defines BB_FEATURE_LINUXRC
25 but not BB_INIT. (init_main used to be referenced, but not compiled)
26 * Fixed a bug in setting TERM for serial console support. TERM now
27 defaults to "ansi" for serial consoles.
28 * Fixed a bug in handling the CONSOLE env. variable for serial consoles.
16 29
17 -Erik Andersen 30 -Erik Andersen
18 31
diff --git a/Makefile b/Makefile
index d0779c5c0..91d4bd1c4 100644
--- a/Makefile
+++ b/Makefile
@@ -33,10 +33,11 @@ ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
33 33
34GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" ) 34GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
35GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" ) 35GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
36GCCEGCS=$(shell $(CC) --version | sed -n "s/.*\(egcs\).*/\1/p" )
36 37
37GCCSUPPORTSOPTSIZE=$(shell \ 38GCCSUPPORTSOPTSIZE=$(shell \
38if ( test $(GCCMAJVERSION) -eq 2 ) ; then \ 39if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
39 if ( test $(GCCMINVERSION) -ge 91 ) ; then \ 40 if ( test $(GCCMINVERSION) -ge 66 ) ; then \
40 echo "true"; \ 41 echo "true"; \
41 else \ 42 else \
42 echo "false"; \ 43 echo "false"; \
@@ -49,11 +50,26 @@ else \
49 fi; \ 50 fi; \
50fi; ) 51fi; )
51 52
53GCCISEGCS=$(shell \
54if ( test "x$(GCCEGCS)" == "xegcs" ) ; then \
55 echo "true"; \
56 else \
57 echo "false"; \
58 fi; )
59
60EGCSEXTREMEFLAGS = -m386 -mcpu=i386 -march=i386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
61GCCEXTREMEFLAGS = -m386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
62
63ifeq ($(GCCISEGCS), true)
64 EXTREMEFLAGS = $(EGCSEXTREMEFLAGS)
65else
66 EXTREMEFLAGS = $(GCCEXTREMEFLAGS)
67endif
52 68
53ifeq ($(GCCSUPPORTSOPTSIZE), true) 69ifeq ($(GCCSUPPORTSOPTSIZE), true)
54 OPTIMIZATION=-Os 70 OPTIMIZATION=-Os $(EXTREMEFLAGS)
55else 71else
56 OPTIMIZATION=-O2 72 OPTIMIZATION=-O2 $(EXTREMEFLAGS)
57endif 73endif
58 74
59# -D_GNU_SOURCE is needed because environ is used in init.c 75# -D_GNU_SOURCE is needed because environ is used in init.c
diff --git a/TODO b/TODO
index 4d209bb46..b951767ea 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,11 @@ around to it some time. If you have any good ideas, please let me know.
6* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not 6* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
7 needed or wanted in busybox (or else I'd have to link in libcrypt). 7 needed or wanted in busybox (or else I'd have to link in libcrypt).
8 8
9* Networking apps are probably going to be split out some time soon into a
10 separate package (named perhaps tiny-netkit?). This currently includes
11 hostid, hostname, mnc, and ping.
12
13
9 -Erik 14 -Erik
10 15
11----------- 16-----------
diff --git a/applets/busybox.c b/applets/busybox.c
index a00f90be0..67485de8d 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -3,8 +3,18 @@
3#include <string.h> 3#include <string.h>
4#include <errno.h> 4#include <errno.h>
5 5
6#ifndef BB_INIT
7#undef BB_FEATURE_LINUXRC
8#endif
9
6static int been_there_done_that = 0; 10static int been_there_done_that = 0;
7 11
12/* It has been alledged that doing such things can
13 * help reduce binary size when staticly linking,
14 * of course with glibc, this is unlikely as long
15 * as we use things like printf -- perhaps a printf
16 * replacement may be in order
17 */
8#if 0 18#if 0
9void exit (int status) __attribute__ ((noreturn)); 19void exit (int status) __attribute__ ((noreturn));
10void exit (int status) { _exit(status); }; 20void exit (int status) { _exit(status); };
@@ -91,6 +101,9 @@ static const struct Applet applets[] = {
91#ifdef BB_HEAD //bin 101#ifdef BB_HEAD //bin
92 {"head", head_main}, 102 {"head", head_main},
93#endif 103#endif
104#ifdef BB_HOSTID //usr/bin
105 {"hostid", hostid_main},
106#endif
94#ifdef BB_HOSTNAME //bin 107#ifdef BB_HOSTNAME //bin
95 {"hostname", hostname_main}, 108 {"hostname", hostname_main},
96#endif 109#endif
@@ -209,6 +222,9 @@ static const struct Applet applets[] = {
209#ifdef BB_LOGGER //usr/bin 222#ifdef BB_LOGGER //usr/bin
210 {"logger", logger_main}, 223 {"logger", logger_main},
211#endif 224#endif
225#ifdef BB_LOGNAME //usr/bin
226 {"logname", logname_main},
227#endif
212#ifdef BB_SWAPONOFF //sbin 228#ifdef BB_SWAPONOFF //sbin
213 {"swapon", swap_on_off_main}, 229 {"swapon", swap_on_off_main},
214 {"swapoff", swap_on_off_main}, 230 {"swapoff", swap_on_off_main},
@@ -229,8 +245,8 @@ static const struct Applet applets[] = {
229 {"true", true_main}, 245 {"true", true_main},
230 {"false", false_main}, 246 {"false", false_main},
231#endif 247#endif
232#ifdef BB_WC //usr/bin 248#ifdef BB_TTY //usr/bin
233 {"wc", wc_main}, 249 {"tty", tty_main},
234#endif 250#endif
235#ifdef BB_UNAME //bin 251#ifdef BB_UNAME //bin
236 {"uname", uname_main}, 252 {"uname", uname_main},
@@ -244,6 +260,15 @@ static const struct Applet applets[] = {
244#ifdef BB_UPDATE //sbin 260#ifdef BB_UPDATE //sbin
245 {"update", update_main}, 261 {"update", update_main},
246#endif 262#endif
263#ifdef BB_WC //usr/bin
264 {"wc", wc_main},
265#endif
266#ifdef BB_WHOAMI //usr/bin
267 {"whoami", whoami_main},
268#endif
269#ifdef BB_YES //usr/bin
270 {"yes", yes_main},
271#endif
247#ifdef BB_GUNZIP //bin 272#ifdef BB_GUNZIP //bin
248 {"zcat", gunzip_main}, 273 {"zcat", gunzip_main},
249 {"gunzip", gunzip_main}, 274 {"gunzip", gunzip_main},
diff --git a/busybox.c b/busybox.c
index a00f90be0..67485de8d 100644
--- a/busybox.c
+++ b/busybox.c
@@ -3,8 +3,18 @@
3#include <string.h> 3#include <string.h>
4#include <errno.h> 4#include <errno.h>
5 5
6#ifndef BB_INIT
7#undef BB_FEATURE_LINUXRC
8#endif
9
6static int been_there_done_that = 0; 10static int been_there_done_that = 0;
7 11
12/* It has been alledged that doing such things can
13 * help reduce binary size when staticly linking,
14 * of course with glibc, this is unlikely as long
15 * as we use things like printf -- perhaps a printf
16 * replacement may be in order
17 */
8#if 0 18#if 0
9void exit (int status) __attribute__ ((noreturn)); 19void exit (int status) __attribute__ ((noreturn));
10void exit (int status) { _exit(status); }; 20void exit (int status) { _exit(status); };
@@ -91,6 +101,9 @@ static const struct Applet applets[] = {
91#ifdef BB_HEAD //bin 101#ifdef BB_HEAD //bin
92 {"head", head_main}, 102 {"head", head_main},
93#endif 103#endif
104#ifdef BB_HOSTID //usr/bin
105 {"hostid", hostid_main},
106#endif
94#ifdef BB_HOSTNAME //bin 107#ifdef BB_HOSTNAME //bin
95 {"hostname", hostname_main}, 108 {"hostname", hostname_main},
96#endif 109#endif
@@ -209,6 +222,9 @@ static const struct Applet applets[] = {
209#ifdef BB_LOGGER //usr/bin 222#ifdef BB_LOGGER //usr/bin
210 {"logger", logger_main}, 223 {"logger", logger_main},
211#endif 224#endif
225#ifdef BB_LOGNAME //usr/bin
226 {"logname", logname_main},
227#endif
212#ifdef BB_SWAPONOFF //sbin 228#ifdef BB_SWAPONOFF //sbin
213 {"swapon", swap_on_off_main}, 229 {"swapon", swap_on_off_main},
214 {"swapoff", swap_on_off_main}, 230 {"swapoff", swap_on_off_main},
@@ -229,8 +245,8 @@ static const struct Applet applets[] = {
229 {"true", true_main}, 245 {"true", true_main},
230 {"false", false_main}, 246 {"false", false_main},
231#endif 247#endif
232#ifdef BB_WC //usr/bin 248#ifdef BB_TTY //usr/bin
233 {"wc", wc_main}, 249 {"tty", tty_main},
234#endif 250#endif
235#ifdef BB_UNAME //bin 251#ifdef BB_UNAME //bin
236 {"uname", uname_main}, 252 {"uname", uname_main},
@@ -244,6 +260,15 @@ static const struct Applet applets[] = {
244#ifdef BB_UPDATE //sbin 260#ifdef BB_UPDATE //sbin
245 {"update", update_main}, 261 {"update", update_main},
246#endif 262#endif
263#ifdef BB_WC //usr/bin
264 {"wc", wc_main},
265#endif
266#ifdef BB_WHOAMI //usr/bin
267 {"whoami", whoami_main},
268#endif
269#ifdef BB_YES //usr/bin
270 {"yes", yes_main},
271#endif
247#ifdef BB_GUNZIP //bin 272#ifdef BB_GUNZIP //bin
248 {"zcat", gunzip_main}, 273 {"zcat", gunzip_main},
249 {"gunzip", gunzip_main}, 274 {"gunzip", gunzip_main},
diff --git a/busybox.def.h b/busybox.def.h
index 099eba96c..b8d7b9730 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -10,10 +10,12 @@
10#define BB_CAT 10#define BB_CAT
11#define BB_CHMOD_CHOWN_CHGRP 11#define BB_CHMOD_CHOWN_CHGRP
12#define BB_CHROOT 12#define BB_CHROOT
13#define BB_CHVT
13#define BB_CLEAR 14#define BB_CLEAR
14#define BB_CP 15#define BB_CP
15#define BB_DATE 16#define BB_DATE
16#define BB_DD 17#define BB_DD
18#define BB_DEALLOCVT
17#define BB_DF 19#define BB_DF
18#define BB_DMESG 20#define BB_DMESG
19//#define BB_DUTMP 21//#define BB_DUTMP
@@ -23,12 +25,12 @@
23#define BB_FIND 25#define BB_FIND
24#define BB_FREE 26#define BB_FREE
25#define BB_FSCK_MINIX 27#define BB_FSCK_MINIX
26#define BB_MKFS_MINIX
27#define BB_CHVT
28#define BB_DEALLOCVT
29#define BB_GREP 28#define BB_GREP
29#define BB_GUNZIP
30#define BB_GZIP
30//#define BB_HALT 31//#define BB_HALT
31#define BB_HEAD 32#define BB_HEAD
33//#define BB_HOSTID
32#define BB_HOSTNAME 34#define BB_HOSTNAME
33#define BB_INIT 35#define BB_INIT
34// Don't turn BB_INSMOD on. It doesn't work. 36// Don't turn BB_INSMOD on. It doesn't work.
@@ -41,9 +43,11 @@
41//#define BB_LOADFONT 43//#define BB_LOADFONT
42//#define BB_LOADKMAP 44//#define BB_LOADKMAP
43//#define BB_LOGGER 45//#define BB_LOGGER
46#define BB_LOGNAME
44#define BB_LS 47#define BB_LS
45#define BB_LSMOD 48#define BB_LSMOD
46//#define BB_MAKEDEVS 49//#define BB_MAKEDEVS
50#define BB_MKFS_MINIX
47//#define BB_MATH 51//#define BB_MATH
48#define BB_MKDIR 52#define BB_MKDIR
49//#define BB_MKFIFO 53//#define BB_MKFIFO
@@ -61,13 +65,13 @@
61//#define BB_PRINTF 65//#define BB_PRINTF
62#define BB_PS 66#define BB_PS
63#define BB_PWD 67#define BB_PWD
64#define BB_REGEXP
65#define BB_REBOOT 68#define BB_REBOOT
69#define BB_REGEXP
66#define BB_RM 70#define BB_RM
67#define BB_RMDIR 71#define BB_RMDIR
68//#define BB_RMMOD 72//#define BB_RMMOD
69//#define BB_SFDISK
70#define BB_SED 73#define BB_SED
74//#define BB_SFDISK
71#define BB_SLEEP 75#define BB_SLEEP
72#define BB_SORT 76#define BB_SORT
73#define BB_SWAPONOFF 77#define BB_SWAPONOFF
@@ -78,13 +82,14 @@
78#define BB_TEE 82#define BB_TEE
79#define BB_TOUCH 83#define BB_TOUCH
80#define BB_TRUE_FALSE 84#define BB_TRUE_FALSE
85#define BB_TTY
81#define BB_WC 86#define BB_WC
87#define BB_WHOAMI
82#define BB_UMOUNT 88#define BB_UMOUNT
83#define BB_UNIQ 89#define BB_UNIQ
84#define BB_UPDATE
85#define BB_UNAME 90#define BB_UNAME
86#define BB_GZIP 91#define BB_UPDATE
87#define BB_GUNZIP 92#define BB_YES
88// End of Applications List 93// End of Applications List
89// 94//
90// 95//
diff --git a/coreutils/hostid.c b/coreutils/hostid.c
new file mode 100644
index 000000000..f8d5862ae
--- /dev/null
+++ b/coreutils/hostid.c
@@ -0,0 +1,28 @@
1/*
2 * Mini hostid implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25extern int hostid_main(int argc, char **argv) {
26 printf ("%lx\n", gethostid());
27 exit( TRUE);
28}
diff --git a/coreutils/logname.c b/coreutils/logname.c
new file mode 100644
index 000000000..5c8275ab4
--- /dev/null
+++ b/coreutils/logname.c
@@ -0,0 +1,40 @@
1/*
2 * Mini logname implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25static const char logname_usage[] = "logname\n\n"
26"Print the name of the current user.\n";
27
28extern int logname_main(int argc, char **argv) {
29 char *cp;
30
31 if (argc > 1) usage (logname_usage);
32
33 cp = getlogin ();
34 if (cp) {
35 puts (cp);
36 exit (TRUE);
37 }
38 fprintf (stderr, "%s: no login name\n", argv[0]);
39 exit (FALSE);
40}
diff --git a/coreutils/tty.c b/coreutils/tty.c
new file mode 100644
index 000000000..83abaffb5
--- /dev/null
+++ b/coreutils/tty.c
@@ -0,0 +1,42 @@
1/*
2 * Mini tty implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <sys/types.h>
25
26static const char tty_usage[] = "tty\n\n"
27"Print the file name of the terminal connected to standard input.\n"
28"\t-s\tprint nothing, only return an exit status\n";
29
30extern int tty_main(int argc, char **argv) {
31 char *tty;
32
33 if (argc > 1) {
34 if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
35 }
36 else {
37 tty = ttyname (0);
38 if (tty) puts (tty);
39 else puts ("not a tty");
40 }
41 exit (isatty (0) ? TRUE : FALSE);
42}
diff --git a/coreutils/wc.c b/coreutils/wc.c
new file mode 100644
index 000000000..a1e2fca56
--- /dev/null
+++ b/coreutils/wc.c
@@ -0,0 +1,162 @@
1/*
2 * Mini wc implementation for busybox
3 *
4 * by Edward Betts <edward@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
26"Print line, word, and byte counts for each FILE, and a total line if\n"
27"more than one FILE is specified. With no FILE, read standard input.\n"
28"\t-c\tprint the byte counts\n"
29"\t-l\tprint the newline counts\n"
30"\t-L\tprint the length of the longest line\n"
31"\t-L\tprint the length of the longest line\n"
32"\t-w\tprint the word counts\n";
33
34static int total_lines, total_words, total_chars, max_length;
35static int print_lines, print_words, print_chars, print_length;
36
37void print_counts (int lines, int words, int chars, int length,
38 const char *name) {
39 char const *space = "";
40 if (print_lines) {
41 printf ("%7d", lines);
42 space = " ";
43 }
44 if (print_words) {
45 printf ("%s%7d", space, words);
46 space = " ";
47 }
48 if (print_chars) {
49 printf ("%s%7d", space, chars);
50 space = " ";
51 }
52 if (print_length)
53 printf ("%s%7d", space, length);
54 if (*name)
55 printf (" %s", name);
56 putchar ('\n');
57}
58
59static void wc_file(FILE *file, const char *name)
60{
61 int lines, words, chars, length;
62 int in_word = 0, linepos = 0;
63 int c;
64 lines = words = chars = length = 0;
65 while ((c = getc(file)) != EOF) {
66 chars++;
67 switch (c) {
68 case '\n':
69 lines++;
70 case '\r':
71 case '\f':
72 if (linepos > length)
73 length = linepos;
74 linepos = 0;
75 goto word_separator;
76 case '\t':
77 linepos += 8 - (linepos % 8);
78 goto word_separator;
79 case ' ':
80 linepos++;
81 case '\v':
82 word_separator:
83 if (in_word) {
84 in_word = 0;
85 words++;
86 }
87 break;
88 default:
89 linepos++;
90 in_word = 1;
91 break;
92 }
93 }
94 if (linepos > length)
95 length = linepos;
96 if (in_word)
97 words++;
98 print_counts (lines, words, chars, length, name);
99 total_lines += lines;
100 total_words += words;
101 total_chars += chars;
102 if (length > max_length)
103 max_length = length;
104 fclose(file);
105 fflush(stdout);
106}
107
108int wc_main(int argc, char **argv) {
109 FILE *file;
110 total_lines = total_words = total_chars = max_length = 0;
111 print_lines = print_words = print_chars = print_length = 0;
112
113 while (--argc && **(++argv) == '-') {
114 while (*++(*argv))
115 switch (**argv) {
116 case 'c':
117 print_chars = 1;
118 break;
119 case 'l':
120 print_lines = 1;
121 break;
122 case 'L':
123 print_length = 1;
124 break;
125 case 'w':
126 print_words = 1;
127 break;
128 default:
129 usage (wc_usage);
130 }
131 }
132
133 if (!print_lines && !print_words && !print_chars && !print_length)
134 print_lines = print_words = print_chars = 1;
135
136 if (argc == 0) {
137 wc_file(stdin, "");
138 exit(TRUE);
139 }
140 else if (argc == 1) {
141 file = fopen(*argv, "r");
142 if (file == NULL) {
143 perror(*argv);
144 exit(FALSE);
145 }
146 wc_file(file, *argv);
147 }
148 else {
149 while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
150 file = fopen(*argv, "r");
151 if (file == NULL) {
152 perror(*argv);
153 exit(FALSE);
154 }
155 wc_file(file, *argv);
156 argv++;
157 }
158 print_counts (total_lines, total_words, total_chars,
159 max_length, "total");
160 }
161 exit(TRUE);
162}
diff --git a/coreutils/whoami.c b/coreutils/whoami.c
new file mode 100644
index 000000000..7fd5d01b2
--- /dev/null
+++ b/coreutils/whoami.c
@@ -0,0 +1,44 @@
1/*
2 * Mini whoami implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <pwd.h>
25
26static const char whoami_usage[] = "whoami\n\n"
27"Print the user name associated with the current effective user id.\n"
28"Same as id -un.\n";
29
30extern int whoami_main(int argc, char **argv) {
31 struct passwd *pw;
32 uid_t uid;
33
34 if (argc > 1) usage (whoami_usage);
35
36 uid = geteuid ();
37 pw = getpwuid (uid);
38 if (pw) {
39 puts (pw->pw_name);
40 exit (TRUE);
41 }
42 fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
43 exit (FALSE);
44}
diff --git a/coreutils/yes.c b/coreutils/yes.c
new file mode 100644
index 000000000..96d6257d0
--- /dev/null
+++ b/coreutils/yes.c
@@ -0,0 +1,41 @@
1/*
2 * Mini yes implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25extern int yes_main(int argc, char **argv) {
26 int i;
27 if (argc == 1)
28 while (1)
29 if (puts ("y") == EOF) {
30 perror ("yes");
31 exit(FALSE);
32 }
33
34 while (1)
35 for (i = 1; i < argc; i++)
36 if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
37 perror ("yes");
38 exit(FALSE);
39 }
40 exit(TRUE);
41}
diff --git a/docs/CommandList b/docs/CommandList
index 8c0a01e23..32d2134d8 100644
--- a/docs/CommandList
+++ b/docs/CommandList
@@ -515,11 +515,14 @@ ________________________________________________________________________________
515 515
516 516
517 517
518mknod (Segmentation Fault when executing this command) 518mknod NAME TYPE MAJOR MINOR
519
520 (No embedix information available for this command.)
521 519
520Make block or character special files.
522 521
522TYPEs include:
523 b: Make a block (buffered) device.
524 c or u: Make a character (un-buffered) device.
525 p: Make a named pipe. Major and minor are ignored for named pipes.
523 526
524 527
525 528
diff --git a/hostid.c b/hostid.c
new file mode 100644
index 000000000..f8d5862ae
--- /dev/null
+++ b/hostid.c
@@ -0,0 +1,28 @@
1/*
2 * Mini hostid implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25extern int hostid_main(int argc, char **argv) {
26 printf ("%lx\n", gethostid());
27 exit( TRUE);
28}
diff --git a/init.c b/init.c
index b4ab1c751..913436353 100644
--- a/init.c
+++ b/init.c
@@ -106,11 +106,11 @@ struct initActionTag {
106initAction* initActionList = NULL; 106initAction* initActionList = NULL;
107 107
108 108
109static char *console = _PATH_CONSOLE;
110static char *secondConsole = VT_SECONDARY; 109static char *secondConsole = VT_SECONDARY;
111static char *log = VT_LOG; 110static char *log = VT_LOG;
112static int kernelVersion = 0; 111static int kernelVersion = 0;
113static char *termType = NULL; 112static char termType[32] = "TERM=ansi";
113static char console[32] = _PATH_CONSOLE;
114 114
115 115
116/* try to open up the specified device */ 116/* try to open up the specified device */
@@ -258,41 +258,37 @@ static void console_init()
258 struct serial_struct sr; 258 struct serial_struct sr;
259 char *s; 259 char *s;
260 260
261 if ((s = getenv("CONSOLE")) != NULL) { 261 if ((s = getenv("TERM")) != NULL) {
262 termType = s; 262 snprintf(termType,sizeof(termType)-1,"TERM=%s",s);
263 } else {
264 termType = "TERM=vt100";
265 } 263 }
266 264
267 if ((s = getenv("CONSOLE")) != NULL) { 265 if ((s = getenv("CONSOLE")) != NULL) {
268 console = s; 266 snprintf(console, sizeof(console)-1, "%s",s);
269 } 267 }
270#if #cpu(sparc) 268#if #cpu(sparc)
271 /* sparc kernel supports console=tty[ab] parameter which is also 269 /* sparc kernel supports console=tty[ab] parameter which is also
272 * passed to init, so catch it here */ 270 * passed to init, so catch it here */
273 else if ((s = getenv("console")) != NULL) { 271 else if ((s = getenv("console")) != NULL) {*/
274 /* remap tty[ab] to /dev/ttyS[01] */ 272 /* remap tty[ab] to /dev/ttyS[01] */
275 if (strcmp( s, "ttya" )==0) 273 if (strcmp( s, "ttya" )==0)
276 console = SERIAL_CON0; 274 snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0);
277 else if (strcmp( s, "ttyb" )==0) 275 else if (strcmp( s, "ttyb" )==0)
278 console = SERIAL_CON1; 276 snprintf(console, sizeof(console)-1, "%s", SERIAL_CON1);
279 } 277 }
280#endif 278#endif
281 else { 279 else {
282 struct vt_stat vt; 280 struct vt_stat vt;
283 static char the_console[13];
284 281
285 console = the_console;
286 /* 2.2 kernels: identify the real console backend and try to use it */ 282 /* 2.2 kernels: identify the real console backend and try to use it */
287 if (ioctl(0, TIOCGSERIAL, &sr) == 0) { 283 if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
288 /* this is a serial console */ 284 /* this is a serial console */
289 snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line ); 285 snprintf(console, sizeof(console)-1, "/dev/ttyS%d", sr.line);
290 } 286 }
291 else if (ioctl(0, VT_GETSTATE, &vt) == 0) { 287 else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
292 /* this is linux virtual tty */ 288 /* this is linux virtual tty */
293 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active ); 289 snprintf(console, sizeof(console)-1, "/dev/tty%d", vt.v_active);
294 } else { 290 } else {
295 console = _PATH_CONSOLE; 291 snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
296 tried_devcons++; 292 tried_devcons++;
297 } 293 }
298 } 294 }
@@ -301,25 +297,25 @@ static void console_init()
301 /* Can't open selected console -- try /dev/console */ 297 /* Can't open selected console -- try /dev/console */
302 if (!tried_devcons) { 298 if (!tried_devcons) {
303 tried_devcons++; 299 tried_devcons++;
304 console = _PATH_CONSOLE; 300 snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
305 continue; 301 continue;
306 } 302 }
307 /* Can't open selected console -- try vt1 */ 303 /* Can't open selected console -- try vt1 */
308 if (!tried_vtprimary) { 304 if (!tried_vtprimary) {
309 tried_vtprimary++; 305 tried_vtprimary++;
310 console = VT_PRIMARY; 306 snprintf(console, sizeof(console)-1, "%s", VT_PRIMARY);
311 continue; 307 continue;
312 } 308 }
313 break; 309 break;
314 } 310 }
315 if (fd < 0) 311 if (fd < 0) {
316 /* Perhaps we should panic here? */ 312 /* Perhaps we should panic here? */
317 console = "/dev/null"; 313 snprintf(console, sizeof(console)-1, "/dev/null");
318 else { 314 } else {
319 /* check for serial console and disable logging to tty3 & running a 315 /* check for serial console and disable logging to tty3 & running a
320 * shell to tty2 */ 316 * shell to tty2 */
321 if (ioctl(0,TIOCGSERIAL,&sr) == 0) { 317 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
322 message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console ); 318 message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n" );
323 log = NULL; 319 log = NULL;
324 secondConsole = NULL; 320 secondConsole = NULL;
325 } 321 }
@@ -337,15 +333,14 @@ static pid_t run(char* command,
337 char* cmd[255]; 333 char* cmd[255];
338 static const char press_enter[] = 334 static const char press_enter[] =
339 "\nPlease press Enter to activate this console. "; 335 "\nPlease press Enter to activate this console. ";
340 static char * environment[] = { 336 char* environment[] = {
341 "HOME=/", 337 "HOME=/",
342 "PATH=/usr/bin:/bin:/usr/sbin:/sbin", 338 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
343 "SHELL=/bin/sh", 339 "SHELL=/bin/sh",
344 0, 340 termType,
345 "USER=root", 341 "USER=root",
346 0 342 0
347 }; 343 };
348 environment[3]=termType;
349 344
350 345
351 if ((pid = fork()) == 0) { 346 if ((pid = fork()) == 0) {
@@ -389,24 +384,23 @@ static pid_t run(char* command,
389 } 384 }
390 385
391 /* Log the process name and args */ 386 /* Log the process name and args */
392 message(LOG|CONSOLE, "Starting pid %d, console %s: '", 387 message(LOG, "Starting pid %d, console %s: '",
393 shell_pgid, terminal, command); 388 shell_pgid, terminal, command);
394 389
395 /* Convert command (char*) into cmd (char**, one word per string) */ 390 /* Convert command (char*) into cmd (char**, one word per string) */
396 for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { 391 for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) {
397 if (*tmpCmd != '\0') { 392 if (*tmpCmd != '\0') {
398 cmd[i] = tmpCmd; 393 cmd[i] = tmpCmd;
399 message(LOG|CONSOLE, "%s ", tmpCmd); 394 message(LOG, "%s ", tmpCmd);
400 tmpCmd++; 395 tmpCmd++;
401 i++; 396 i++;
402 } 397 }
403 } 398 }
404 cmd[i] = NULL; 399 cmd[i] = NULL;
405 message(LOG|CONSOLE, "'\r\n"); 400 message(LOG, "'\r\n");
406 401
407 /* Now run it. The new program will take over this PID, 402 /* Now run it. The new program will take over this PID,
408 * so nothing further in init.c should be run. */ 403 * so nothing further in init.c should be run. */
409 //execvp(cmd[0], cmd);
410 execve(cmd[0], cmd, environment); 404 execve(cmd[0], cmd, environment);
411 405
412 /* We're still here? Some error happened. */ 406 /* We're still here? Some error happened. */
@@ -541,8 +535,8 @@ void new_initAction (initActionEnum action,
541 } else 535 } else
542 strncpy(newAction->console, console, 255); 536 strncpy(newAction->console, console, 255);
543 newAction->pid = 0; 537 newAction->pid = 0;
544 message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", 538// message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n",
545 newAction->process, newAction->action, newAction->console); 539// newAction->process, newAction->action, newAction->console);
546} 540}
547 541
548void delete_initAction (initAction *action) 542void delete_initAction (initAction *action)
@@ -673,6 +667,9 @@ extern int init_main(int argc, char **argv)
673 usage( "init\n\nInit is the parent of all processes.\n\n" 667 usage( "init\n\nInit is the parent of all processes.\n\n"
674 "This version of init is designed to be run only by the kernel\n"); 668 "This version of init is designed to be run only by the kernel\n");
675 } 669 }
670 /* Fix up argv[0] to be certain we claim to be init */
671 strncpy(argv[0], "init", strlen(argv[0]));
672
676 /* Set up sig handlers -- be sure to 673 /* Set up sig handlers -- be sure to
677 * clear all of these in run() */ 674 * clear all of these in run() */
678 signal(SIGUSR1, halt_signal); 675 signal(SIGUSR1, halt_signal);
diff --git a/init/init.c b/init/init.c
index b4ab1c751..913436353 100644
--- a/init/init.c
+++ b/init/init.c
@@ -106,11 +106,11 @@ struct initActionTag {
106initAction* initActionList = NULL; 106initAction* initActionList = NULL;
107 107
108 108
109static char *console = _PATH_CONSOLE;
110static char *secondConsole = VT_SECONDARY; 109static char *secondConsole = VT_SECONDARY;
111static char *log = VT_LOG; 110static char *log = VT_LOG;
112static int kernelVersion = 0; 111static int kernelVersion = 0;
113static char *termType = NULL; 112static char termType[32] = "TERM=ansi";
113static char console[32] = _PATH_CONSOLE;
114 114
115 115
116/* try to open up the specified device */ 116/* try to open up the specified device */
@@ -258,41 +258,37 @@ static void console_init()
258 struct serial_struct sr; 258 struct serial_struct sr;
259 char *s; 259 char *s;
260 260
261 if ((s = getenv("CONSOLE")) != NULL) { 261 if ((s = getenv("TERM")) != NULL) {
262 termType = s; 262 snprintf(termType,sizeof(termType)-1,"TERM=%s",s);
263 } else {
264 termType = "TERM=vt100";
265 } 263 }
266 264
267 if ((s = getenv("CONSOLE")) != NULL) { 265 if ((s = getenv("CONSOLE")) != NULL) {
268 console = s; 266 snprintf(console, sizeof(console)-1, "%s",s);
269 } 267 }
270#if #cpu(sparc) 268#if #cpu(sparc)
271 /* sparc kernel supports console=tty[ab] parameter which is also 269 /* sparc kernel supports console=tty[ab] parameter which is also
272 * passed to init, so catch it here */ 270 * passed to init, so catch it here */
273 else if ((s = getenv("console")) != NULL) { 271 else if ((s = getenv("console")) != NULL) {*/
274 /* remap tty[ab] to /dev/ttyS[01] */ 272 /* remap tty[ab] to /dev/ttyS[01] */
275 if (strcmp( s, "ttya" )==0) 273 if (strcmp( s, "ttya" )==0)
276 console = SERIAL_CON0; 274 snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0);
277 else if (strcmp( s, "ttyb" )==0) 275 else if (strcmp( s, "ttyb" )==0)
278 console = SERIAL_CON1; 276 snprintf(console, sizeof(console)-1, "%s", SERIAL_CON1);
279 } 277 }
280#endif 278#endif
281 else { 279 else {
282 struct vt_stat vt; 280 struct vt_stat vt;
283 static char the_console[13];
284 281
285 console = the_console;
286 /* 2.2 kernels: identify the real console backend and try to use it */ 282 /* 2.2 kernels: identify the real console backend and try to use it */
287 if (ioctl(0, TIOCGSERIAL, &sr) == 0) { 283 if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
288 /* this is a serial console */ 284 /* this is a serial console */
289 snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line ); 285 snprintf(console, sizeof(console)-1, "/dev/ttyS%d", sr.line);
290 } 286 }
291 else if (ioctl(0, VT_GETSTATE, &vt) == 0) { 287 else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
292 /* this is linux virtual tty */ 288 /* this is linux virtual tty */
293 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active ); 289 snprintf(console, sizeof(console)-1, "/dev/tty%d", vt.v_active);
294 } else { 290 } else {
295 console = _PATH_CONSOLE; 291 snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
296 tried_devcons++; 292 tried_devcons++;
297 } 293 }
298 } 294 }
@@ -301,25 +297,25 @@ static void console_init()
301 /* Can't open selected console -- try /dev/console */ 297 /* Can't open selected console -- try /dev/console */
302 if (!tried_devcons) { 298 if (!tried_devcons) {
303 tried_devcons++; 299 tried_devcons++;
304 console = _PATH_CONSOLE; 300 snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
305 continue; 301 continue;
306 } 302 }
307 /* Can't open selected console -- try vt1 */ 303 /* Can't open selected console -- try vt1 */
308 if (!tried_vtprimary) { 304 if (!tried_vtprimary) {
309 tried_vtprimary++; 305 tried_vtprimary++;
310 console = VT_PRIMARY; 306 snprintf(console, sizeof(console)-1, "%s", VT_PRIMARY);
311 continue; 307 continue;
312 } 308 }
313 break; 309 break;
314 } 310 }
315 if (fd < 0) 311 if (fd < 0) {
316 /* Perhaps we should panic here? */ 312 /* Perhaps we should panic here? */
317 console = "/dev/null"; 313 snprintf(console, sizeof(console)-1, "/dev/null");
318 else { 314 } else {
319 /* check for serial console and disable logging to tty3 & running a 315 /* check for serial console and disable logging to tty3 & running a
320 * shell to tty2 */ 316 * shell to tty2 */
321 if (ioctl(0,TIOCGSERIAL,&sr) == 0) { 317 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
322 message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console ); 318 message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n" );
323 log = NULL; 319 log = NULL;
324 secondConsole = NULL; 320 secondConsole = NULL;
325 } 321 }
@@ -337,15 +333,14 @@ static pid_t run(char* command,
337 char* cmd[255]; 333 char* cmd[255];
338 static const char press_enter[] = 334 static const char press_enter[] =
339 "\nPlease press Enter to activate this console. "; 335 "\nPlease press Enter to activate this console. ";
340 static char * environment[] = { 336 char* environment[] = {
341 "HOME=/", 337 "HOME=/",
342 "PATH=/usr/bin:/bin:/usr/sbin:/sbin", 338 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
343 "SHELL=/bin/sh", 339 "SHELL=/bin/sh",
344 0, 340 termType,
345 "USER=root", 341 "USER=root",
346 0 342 0
347 }; 343 };
348 environment[3]=termType;
349 344
350 345
351 if ((pid = fork()) == 0) { 346 if ((pid = fork()) == 0) {
@@ -389,24 +384,23 @@ static pid_t run(char* command,
389 } 384 }
390 385
391 /* Log the process name and args */ 386 /* Log the process name and args */
392 message(LOG|CONSOLE, "Starting pid %d, console %s: '", 387 message(LOG, "Starting pid %d, console %s: '",
393 shell_pgid, terminal, command); 388 shell_pgid, terminal, command);
394 389
395 /* Convert command (char*) into cmd (char**, one word per string) */ 390 /* Convert command (char*) into cmd (char**, one word per string) */
396 for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { 391 for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) {
397 if (*tmpCmd != '\0') { 392 if (*tmpCmd != '\0') {
398 cmd[i] = tmpCmd; 393 cmd[i] = tmpCmd;
399 message(LOG|CONSOLE, "%s ", tmpCmd); 394 message(LOG, "%s ", tmpCmd);
400 tmpCmd++; 395 tmpCmd++;
401 i++; 396 i++;
402 } 397 }
403 } 398 }
404 cmd[i] = NULL; 399 cmd[i] = NULL;
405 message(LOG|CONSOLE, "'\r\n"); 400 message(LOG, "'\r\n");
406 401
407 /* Now run it. The new program will take over this PID, 402 /* Now run it. The new program will take over this PID,
408 * so nothing further in init.c should be run. */ 403 * so nothing further in init.c should be run. */
409 //execvp(cmd[0], cmd);
410 execve(cmd[0], cmd, environment); 404 execve(cmd[0], cmd, environment);
411 405
412 /* We're still here? Some error happened. */ 406 /* We're still here? Some error happened. */
@@ -541,8 +535,8 @@ void new_initAction (initActionEnum action,
541 } else 535 } else
542 strncpy(newAction->console, console, 255); 536 strncpy(newAction->console, console, 255);
543 newAction->pid = 0; 537 newAction->pid = 0;
544 message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", 538// message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n",
545 newAction->process, newAction->action, newAction->console); 539// newAction->process, newAction->action, newAction->console);
546} 540}
547 541
548void delete_initAction (initAction *action) 542void delete_initAction (initAction *action)
@@ -673,6 +667,9 @@ extern int init_main(int argc, char **argv)
673 usage( "init\n\nInit is the parent of all processes.\n\n" 667 usage( "init\n\nInit is the parent of all processes.\n\n"
674 "This version of init is designed to be run only by the kernel\n"); 668 "This version of init is designed to be run only by the kernel\n");
675 } 669 }
670 /* Fix up argv[0] to be certain we claim to be init */
671 strncpy(argv[0], "init", strlen(argv[0]));
672
676 /* Set up sig handlers -- be sure to 673 /* Set up sig handlers -- be sure to
677 * clear all of these in run() */ 674 * clear all of these in run() */
678 signal(SIGUSR1, halt_signal); 675 signal(SIGUSR1, halt_signal);
diff --git a/internal.h b/internal.h
index 49cfcf05c..e57096d4a 100644
--- a/internal.h
+++ b/internal.h
@@ -54,7 +54,6 @@ struct Applet {
54extern int busybox_main(int argc, char** argv); 54extern int busybox_main(int argc, char** argv);
55extern int block_device_main(int argc, char** argv); 55extern int block_device_main(int argc, char** argv);
56extern int cat_main(int argc, char** argv); 56extern int cat_main(int argc, char** argv);
57extern int more_main(int argc, char** argv);
58extern int cp_main(int argc, char** argv); 57extern int cp_main(int argc, char** argv);
59extern int chmod_chown_chgrp_main(int argc, char** argv); 58extern int chmod_chown_chgrp_main(int argc, char** argv);
60extern int chroot_main(int argc, char** argv); 59extern int chroot_main(int argc, char** argv);
@@ -75,17 +74,23 @@ extern int fsck_minix_main(int argc, char **argv);
75extern int find_main(int argc, char** argv); 74extern int find_main(int argc, char** argv);
76extern int free_main(int argc, char** argv); 75extern int free_main(int argc, char** argv);
77extern int grep_main(int argc, char** argv); 76extern int grep_main(int argc, char** argv);
77extern int gunzip_main (int argc, char** argv);
78extern int gzip_main(int argc, char** argv);
78extern int halt_main(int argc, char** argv); 79extern int halt_main(int argc, char** argv);
79extern int head_main(int argc, char** argv); 80extern int head_main(int argc, char** argv);
81extern int hostid_main(int argc, char** argv);
80extern int hostname_main(int argc, char** argv); 82extern int hostname_main(int argc, char** argv);
81extern int init_main(int argc, char** argv); 83extern int init_main(int argc, char** argv);
82extern int insmod_main(int argc, char** argv); 84extern int insmod_main(int argc, char** argv);
83extern int kill_main(int argc, char** argv); 85extern int kill_main(int argc, char** argv);
84extern int length_main(int argc, char** argv); 86extern int length_main(int argc, char** argv);
85extern int ln_main(int argc, char** argv); 87extern int ln_main(int argc, char** argv);
88extern int loadacm_main(int argc, char** argv);
86extern int loadfont_main(int argc, char** argv); 89extern int loadfont_main(int argc, char** argv);
87extern int loadkmap_main(int argc, char** argv); 90extern int loadkmap_main(int argc, char** argv);
88extern int losetup_main(int argc, char** argv); 91extern int losetup_main(int argc, char** argv);
92extern int logger_main(int argc, char **argv);
93extern int logname_main(int argc, char **argv);
89extern int ls_main(int argc, char** argv); 94extern int ls_main(int argc, char** argv);
90extern int lsmod_main(int argc, char** argv); 95extern int lsmod_main(int argc, char** argv);
91extern int makedevs_main(int argc, char** argv); 96extern int makedevs_main(int argc, char** argv);
@@ -96,6 +101,7 @@ extern int mkfs_minix_main(int argc, char **argv);
96extern int mknod_main(int argc, char** argv); 101extern int mknod_main(int argc, char** argv);
97extern int mkswap_main(int argc, char** argv); 102extern int mkswap_main(int argc, char** argv);
98extern int mnc_main(int argc, char** argv); 103extern int mnc_main(int argc, char** argv);
104extern int more_main(int argc, char** argv);
99extern int mount_main(int argc, char** argv); 105extern int mount_main(int argc, char** argv);
100extern int mt_main(int argc, char** argv); 106extern int mt_main(int argc, char** argv);
101extern int mv_main(int argc, char** argv); 107extern int mv_main(int argc, char** argv);
@@ -108,31 +114,28 @@ extern int reboot_main(int argc, char** argv);
108extern int rm_main(int argc, char** argv); 114extern int rm_main(int argc, char** argv);
109extern int rmdir_main(int argc, char **argv); 115extern int rmdir_main(int argc, char **argv);
110extern int rmmod_main(int argc, char** argv); 116extern int rmmod_main(int argc, char** argv);
111extern int scan_partitions_main(int argc, char** argv);
112extern int sh_main(int argc, char** argv);
113extern int sfdisk_main(int argc, char** argv);
114extern int sed_main(int argc, char** argv); 117extern int sed_main(int argc, char** argv);
118extern int sfdisk_main(int argc, char** argv);
115extern int sleep_main(int argc, char** argv); 119extern int sleep_main(int argc, char** argv);
116extern int sort_main(int argc, char** argv); 120extern int sort_main(int argc, char** argv);
117extern int swap_on_off_main(int argc, char** argv); 121extern int swap_on_off_main(int argc, char** argv);
118extern int sync_main(int argc, char** argv); 122extern int sync_main(int argc, char** argv);
119extern int syslogd_main(int argc, char **argv); 123extern int syslogd_main(int argc, char **argv);
120extern int logger_main(int argc, char **argv);
121extern int tar_main(int argc, char** argv);
122extern int tail_main(int argc, char** argv); 124extern int tail_main(int argc, char** argv);
125extern int tar_main(int argc, char** argv);
123extern int tee_main(int argc, char** argv); 126extern int tee_main(int argc, char** argv);
124extern int touch_main(int argc, char** argv); 127extern int touch_main(int argc, char** argv);
125extern int tput_main(int argc, char** argv);
126extern int true_main(int argc, char** argv); 128extern int true_main(int argc, char** argv);
129extern int tput_main(int argc, char** argv);
127extern int tryopen_main(int argc, char** argv); 130extern int tryopen_main(int argc, char** argv);
128extern int wc_main(int argc, char** argv); 131extern int tty_main(int argc, char** argv);
129extern int umount_main(int argc, char** argv); 132extern int umount_main(int argc, char** argv);
133extern int uname_main(int argc, char** argv);
130extern int uniq_main(int argc, char** argv); 134extern int uniq_main(int argc, char** argv);
131extern int update_main(int argc, char** argv); 135extern int update_main(int argc, char** argv);
132extern int uname_main(int argc, char** argv); 136extern int wc_main(int argc, char** argv);
133extern int gunzip_main (int argc, char** argv); 137extern int whoami_main(int argc, char** argv);
134extern int gzip_main(int argc, char** argv); 138extern int yes_main(int argc, char** argv);
135extern int loadacm_main(int argc, char** argv);
136 139
137 140
138const char *modeString(int mode); 141const char *modeString(int mode);
@@ -204,6 +207,11 @@ static inline int clrbit(char * addr,unsigned int nr)
204#endif /* inline bitops junk */ 207#endif /* inline bitops junk */
205 208
206 209
210#ifndef RB_POWER_OFF
211/* Stop system and switch power off if possable. */
212#define RB_POWER_OFF 0x4321fedc
213#endif
214
207 215
208#endif /* _INTERNAL_H_ */ 216#endif /* _INTERNAL_H_ */
209 217
diff --git a/logname.c b/logname.c
new file mode 100644
index 000000000..5c8275ab4
--- /dev/null
+++ b/logname.c
@@ -0,0 +1,40 @@
1/*
2 * Mini logname implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25static const char logname_usage[] = "logname\n\n"
26"Print the name of the current user.\n";
27
28extern int logname_main(int argc, char **argv) {
29 char *cp;
30
31 if (argc > 1) usage (logname_usage);
32
33 cp = getlogin ();
34 if (cp) {
35 puts (cp);
36 exit (TRUE);
37 }
38 fprintf (stderr, "%s: no login name\n", argv[0]);
39 exit (FALSE);
40}
diff --git a/mount.c b/mount.c
index 8777a3be4..713e5e850 100644
--- a/mount.c
+++ b/mount.c
@@ -24,11 +24,13 @@
24 * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. 24 * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
25 * 25 *
26 * 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>. 26 * 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>.
27 * Rewrote of a lot of code. Removed mtab usage (I plan on 27 * Rewrite of a lot of code. Removed mtab usage (I plan on
28 * putting it back as a compile-time option some time), 28 * putting it back as a compile-time option some time),
29 * major adjustments to option parsing, and some serious 29 * major adjustments to option parsing, and some serious
30 * dieting all around. 30 * dieting all around.
31 * 31 *
32 * 1999-11-06 mtab suppport is back - andersee
33 *
32 * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's 34 * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
33 * mount to add loop support. 35 * mount to add loop support.
34 */ 36 */
diff --git a/tty.c b/tty.c
new file mode 100644
index 000000000..83abaffb5
--- /dev/null
+++ b/tty.c
@@ -0,0 +1,42 @@
1/*
2 * Mini tty implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <sys/types.h>
25
26static const char tty_usage[] = "tty\n\n"
27"Print the file name of the terminal connected to standard input.\n"
28"\t-s\tprint nothing, only return an exit status\n";
29
30extern int tty_main(int argc, char **argv) {
31 char *tty;
32
33 if (argc > 1) {
34 if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
35 }
36 else {
37 tty = ttyname (0);
38 if (tty) puts (tty);
39 else puts ("not a tty");
40 }
41 exit (isatty (0) ? TRUE : FALSE);
42}
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 8777a3be4..713e5e850 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -24,11 +24,13 @@
24 * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. 24 * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
25 * 25 *
26 * 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>. 26 * 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>.
27 * Rewrote of a lot of code. Removed mtab usage (I plan on 27 * Rewrite of a lot of code. Removed mtab usage (I plan on
28 * putting it back as a compile-time option some time), 28 * putting it back as a compile-time option some time),
29 * major adjustments to option parsing, and some serious 29 * major adjustments to option parsing, and some serious
30 * dieting all around. 30 * dieting all around.
31 * 31 *
32 * 1999-11-06 mtab suppport is back - andersee
33 *
32 * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's 34 * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
33 * mount to add loop support. 35 * mount to add loop support.
34 */ 36 */
diff --git a/utility.c b/utility.c
index c18cb4b27..ade47bde0 100644
--- a/utility.c
+++ b/utility.c
@@ -317,7 +317,9 @@ const char *timeString(time_t timeVal)
317 317
318 return buf; 318 return buf;
319} 319}
320#endif
320 321
322#if defined BB_TAR || defined BB_CP || defined BB_MV
321/* 323/*
322 * Write all of the supplied buffer out to a file. 324 * Write all of the supplied buffer out to a file.
323 * This does multiple writes as necessary. 325 * This does multiple writes as necessary.
diff --git a/wc.c b/wc.c
new file mode 100644
index 000000000..a1e2fca56
--- /dev/null
+++ b/wc.c
@@ -0,0 +1,162 @@
1/*
2 * Mini wc implementation for busybox
3 *
4 * by Edward Betts <edward@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
26"Print line, word, and byte counts for each FILE, and a total line if\n"
27"more than one FILE is specified. With no FILE, read standard input.\n"
28"\t-c\tprint the byte counts\n"
29"\t-l\tprint the newline counts\n"
30"\t-L\tprint the length of the longest line\n"
31"\t-L\tprint the length of the longest line\n"
32"\t-w\tprint the word counts\n";
33
34static int total_lines, total_words, total_chars, max_length;
35static int print_lines, print_words, print_chars, print_length;
36
37void print_counts (int lines, int words, int chars, int length,
38 const char *name) {
39 char const *space = "";
40 if (print_lines) {
41 printf ("%7d", lines);
42 space = " ";
43 }
44 if (print_words) {
45 printf ("%s%7d", space, words);
46 space = " ";
47 }
48 if (print_chars) {
49 printf ("%s%7d", space, chars);
50 space = " ";
51 }
52 if (print_length)
53 printf ("%s%7d", space, length);
54 if (*name)
55 printf (" %s", name);
56 putchar ('\n');
57}
58
59static void wc_file(FILE *file, const char *name)
60{
61 int lines, words, chars, length;
62 int in_word = 0, linepos = 0;
63 int c;
64 lines = words = chars = length = 0;
65 while ((c = getc(file)) != EOF) {
66 chars++;
67 switch (c) {
68 case '\n':
69 lines++;
70 case '\r':
71 case '\f':
72 if (linepos > length)
73 length = linepos;
74 linepos = 0;
75 goto word_separator;
76 case '\t':
77 linepos += 8 - (linepos % 8);
78 goto word_separator;
79 case ' ':
80 linepos++;
81 case '\v':
82 word_separator:
83 if (in_word) {
84 in_word = 0;
85 words++;
86 }
87 break;
88 default:
89 linepos++;
90 in_word = 1;
91 break;
92 }
93 }
94 if (linepos > length)
95 length = linepos;
96 if (in_word)
97 words++;
98 print_counts (lines, words, chars, length, name);
99 total_lines += lines;
100 total_words += words;
101 total_chars += chars;
102 if (length > max_length)
103 max_length = length;
104 fclose(file);
105 fflush(stdout);
106}
107
108int wc_main(int argc, char **argv) {
109 FILE *file;
110 total_lines = total_words = total_chars = max_length = 0;
111 print_lines = print_words = print_chars = print_length = 0;
112
113 while (--argc && **(++argv) == '-') {
114 while (*++(*argv))
115 switch (**argv) {
116 case 'c':
117 print_chars = 1;
118 break;
119 case 'l':
120 print_lines = 1;
121 break;
122 case 'L':
123 print_length = 1;
124 break;
125 case 'w':
126 print_words = 1;
127 break;
128 default:
129 usage (wc_usage);
130 }
131 }
132
133 if (!print_lines && !print_words && !print_chars && !print_length)
134 print_lines = print_words = print_chars = 1;
135
136 if (argc == 0) {
137 wc_file(stdin, "");
138 exit(TRUE);
139 }
140 else if (argc == 1) {
141 file = fopen(*argv, "r");
142 if (file == NULL) {
143 perror(*argv);
144 exit(FALSE);
145 }
146 wc_file(file, *argv);
147 }
148 else {
149 while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
150 file = fopen(*argv, "r");
151 if (file == NULL) {
152 perror(*argv);
153 exit(FALSE);
154 }
155 wc_file(file, *argv);
156 argv++;
157 }
158 print_counts (total_lines, total_words, total_chars,
159 max_length, "total");
160 }
161 exit(TRUE);
162}
diff --git a/whoami.c b/whoami.c
new file mode 100644
index 000000000..7fd5d01b2
--- /dev/null
+++ b/whoami.c
@@ -0,0 +1,44 @@
1/*
2 * Mini whoami implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24#include <pwd.h>
25
26static const char whoami_usage[] = "whoami\n\n"
27"Print the user name associated with the current effective user id.\n"
28"Same as id -un.\n";
29
30extern int whoami_main(int argc, char **argv) {
31 struct passwd *pw;
32 uid_t uid;
33
34 if (argc > 1) usage (whoami_usage);
35
36 uid = geteuid ();
37 pw = getpwuid (uid);
38 if (pw) {
39 puts (pw->pw_name);
40 exit (TRUE);
41 }
42 fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
43 exit (FALSE);
44}
diff --git a/yes.c b/yes.c
new file mode 100644
index 000000000..96d6257d0
--- /dev/null
+++ b/yes.c
@@ -0,0 +1,41 @@
1/*
2 * Mini yes implementation for busybox
3 *
4 * Copyright (C) 2000 Edward Betts <edward@debian.org>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include "internal.h"
23#include <stdio.h>
24
25extern int yes_main(int argc, char **argv) {
26 int i;
27 if (argc == 1)
28 while (1)
29 if (puts ("y") == EOF) {
30 perror ("yes");
31 exit(FALSE);
32 }
33
34 while (1)
35 for (i = 1; i < argc; i++)
36 if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
37 perror ("yes");
38 exit(FALSE);
39 }
40 exit(TRUE);
41}