Compare commits

..
8 Commits
Author SHA1 Message Date
Erik Andersen 83865e3e90 Ready for release 2000-01-15 22:33:09 +00:00
Erik Andersen 3163821967 Sync up busybox with the latest and greatest. This is not stuff for
the Embedix release.
 -Erik
2000-01-15 22:28:50 +00:00
Erik Andersen b7cc49d992 * Added -o loop option for mount, and support in umount for loop
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
    <bcollins@debian.org>

 -Erik
2000-01-13 06:38:14 +00:00
Erik Andersen 05df239ed9 Bug fixes.
-Erik
2000-01-13 04:43:48 +00:00
Erik Andersen 9a9a261569 Fix a logger bug.
-Erik
2000-01-09 06:49:08 +00:00
Erik Andersen ac6e71f0c4 Possible fixes...
-Erik
2000-01-08 22:04:33 +00:00
Erik Andersen 766f9c7a19 Oops. left debug on.
-Erik
2000-01-08 21:20:49 +00:00
Erik Andersen 1dbc17f630 Fix cp and mv so 'cp foo/README bar' where foo and bar are directories,
and README is a file.
 -Erik
2000-01-08 21:16:29 +00:00
41 changed files with 1529 additions and 282 deletions

No files matched your search

+31
View File
@@ -1,3 +1,34 @@
0.41
* New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
by Edward Betts <edward@debian.org>
* Fixed a bug in both cp and mv preventing 'cp foo/README bar'
type commands (file in a directory to another directory)
from working.
* Fixed a logger bug that caused garbage to be written to the syslog
(unless you used busybox syslog, which hid the bug). Thanks
to Alex Holden <alex@linuxhacker.org> for the fix.
* /bin/true and /bin/false were echoing a blank line when run. Now fixed.
* mkdir -p would print an error when asked to mkdir an existing dir
with no interveining subdirectories.
* Fixed "syslogd -O" so that it works.
* Added -o loop option for mount, and support in umount for loop
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
<bcollins@debian.org>
* Several fixes from Marco Pantaleoni <panta@prosa.it>
* compile in fullWrite() not only if BB_TAR is defined, but also
if BB_CP or BB_MV are (fullWrite() is referenced by copyFile())
* add some compiler optimizations to further reduce executable size
(as a side note, on my machines the largest code is generated by
gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with -O2
-m386 ...)
* Compile no longer fails if busybox.def.h defines BB_FEATURE_LINUXRC
but not BB_INIT. (init_main used to be referenced, but not compiled)
* Fixed a bug in setting TERM for serial console support. TERM now
defaults to "ansi" for serial consoles.
* Fixed a bug in handling the CONSOLE env. variable for serial consoles.
-Erik Andersen, Jan 15, 2000
0.40
* New Apps: sort, uniq. -beppu
* New Apps: lsmod, rmmod -erik
+20 -4
View File
@@ -17,7 +17,7 @@
PROG=busybox
VERSION=0.40
VERSION=0.41
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
# Comment out the following to make a debuggable build
@@ -33,10 +33,11 @@ ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
GCCEGCS=$(shell $(CC) --version | sed -n "s/.*\(egcs\).*/\1/p" )
GCCSUPPORTSOPTSIZE=$(shell \
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
if ( test $(GCCMINVERSION) -ge 91 ) ; then \
if ( test $(GCCMINVERSION) -ge 66 ) ; then \
echo "true"; \
else \
echo "false"; \
@@ -49,11 +50,26 @@ else \
fi; \
fi; )
GCCISEGCS=$(shell \
if ( test "x$(GCCEGCS)" == "xegcs" ) ; then \
echo "true"; \
else \
echo "false"; \
fi; )
EGCSEXTREMEFLAGS = -m386 -mcpu=i386 -march=i386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
GCCEXTREMEFLAGS = -m386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
ifeq ($(GCCISEGCS), true)
EXTREMEFLAGS = $(EGCSEXTREMEFLAGS)
else
EXTREMEFLAGS = $(GCCEXTREMEFLAGS)
endif
ifeq ($(GCCSUPPORTSOPTSIZE), true)
OPTIMIZATION=-Os
OPTIMIZATION=-Os $(EXTREMEFLAGS)
else
OPTIMIZATION=-O2
OPTIMIZATION=-O2 $(EXTREMEFLAGS)
endif
# -D_GNU_SOURCE is needed because environ is used in init.c
+5 -1
View File
@@ -6,6 +6,11 @@ around to it some time. If you have any good ideas, please let me know.
* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
needed or wanted in busybox (or else I'd have to link in libcrypt).
* Networking apps are probably going to be split out some time soon into a
separate package (named perhaps tiny-netkit?). This currently includes
hostid, hostname, mnc, and ping.
-Erik
-----------
@@ -18,7 +23,6 @@ around to it some time. If you have any good ideas, please let me know.
* hwclock
* killall
* stty
* wc
* tr
* expr (maybe?) (ash builtin?)
+40
View File
@@ -3,8 +3,28 @@
#include <string.h>
#include <errno.h>
#ifndef BB_INIT
#undef BB_FEATURE_LINUXRC
#endif
static int been_there_done_that = 0;
/* It has been alledged that doing such things can
* help reduce binary size when staticly linking,
* of course with glibc, this is unlikely as long
* as we use things like printf -- perhaps a printf
* replacement may be in order
*/
#if 0
void exit (int status) __attribute__ ((noreturn));
void exit (int status) { _exit(status); };
void abort (void) __attribute__ ((__noreturn__));
void abort (void) { _exit(0); };
int atexit (void (*__func) (void)) { _exit(0); };
void *__libc_stack_end;
#endif
static const struct Applet applets[] = {
#ifdef BB_BUSYBOX //bin
@@ -81,6 +101,9 @@ static const struct Applet applets[] = {
#ifdef BB_HEAD //bin
{"head", head_main},
#endif
#ifdef BB_HOSTID //usr/bin
{"hostid", hostid_main},
#endif
#ifdef BB_HOSTNAME //bin
{"hostname", hostname_main},
#endif
@@ -199,6 +222,9 @@ static const struct Applet applets[] = {
#ifdef BB_LOGGER //usr/bin
{"logger", logger_main},
#endif
#ifdef BB_LOGNAME //usr/bin
{"logname", logname_main},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
@@ -219,6 +245,9 @@ static const struct Applet applets[] = {
{"true", true_main},
{"false", false_main},
#endif
#ifdef BB_TTY //usr/bin
{"tty", tty_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
@@ -231,6 +260,15 @@ static const struct Applet applets[] = {
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_WC //usr/bin
{"wc", wc_main},
#endif
#ifdef BB_WHOAMI //usr/bin
{"whoami", whoami_main},
#endif
#ifdef BB_YES //usr/bin
{"yes", yes_main},
#endif
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
@@ -241,6 +279,8 @@ static const struct Applet applets[] = {
{0}
};
int main(int argc, char **argv)
{
char *s = argv[0];
+40
View File
@@ -3,8 +3,28 @@
#include <string.h>
#include <errno.h>
#ifndef BB_INIT
#undef BB_FEATURE_LINUXRC
#endif
static int been_there_done_that = 0;
/* It has been alledged that doing such things can
* help reduce binary size when staticly linking,
* of course with glibc, this is unlikely as long
* as we use things like printf -- perhaps a printf
* replacement may be in order
*/
#if 0
void exit (int status) __attribute__ ((noreturn));
void exit (int status) { _exit(status); };
void abort (void) __attribute__ ((__noreturn__));
void abort (void) { _exit(0); };
int atexit (void (*__func) (void)) { _exit(0); };
void *__libc_stack_end;
#endif
static const struct Applet applets[] = {
#ifdef BB_BUSYBOX //bin
@@ -81,6 +101,9 @@ static const struct Applet applets[] = {
#ifdef BB_HEAD //bin
{"head", head_main},
#endif
#ifdef BB_HOSTID //usr/bin
{"hostid", hostid_main},
#endif
#ifdef BB_HOSTNAME //bin
{"hostname", hostname_main},
#endif
@@ -199,6 +222,9 @@ static const struct Applet applets[] = {
#ifdef BB_LOGGER //usr/bin
{"logger", logger_main},
#endif
#ifdef BB_LOGNAME //usr/bin
{"logname", logname_main},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
@@ -219,6 +245,9 @@ static const struct Applet applets[] = {
{"true", true_main},
{"false", false_main},
#endif
#ifdef BB_TTY //usr/bin
{"tty", tty_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
@@ -231,6 +260,15 @@ static const struct Applet applets[] = {
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_WC //usr/bin
{"wc", wc_main},
#endif
#ifdef BB_WHOAMI //usr/bin
{"whoami", whoami_main},
#endif
#ifdef BB_YES //usr/bin
{"yes", yes_main},
#endif
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
@@ -241,6 +279,8 @@ static const struct Applet applets[] = {
{0}
};
int main(int argc, char **argv)
{
char *s = argv[0];
+26 -9
View File
@@ -10,10 +10,12 @@
#define BB_CAT
#define BB_CHMOD_CHOWN_CHGRP
#define BB_CHROOT
#define BB_CHVT
#define BB_CLEAR
#define BB_CP
#define BB_DATE
#define BB_DD
#define BB_DEALLOCVT
#define BB_DF
#define BB_DMESG
//#define BB_DUTMP
@@ -23,12 +25,12 @@
#define BB_FIND
#define BB_FREE
#define BB_FSCK_MINIX
#define BB_MKFS_MINIX
#define BB_CHVT
#define BB_DEALLOCVT
#define BB_GREP
#define BB_GUNZIP
#define BB_GZIP
//#define BB_HALT
#define BB_HEAD
//#define BB_HOSTID
#define BB_HOSTNAME
#define BB_INIT
// Don't turn BB_INSMOD on. It doesn't work.
@@ -41,9 +43,11 @@
//#define BB_LOADFONT
//#define BB_LOADKMAP
//#define BB_LOGGER
#define BB_LOGNAME
#define BB_LS
#define BB_LSMOD
//#define BB_MAKEDEVS
#define BB_MKFS_MINIX
//#define BB_MATH
#define BB_MKDIR
//#define BB_MKFIFO
@@ -61,29 +65,31 @@
//#define BB_PRINTF
#define BB_PS
#define BB_PWD
#define BB_REGEXP
#define BB_REBOOT
#define BB_REGEXP
#define BB_RM
#define BB_RMDIR
//#define BB_RMMOD
//#define BB_SFDISK
#define BB_SED
//#define BB_SFDISK
#define BB_SLEEP
#define BB_SORT
#define BB_SWAPONOFF
#define BB_SYNC
//#define BB_SYSLOGD
#define BB_SYSLOGD
#define BB_TAIL
#define BB_TAR
#define BB_TEE
#define BB_TOUCH
#define BB_TRUE_FALSE
#define BB_TTY
#define BB_WC
#define BB_WHOAMI
#define BB_UMOUNT
#define BB_UNIQ
#define BB_UPDATE
#define BB_UNAME
#define BB_GZIP
#define BB_GUNZIP
#define BB_UPDATE
#define BB_YES
// End of Applications List
//
//
@@ -102,20 +108,31 @@
// enable features that use the /proc filesystem (apps that
// break without this will tell you on compile)...
#define BB_FEATURE_USE_PROCFS
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
//
// calculate terminal & column widths (for more and ls)
#define BB_FEATURE_AUTOWIDTH
//
// show username/groupnames (bypasses libc6 NSS) for ls
#define BB_FEATURE_LS_USERNAME
//
// show file timestamps in ls
#define BB_FEATURE_LS_TIMESTAMPS
//
// enable ls -p and -F
#define BB_FEATURE_LS_FILETYPES
//
// Change ping implementation -- simplified, featureless, but really small.
//#define BB_SIMPLE_PING
////
// Make init use a simplified /etc/inittab file (recommended).
#define BB_FEATURE_USE_INITTAB
//
//Enable init being called as /linuxrc
#define BB_FEATURE_LINUXRC
//
// Enable support for loop devices in mount
#define BB_FEATURE_MOUNT_LOOP
//
+2 -2
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.40
Version: 0.41
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -21,7 +21,7 @@ embedded system.
%setup -q -n %{Name}-%{Version}
%Build
BB_INIT_SCRIPT='\"/etc/rc.d/init.d/rcS\"' make
make
%Install
rm -rf $RPM_BUILD_ROOT
+6 -1
View File
@@ -48,6 +48,7 @@ static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
@@ -62,7 +63,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
strcat(newdestName, srcName);
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
+28
View File
@@ -0,0 +1,28 @@
/*
* Mini hostid implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
extern int hostid_main(int argc, char **argv) {
printf ("%lx\n", gethostid());
exit( TRUE);
}
+40
View File
@@ -0,0 +1,40 @@
/*
* Mini logname implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
static const char logname_usage[] = "logname\n\n"
"Print the name of the current user.\n";
extern int logname_main(int argc, char **argv) {
char *cp;
if (argc > 1) usage (logname_usage);
cp = getlogin ();
if (cp) {
puts (cp);
exit (TRUE);
}
fprintf (stderr, "%s: no login name\n", argv[0]);
exit (FALSE);
}
+2 -2
View File
@@ -84,7 +84,7 @@ extern int mkdir_main(int argc, char **argv)
strcpy (buf, *argv);
status=stat(buf, &statBuf);
if (status != -1 && status != ENOENT ) {
if (parentFlag == FALSE && status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", buf);
exit( FALSE);
}
@@ -93,7 +93,7 @@ extern int mkdir_main(int argc, char **argv)
createPath(buf, mode);
}
else {
if (mkdir (buf, mode) != 0) {
if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
perror(buf);
exit( FALSE);
}
+6 -1
View File
@@ -40,6 +40,7 @@ static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
@@ -50,7 +51,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
strcat(newdestName, srcName);
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, TRUE, TRUE));
+42
View File
@@ -0,0 +1,42 @@
/*
* Mini tty implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
#include <sys/types.h>
static const char tty_usage[] = "tty\n\n"
"Print the file name of the terminal connected to standard input.\n"
"\t-s\tprint nothing, only return an exit status\n";
extern int tty_main(int argc, char **argv) {
char *tty;
if (argc > 1) {
if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
}
else {
tty = ttyname (0);
if (tty) puts (tty);
else puts ("not a tty");
}
exit (isatty (0) ? TRUE : FALSE);
}
+162
View File
@@ -0,0 +1,162 @@
/*
* Mini wc implementation for busybox
*
* by Edward Betts <edward@debian.org>
*
* 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 <stdio.h>
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
"Print line, word, and byte counts for each FILE, and a total line if\n"
"more than one FILE is specified. With no FILE, read standard input.\n"
"\t-c\tprint the byte counts\n"
"\t-l\tprint the newline counts\n"
"\t-L\tprint the length of the longest line\n"
"\t-L\tprint the length of the longest line\n"
"\t-w\tprint the word counts\n";
static int total_lines, total_words, total_chars, max_length;
static int print_lines, print_words, print_chars, print_length;
void print_counts (int lines, int words, int chars, int length,
const char *name) {
char const *space = "";
if (print_lines) {
printf ("%7d", lines);
space = " ";
}
if (print_words) {
printf ("%s%7d", space, words);
space = " ";
}
if (print_chars) {
printf ("%s%7d", space, chars);
space = " ";
}
if (print_length)
printf ("%s%7d", space, length);
if (*name)
printf (" %s", name);
putchar ('\n');
}
static void wc_file(FILE *file, const char *name)
{
int lines, words, chars, length;
int in_word = 0, linepos = 0;
int c;
lines = words = chars = length = 0;
while ((c = getc(file)) != EOF) {
chars++;
switch (c) {
case '\n':
lines++;
case '\r':
case '\f':
if (linepos > length)
length = linepos;
linepos = 0;
goto word_separator;
case '\t':
linepos += 8 - (linepos % 8);
goto word_separator;
case ' ':
linepos++;
case '\v':
word_separator:
if (in_word) {
in_word = 0;
words++;
}
break;
default:
linepos++;
in_word = 1;
break;
}
}
if (linepos > length)
length = linepos;
if (in_word)
words++;
print_counts (lines, words, chars, length, name);
total_lines += lines;
total_words += words;
total_chars += chars;
if (length > max_length)
max_length = length;
fclose(file);
fflush(stdout);
}
int wc_main(int argc, char **argv) {
FILE *file;
total_lines = total_words = total_chars = max_length = 0;
print_lines = print_words = print_chars = print_length = 0;
while (--argc && **(++argv) == '-') {
while (*++(*argv))
switch (**argv) {
case 'c':
print_chars = 1;
break;
case 'l':
print_lines = 1;
break;
case 'L':
print_length = 1;
break;
case 'w':
print_words = 1;
break;
default:
usage (wc_usage);
}
}
if (!print_lines && !print_words && !print_chars && !print_length)
print_lines = print_words = print_chars = 1;
if (argc == 0) {
wc_file(stdin, "");
exit(TRUE);
}
else if (argc == 1) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
}
wc_file(file, *argv);
}
else {
while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
}
wc_file(file, *argv);
argv++;
}
print_counts (total_lines, total_words, total_chars,
max_length, "total");
}
exit(TRUE);
}
+44
View File
@@ -0,0 +1,44 @@
/*
* Mini whoami implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
#include <pwd.h>
static const char whoami_usage[] = "whoami\n\n"
"Print the user name associated with the current effective user id.\n"
"Same as id -un.\n";
extern int whoami_main(int argc, char **argv) {
struct passwd *pw;
uid_t uid;
if (argc > 1) usage (whoami_usage);
uid = geteuid ();
pw = getpwuid (uid);
if (pw) {
puts (pw->pw_name);
exit (TRUE);
}
fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
exit (FALSE);
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Mini yes implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
extern int yes_main(int argc, char **argv) {
int i;
if (argc == 1)
while (1)
if (puts ("y") == EOF) {
perror ("yes");
exit(FALSE);
}
while (1)
for (i = 1; i < argc; i++)
if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
perror ("yes");
exit(FALSE);
}
exit(TRUE);
}
+6 -1
View File
@@ -48,6 +48,7 @@ static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
@@ -62,7 +63,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
strcat(newdestName, srcName);
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
+52 -83
View File
@@ -12,6 +12,9 @@ ________________________________________________________________________________
BusyBox 0.38, Functions and the Arguments they Support
New Apps that have been added to BusyBox since this document was written:
ping, hostname, mkfifo, free, tail, du, tee, head, sort, uniq, lsmod, rmmod, fbset, and loadacm.
______________________________________________________________________________________________________
@@ -154,7 +157,7 @@ cp [option] fileA fileB
attributes group permissions and time information.
-R recursive Copy to the current location and all subdirectories in the tree.
-R recursive Copies directories recursively
@@ -321,7 +324,7 @@ fsck.minix [-larvsmf] /dev/name
-r Perform interactive repairs.
-q Perform automatic repairs
-a Perform automatic repairs
-v Verbose
@@ -512,11 +515,14 @@ ________________________________________________________________________________
mknod (Segmentation Fault when executing this command)
(No embedix information available for this command.)
mknod NAME TYPE MAJOR MINOR
Make block or character special files.
TYPEs include:
b: Make a block (buffered) device.
c or u: Make a character (un-buffered) device.
p: Make a named pipe. Major and minor are ignored for named pipes.
@@ -712,76 +718,32 @@ ________________________________________________________________________________
sed
Usage: sed [-n] -e script [file...]
Sed scripts are subject to the following format: 's/regexp/replacement/[gp]' which attempts to
Allowed sed scripts come in the following form:
'ADDR [!] COMMAND'
to match regexp against the pattern space and if successful, replaces the matched portion with
where address ADDR can be:
NUMBER Match specified line number
$ Match last line
/REGEXP/ Match specified regexp
(! inverts the meaning of the match)
replacement -r or -R Remove contents of directories recursively.
and COMMAND can be:
s/regexp/replacement/[igp]
which attempt to match regexp against the pattern space
and if successful replaces the matched portion with replacement.
aTEXT
which appends TEXT after the pattern space
Options:
-e add the script to the commands to be executed
-n suppress automatic printing of pattern space
This version of sed matches full regular expresions.
________________________________________________________________________________________________________
rmdir [OPTION] ... directory
Remove directories if they are empty.
________________________________________________________________________________________________________
rmdir [OPTION] ... directory
Remove directories if they are empty.
________________________________________________________________________________________________________
sed
Sed scripts are subject to the following format: 's/regexp/replacement/[gp]' which attempts to
match regexp against the pattern space and if successful, replaces the matched portion with
replacement. This version of sed matches
full regular expressions.
-e Add the script to the commands to be executed.
-n Suppress automatic printing of pattern space..
-e Add the script to the commands to be executed.
-n Suppress automatic printing of pattern space..
-e Add the script to the commands to be executed.
-n Suppress automatic printing of pattern space.
________________________________________________________________________________________________________
@@ -977,9 +939,25 @@ ________________________________________________________________________________
zcat [options] files
Uncompress file from gzip, gunzip or compress command or standard input if file is '-'.
Usage: zcat [OPTION]... FILE
-c Write output to standard output.
Uncompress FILE (or standard input if FILE is '-').
(When invoked as zcat, defaults to having -c turned on)
Options:
-c Write output to standard output
-t Test compressed file integrity
________________________________________________________________________________________________________
gunzip (Same as zcat, but without the "-c" option.)
@@ -991,22 +969,13 @@ ________________________________________________________________________________
gunzip (Same as zcat)
________________________________________________________________________________________________________
gzip (Same as zcat)
gzip [OPTION]... FILE
Compress FILE with maximum compression.
When FILE is -, reads standard input. Implies -c.
Options:
-c Write output to standard output instead of FILE.gz
+2 -2
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.40
Version: 0.41
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -21,7 +21,7 @@ embedded system.
%setup -q -n %{Name}-%{Version}
%Build
BB_INIT_SCRIPT='\"/etc/rc.d/init.d/rcS\"' make
make
%Install
rm -rf $RPM_BUILD_ROOT
+28
View File
@@ -0,0 +1,28 @@
/*
* Mini hostid implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
extern int hostid_main(int argc, char **argv) {
printf ("%lx\n", gethostid());
exit( TRUE);
}
+60 -48
View File
@@ -106,10 +106,11 @@ struct initActionTag {
initAction* initActionList = NULL;
static char *console = _PATH_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *secondConsole = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
static int kernelVersion = 0;
static char termType[32] = "TERM=ansi";
static char console[32] = _PATH_CONSOLE;
/* try to open up the specified device */
@@ -257,35 +258,37 @@ static void console_init()
struct serial_struct sr;
char *s;
if ((s = getenv("TERM")) != NULL) {
snprintf(termType,sizeof(termType)-1,"TERM=%s",s);
}
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
snprintf(console, sizeof(console)-1, "%s",s);
}
#if #cpu(sparc)
/* sparc kernel supports console=tty[ab] parameter which is also
* passed to init, so catch it here */
else if ((s = getenv("console")) != NULL) {
else if ((s = getenv("console")) != NULL) {*/
/* remap tty[ab] to /dev/ttyS[01] */
if (strcmp( s, "ttya" )==0)
console = SERIAL_CON0;
snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0);
else if (strcmp( s, "ttyb" )==0)
console = SERIAL_CON1;
snprintf(console, sizeof(console)-1, "%s", SERIAL_CON1);
}
#endif
else {
struct vt_stat vt;
static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
snprintf(console, sizeof(console)-1, "/dev/ttyS%d", sr.line);
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
snprintf(console, sizeof(console)-1, "/dev/tty%d", vt.v_active);
} else {
console = _PATH_CONSOLE;
snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
tried_devcons++;
}
}
@@ -294,27 +297,27 @@ static void console_init()
/* Can't open selected console -- try /dev/console */
if (!tried_devcons) {
tried_devcons++;
console = _PATH_CONSOLE;
snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
continue;
}
/* Can't open selected console -- try vt1 */
if (!tried_vtprimary) {
tried_vtprimary++;
console = VT_PRIMARY;
snprintf(console, sizeof(console)-1, "%s", VT_PRIMARY);
continue;
}
break;
}
if (fd < 0)
if (fd < 0) {
/* Perhaps we should panic here? */
console = "/dev/null";
else {
snprintf(console, sizeof(console)-1, "/dev/null");
} else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console );
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n" );
log = NULL;
second_console = NULL;
secondConsole = NULL;
}
close(fd);
}
@@ -324,15 +327,23 @@ static void console_init()
static pid_t run(char* command,
char *terminal, int get_enter)
{
int i;
int i, fd;
pid_t pid;
char* tmpCmd;
char* cmd[255];
static const char press_enter[] =
"\nPlease press Enter to activate this console. ";
char* environment[] = {
"HOME=/",
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
"SHELL=/bin/sh",
termType,
"USER=root",
0
};
if ((pid = fork()) == 0) {
int fd;
pid_t shell_pgid = getpid ();
/* Clean up */
@@ -341,21 +352,20 @@ static pid_t run(char* command,
close(2);
setsid();
if ((fd=device_open(terminal, O_RDWR)) < 0) {
message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal);
exit(1);
}
dup(fd);
dup(fd);
set_term(fd);
tcsetpgrp (fd, getpgrp());
/* Reset signal handlers set for parent process */
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal);
exit(1);
}
dup(fd);
dup(fd);
tcsetpgrp (0, getpgrp());
set_term(0);
if (get_enter==TRUE) {
/*
@@ -373,23 +383,25 @@ static pid_t run(char* command,
read(fileno(stdin), &c, 1);
}
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '",
shell_pgid, terminal, command);
/* Convert command (char*) into cmd (char**, one word per string) */
for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) {
if (*tmpCmd != '\0') {
cmd[i] = tmpCmd;
message(LOG, "%s ", tmpCmd);
tmpCmd++;
i++;
}
}
cmd[i] = NULL;
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
shell_pgid, terminal, cmd[0]);
message(LOG, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execvp(cmd[0], cmd);
execve(cmd[0], cmd, environment);
/* We're still here? Some error happened. */
message(LOG|CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0],
@@ -464,7 +476,7 @@ static void shutdown_system(void)
message(CONSOLE, "Unmounting filesystems.\r\n");
waitfor("umount -a", console, FALSE);
sync();
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
@@ -505,7 +517,7 @@ void new_initAction (initActionEnum action,
/* If BusyBox detects that a serial console is in use,
* then entries containing non-empty id fields will _not_ be run.
*/
if (second_console == NULL && *cons != '\0') {
if (secondConsole == NULL && *cons != '\0') {
return;
}
@@ -563,8 +575,8 @@ void parse_inittab(void)
/* Askfirst shell on tty1 */
new_initAction( ASKFIRST, SHELL, console );
/* Askfirst shell on tty2 */
if (second_console != NULL)
new_initAction( ASKFIRST, SHELL, second_console );
if (secondConsole != NULL)
new_initAction( ASKFIRST, SHELL, secondConsole );
/* sysinit */
new_initAction( SYSINIT, INIT_SCRIPT, console );
@@ -655,11 +667,11 @@ extern int init_main(int argc, char **argv)
usage( "init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\n");
}
/* Fix up argv[0] to be certain we claim to be init */
strncpy(argv[0], "init", strlen(argv[0]));
/* from the controlling terminal */
setsid();
/* Set up sig handlers -- be sure to clear all of these in run() */
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
@@ -669,7 +681,7 @@ extern int init_main(int argc, char **argv)
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD);
#endif
/* Figure out where the default console should be */
console_init();
@@ -678,11 +690,11 @@ extern int init_main(int argc, char **argv)
close(1);
close(2);
set_term(0);
setsid();
/* Make sure PATH is set to something sane */
putenv(_PATH_STDPATH);
/* Hello world */
#ifndef DEBUG_INIT
message(LOG|CONSOLE,
@@ -698,7 +710,7 @@ extern int init_main(int argc, char **argv)
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
message(LOG|CONSOLE, "Mounting /proc: done.\n");
kernel_version = get_kernel_revision();
kernelVersion = get_kernel_revision();
} else
message(LOG|CONSOLE, "Mounting /proc: failed!\n");
@@ -710,8 +722,8 @@ extern int init_main(int argc, char **argv)
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1")))
{
/* Ask first then start a shell on tty2 */
if (second_console != NULL)
new_initAction( ASKFIRST, SHELL, second_console);
if (secondConsole != NULL)
new_initAction( ASKFIRST, SHELL, secondConsole);
/* Ask first then start a shell on tty1 */
new_initAction( ASKFIRST, SHELL, console);
} else {
+60 -48
View File
@@ -106,10 +106,11 @@ struct initActionTag {
initAction* initActionList = NULL;
static char *console = _PATH_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *secondConsole = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
static int kernelVersion = 0;
static char termType[32] = "TERM=ansi";
static char console[32] = _PATH_CONSOLE;
/* try to open up the specified device */
@@ -257,35 +258,37 @@ static void console_init()
struct serial_struct sr;
char *s;
if ((s = getenv("TERM")) != NULL) {
snprintf(termType,sizeof(termType)-1,"TERM=%s",s);
}
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
snprintf(console, sizeof(console)-1, "%s",s);
}
#if #cpu(sparc)
/* sparc kernel supports console=tty[ab] parameter which is also
* passed to init, so catch it here */
else if ((s = getenv("console")) != NULL) {
else if ((s = getenv("console")) != NULL) {*/
/* remap tty[ab] to /dev/ttyS[01] */
if (strcmp( s, "ttya" )==0)
console = SERIAL_CON0;
snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0);
else if (strcmp( s, "ttyb" )==0)
console = SERIAL_CON1;
snprintf(console, sizeof(console)-1, "%s", SERIAL_CON1);
}
#endif
else {
struct vt_stat vt;
static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
snprintf(console, sizeof(console)-1, "/dev/ttyS%d", sr.line);
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
snprintf(console, sizeof(console)-1, "/dev/tty%d", vt.v_active);
} else {
console = _PATH_CONSOLE;
snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
tried_devcons++;
}
}
@@ -294,27 +297,27 @@ static void console_init()
/* Can't open selected console -- try /dev/console */
if (!tried_devcons) {
tried_devcons++;
console = _PATH_CONSOLE;
snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE);
continue;
}
/* Can't open selected console -- try vt1 */
if (!tried_vtprimary) {
tried_vtprimary++;
console = VT_PRIMARY;
snprintf(console, sizeof(console)-1, "%s", VT_PRIMARY);
continue;
}
break;
}
if (fd < 0)
if (fd < 0) {
/* Perhaps we should panic here? */
console = "/dev/null";
else {
snprintf(console, sizeof(console)-1, "/dev/null");
} else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console );
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n" );
log = NULL;
second_console = NULL;
secondConsole = NULL;
}
close(fd);
}
@@ -324,15 +327,23 @@ static void console_init()
static pid_t run(char* command,
char *terminal, int get_enter)
{
int i;
int i, fd;
pid_t pid;
char* tmpCmd;
char* cmd[255];
static const char press_enter[] =
"\nPlease press Enter to activate this console. ";
char* environment[] = {
"HOME=/",
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
"SHELL=/bin/sh",
termType,
"USER=root",
0
};
if ((pid = fork()) == 0) {
int fd;
pid_t shell_pgid = getpid ();
/* Clean up */
@@ -341,21 +352,20 @@ static pid_t run(char* command,
close(2);
setsid();
if ((fd=device_open(terminal, O_RDWR)) < 0) {
message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal);
exit(1);
}
dup(fd);
dup(fd);
set_term(fd);
tcsetpgrp (fd, getpgrp());
/* Reset signal handlers set for parent process */
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal);
exit(1);
}
dup(fd);
dup(fd);
tcsetpgrp (0, getpgrp());
set_term(0);
if (get_enter==TRUE) {
/*
@@ -373,23 +383,25 @@ static pid_t run(char* command,
read(fileno(stdin), &c, 1);
}
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '",
shell_pgid, terminal, command);
/* Convert command (char*) into cmd (char**, one word per string) */
for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) {
if (*tmpCmd != '\0') {
cmd[i] = tmpCmd;
message(LOG, "%s ", tmpCmd);
tmpCmd++;
i++;
}
}
cmd[i] = NULL;
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
shell_pgid, terminal, cmd[0]);
message(LOG, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execvp(cmd[0], cmd);
execve(cmd[0], cmd, environment);
/* We're still here? Some error happened. */
message(LOG|CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0],
@@ -464,7 +476,7 @@ static void shutdown_system(void)
message(CONSOLE, "Unmounting filesystems.\r\n");
waitfor("umount -a", console, FALSE);
sync();
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
@@ -505,7 +517,7 @@ void new_initAction (initActionEnum action,
/* If BusyBox detects that a serial console is in use,
* then entries containing non-empty id fields will _not_ be run.
*/
if (second_console == NULL && *cons != '\0') {
if (secondConsole == NULL && *cons != '\0') {
return;
}
@@ -563,8 +575,8 @@ void parse_inittab(void)
/* Askfirst shell on tty1 */
new_initAction( ASKFIRST, SHELL, console );
/* Askfirst shell on tty2 */
if (second_console != NULL)
new_initAction( ASKFIRST, SHELL, second_console );
if (secondConsole != NULL)
new_initAction( ASKFIRST, SHELL, secondConsole );
/* sysinit */
new_initAction( SYSINIT, INIT_SCRIPT, console );
@@ -655,11 +667,11 @@ extern int init_main(int argc, char **argv)
usage( "init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\n");
}
/* Fix up argv[0] to be certain we claim to be init */
strncpy(argv[0], "init", strlen(argv[0]));
/* from the controlling terminal */
setsid();
/* Set up sig handlers -- be sure to clear all of these in run() */
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
@@ -669,7 +681,7 @@ extern int init_main(int argc, char **argv)
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD);
#endif
/* Figure out where the default console should be */
console_init();
@@ -678,11 +690,11 @@ extern int init_main(int argc, char **argv)
close(1);
close(2);
set_term(0);
setsid();
/* Make sure PATH is set to something sane */
putenv(_PATH_STDPATH);
/* Hello world */
#ifndef DEBUG_INIT
message(LOG|CONSOLE,
@@ -698,7 +710,7 @@ extern int init_main(int argc, char **argv)
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
message(LOG|CONSOLE, "Mounting /proc: done.\n");
kernel_version = get_kernel_revision();
kernelVersion = get_kernel_revision();
} else
message(LOG|CONSOLE, "Mounting /proc: failed!\n");
@@ -710,8 +722,8 @@ extern int init_main(int argc, char **argv)
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1")))
{
/* Ask first then start a shell on tty2 */
if (second_console != NULL)
new_initAction( ASKFIRST, SHELL, second_console);
if (secondConsole != NULL)
new_initAction( ASKFIRST, SHELL, secondConsole);
/* Ask first then start a shell on tty1 */
new_initAction( ASKFIRST, SHELL, console);
} else {
+20 -11
View File
@@ -54,7 +54,6 @@ struct Applet {
extern int busybox_main(int argc, char** argv);
extern int block_device_main(int argc, char** argv);
extern int cat_main(int argc, char** argv);
extern int more_main(int argc, char** argv);
extern int cp_main(int argc, char** argv);
extern int chmod_chown_chgrp_main(int argc, char** argv);
extern int chroot_main(int argc, char** argv);
@@ -75,17 +74,23 @@ extern int fsck_minix_main(int argc, char **argv);
extern int find_main(int argc, char** argv);
extern int free_main(int argc, char** argv);
extern int grep_main(int argc, char** argv);
extern int gunzip_main (int argc, char** argv);
extern int gzip_main(int argc, char** argv);
extern int halt_main(int argc, char** argv);
extern int head_main(int argc, char** argv);
extern int hostid_main(int argc, char** argv);
extern int hostname_main(int argc, char** argv);
extern int init_main(int argc, char** argv);
extern int insmod_main(int argc, char** argv);
extern int kill_main(int argc, char** argv);
extern int length_main(int argc, char** argv);
extern int ln_main(int argc, char** argv);
extern int loadacm_main(int argc, char** argv);
extern int loadfont_main(int argc, char** argv);
extern int loadkmap_main(int argc, char** argv);
extern int losetup_main(int argc, char** argv);
extern int logger_main(int argc, char **argv);
extern int logname_main(int argc, char **argv);
extern int ls_main(int argc, char** argv);
extern int lsmod_main(int argc, char** argv);
extern int makedevs_main(int argc, char** argv);
@@ -96,6 +101,7 @@ extern int mkfs_minix_main(int argc, char **argv);
extern int mknod_main(int argc, char** argv);
extern int mkswap_main(int argc, char** argv);
extern int mnc_main(int argc, char** argv);
extern int more_main(int argc, char** argv);
extern int mount_main(int argc, char** argv);
extern int mt_main(int argc, char** argv);
extern int mv_main(int argc, char** argv);
@@ -108,30 +114,28 @@ extern int reboot_main(int argc, char** argv);
extern int rm_main(int argc, char** argv);
extern int rmdir_main(int argc, char **argv);
extern int rmmod_main(int argc, char** argv);
extern int scan_partitions_main(int argc, char** argv);
extern int sh_main(int argc, char** argv);
extern int sfdisk_main(int argc, char** argv);
extern int sed_main(int argc, char** argv);
extern int sfdisk_main(int argc, char** argv);
extern int sleep_main(int argc, char** argv);
extern int sort_main(int argc, char** argv);
extern int swap_on_off_main(int argc, char** argv);
extern int sync_main(int argc, char** argv);
extern int syslogd_main(int argc, char **argv);
extern int logger_main(int argc, char **argv);
extern int tar_main(int argc, char** argv);
extern int tail_main(int argc, char** argv);
extern int tar_main(int argc, char** argv);
extern int tee_main(int argc, char** argv);
extern int touch_main(int argc, char** argv);
extern int tput_main(int argc, char** argv);
extern int true_main(int argc, char** argv);
extern int tput_main(int argc, char** argv);
extern int tryopen_main(int argc, char** argv);
extern int tty_main(int argc, char** argv);
extern int umount_main(int argc, char** argv);
extern int uname_main(int argc, char** argv);
extern int uniq_main(int argc, char** argv);
extern int update_main(int argc, char** argv);
extern int uname_main(int argc, char** argv);
extern int gunzip_main (int argc, char** argv);
extern int gzip_main(int argc, char** argv);
extern int loadacm_main(int argc, char** argv);
extern int wc_main(int argc, char** argv);
extern int whoami_main(int argc, char** argv);
extern int yes_main(int argc, char** argv);
const char *modeString(int mode);
@@ -203,6 +207,11 @@ static inline int clrbit(char * addr,unsigned int nr)
#endif /* inline bitops junk */
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possable. */
#define RB_POWER_OFF 0x4321fedc
#endif
#endif /* _INTERNAL_H_ */
+1 -1
View File
@@ -186,7 +186,7 @@ extern int logger_main(int argc, char **argv)
if (toStdErrFlag==TRUE)
fprintf(stderr, "%s\n", buf);
write( fd, buf, sizeof(buf));
write( fd, buf, strlen(buf)+1);
close(fd);
exit( TRUE);
+40
View File
@@ -0,0 +1,40 @@
/*
* Mini logname implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
static const char logname_usage[] = "logname\n\n"
"Print the name of the current user.\n";
extern int logname_main(int argc, char **argv) {
char *cp;
if (argc > 1) usage (logname_usage);
cp = getlogin ();
if (cp) {
puts (cp);
exit (TRUE);
}
fprintf (stderr, "%s: no login name\n", argv[0]);
exit (FALSE);
}
+2 -2
View File
@@ -84,7 +84,7 @@ extern int mkdir_main(int argc, char **argv)
strcpy (buf, *argv);
status=stat(buf, &statBuf);
if (status != -1 && status != ENOENT ) {
if (parentFlag == FALSE && status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", buf);
exit( FALSE);
}
@@ -93,7 +93,7 @@ extern int mkdir_main(int argc, char **argv)
createPath(buf, mode);
}
else {
if (mkdir (buf, mode) != 0) {
if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
perror(buf);
exit( FALSE);
}
+128 -15
View File
@@ -24,11 +24,16 @@
* 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
*
* 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>.
* Rewrote of a lot of code. Removed mtab usage (I plan on
* Rewrite of a lot of code. Removed mtab usage (I plan on
* putting it back as a compile-time option some time),
* major adjustments to option parsing, and some serious
* dieting all around.
*/
*
* 1999-11-06 mtab suppport is back - andersee
*
* 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
* mount to add loop support.
*/
#include "internal.h"
#include <stdlib.h>
@@ -41,6 +46,17 @@
#include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
static int set_loop(const char *device, const char *file, int offset, int *loopro);
static char *find_unused_loop_device (void);
static int use_loop = 0;
#endif
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "\tmount [flags]\n"
@@ -61,6 +77,9 @@ static const char mount_usage[] = "\tmount [flags]\n"
"\tasync / sync:\tWrites are asynchronous / synchronous.\n"
"\tdev / nodev:\tAllow use of special device files / disallow them.\n"
"\texec / noexec:\tAllow use of executable files / disallow them.\n"
#if defined BB_FEATURE_MOUNT_LOOP
"\tloop: Mounts a file via loop device.\n"
#endif
"\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
"\tro / rw: Mount for read-only / read-write.\n"
@@ -91,28 +110,48 @@ static const struct mount_options mount_options[] = {
{0, 0, 0}
};
#if ! defined BB_MTAB
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
mount(specialfile, dir, filesystemtype, flags, string_flags)
#else
static int
do_mount(char* specialfile, char* dir, char* filesystemtype,
long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
{
int status=0;
#if defined BB_MTAB
if (fakeIt==FALSE)
#endif
{
#if defined BB_FEATURE_MOUNT_LOOP
if (use_loop) {
int loro = flags & MS_RDONLY;
char *lofile = specialfile;
specialfile = find_unused_loop_device();
if (specialfile == NULL) {
fprintf(stderr, "Could not find a spare loop device\n");
exit(1);
}
if (set_loop (specialfile, lofile, 0, &loro)) {
fprintf(stderr, "Could not setup loop device\n");
exit(1);
}
if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */
fprintf(stderr, "WARNING: loop device is read-only\n");
flags &= ~MS_RDONLY;
}
}
#endif
status=mount(specialfile, dir, filesystemtype, flags, string_flags);
if ( status == 0 ) {
if ( useMtab==TRUE )
}
#if defined BB_MTAB
if (status == 0) {
if (useMtab==TRUE)
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
return 0;
}
else
return( status);
}
else
#endif
return(status);
}
#if defined BB_MTAB
@@ -148,16 +187,20 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
}
f++;
}
#if defined BB_FEATURE_MOUNT_LOOP
if (gotone==FALSE && !strcasecmp ("loop", options)) { /* loop device support */
use_loop = 1;
gotone=TRUE;
}
#endif
if (*strflags && strflags!= '\0' && gotone==FALSE) {
char *temp=strflags;
temp += strlen (strflags);
*temp++ = ',';
*temp++ = '\0';
}
if (gotone==FALSE) {
if (gotone==FALSE)
strcat (strflags, options);
gotone=FALSE;
}
if (comma) {
*comma = ',';
options = ++comma;
@@ -356,3 +399,73 @@ extern int mount_main (int argc, char **argv)
goodbye:
usage( mount_usage);
}
#if defined BB_FEATURE_MOUNT_LOOP
static int set_loop(const char *device, const char *file, int offset, int *loopro)
{
struct loop_info loopinfo;
int fd, ffd, mode;
mode = *loopro ? O_RDONLY : O_RDWR;
if ((ffd = open (file, mode)) < 0 && !*loopro
&& (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
perror (file);
return 1;
}
if ((fd = open (device, mode)) < 0) {
close(ffd);
perror (device);
return 1;
}
*loopro = (mode == O_RDONLY);
memset(&loopinfo, 0, sizeof(loopinfo));
strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
loopinfo.lo_offset = offset;
loopinfo.lo_encrypt_key_size = 0;
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
perror("ioctl: LOOP_SET_FD");
exit(1);
}
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
(void) ioctl(fd, LOOP_CLR_FD, 0);
perror("ioctl: LOOP_SET_STATUS");
exit(1);
}
close(fd);
close(ffd);
return 0;
}
static char *find_unused_loop_device (void)
{
char dev[20];
int i, fd, somedev = 0, someloop = 0;
struct stat statbuf;
struct loop_info loopinfo;
for(i = 0; i < 256; i++) {
sprintf(dev, "/dev/loop%d", i);
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
somedev++;
fd = open (dev, O_RDONLY);
if (fd >= 0) {
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
someloop++; /* in use */
else if (errno == ENXIO) {
close (fd);
return strdup(dev); /* probably free */
}
close (fd);
}
continue;
}
if (i >= 7)
break;
}
return NULL;
}
#endif /* BB_FEATURE_MOUNT_LOOP */
+6 -1
View File
@@ -40,6 +40,7 @@ static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
@@ -50,7 +51,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
strcat(newdestName, srcName);
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, TRUE, TRUE));
+22 -12
View File
@@ -9,7 +9,7 @@ if ! eval diff -u tar.c testdir ; then
echo "Bummer. File copy failed."
exit 0
else
echo "Cool. File copy is ok."
echo "Cool. 'cp tar.c testdir' is ok."
fi
rm -rf testdir
@@ -20,7 +20,7 @@ if ! eval diff -u tar.c testdir/foo/tar.c ; then
echo "Bummer. File copy to a directory failed."
exit 0
else
echo "Cool. File copy to a directory is ok."
echo "Cool. 'cp tar.c testdir/foo' is ok."
fi
@@ -32,7 +32,7 @@ if ! eval diff -u tar.c testdir/foo/tar.c ; then
echo "Bummer. File copy to a directory w/ a '/' failed."
exit 0
else
echo "Cool. File copy to a directory w/ a '/' is ok."
echo "Cool. 'cp tar.c testdir/foo/' is ok."
fi
@@ -44,7 +44,7 @@ if ! eval diff -ur X11 testdir ; then
echo "Bummer. Local dir copy failed."
exit 0
else
echo "Cool. Local dir copy is ok."
echo "Cool. 'cp -a X11 testdir' is ok."
fi
rm -rf testdir X11
@@ -55,7 +55,7 @@ if ! eval diff -ur X11 testdir ; then
echo "Bummer. Local dir copy w/ a '/' failed."
exit 0
else
echo "Cool. Local dir copy w/ a '/' is ok."
echo "Cool. 'cp -a X11 testdir/' is ok."
fi
rm -rf testdir X11
@@ -66,7 +66,7 @@ if ! eval diff -ur X11 testdir ; then
echo "Bummer. Local dir copy w/ a src '/' failed."
exit 0
else
echo "Cool. Local dir copy w/ a src '/' is ok."
echo "Cool. 'cp -a X11/ testdir' is ok."
fi
rm -rf testdir X11
@@ -77,7 +77,7 @@ if ! eval diff -ur X11 testdir ; then
echo "Bummer. Local dir copy w/ 2x '/'s failed."
exit 0
else
echo "Cool. Local dir copy w/ 2x '/'s is ok."
echo "Cool. 'cp -a X11/ testdir/' is ok."
fi
rm -rf testdir X11
@@ -86,7 +86,7 @@ if ! eval diff -ur /etc/X11 testdir ; then
echo "Bummer. Remote dir copy failed."
exit 0
else
echo "Cool. Remote dir copy is ok."
echo "Cool. 'cp -a /etc/X11 testdir' is ok."
fi
@@ -98,7 +98,7 @@ if ! eval diff -ur /etc/X11 testdir/foo ; then
echo "Bummer. Remote dir copy to a directory failed."
exit 0
else
echo "Cool. Remote dir copy to a directory is ok."
echo "Cool. 'cp -a /etc/X11 testdir/foo' is ok."
fi
@@ -110,7 +110,7 @@ if ! eval diff -ur /etc/X11 testdir/foo ; then
echo "Bummer. Remote dir copy to a directory w/ a '/' failed."
exit 0
else
echo "Cool. Remote dir copy to a directory w/ a '/' is ok."
echo "Cool. 'cp -a /etc/X11 testdir/foo/' is ok."
fi
rm -rf testdir
@@ -124,14 +124,24 @@ if ! eval ./busybox cp README foo ; then
echo "Bummer. cp README foo failed."
exit 0
else
echo "Cool. cp README foo is ok."
echo "Cool. 'cp README foo' is ok."
fi
if ! eval ./busybox cp foo/README bar ; then
echo "Bummer. cp foo/README bar failed."
exit 0
else
echo "Cool. cp foo/README bar is ok."
echo "Cool. 'cp foo/README bar' is ok."
fi
rm -f bar/README
ENVVAR1=foo
ENVVAR2=bar
if ! eval ./busybox cp $ENVVAR1/README $ENVVAR2 ; then
echo "Bummer. cp foo/README bar failed."
exit 0
else
echo "Cool. 'cp \$ENVVAR1/README \$ENVVAR2' is ok."
fi
rm -rf foo bar
+1 -1
View File
@@ -186,7 +186,7 @@ extern int logger_main(int argc, char **argv)
if (toStdErrFlag==TRUE)
fprintf(stderr, "%s\n", buf);
write( fd, buf, sizeof(buf));
write( fd, buf, strlen(buf)+1);
close(fd);
exit( TRUE);
+4 -1
View File
@@ -337,11 +337,13 @@ extern int syslogd_main(int argc, char **argv)
#ifdef BB_KLOGD
int startKlogd = TRUE;
#endif
int stopDoingThat = FALSE;
char *p;
char **argv1=argv;
while (--argc > 0 && **(++argv1) == '-') {
while (*(++(*argv1))) {
stopDoingThat = FALSE;
while (stopDoingThat == FALSE && *(++(*argv1))) {
switch (**argv1) {
case 'm':
if (--argc == 0) {
@@ -362,6 +364,7 @@ extern int syslogd_main(int argc, char **argv)
usage(syslogd_usage);
}
logFilePath = *(++argv1);
stopDoingThat = TRUE;
break;
default:
usage(syslogd_usage);
+4 -1
View File
@@ -337,11 +337,13 @@ extern int syslogd_main(int argc, char **argv)
#ifdef BB_KLOGD
int startKlogd = TRUE;
#endif
int stopDoingThat = FALSE;
char *p;
char **argv1=argv;
while (--argc > 0 && **(++argv1) == '-') {
while (*(++(*argv1))) {
stopDoingThat = FALSE;
while (stopDoingThat == FALSE && *(++(*argv1))) {
switch (**argv1) {
case 'm':
if (--argc == 0) {
@@ -362,6 +364,7 @@ extern int syslogd_main(int argc, char **argv)
usage(syslogd_usage);
}
logFilePath = *(++argv1);
stopDoingThat = TRUE;
break;
default:
usage(syslogd_usage);
+2 -2
View File
@@ -27,12 +27,12 @@
extern int
true_main(int argc, char** argv)
{
return( TRUE);
exit( TRUE);
}
extern int
false_main(int argc, char** argv)
{
return( FALSE);
exit( FALSE);
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Mini tty implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
#include <sys/types.h>
static const char tty_usage[] = "tty\n\n"
"Print the file name of the terminal connected to standard input.\n"
"\t-s\tprint nothing, only return an exit status\n";
extern int tty_main(int argc, char **argv) {
char *tty;
if (argc > 1) {
if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
}
else {
tty = ttyname (0);
if (tty) puts (tty);
else puts ("not a tty");
}
exit (isatty (0) ? TRUE : FALSE);
}
+64 -8
View File
@@ -28,6 +28,14 @@
#include <fstab.h>
#include <errno.h>
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
static int del_loop(const char *device);
#endif
static const char umount_usage[] =
"Usage: umount [flags] filesystem|directory\n\n"
"Flags:\n"
@@ -44,23 +52,54 @@ static int useMtab = TRUE;
static int umountAll = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
#if ! defined BB_MTAB
#define do_umount( blockDevice, useMtab) umount( blockDevice)
#else
static int
do_umount(const char* name, int useMtab)
{
int status = umount(name);
int status;
#if defined BB_FEATURE_MOUNT_LOOP
/* check to see if this is a loop device */
struct stat fst;
char dev[20];
const char *oldname = NULL;
int i;
if (stat(name, &fst)) {
fprintf(stderr, "umount: %s: %s\n", name, strerror(errno));
exit(1);
}
for (i = 0 ; i <= 7 ; i++) {
struct stat lst;
sprintf(dev, "/dev/loop%d", i);
if (stat(dev, &lst))
continue;
if (lst.st_dev == fst.st_dev) {
oldname = name;
name = dev;
break;
}
}
#endif
status = umount(name);
#if defined BB_FEATURE_MOUNT_LOOP
if (!strncmp("/dev/loop", name, 9)) { /* this was a loop device, delete it */
del_loop(name);
if (oldname != NULL)
name = oldname;
}
#endif
#if defined BB_MTAB
if ( status == 0 ) {
if ( useMtab==TRUE )
erase_mtab(name);
return 0;
}
else
return( status);
}
else
#endif
return(status);
}
static int
umount_all(int useMtab)
@@ -135,7 +174,24 @@ umount_main(int argc, char** argv)
exit (TRUE);
else {
perror("umount");
exit( FALSE);
exit(FALSE);
}
}
#if defined BB_FEATURE_MOUNT_LOOP
static int del_loop(const char *device)
{
int fd;
if ((fd = open(device, O_RDONLY)) < 0) {
perror(device);
exit(1);
}
if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
perror("ioctl: LOOP_CLR_FD");
exit(1);
}
close(fd);
return(0);
}
#endif
+128 -15
View File
@@ -24,11 +24,16 @@
* 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
*
* 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>.
* Rewrote of a lot of code. Removed mtab usage (I plan on
* Rewrite of a lot of code. Removed mtab usage (I plan on
* putting it back as a compile-time option some time),
* major adjustments to option parsing, and some serious
* dieting all around.
*/
*
* 1999-11-06 mtab suppport is back - andersee
*
* 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
* mount to add loop support.
*/
#include "internal.h"
#include <stdlib.h>
@@ -41,6 +46,17 @@
#include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
static int set_loop(const char *device, const char *file, int offset, int *loopro);
static char *find_unused_loop_device (void);
static int use_loop = 0;
#endif
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "\tmount [flags]\n"
@@ -61,6 +77,9 @@ static const char mount_usage[] = "\tmount [flags]\n"
"\tasync / sync:\tWrites are asynchronous / synchronous.\n"
"\tdev / nodev:\tAllow use of special device files / disallow them.\n"
"\texec / noexec:\tAllow use of executable files / disallow them.\n"
#if defined BB_FEATURE_MOUNT_LOOP
"\tloop: Mounts a file via loop device.\n"
#endif
"\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
"\tro / rw: Mount for read-only / read-write.\n"
@@ -91,28 +110,48 @@ static const struct mount_options mount_options[] = {
{0, 0, 0}
};
#if ! defined BB_MTAB
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
mount(specialfile, dir, filesystemtype, flags, string_flags)
#else
static int
do_mount(char* specialfile, char* dir, char* filesystemtype,
long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
{
int status=0;
#if defined BB_MTAB
if (fakeIt==FALSE)
#endif
{
#if defined BB_FEATURE_MOUNT_LOOP
if (use_loop) {
int loro = flags & MS_RDONLY;
char *lofile = specialfile;
specialfile = find_unused_loop_device();
if (specialfile == NULL) {
fprintf(stderr, "Could not find a spare loop device\n");
exit(1);
}
if (set_loop (specialfile, lofile, 0, &loro)) {
fprintf(stderr, "Could not setup loop device\n");
exit(1);
}
if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */
fprintf(stderr, "WARNING: loop device is read-only\n");
flags &= ~MS_RDONLY;
}
}
#endif
status=mount(specialfile, dir, filesystemtype, flags, string_flags);
if ( status == 0 ) {
if ( useMtab==TRUE )
}
#if defined BB_MTAB
if (status == 0) {
if (useMtab==TRUE)
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
return 0;
}
else
return( status);
}
else
#endif
return(status);
}
#if defined BB_MTAB
@@ -148,16 +187,20 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
}
f++;
}
#if defined BB_FEATURE_MOUNT_LOOP
if (gotone==FALSE && !strcasecmp ("loop", options)) { /* loop device support */
use_loop = 1;
gotone=TRUE;
}
#endif
if (*strflags && strflags!= '\0' && gotone==FALSE) {
char *temp=strflags;
temp += strlen (strflags);
*temp++ = ',';
*temp++ = '\0';
}
if (gotone==FALSE) {
if (gotone==FALSE)
strcat (strflags, options);
gotone=FALSE;
}
if (comma) {
*comma = ',';
options = ++comma;
@@ -356,3 +399,73 @@ extern int mount_main (int argc, char **argv)
goodbye:
usage( mount_usage);
}
#if defined BB_FEATURE_MOUNT_LOOP
static int set_loop(const char *device, const char *file, int offset, int *loopro)
{
struct loop_info loopinfo;
int fd, ffd, mode;
mode = *loopro ? O_RDONLY : O_RDWR;
if ((ffd = open (file, mode)) < 0 && !*loopro
&& (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
perror (file);
return 1;
}
if ((fd = open (device, mode)) < 0) {
close(ffd);
perror (device);
return 1;
}
*loopro = (mode == O_RDONLY);
memset(&loopinfo, 0, sizeof(loopinfo));
strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
loopinfo.lo_offset = offset;
loopinfo.lo_encrypt_key_size = 0;
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
perror("ioctl: LOOP_SET_FD");
exit(1);
}
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
(void) ioctl(fd, LOOP_CLR_FD, 0);
perror("ioctl: LOOP_SET_STATUS");
exit(1);
}
close(fd);
close(ffd);
return 0;
}
static char *find_unused_loop_device (void)
{
char dev[20];
int i, fd, somedev = 0, someloop = 0;
struct stat statbuf;
struct loop_info loopinfo;
for(i = 0; i < 256; i++) {
sprintf(dev, "/dev/loop%d", i);
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
somedev++;
fd = open (dev, O_RDONLY);
if (fd >= 0) {
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
someloop++; /* in use */
else if (errno == ENXIO) {
close (fd);
return strdup(dev); /* probably free */
}
close (fd);
}
continue;
}
if (i >= 7)
break;
}
return NULL;
}
#endif /* BB_FEATURE_MOUNT_LOOP */
+64 -8
View File
@@ -28,6 +28,14 @@
#include <fstab.h>
#include <errno.h>
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
static int del_loop(const char *device);
#endif
static const char umount_usage[] =
"Usage: umount [flags] filesystem|directory\n\n"
"Flags:\n"
@@ -44,23 +52,54 @@ static int useMtab = TRUE;
static int umountAll = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
#if ! defined BB_MTAB
#define do_umount( blockDevice, useMtab) umount( blockDevice)
#else
static int
do_umount(const char* name, int useMtab)
{
int status = umount(name);
int status;
#if defined BB_FEATURE_MOUNT_LOOP
/* check to see if this is a loop device */
struct stat fst;
char dev[20];
const char *oldname = NULL;
int i;
if (stat(name, &fst)) {
fprintf(stderr, "umount: %s: %s\n", name, strerror(errno));
exit(1);
}
for (i = 0 ; i <= 7 ; i++) {
struct stat lst;
sprintf(dev, "/dev/loop%d", i);
if (stat(dev, &lst))
continue;
if (lst.st_dev == fst.st_dev) {
oldname = name;
name = dev;
break;
}
}
#endif
status = umount(name);
#if defined BB_FEATURE_MOUNT_LOOP
if (!strncmp("/dev/loop", name, 9)) { /* this was a loop device, delete it */
del_loop(name);
if (oldname != NULL)
name = oldname;
}
#endif
#if defined BB_MTAB
if ( status == 0 ) {
if ( useMtab==TRUE )
erase_mtab(name);
return 0;
}
else
return( status);
}
else
#endif
return(status);
}
static int
umount_all(int useMtab)
@@ -135,7 +174,24 @@ umount_main(int argc, char** argv)
exit (TRUE);
else {
perror("umount");
exit( FALSE);
exit(FALSE);
}
}
#if defined BB_FEATURE_MOUNT_LOOP
static int del_loop(const char *device)
{
int fd;
if ((fd = open(device, O_RDONLY)) < 0) {
perror(device);
exit(1);
}
if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
perror("ioctl: LOOP_CLR_FD");
exit(1);
}
close(fd);
return(0);
}
#endif
+11 -2
View File
@@ -317,7 +317,9 @@ const char *timeString(time_t timeVal)
return buf;
}
#endif
#if defined BB_TAR || defined BB_CP || defined BB_MV
/*
* Write all of the supplied buffer out to a file.
* This does multiple writes as necessary.
@@ -396,7 +398,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
int (*dirAction) (const char *fileName, struct stat* statbuf))
{
int status;
struct stat statbuf;
struct stat statbuf, statbuf1;
struct dirent *next;
if (followLinks == TRUE)
@@ -404,6 +406,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
else
status = lstat(fileName, &statbuf);
status = lstat(fileName, &statbuf);
if (status < 0) {
perror(fileName);
return (FALSE);
@@ -424,8 +427,14 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
return (TRUE);
}
}
status = lstat(fileName, &statbuf1);
if (status < 0) {
perror(fileName);
return (FALSE);
}
if (S_ISDIR(statbuf.st_mode)) {
if (S_ISDIR(statbuf.st_mode) && S_ISDIR(statbuf1.st_mode)) {
DIR *dir;
dir = opendir(fileName);
if (!dir) {
+162
View File
@@ -0,0 +1,162 @@
/*
* Mini wc implementation for busybox
*
* by Edward Betts <edward@debian.org>
*
* 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 <stdio.h>
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
"Print line, word, and byte counts for each FILE, and a total line if\n"
"more than one FILE is specified. With no FILE, read standard input.\n"
"\t-c\tprint the byte counts\n"
"\t-l\tprint the newline counts\n"
"\t-L\tprint the length of the longest line\n"
"\t-L\tprint the length of the longest line\n"
"\t-w\tprint the word counts\n";
static int total_lines, total_words, total_chars, max_length;
static int print_lines, print_words, print_chars, print_length;
void print_counts (int lines, int words, int chars, int length,
const char *name) {
char const *space = "";
if (print_lines) {
printf ("%7d", lines);
space = " ";
}
if (print_words) {
printf ("%s%7d", space, words);
space = " ";
}
if (print_chars) {
printf ("%s%7d", space, chars);
space = " ";
}
if (print_length)
printf ("%s%7d", space, length);
if (*name)
printf (" %s", name);
putchar ('\n');
}
static void wc_file(FILE *file, const char *name)
{
int lines, words, chars, length;
int in_word = 0, linepos = 0;
int c;
lines = words = chars = length = 0;
while ((c = getc(file)) != EOF) {
chars++;
switch (c) {
case '\n':
lines++;
case '\r':
case '\f':
if (linepos > length)
length = linepos;
linepos = 0;
goto word_separator;
case '\t':
linepos += 8 - (linepos % 8);
goto word_separator;
case ' ':
linepos++;
case '\v':
word_separator:
if (in_word) {
in_word = 0;
words++;
}
break;
default:
linepos++;
in_word = 1;
break;
}
}
if (linepos > length)
length = linepos;
if (in_word)
words++;
print_counts (lines, words, chars, length, name);
total_lines += lines;
total_words += words;
total_chars += chars;
if (length > max_length)
max_length = length;
fclose(file);
fflush(stdout);
}
int wc_main(int argc, char **argv) {
FILE *file;
total_lines = total_words = total_chars = max_length = 0;
print_lines = print_words = print_chars = print_length = 0;
while (--argc && **(++argv) == '-') {
while (*++(*argv))
switch (**argv) {
case 'c':
print_chars = 1;
break;
case 'l':
print_lines = 1;
break;
case 'L':
print_length = 1;
break;
case 'w':
print_words = 1;
break;
default:
usage (wc_usage);
}
}
if (!print_lines && !print_words && !print_chars && !print_length)
print_lines = print_words = print_chars = 1;
if (argc == 0) {
wc_file(stdin, "");
exit(TRUE);
}
else if (argc == 1) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
}
wc_file(file, *argv);
}
else {
while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
}
wc_file(file, *argv);
argv++;
}
print_counts (total_lines, total_words, total_chars,
max_length, "total");
}
exit(TRUE);
}
+44
View File
@@ -0,0 +1,44 @@
/*
* Mini whoami implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
#include <pwd.h>
static const char whoami_usage[] = "whoami\n\n"
"Print the user name associated with the current effective user id.\n"
"Same as id -un.\n";
extern int whoami_main(int argc, char **argv) {
struct passwd *pw;
uid_t uid;
if (argc > 1) usage (whoami_usage);
uid = geteuid ();
pw = getpwuid (uid);
if (pw) {
puts (pw->pw_name);
exit (TRUE);
}
fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
exit (FALSE);
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Mini yes implementation for busybox
*
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
*
* 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 <stdio.h>
extern int yes_main(int argc, char **argv) {
int i;
if (argc == 1)
while (1)
if (puts ("y") == EOF) {
perror ("yes");
exit(FALSE);
}
while (1)
for (i = 1; i < argc; i++)
if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
perror ("yes");
exit(FALSE);
}
exit(TRUE);
}