Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5338ce19c8 | ||
|
|
5f2df6ccb4 | ||
|
|
9b5c0b7611 | ||
|
|
812d46667d | ||
|
|
96e2abd084 | ||
|
|
286b0de74d | ||
|
|
d38eaef70b | ||
|
|
0e3782f7c3 | ||
|
|
9324b400ab | ||
|
|
9d83165d9e | ||
|
|
96f1f33e56 | ||
|
|
3695052813 | ||
|
|
9e7372584f | ||
|
|
0b874ed41f | ||
|
|
abb4772b28 | ||
|
|
0881de706e | ||
|
|
f4a99cc02c | ||
|
|
fb62e3225f | ||
|
|
7dc160721e | ||
|
|
9c88cac5cb | ||
|
|
1266a13e1f | ||
|
|
a89910829c | ||
|
|
f664c004db | ||
|
|
2fe08c7afb | ||
|
|
00266d3df6 | ||
|
|
69ba6b2956 | ||
|
|
98f67e35d8 | ||
|
|
00417a38c1 | ||
|
|
ee512a3f86 | ||
|
|
568cb7b45f | ||
|
|
d19385e160 | ||
|
|
f3e59041b5 | ||
|
|
019513a59f | ||
|
|
38efa7902e | ||
|
|
c0ca473af9 | ||
|
|
3fe2ecf0d9 | ||
|
|
d387d01f11 | ||
|
|
f294a0288d | ||
|
|
021043205c | ||
|
|
10c341af35 | ||
|
|
4d1d0113fd | ||
|
|
6da0ae8183 | ||
|
|
c144e330c0 | ||
|
|
2129b146db | ||
|
|
3d7e3414da | ||
|
|
0aa6118167 | ||
|
|
1c5b2589d1 | ||
|
|
6f23cec5d0 | ||
|
|
935fb3886f | ||
|
|
25ab653457 | ||
|
|
e1618e42a8 | ||
|
|
3cd5d2541f | ||
|
|
0f0fcecf7f | ||
|
|
664584b50e | ||
|
|
19db07b3d4 |
No files matched your search
@@ -0,0 +1,40 @@
|
||||
List of the authors of code contained in busybox.
|
||||
|
||||
If you should be listed here, or the description of
|
||||
what you have done needs more detail, or is incorect,
|
||||
_please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, tee
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
|
||||
Randolph Chung <tausq@debian.org>
|
||||
fbset, ping, hostname, and mkfifo
|
||||
|
||||
Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
gzip, mini-netcat(nc)
|
||||
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
0.40
|
||||
* New Apps: sort, uniq. -beppu
|
||||
* New Apps: lsmod, rmmod -erik
|
||||
* New Apps: fbset contributed by Randolph Chung <tausq@debian.org>.
|
||||
* New App:: loadacm contributed by Peter Novodvorsky <petya@logic.ru>
|
||||
for loading application character maps for Unicode fonts.
|
||||
* Major init re-work. init now supports inittab (slightly different
|
||||
but similar to sysvinit), allowing me to get all the policy out
|
||||
of init and into the conf file. It works just fine without inittab
|
||||
being present, but if you dont like the defautl behavior you can
|
||||
now do something about it. Init is much cleaner as a result.
|
||||
* Fixed an bug in syslogd causing it to stop after 20 minutes. -erik
|
||||
* Fixed an embarrasing segfault in head -beppu
|
||||
* Fixed the embarrasing failure of 'logger -p'. -erik
|
||||
* Added the -s option to du -beppu
|
||||
* Re-worked the source tree a bit so it will compile under glibc 2.0.7
|
||||
with the 2.0.x Linux kernel.
|
||||
* Added 'grep -q' thanks to a patch from "Konstantin Boldyshev"
|
||||
<konst@voshod.com>.
|
||||
* Grep -i previously failed on UPPER CASE patterns due to a silly
|
||||
regexp implementation bug that is now fixed.
|
||||
* Fixed a bug where tar would set, and then clear SGID and SUID bits.
|
||||
* Fixed a bug where tar would not set the user and group on device
|
||||
special files.
|
||||
* Fixed a bug where tar would not restore the time to files.
|
||||
* Fixed a major security problem with tar -- it changed ownership
|
||||
of any file pointed to by a symlink to 777 (like say libc....)
|
||||
Ouch!!!
|
||||
* cp and mv were very broken when moving directories. I have rewritten
|
||||
them so they should now work as expected.
|
||||
* sed now supports addresses (numeric or regexp, with negation) and
|
||||
has an append command, thanks to Marco Pantaleoni <panta@prosa.it>
|
||||
* Fixed dmesg. It wasn't parsing its options (-n or -s) properly.
|
||||
* Some cosmetic fixes to ls output formatting to make it behave more
|
||||
like GNU ls.
|
||||
* Fixed a stupid segfault in kill.
|
||||
* Several fixes from Friedrich Vedder <fwv@myrtle.lahn.de>:
|
||||
- Added gunzip -t, removed gunzip.c dead code,
|
||||
- fixed several typos
|
||||
- Glibc 2.0.7 and libc5 compile fixes
|
||||
* Fixed a bug where 'mknod --help' would segfault.
|
||||
|
||||
|
||||
-Erik Andersen, Jan 07, 2000
|
||||
|
||||
0.39
|
||||
* New Apps: ping and hostname contributed by Randolph Chung
|
||||
<tausq@debian.org>. 2 items off the TODO list!
|
||||
* New Apps: ping, hostname, and mkfifo contributed by Randolph Chung
|
||||
<tausq@debian.org>. 3 items off the TODO list!
|
||||
* I wrote free (just calls "cat /proc/meminfo").
|
||||
* Added tail, based on tail from GNU textutils-1.19, but adjusted
|
||||
to suit my evil purposes. Costs 6k. I'll make it smaller sometime.
|
||||
@@ -21,7 +66,7 @@
|
||||
* Implemented tee. -beppu
|
||||
* Implemented head. -beppu
|
||||
|
||||
-Erik Andrsen, Dec 10, 1999
|
||||
-Erik Andersen, Dec 10, 1999
|
||||
|
||||
0.38
|
||||
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
|
||||
@@ -40,7 +85,7 @@
|
||||
will complain if you enable them when you disable
|
||||
BB_FEATURE_USE_PROCFS.
|
||||
|
||||
-Erik Andrsen, Dec 5, 1999
|
||||
-Erik Andersen, Dec 5, 1999
|
||||
|
||||
0.37
|
||||
* Wrote a micro syslogd, and a logger util (to log things to the syslog
|
||||
@@ -62,7 +107,7 @@
|
||||
* Also added a TODO.
|
||||
|
||||
|
||||
-Erik Andrsen, Nov 25, 1999
|
||||
-Erik Andersen, Nov 25, 1999
|
||||
|
||||
0.36
|
||||
* fixed dd so it properly defaults to stdin and stdout when no
|
||||
|
||||
@@ -26,7 +26,7 @@ Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersee@deban.org>
|
||||
<andersee@debian.org>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
PROG=busybox
|
||||
VERSION=0.39
|
||||
VERSION=0.40
|
||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||
|
||||
# Comment out the following to make a debuggable build
|
||||
@@ -31,8 +31,8 @@ DOSTATIC=false
|
||||
#This will choke on a non-debian system
|
||||
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
|
||||
GCCMAJVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\1/p"`
|
||||
GCCMINVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\2/p"`
|
||||
GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
|
||||
GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
|
||||
|
||||
GCCSUPPORTSOPTSIZE=$(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
@@ -80,8 +80,8 @@ LIBRARIES=
|
||||
OBJECTS=$(shell ./busybox.sh)
|
||||
CFLAGS+= -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_RC_EXIT_CMD
|
||||
CFLAGS += -DBB_INIT_CMD_IF_RC_SCRIPT_EXITS=${BB_INIT_RC_EXIT_CMD}
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
@@ -108,6 +108,6 @@ install: busybox busybox.links
|
||||
dist: release
|
||||
|
||||
release: distclean
|
||||
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
|
||||
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/scripts/CVS busybox-$(VERSION)/docs/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ PREFIX environment variable.
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersee@deban.org>
|
||||
<andersee@debian.org>
|
||||
|
||||
<blatent plug>
|
||||
Many thanks to go to Lineo for paying me to work on busybox.
|
||||
|
||||
@@ -3,25 +3,22 @@ is listed here doesn't mean that it is going to be added to busybox,
|
||||
or that doing so is even a good idea. It just means that I _might_ get
|
||||
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).
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Add in a mini insmod, rmmod, lsmod
|
||||
* init clearly needs to support some type of minimalist /etc/inittab. I
|
||||
currently have _way_ too much policy hardcoded in the source. Adding
|
||||
support for getty has made me realize how much that sucks.
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/nslookup/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* sort/uniq
|
||||
* wc
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
* login/sulogin/passwd/getty (These are actully now part of tinylogin, which
|
||||
I've just started to maintain).
|
||||
|
||||
@@ -51,6 +51,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#endif
|
||||
@@ -84,6 +87,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
@@ -96,6 +102,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#endif
|
||||
@@ -105,6 +114,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#endif
|
||||
@@ -114,6 +126,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#endif
|
||||
@@ -159,6 +174,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
@@ -169,6 +187,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
@@ -204,6 +225,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
|
||||
+20
-16
@@ -8,7 +8,8 @@ static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output\n";
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -653,7 +654,7 @@ DECLARE(uch, window, 2L*WSIZE);
|
||||
|
||||
/* local variables */
|
||||
|
||||
int force = 0; /* don't ask questions, compress links (-f) */
|
||||
int test_mode = 0; /* check file integrity option */
|
||||
int foreground; /* set if program run in foreground */
|
||||
int maxbits = BITS; /* max bits per code for LZW */
|
||||
int method = DEFLATED;/* compression method */
|
||||
@@ -714,6 +715,10 @@ int gunzip_main (int argc, char** argv)
|
||||
case 'c':
|
||||
to_stdout = 1;
|
||||
break;
|
||||
case 't':
|
||||
test_mode = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(gunzip_usage);
|
||||
}
|
||||
@@ -786,6 +791,9 @@ int gunzip_main (int argc, char** argv)
|
||||
/* Actually do the compression/decompression. */
|
||||
unzip(inFileNum, outFileNum);
|
||||
|
||||
} else if (test_mode) {
|
||||
/* Actually do the compression/decompression. */
|
||||
unzip(inFileNum, 2);
|
||||
} else {
|
||||
char* pos;
|
||||
|
||||
@@ -805,7 +813,11 @@ int gunzip_main (int argc, char** argv)
|
||||
}
|
||||
|
||||
/* Open output fille */
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
#else
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL);
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
@@ -853,17 +865,8 @@ local int get_method(in)
|
||||
uch flags; /* compression flags */
|
||||
char magic[2]; /* magic header */
|
||||
|
||||
/* If --force and --stdout, zcat == cat, so do not complain about
|
||||
* premature end of file: use try_byte instead of get_byte.
|
||||
*/
|
||||
if (force) {
|
||||
magic[0] = (char)try_byte();
|
||||
magic[1] = (char)try_byte();
|
||||
/* If try_byte returned EOF, magic[1] == 0xff */
|
||||
} else {
|
||||
magic[0] = (char)get_byte();
|
||||
magic[1] = (char)get_byte();
|
||||
}
|
||||
magic[0] = (char)get_byte();
|
||||
magic[1] = (char)get_byte();
|
||||
method = -1; /* unknown yet */
|
||||
part_nb++; /* number of parts in gzip file */
|
||||
header_bytes = 0;
|
||||
@@ -1184,7 +1187,8 @@ void flush_outbuf()
|
||||
{
|
||||
if (outcnt == 0) return;
|
||||
|
||||
write_buf(ofd, (char *)outbuf, outcnt);
|
||||
if (!test_mode)
|
||||
write_buf(ofd, (char *)outbuf, outcnt);
|
||||
bytes_out += (ulg)outcnt;
|
||||
outcnt = 0;
|
||||
}
|
||||
@@ -1198,8 +1202,8 @@ void flush_window()
|
||||
if (outcnt == 0) return;
|
||||
updcrc(window, outcnt);
|
||||
|
||||
write_buf(ofd, (char *)window, outcnt);
|
||||
|
||||
if (!test_mode)
|
||||
write_buf(ofd, (char *)window, outcnt);
|
||||
bytes_out += (ulg)outcnt;
|
||||
outcnt = 0;
|
||||
}
|
||||
|
||||
@@ -1877,7 +1877,11 @@ int gzip_main(int argc, char ** argv)
|
||||
|
||||
|
||||
/* Open output fille */
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
#else
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL);
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
|
||||
+80
-51
@@ -37,6 +37,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
@@ -106,8 +107,12 @@ static int warnedRoot;
|
||||
static int eofFlag;
|
||||
static long dataCc;
|
||||
static int outFd;
|
||||
static char outName[TAR_NAME_SIZE];
|
||||
static const char *outName;
|
||||
|
||||
static int mode;
|
||||
static int uid;
|
||||
static int gid;
|
||||
static time_t mtime;
|
||||
|
||||
/*
|
||||
* Static data associated with the tar file.
|
||||
@@ -364,8 +369,9 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
* message is required on errors.
|
||||
*/
|
||||
if (tostdoutFlag == FALSE) {
|
||||
if (outFd >= 0)
|
||||
(void) close (outFd);
|
||||
if (outFd >= 0) {
|
||||
close (outFd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,29 +384,25 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
static void
|
||||
readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
{
|
||||
int mode;
|
||||
int uid;
|
||||
int gid;
|
||||
int checkSum;
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
long size;
|
||||
time_t mtime;
|
||||
const char *name;
|
||||
int cc;
|
||||
int hardLink;
|
||||
int softLink;
|
||||
int devFileFlag;
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
long size;
|
||||
struct utimbuf utb;
|
||||
|
||||
/*
|
||||
* If the block is completely empty, then this is the end of the
|
||||
* archive file. If the name is null, then just skip this header.
|
||||
*/
|
||||
name = hp->name;
|
||||
outName = hp->name;
|
||||
|
||||
if (*name == '\0') {
|
||||
if (*outName == '\0') {
|
||||
for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) {
|
||||
if (*name++)
|
||||
if (*outName++)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -447,16 +449,16 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
/*
|
||||
* Check for a directory.
|
||||
*/
|
||||
if (name[strlen (name) - 1] == '/')
|
||||
if (outName[strlen (outName) - 1] == '/')
|
||||
mode |= S_IFDIR;
|
||||
|
||||
/*
|
||||
* Check for absolute paths in the file.
|
||||
* If we find any, then warn the user and make them relative.
|
||||
*/
|
||||
if (*name == '/') {
|
||||
while (*name == '/')
|
||||
name++;
|
||||
if (*outName == '/') {
|
||||
while (*outName == '/')
|
||||
outName++;
|
||||
|
||||
if (warnedRoot==FALSE) {
|
||||
fprintf (stderr,
|
||||
@@ -470,7 +472,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* See if we want this file to be restored.
|
||||
* If not, then set up to skip it.
|
||||
*/
|
||||
if (wantFileName (name, fileCount, fileTable) == FALSE) {
|
||||
if (wantFileName (outName, fileCount, fileTable) == FALSE) {
|
||||
if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
|
||||
|| S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
@@ -494,7 +496,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
else
|
||||
printf ("%9ld %s ", size, timeString (mtime));
|
||||
}
|
||||
printf ("%s", name);
|
||||
printf ("%s", outName);
|
||||
|
||||
if (hardLink)
|
||||
printf (" (link to \"%s\")", hp->linkName);
|
||||
@@ -515,22 +517,35 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* We really want to extract the file.
|
||||
*/
|
||||
if (verboseFlag==TRUE)
|
||||
printf ("x %s\n", name);
|
||||
printf ("x %s\n", outName);
|
||||
|
||||
if (hardLink) {
|
||||
if (link (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
if (link (hp->linkName, outName) < 0)
|
||||
perror (outName);
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (softLink) {
|
||||
#ifdef S_ISLNK
|
||||
if (symlink (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
if (symlink (hp->linkName, outName) < 0)
|
||||
perror (outName);
|
||||
/* Try to change ownership of the symlink.
|
||||
* If libs doesn't support that, don't bother.
|
||||
* Changing the pointed-to file is the Wrong Thing(tm).
|
||||
*/
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
lchown(outName, uid, gid);
|
||||
#endif
|
||||
|
||||
/* Do not change permissions or date on symlink,
|
||||
* since it changes the pointed to file instead. duh. */
|
||||
#else
|
||||
fprintf (stderr, "Cannot create symbolic links\n");
|
||||
#endif
|
||||
@@ -545,10 +560,14 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* If the file is a directory, then just create the path.
|
||||
*/
|
||||
if (S_ISDIR (mode)) {
|
||||
createPath (name, mode);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
|
||||
createPath (outName, mode);
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -556,7 +575,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* There is a file to write.
|
||||
* First create the path to it if necessary with default permissions.
|
||||
*/
|
||||
createPath (name, 0777);
|
||||
createPath (outName, 0777);
|
||||
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
dataCc = size;
|
||||
@@ -569,31 +588,34 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
else {
|
||||
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mknod (name, mode, makedev(major, minor) );
|
||||
outFd = mknod (outName, mode, makedev(major, minor) );
|
||||
}
|
||||
else if (S_ISFIFO(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mkfifo(name, mode);
|
||||
outFd = mkfifo(outName, mode);
|
||||
} else {
|
||||
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
outFd = open (outName, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
if (outFd < 0) {
|
||||
perror (outName);
|
||||
skipFileFlag = TRUE;
|
||||
return;
|
||||
}
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
}
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (name);
|
||||
skipFileFlag = TRUE;
|
||||
return;
|
||||
}
|
||||
if (tostdoutFlag == FALSE) {
|
||||
fchmod(outFd, mode);
|
||||
fchown(outFd, uid, gid);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the file is empty, then that's all we need to do.
|
||||
*/
|
||||
if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
|
||||
(void) close (outFd);
|
||||
close (outFd);
|
||||
outFd = -1;
|
||||
}
|
||||
}
|
||||
@@ -627,7 +649,7 @@ static void readData (const char *cp, int count)
|
||||
if (fullWrite (outFd, cp, count) < 0) {
|
||||
perror (outName);
|
||||
if (tostdoutFlag == FALSE) {
|
||||
(void) close (outFd);
|
||||
close (outFd);
|
||||
outFd = -1;
|
||||
}
|
||||
skipFileFlag = TRUE;
|
||||
@@ -635,13 +657,21 @@ static void readData (const char *cp, int count)
|
||||
}
|
||||
|
||||
/*
|
||||
* If the write failed, close the file and disable further
|
||||
* writes to this file.
|
||||
* Check if we are done writing to the file now.
|
||||
*/
|
||||
if (dataCc <= 0 && tostdoutFlag == FALSE) {
|
||||
struct utimbuf utb;
|
||||
if (close (outFd))
|
||||
perror (outName);
|
||||
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
|
||||
outFd = -1;
|
||||
}
|
||||
}
|
||||
@@ -722,7 +752,6 @@ static void writeTarFile (int fileCount, char **fileTable)
|
||||
static void saveFile (const char *fileName, int seeLinks)
|
||||
{
|
||||
int status;
|
||||
int mode;
|
||||
struct stat statbuf;
|
||||
|
||||
if (verboseFlag==TRUE)
|
||||
|
||||
@@ -51,6 +51,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#endif
|
||||
@@ -84,6 +87,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
@@ -96,6 +102,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#endif
|
||||
@@ -105,6 +114,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#endif
|
||||
@@ -114,6 +126,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#endif
|
||||
@@ -159,6 +174,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
@@ -169,6 +187,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
@@ -204,6 +225,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
|
||||
+37
-17
@@ -1,8 +1,11 @@
|
||||
/*
|
||||
* This file is parsed by sed. You MUST use single line comments.
|
||||
* IE //#define BB_BLAH
|
||||
*/
|
||||
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e. //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_BUSYBOX
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
@@ -15,6 +18,7 @@
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
@@ -27,17 +31,22 @@
|
||||
#define BB_HEAD
|
||||
#define BB_HOSTNAME
|
||||
#define BB_INIT
|
||||
// Don't turn BB_INSMOD on. It doesn't work.
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
//#define BB_MATH
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
@@ -56,22 +65,29 @@
|
||||
#define BB_REBOOT
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
//#define BB_SFDISK
|
||||
#define BB_SED
|
||||
#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_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UPDATE
|
||||
#define BB_UNAME
|
||||
#define BB_GZIP
|
||||
#define BB_GUNZIP
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// Don't turn BB_UTILITY off. It contains support code
|
||||
// that compiles to 0 if everything else if turned off.
|
||||
#define BB_UTILITY
|
||||
@@ -83,19 +99,23 @@
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// enable a second console on TTY2 in init
|
||||
#define BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
// enable features that use the /proc filesystem
|
||||
// enable features that use the /proc filesystem (apps that
|
||||
// break without this will tell you on compile)...
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
// calculate terminal & column widths
|
||||
// calculate terminal & column widths (for more and ls)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
// show username/groupnames (bypasses libc6 NSS)
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
// show file timestamps
|
||||
// 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
|
||||
//
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.39
|
||||
Version: 0.40
|
||||
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
|
||||
make
|
||||
BB_INIT_SCRIPT='\"/etc/rc.d/init.d/rcS\"' make
|
||||
|
||||
%Install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef __BUSYBOX_FUNCTIONS_H__
|
||||
#define __BUSYBOX_FUNCTIONS_H__
|
||||
|
||||
int
|
||||
mkswap(char *device_name, int pages, int check);
|
||||
/* pages = 0 for autodetection */
|
||||
|
||||
int
|
||||
fdflush(char *filename);
|
||||
|
||||
#endif /* __BUSYBOX_FUNCTIONS_H__ */
|
||||
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
* Derived from
|
||||
* mapscrn.c - version 0.92
|
||||
*
|
||||
* Was taken from console-tools and adapted by
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]);
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode);
|
||||
unicode utf8_to_ucs2 (char* buf);
|
||||
int screen_map_load(int fd, FILE *fp);
|
||||
|
||||
int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin))
|
||||
{
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE *fp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed reading binary 16bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode)
|
||||
{
|
||||
if (ioctl(fd,PIO_UNISCRNMAP,wbuf))
|
||||
perror("PIO_UNISCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* rewind... */
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed assuming 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
|
||||
else
|
||||
perror ("fseek for binary 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(buf,E_TABSZ,1,fp) != 1)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ioctl(fd,PIO_SCRNMAP,buf))
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - reads `fp' as a 16-bit ASCII SFM file.
|
||||
* - returns -1 on error.
|
||||
* - returns it in `unicode' in an E_TABSZ-elements array.
|
||||
* - sets `*is_unicode' flagiff there were any non-8-bit
|
||||
* (ie. real 16-bit) mapping.
|
||||
*
|
||||
* FIXME: ignores everything after second word
|
||||
*/
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode)
|
||||
{
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t sigset, old_sigset;
|
||||
|
||||
assert (is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i=0; i<128; i++) buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset (&sigset);
|
||||
sigaddset (&sigset, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigset, &old_sigset);
|
||||
|
||||
do
|
||||
{
|
||||
if (NULL == fgets(buffer, sizeof(buffer),fp))
|
||||
{
|
||||
if (feof (fp))
|
||||
break;
|
||||
else
|
||||
{
|
||||
perror ("uni_screen_map_read_ascii() can't read line");
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL," \t\n");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* restore sig mask */
|
||||
sigprocmask (SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
|
||||
{
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
for (in=0; in<256; in++) buf[in]=in;
|
||||
|
||||
while (fgets(buffer,sizeof(buffer)-1,fp))
|
||||
{
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
q = strtok(NULL," \t\n#");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255) return -1;
|
||||
|
||||
buf[in] = on;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - converts a string into an int.
|
||||
* - supports dec and hex bytes, hex UCS2, single-quoted byte and UTF8 chars.
|
||||
* - returns the converted value
|
||||
* - if `is_unicode != NULL', use it to tell whether it was unicode
|
||||
*
|
||||
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
|
||||
*/
|
||||
long int ctoi(unsigned char *s, int *is_unicode)
|
||||
{
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
ls = strlen(s);
|
||||
if (is_unicode) *is_unicode = 0;
|
||||
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s,"U+",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
{
|
||||
sscanf(s+2,"%x",&i);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
sscanf(s+2,"%x",&i);
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') &&
|
||||
(strspn(s,"01234567") == ls))
|
||||
sscanf(s,"%o",&i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s,"0123456789") == ls)
|
||||
sscanf(s,"%d",&i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i=s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls-1] == '\''))
|
||||
{
|
||||
s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s+1);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
|
||||
return(i);
|
||||
}
|
||||
|
||||
|
||||
void saveoldmap(int fd, char *omfil)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[E_TABSZ];
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
unicode xbuf[E_TABSZ];
|
||||
int is_old_map = 0;
|
||||
|
||||
if (ioctl(fd,GIO_UNISCRNMAP,xbuf))
|
||||
{
|
||||
perror("GIO_UNISCRNMAP ioctl error");
|
||||
#endif
|
||||
if (ioctl(fd,GIO_SCRNMAP,buf))
|
||||
{
|
||||
perror("GIO_SCRNMAP ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
is_old_map = 1;
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(omfil, "w")) == NULL)
|
||||
{
|
||||
perror(omfil);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
if (is_old_map)
|
||||
{
|
||||
#endif
|
||||
if (fwrite(buf,E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
else
|
||||
if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unicode utf8_to_ucs2 (char* buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
unsigned char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = *buf;
|
||||
buf++;
|
||||
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if(c & 0x80)
|
||||
{
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80)
|
||||
{
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else /* Possibly 1st char of a UTF8 sequence */
|
||||
{
|
||||
if ((c & 0xe0) == 0xc0)
|
||||
{
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
}
|
||||
else if ((c & 0xf0) == 0xe0)
|
||||
{
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
}
|
||||
else if ((c & 0xf8) == 0xf0)
|
||||
{
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
}
|
||||
else if ((c & 0xfc) == 0xf8)
|
||||
{
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
}
|
||||
else if ((c & 0xfe) == 0xfc)
|
||||
{
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
}
|
||||
else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
{
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
+21
-16
@@ -33,7 +33,7 @@ static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possable\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
@@ -42,27 +42,34 @@ static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static const char *skipName;
|
||||
static int dirFlag = FALSE;
|
||||
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if (dirFlag==TRUE) {
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(fileName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
@@ -96,18 +103,16 @@ extern int cp_main(int argc, char **argv)
|
||||
|
||||
|
||||
destName = argv[argc - 1];
|
||||
dirFlag = isDirectory(destName);
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && dirFlag==FALSE) {
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
if (skipName)
|
||||
skipName++;
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
|
||||
@@ -72,9 +72,6 @@ extern int df_main(int argc, char **argv)
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
/* Only compiled in if BB_MTAB is not defined */
|
||||
whine_if_fstab_is_missing();
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
+29
-7
@@ -32,17 +32,32 @@
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n";
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void
|
||||
print(size_t size, char *filename)
|
||||
print_normal(size_t size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(size_t size, char *filename)
|
||||
{
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
@@ -54,6 +69,8 @@ du(char *filename)
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
@@ -76,6 +93,7 @@ du(char *filename)
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -85,12 +103,16 @@ du_main(int argc, char **argv)
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
@@ -110,12 +132,12 @@ du_main(int argc, char **argv)
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]) >> 1;
|
||||
if (sum) printf("%-7d %s\n", sum, argv[i]);
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
|
||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
||||
+2
-2
@@ -54,7 +54,7 @@ head_main(int argc, char **argv)
|
||||
int len = 10;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
@@ -103,4 +103,4 @@ head_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
|
||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
||||
+15
-11
@@ -193,11 +193,13 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
fputs(" ", stdout);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
scratch[0]='\0';
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
@@ -208,20 +210,21 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
tab(16);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
scratch[0]='\0';
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
tab(17);
|
||||
//tab(26);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -230,6 +233,7 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
fputs(" ", stdout);
|
||||
//tab(32);
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Mini mkfifo implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@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>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0666;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(mkfifo_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--; argv++;
|
||||
parse_mode(*argv, &mode);
|
||||
break;
|
||||
default:
|
||||
usage (mkfifo_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage (mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -27,9 +27,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
"Options:\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
|
||||
@@ -40,6 +40,9 @@ mknod_main(int argc, char** argv)
|
||||
mode_t mode = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if ( argc != 5 || **(argv+1) == '-' ) {
|
||||
usage (mknod_usage);
|
||||
}
|
||||
switch(argv[2][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
|
||||
+47
-25
@@ -27,7 +27,6 @@
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
@@ -35,14 +34,49 @@ static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static const char *skipName;
|
||||
static int dirFlag = FALSE;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, TRUE, TRUE));
|
||||
}
|
||||
|
||||
static int rmfileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
static int rmdirAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int mv_main(int argc, char **argv)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
if (argc < 3) {
|
||||
usage (mv_usage);
|
||||
}
|
||||
@@ -50,34 +84,22 @@ extern int mv_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
destName = argv[argc - 1];
|
||||
dirFlag = isDirectory(destName);
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && dirFlag==FALSE) {
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
if (skipName)
|
||||
skipName++;
|
||||
strcpy(newdestName, destName);
|
||||
if (dirFlag==TRUE) {
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(srcName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
fprintf(stderr, "srcName='%s'\n", srcName);
|
||||
fprintf(stderr, "skipName='%s'\n", skipName);
|
||||
fprintf(stderr, "newdestName='%s'\n", newdestName);
|
||||
}
|
||||
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
if (unlink (srcName) < 0) {
|
||||
perror (srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Mini sort implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] =
|
||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
||||
;
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
/* line node */
|
||||
typedef struct Line {
|
||||
char *data; /* line data */
|
||||
struct Line *next; /* pointer to next line node */
|
||||
} Line;
|
||||
|
||||
/* singly-linked list of lines */
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
|
||||
/* comparison function */
|
||||
typedef int (Compare)(const void *, const void *);
|
||||
|
||||
|
||||
/* methods ________________________________________________________________ */
|
||||
|
||||
static const int max = 1024;
|
||||
|
||||
/* mallocate Line */
|
||||
static Line *
|
||||
line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Initialize Line with string */
|
||||
static Line *
|
||||
line_init(Line *self, const char *string)
|
||||
{
|
||||
self->data = malloc((strlen(string) + 1) * sizeof(char));
|
||||
if (self->data == NULL) { return NULL; }
|
||||
strcpy(self->data, string);
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *
|
||||
line_newFromFile(FILE *src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) { return NULL; }
|
||||
line_init(self, buffer);
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Line destructor */
|
||||
static Line *
|
||||
line_release(Line *self)
|
||||
{
|
||||
if (self->data) {
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/* Comparison */
|
||||
|
||||
/* ascii order */
|
||||
static int
|
||||
compare_ascii(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
static int
|
||||
compare_numeric(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
int xint, yint;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
}
|
||||
|
||||
|
||||
/* List */
|
||||
|
||||
/* */
|
||||
static List *
|
||||
list_init(List *self)
|
||||
{
|
||||
self->len = 0;
|
||||
self->sorted = NULL;
|
||||
self->head = NULL;
|
||||
self->current = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* for simplicity, the List gains ownership of the line */
|
||||
static List *
|
||||
list_insert(List *self, Line *line)
|
||||
{
|
||||
if (line == NULL) { return NULL; }
|
||||
|
||||
/* first insertion */
|
||||
if (self->head == NULL) {
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
}
|
||||
self->len++;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* order the list according to compare() */
|
||||
static List *
|
||||
list_sort(List *self, Compare *compare)
|
||||
{
|
||||
int i;
|
||||
Line *line;
|
||||
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line*));
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
line = self->head;
|
||||
while (line) {
|
||||
self->sorted[i++] = line;
|
||||
line = line->next;
|
||||
}
|
||||
|
||||
/* apply qsort */
|
||||
qsort(self->sorted, self->len, sizeof(Line*), compare);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* precondition: list must be sorted */
|
||||
static List *
|
||||
list_writeToFile(List *self, FILE* dst)
|
||||
{
|
||||
int i;
|
||||
Line **line = self->sorted;
|
||||
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
for (i = 0; i < self->len; i++) {
|
||||
fprintf(dst, "%s", line[i]->data);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/* deallocate */
|
||||
static void
|
||||
list_release(List *self)
|
||||
{
|
||||
Line *i;
|
||||
Line *die;
|
||||
|
||||
i = self->head;
|
||||
while (i) {
|
||||
die = i;
|
||||
i = die->next;
|
||||
line_release(die);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* I need a list
|
||||
* to insert lines into
|
||||
* then I need to sort this list
|
||||
* and finally print it
|
||||
*/
|
||||
|
||||
int
|
||||
sort_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
List list;
|
||||
Line *l;
|
||||
Compare *compare;
|
||||
|
||||
/* init */
|
||||
compare = compare_ascii;
|
||||
list_init(&list);
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'r':
|
||||
/* reverse */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* this could be factored better */
|
||||
|
||||
/* work w/ stdin */
|
||||
if (i >= argc) {
|
||||
while ( (l = line_newFromFile(stdin))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
|
||||
/* work w/ what's left in argv[] */
|
||||
} else {
|
||||
FILE *src;
|
||||
|
||||
for ( ; i < argc; i++) {
|
||||
src = fopen(argv[i], "r");
|
||||
if (src == NULL) { break; }
|
||||
while ( (l = line_newFromFile(src))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Mini uniq implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n"
|
||||
;
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
|
||||
typedef void (Print)(FILE *, const char *);
|
||||
|
||||
typedef int (Decide)(const char *, const char *);
|
||||
|
||||
/* container for two lines to be compared */
|
||||
typedef struct {
|
||||
char *a;
|
||||
char *b;
|
||||
int recurrence;
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
void *func;
|
||||
} Subject;
|
||||
|
||||
/* set up all the variables of a uniq operation */
|
||||
static Subject *
|
||||
subject_init(Subject *self, FILE *in, FILE *out, void *func)
|
||||
{
|
||||
self->a = NULL;
|
||||
self->b = NULL;
|
||||
self->in = in;
|
||||
self->out = out;
|
||||
self->func = func;
|
||||
self->recurrence = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* point a and b to the appropriate lines;
|
||||
* count the recurrences (if any) of a string;
|
||||
*/
|
||||
static Subject *
|
||||
subject_next(Subject *self)
|
||||
{
|
||||
/* tmp line holders */
|
||||
static char line[2][UNIQ_MAX];
|
||||
static int alternator = 0;
|
||||
|
||||
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
|
||||
self->a = self->b;
|
||||
self->b = line[alternator];
|
||||
alternator ^= 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_last(Subject *self)
|
||||
{
|
||||
self->a = self->b;
|
||||
self->b = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_study(Subject *self)
|
||||
{
|
||||
if (self->a == NULL) {
|
||||
return self;
|
||||
}
|
||||
if (self->b == NULL) {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
return self;
|
||||
}
|
||||
if (strcmp(self->a, self->b) == 0) {
|
||||
self->recurrence++;
|
||||
} else {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
self->recurrence = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static int
|
||||
set_file_pointers(int schema, FILE **in, FILE **out, char **argv)
|
||||
{
|
||||
switch (schema) {
|
||||
case 0:
|
||||
*in = stdin;
|
||||
*out = stdout;
|
||||
break;
|
||||
case 1:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = stdout;
|
||||
break;
|
||||
case 2:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = fopen(argv[1], "w");
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* one variable is the decision algo */
|
||||
/* another variable is the printing algo */
|
||||
|
||||
/* I don't think I have to have more than a 1 line memory
|
||||
this is the one constant */
|
||||
|
||||
/* it seems like GNU/uniq only takes one or two files as an option */
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
int
|
||||
uniq_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
FILE *in, *out;
|
||||
Subject s;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(uniq_usage);
|
||||
default:
|
||||
usage(uniq_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 0 src: stdin; dst: stdout */
|
||||
/* 1 src: file; dst: stdout */
|
||||
/* 2 src: file; dst: file */
|
||||
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
subject_init(&s, in, out, NULL);
|
||||
while (subject_next(&s)) {
|
||||
subject_study(&s);
|
||||
}
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
||||
@@ -33,7 +33,7 @@ static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possable\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
@@ -42,27 +42,34 @@ static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static const char *skipName;
|
||||
static int dirFlag = FALSE;
|
||||
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if (dirFlag==TRUE) {
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(fileName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
@@ -96,18 +103,16 @@ extern int cp_main(int argc, char **argv)
|
||||
|
||||
|
||||
destName = argv[argc - 1];
|
||||
dirFlag = isDirectory(destName);
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && dirFlag==FALSE) {
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
if (skipName)
|
||||
skipName++;
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
|
||||
@@ -72,9 +72,6 @@ extern int df_main(int argc, char **argv)
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
/* Only compiled in if BB_MTAB is not defined */
|
||||
whine_if_fstab_is_missing();
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
@@ -44,10 +44,15 @@ int dmesg_main( int argc, char** argv )
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
while (*++(*argv))
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
@@ -57,19 +62,22 @@ int dmesg_main( int argc, char** argv )
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi (*(++argv));
|
||||
--argc;
|
||||
++argv;
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi (*(++argv));
|
||||
--argc;
|
||||
++argv;
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
|
||||
+1056
File diff suppressed because it is too large.
Load diff
@@ -32,17 +32,32 @@
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n";
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void
|
||||
print(size_t size, char *filename)
|
||||
print_normal(size_t size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(size_t size, char *filename)
|
||||
{
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
@@ -54,6 +69,8 @@ du(char *filename)
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
@@ -76,6 +93,7 @@ du(char *filename)
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -85,12 +103,16 @@ du_main(int argc, char **argv)
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
@@ -110,12 +132,12 @@ du_main(int argc, char **argv)
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]) >> 1;
|
||||
if (sum) printf("%-7d %s\n", sum, argv[i]);
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
|
||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
||||
+254
-84
@@ -5,6 +5,11 @@
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* Modifications for addresses and append command have been
|
||||
* written by Marco Pantaleoni <panta@prosa.it>, <panta@elasticworld.org>
|
||||
* and are:
|
||||
* Copyright (C) 1999 Marco Pantaleoni.
|
||||
*
|
||||
* 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
|
||||
@@ -31,48 +36,144 @@
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] [-e script] [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t's/regexp/replacement/[gp]'\n"
|
||||
"which attempt to match regexp against the pattern space\n"
|
||||
"and if successful replaces the matched portion with replacement.\n\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] -e script [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
/* Flags & variables */
|
||||
|
||||
typedef enum { f_none, f_replace, f_append } sed_function;
|
||||
|
||||
#define NO_LINE -2
|
||||
#define LAST_LINE -1
|
||||
static int addr_line = NO_LINE;
|
||||
static char *addr_pattern = NULL;
|
||||
static int negated = 0;
|
||||
|
||||
#define SKIPSPACES(p) do { while (isspace(*(p))) (p)++; } while (0)
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
static inline int at_last(FILE * fp)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
int res = 0;
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
char ch;
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void do_sed_repl(FILE * fp, char *needle, char *newNeedle,
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
static void do_sed_append(FILE * fp, char *appendline, int quietFlag)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle=NULL, *newNeedle=NULL;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -83,68 +184,119 @@ extern int sed_main (int argc, char **argv)
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
usage( sed_usage);
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if ( *++cp != 's')
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
*pos=0;
|
||||
newNeedle=++pos;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag=TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -153,30 +305,48 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose (fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.39
|
||||
Version: 0.40
|
||||
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
|
||||
make
|
||||
BB_INIT_SCRIPT='\"/etc/rc.d/init.d/rcS\"' make
|
||||
|
||||
%Install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# /etc/inittab init(8) configuration for BusyBox
|
||||
#
|
||||
# Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen
|
||||
# <andersen@lineo.com>, <andersee@debian.org>
|
||||
#
|
||||
#
|
||||
# Note, BusyBox init doesn't support runlevels. The runlevels field is
|
||||
# completely ignored by BusyBox init. If you want runlevels, use sysvinit.
|
||||
#
|
||||
#
|
||||
# Format for each entry: <id>:<runlevels>:<action>:<process>
|
||||
#
|
||||
# <id>: WARNING: This field has a non-traditional meaning for BusyBox init!
|
||||
#
|
||||
# The id field is used by BusyBox init to specify the controlling tty for
|
||||
# the specified process to run on. The contents of this field are
|
||||
# appended to "/dev/" and used as-is. There is no need for this field to
|
||||
# be unique, although if it isn't you may have strange results. If this
|
||||
# field is left blank, it is completely ignored. Also note that if
|
||||
# BusyBox detects that a serial console is in use, then all entries
|
||||
# containing non-empty id fields will _not_ be run. BusyBox init does
|
||||
# nothing with utmp. We don't need no stinkin' utmp.
|
||||
#
|
||||
# <runlevels>: The runlevels field is completely ignored.
|
||||
#
|
||||
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, and once.
|
||||
#
|
||||
# Note: askfirst acts just like respawn, but before running the specified
|
||||
# process it displays the line "Please press Enter to activate this
|
||||
# console." and then waits for the user to press enter before starting
|
||||
# the specified process.
|
||||
#
|
||||
# Note: unrecognised actions (like initdefault) will cause init to emit
|
||||
# an error message, and then go along with its business.
|
||||
#
|
||||
# <process>: Specifies the process to be executed and it's command line.
|
||||
#
|
||||
# Note: BusyBox init works just fine without an inittab. If no inittab
|
||||
# is found, it has the following default behavior:
|
||||
# ::sysinit:/etc/init.d/rcS
|
||||
# ::askfirst:/bin/sh
|
||||
# if it detects that /dev/console is _not_ a serial console, it will also run:
|
||||
# tty2::askfirst:/bin/sh
|
||||
#
|
||||
|
||||
|
||||
# Boot-time system configuration/initialization script.
|
||||
# This is run first except when booting in single-user mode.
|
||||
#
|
||||
::sysinit:/etc/init.d/rcS
|
||||
|
||||
# /bin/sh invocations on selected ttys
|
||||
#
|
||||
# Start an "askfirst" shell on the console (whatever that may be)
|
||||
::askfirst:/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2
|
||||
tty2::askfirst:/bin/sh
|
||||
|
||||
# /sbin/getty invocations for selected ttys
|
||||
#
|
||||
tty4::respawn:/sbin/getty 38400 tty4
|
||||
tty5::respawn:/sbin/getty 38400 tty5
|
||||
|
||||
|
||||
# Example of how to put a getty on a serial line (for a terminal)
|
||||
#
|
||||
#ttyS0::respawn:/sbin/getty -L ttyS0 9600 vt100
|
||||
#ttyS1::respawn:/sbin/getty -L ttyS1 9600 vt100
|
||||
#
|
||||
# Example how to put a getty on a modem line.
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
|
||||
# Not currently supported, but may be sometime in the future...
|
||||
#::ctrlaltdel:/sbin/reboot
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Mini fbset implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@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
|
||||
*
|
||||
* This is a from-scratch implementation of fbset; but the de facto fbset
|
||||
* implementation was a good reference. fbset (original) is released under
|
||||
* the GPL, and is (c) 1995-1999 by:
|
||||
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/version.h>
|
||||
|
||||
#define PERROR(ctx) do { perror(ctx); exit(1); } while(0)
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#define DEFAULTFBDEV "/dev/fb0"
|
||||
#define DEFAULTFBMODE "/etc/fb.modes"
|
||||
|
||||
#define OPT_CHANGE 1
|
||||
#define OPT_INFO (1 << 1)
|
||||
#define OPT_READMODE (1 << 2)
|
||||
|
||||
#define CMD_HELP 0
|
||||
#define CMD_FB 1
|
||||
#define CMD_DB 2
|
||||
#define CMD_GEOMETRY 3
|
||||
#define CMD_TIMING 4
|
||||
#define CMD_ACCEL 5
|
||||
#define CMD_HSYNC 6
|
||||
#define CMD_VSYNC 7
|
||||
#define CMD_LACED 8
|
||||
#define CMD_DOUBLE 9
|
||||
/* #define CMD_XCOMPAT 10 */
|
||||
#define CMD_ALL 11
|
||||
#define CMD_INFO 12
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#define CMD_XRES 13
|
||||
#define CMD_YRES 14
|
||||
#define CMD_VXRES 15
|
||||
#define CMD_VYRES 16
|
||||
#define CMD_DEPTH 17
|
||||
#define CMD_MATCH 18
|
||||
#define CMD_PIXCLOCK 19
|
||||
#define CMD_LEFT 20
|
||||
#define CMD_RIGHT 21
|
||||
#define CMD_UPPER 22
|
||||
#define CMD_LOWER 23
|
||||
#define CMD_HSLEN 24
|
||||
#define CMD_VSLEN 25
|
||||
#define CMD_CSYNC 26
|
||||
#define CMD_GSYNC 27
|
||||
#define CMD_EXTSYNC 28
|
||||
#define CMD_BCAST 29
|
||||
#define CMD_RGBA 30
|
||||
#define CMD_STEP 31
|
||||
#define CMD_MOVE 32
|
||||
#endif
|
||||
|
||||
static unsigned int g_options = 0;
|
||||
|
||||
struct cmdoptions_t {
|
||||
char *name;
|
||||
unsigned char param_count;
|
||||
unsigned char code;
|
||||
} g_cmdoptions[] = {
|
||||
{ "-h", 0, CMD_HELP },
|
||||
{ "-fb", 1, CMD_FB },
|
||||
{ "-db", 1, CMD_DB },
|
||||
{ "-a", 0, CMD_ALL },
|
||||
{ "-i", 0, CMD_INFO },
|
||||
{ "-g", 5, CMD_GEOMETRY },
|
||||
{ "-t", 7, CMD_TIMING },
|
||||
{ "-accel", 1, CMD_ACCEL },
|
||||
{ "-hsync", 1, CMD_HSYNC },
|
||||
{ "-vsync", 1, CMD_VSYNC },
|
||||
{ "-laced", 1, CMD_LACED },
|
||||
{ "-double", 1, CMD_DOUBLE },
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
{ "--help", 0, CMD_HELP },
|
||||
{ "-all", 0, CMD_ALL },
|
||||
{ "-xres", 1, CMD_XRES },
|
||||
{ "-yres", 1, CMD_YRES },
|
||||
{ "-vxres", 1, CMD_VXRES },
|
||||
{ "-vyres", 1, CMD_VYRES },
|
||||
{ "-depth", 1, CMD_DEPTH },
|
||||
{ "-match", 0, CMD_MATCH },
|
||||
{ "--geometry", 5, CMD_GEOMETRY },
|
||||
|
||||
{ "-pixclock", 1, CMD_PIXCLOCK },
|
||||
{ "-left", 1, CMD_LEFT },
|
||||
{ "-right", 1, CMD_RIGHT },
|
||||
{ "-upper", 1, CMD_UPPER },
|
||||
{ "-lower", 1, CMD_LOWER },
|
||||
{ "-hslen", 1, CMD_HSLEN },
|
||||
{ "-vslen", 1, CMD_VSLEN },
|
||||
{ "--timings", 7, CMD_TIMING },
|
||||
|
||||
{ "-csync", 1, CMD_CSYNC },
|
||||
{ "-gsync", 1, CMD_GSYNC },
|
||||
{ "-extsync", 1, CMD_EXTSYNC },
|
||||
{ "-bcast", 1, CMD_BCAST },
|
||||
{ "-rgba", 1, CMD_RGBA },
|
||||
{ "-step", 1, CMD_STEP },
|
||||
{ "-move", 1, CMD_MOVE },
|
||||
#endif
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
const char *mode)
|
||||
{
|
||||
#ifdef BB_FBSET_READMODE
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *p = buf;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL) PERROR("readmode(fopen)");
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
|
||||
p += 5;
|
||||
if ((p = strstr(buf, mode))) {
|
||||
p += strlen(mode);
|
||||
if (!isspace(*p) && (*p != 0) && (*p != '"') && (*p != '\r')
|
||||
&& (*p != '\n')) continue; /* almost, but not quite */
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if (!strstr(buf, "endmode")) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "W: mode reading was disabled on this copy of fbset; ignoring request\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setmode(struct fb_var_screeninfo *base,
|
||||
struct fb_var_screeninfo *set)
|
||||
{
|
||||
if ((int)set->xres > 0) base->xres = set->xres;
|
||||
if ((int)set->yres > 0) base->yres = set->yres;
|
||||
if ((int)set->xres_virtual > 0) base->xres_virtual = set->xres_virtual;
|
||||
if ((int)set->yres_virtual > 0) base->yres_virtual = set->yres_virtual;
|
||||
if ((int)set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel;
|
||||
}
|
||||
|
||||
static void showmode(struct fb_var_screeninfo *v)
|
||||
{
|
||||
double drate = 0, hrate = 0, vrate = 0;
|
||||
if (v->pixclock) {
|
||||
drate = 1e12 / v->pixclock;
|
||||
hrate = drate / (v->left_margin+v->xres+v->right_margin+v->hsync_len);
|
||||
vrate = hrate / (v->upper_margin+v->yres+v->lower_margin+v->vsync_len);
|
||||
}
|
||||
printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int)(vrate+0.5));
|
||||
#ifdef BB_FBSET_FANCY
|
||||
printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate/1e6, hrate/1e3,
|
||||
vrate);
|
||||
#endif
|
||||
printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
|
||||
v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
|
||||
#else
|
||||
printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
#endif
|
||||
printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, v->red.offset,
|
||||
v->green.length, v->green.offset, v->blue.length, v->blue.offset,
|
||||
v->transp.length, v->transp.offset);
|
||||
printf("endmode\n");
|
||||
}
|
||||
|
||||
static void fbset_usage(void)
|
||||
{
|
||||
int i;
|
||||
#ifndef STANDALONE
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
|
||||
#endif
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n");
|
||||
fprintf(stderr, "\tThe following options are recognized:\n");
|
||||
for (i = 0; g_cmdoptions[i].name; i++)
|
||||
fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
int main(int argc, char **argv)
|
||||
#else
|
||||
extern int fbset_main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
struct fb_var_screeninfo var, varset;
|
||||
int fh, i;
|
||||
char *fbdev = DEFAULTFBDEV;
|
||||
char *modefile = DEFAULTFBMODE;
|
||||
char *thisarg, *mode = NULL;
|
||||
|
||||
memset(&varset, 0xFF, sizeof(varset));
|
||||
|
||||
/* parse cmd args.... why do they have to make things so difficult? */
|
||||
argv++; argc--;
|
||||
for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
|
||||
for (i = 0; g_cmdoptions[i].name; i++) {
|
||||
if (!strcmp(thisarg, g_cmdoptions[i].name)) {
|
||||
if (argc - 1 < g_cmdoptions[i].param_count) fbset_usage();
|
||||
switch (g_cmdoptions[i].code) {
|
||||
case CMD_HELP: fbset_usage();
|
||||
case CMD_FB: fbdev = argv[1]; break;
|
||||
case CMD_DB: modefile = argv[1]; break;
|
||||
case CMD_GEOMETRY:
|
||||
varset.xres = strtoul(argv[1],0,0);
|
||||
varset.yres = strtoul(argv[2],0,0);
|
||||
varset.xres_virtual = strtoul(argv[3],0,0);
|
||||
varset.yres_virtual = strtoul(argv[4],0,0);
|
||||
varset.bits_per_pixel = strtoul(argv[5],0,0);
|
||||
break;
|
||||
case CMD_TIMING:
|
||||
varset.pixclock = strtoul(argv[1],0,0);
|
||||
varset.left_margin = strtoul(argv[2],0,0);
|
||||
varset.right_margin = strtoul(argv[3],0,0);
|
||||
varset.upper_margin = strtoul(argv[4],0,0);
|
||||
varset.lower_margin = strtoul(argv[5],0,0);
|
||||
varset.hsync_len = strtoul(argv[6],0,0);
|
||||
varset.vsync_len = strtoul(argv[7],0,0);
|
||||
break;
|
||||
#ifdef BB_FBSET_FANCY
|
||||
case CMD_XRES: varset.xres = strtoul(argv[1],0,0); break;
|
||||
case CMD_YRES: varset.yres = strtoul(argv[1],0,0); break;
|
||||
#endif
|
||||
}
|
||||
argc -= g_cmdoptions[i].param_count;
|
||||
argv += g_cmdoptions[i].param_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!g_cmdoptions[i].name) {
|
||||
if (argc == 1) {
|
||||
mode = *argv;
|
||||
g_options |= OPT_READMODE;
|
||||
} else {
|
||||
fbset_usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((fh = open(fbdev, O_RDONLY)) < 0) PERROR("fbset(open)");
|
||||
if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
if (g_options & OPT_READMODE) {
|
||||
if (!readmode(&var, modefile, mode)) {
|
||||
fprintf(stderr, "Unknown video mode `%s'\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
setmode(&var, &varset);
|
||||
if (g_options & OPT_CHANGE)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
close(fh);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
+20
-3
@@ -21,6 +21,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||
|
||||
+ -q option (be quiet)
|
||||
+ exit code depending on grep result (TRUE or FALSE)
|
||||
(useful for scripts)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
@@ -37,13 +45,15 @@ static const char grep_usage[] =
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
@@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
if (beQuiet==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv)
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
@@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv)
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
exit(match);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||
|
||||
+ -q option (be quiet)
|
||||
+ exit code depending on grep result (TRUE or FALSE)
|
||||
(useful for scripts)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
@@ -37,13 +45,15 @@ static const char grep_usage[] =
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
@@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
if (beQuiet==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv)
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
@@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv)
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
exit(match);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output\n";
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -653,7 +654,7 @@ DECLARE(uch, window, 2L*WSIZE);
|
||||
|
||||
/* local variables */
|
||||
|
||||
int force = 0; /* don't ask questions, compress links (-f) */
|
||||
int test_mode = 0; /* check file integrity option */
|
||||
int foreground; /* set if program run in foreground */
|
||||
int maxbits = BITS; /* max bits per code for LZW */
|
||||
int method = DEFLATED;/* compression method */
|
||||
@@ -714,6 +715,10 @@ int gunzip_main (int argc, char** argv)
|
||||
case 'c':
|
||||
to_stdout = 1;
|
||||
break;
|
||||
case 't':
|
||||
test_mode = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(gunzip_usage);
|
||||
}
|
||||
@@ -786,6 +791,9 @@ int gunzip_main (int argc, char** argv)
|
||||
/* Actually do the compression/decompression. */
|
||||
unzip(inFileNum, outFileNum);
|
||||
|
||||
} else if (test_mode) {
|
||||
/* Actually do the compression/decompression. */
|
||||
unzip(inFileNum, 2);
|
||||
} else {
|
||||
char* pos;
|
||||
|
||||
@@ -805,7 +813,11 @@ int gunzip_main (int argc, char** argv)
|
||||
}
|
||||
|
||||
/* Open output fille */
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
#else
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL);
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
@@ -853,17 +865,8 @@ local int get_method(in)
|
||||
uch flags; /* compression flags */
|
||||
char magic[2]; /* magic header */
|
||||
|
||||
/* If --force and --stdout, zcat == cat, so do not complain about
|
||||
* premature end of file: use try_byte instead of get_byte.
|
||||
*/
|
||||
if (force) {
|
||||
magic[0] = (char)try_byte();
|
||||
magic[1] = (char)try_byte();
|
||||
/* If try_byte returned EOF, magic[1] == 0xff */
|
||||
} else {
|
||||
magic[0] = (char)get_byte();
|
||||
magic[1] = (char)get_byte();
|
||||
}
|
||||
magic[0] = (char)get_byte();
|
||||
magic[1] = (char)get_byte();
|
||||
method = -1; /* unknown yet */
|
||||
part_nb++; /* number of parts in gzip file */
|
||||
header_bytes = 0;
|
||||
@@ -1184,7 +1187,8 @@ void flush_outbuf()
|
||||
{
|
||||
if (outcnt == 0) return;
|
||||
|
||||
write_buf(ofd, (char *)outbuf, outcnt);
|
||||
if (!test_mode)
|
||||
write_buf(ofd, (char *)outbuf, outcnt);
|
||||
bytes_out += (ulg)outcnt;
|
||||
outcnt = 0;
|
||||
}
|
||||
@@ -1198,8 +1202,8 @@ void flush_window()
|
||||
if (outcnt == 0) return;
|
||||
updcrc(window, outcnt);
|
||||
|
||||
write_buf(ofd, (char *)window, outcnt);
|
||||
|
||||
if (!test_mode)
|
||||
write_buf(ofd, (char *)window, outcnt);
|
||||
bytes_out += (ulg)outcnt;
|
||||
outcnt = 0;
|
||||
}
|
||||
|
||||
@@ -1877,7 +1877,11 @@ int gzip_main(int argc, char ** argv)
|
||||
|
||||
|
||||
/* Open output fille */
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
#else
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL);
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
|
||||
@@ -54,7 +54,7 @@ head_main(int argc, char **argv)
|
||||
int len = 10;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
@@ -103,4 +103,4 @@ head_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
|
||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
@@ -41,6 +42,7 @@
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/version.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
#endif
|
||||
@@ -49,18 +51,61 @@
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define GETTY "/sbin/getty" /* Default location of getty */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#ifndef INIT_SCRIPT
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#endif
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
|
||||
/* Allowed init action types */
|
||||
typedef enum {
|
||||
SYSINIT=1,
|
||||
RESPAWN,
|
||||
ASKFIRST,
|
||||
WAIT,
|
||||
ONCE
|
||||
} initActionEnum;
|
||||
|
||||
/* And now a list of the actions we support in the version of init */
|
||||
typedef struct initActionType{
|
||||
const char* name;
|
||||
initActionEnum action;
|
||||
} initActionType;
|
||||
|
||||
static const struct initActionType actions[] = {
|
||||
{"sysinit", SYSINIT},
|
||||
{"respawn", RESPAWN},
|
||||
{"askfirst", ASKFIRST},
|
||||
{"wait", WAIT},
|
||||
{"once", ONCE},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* Set up a linked list of initactions, to be read from inittab */
|
||||
typedef struct initActionTag initAction;
|
||||
struct initActionTag {
|
||||
pid_t pid;
|
||||
char process[256];
|
||||
char console[256];
|
||||
initAction *nextPtr;
|
||||
initActionEnum action;
|
||||
};
|
||||
initAction* initActionList = NULL;
|
||||
|
||||
|
||||
static char *console = _PATH_CONSOLE;
|
||||
static char *second_console = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
@@ -90,8 +135,9 @@ int device_open(char *device, int mode)
|
||||
* device may be bitwise-or'd from LOG | CONSOLE */
|
||||
void message(int device, char *fmt, ...)
|
||||
{
|
||||
int fd;
|
||||
va_list arguments;
|
||||
int fd;
|
||||
|
||||
#ifdef BB_SYSLOGD
|
||||
|
||||
/* Log the message to syslogd */
|
||||
@@ -266,7 +312,7 @@ static void console_init()
|
||||
/* 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 2nd virtual terminal.\r\n", console );
|
||||
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console );
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
@@ -275,49 +321,41 @@ static void console_init()
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
static int waitfor(int pid)
|
||||
{
|
||||
int status, wpid;
|
||||
|
||||
message(LOG, "Waiting for process %d.\n", pid);
|
||||
while ((wpid = wait(&status)) != pid) {
|
||||
if (wpid > 0)
|
||||
message(LOG, "pid %d exited, status=0x%x.\n", wpid, status);
|
||||
}
|
||||
return wpid;
|
||||
}
|
||||
|
||||
|
||||
static pid_t run(const char * const* command,
|
||||
static pid_t run(char* command,
|
||||
char *terminal, int get_enter)
|
||||
{
|
||||
int fd;
|
||||
int i;
|
||||
pid_t pid;
|
||||
const char * const* cmd = command+1;
|
||||
char* tmpCmd;
|
||||
char* cmd[255];
|
||||
static const char press_enter[] =
|
||||
"\nPlease press Enter to activate this console. ";
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
int fd;
|
||||
pid_t shell_pgid = getpid ();
|
||||
|
||||
/* Clean up */
|
||||
close(0);
|
||||
close(1);
|
||||
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, "Bummer, can't open %s\r\n", terminal);
|
||||
exit(-1);
|
||||
}
|
||||
dup(fd);
|
||||
dup(fd);
|
||||
tcsetpgrp(0, getpgrp());
|
||||
set_term(0);
|
||||
|
||||
if (get_enter==TRUE) {
|
||||
/*
|
||||
@@ -330,40 +368,68 @@ static pid_t run(const char * const* command,
|
||||
*/
|
||||
char c;
|
||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||
*cmd, getpid(), terminal );
|
||||
write(1, press_enter, sizeof(press_enter) - 1);
|
||||
read(0, &c, 1);
|
||||
command, shell_pgid, terminal );
|
||||
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
||||
read(fileno(stdin), &c, 1);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
tmpCmd++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
cmd[i] = NULL;
|
||||
|
||||
/* Log the process name and args */
|
||||
message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
|
||||
message(LOG|CONSOLE, "'\r\n");
|
||||
|
||||
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
||||
shell_pgid, terminal, cmd[0]);
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
execvp(*command, (char**)command+1);
|
||||
execvp(cmd[0], cmd);
|
||||
|
||||
message(LOG, "Bummer, could not run '%s'\n", command);
|
||||
/* We're still here? Some error happened. */
|
||||
message(LOG|CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0],
|
||||
strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static int waitfor(char* command,
|
||||
char *terminal, int get_enter)
|
||||
{
|
||||
int status, wpid;
|
||||
int pid = run( command, terminal, get_enter);
|
||||
|
||||
while (1) {
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "Process '%s' (pid %d) exited.\n",
|
||||
command, wpid);
|
||||
break;
|
||||
}
|
||||
if (wpid == pid )
|
||||
break;
|
||||
}
|
||||
return wpid;
|
||||
}
|
||||
|
||||
/* Make sure there is enough memory to do something useful. *
|
||||
* Calls swapon if needed so be sure /proc is mounted. */
|
||||
static void check_memory()
|
||||
{
|
||||
struct stat statbuf;
|
||||
const char* const swap_on_cmd[] =
|
||||
{ "/bin/swapon", "swapon", "-a", 0};
|
||||
struct stat statBuf;
|
||||
|
||||
if (mem_total() > 3500)
|
||||
return;
|
||||
|
||||
if (stat("/etc/fstab", &statbuf) == 0) {
|
||||
if (stat("/etc/fstab", &statBuf) == 0) {
|
||||
/* Try to turn on swap */
|
||||
waitfor(run(swap_on_cmd, log, FALSE));
|
||||
waitfor("/bin/swapon swapon -a", log, FALSE);
|
||||
if (mem_total() < 3500)
|
||||
goto goodnight;
|
||||
} else
|
||||
@@ -375,37 +441,31 @@ goodnight:
|
||||
while (1) sleep(1);
|
||||
}
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
static void shutdown_system(void)
|
||||
{
|
||||
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", 0};
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||
reboot(RB_ENABLE_CAD);
|
||||
#endif
|
||||
message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
|
||||
sync();
|
||||
|
||||
/* Send signals to every process _except_ pid 1 */
|
||||
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
|
||||
#ifndef DEBUG_INIT
|
||||
kill(-1, SIGHUP);
|
||||
#endif
|
||||
sleep(2);
|
||||
sync();
|
||||
|
||||
message(CONSOLE, "Sending SIGKILL to all processes.\r\n");
|
||||
#ifndef DEBUG_INIT
|
||||
kill(-1, SIGKILL);
|
||||
#endif
|
||||
sleep(1);
|
||||
|
||||
message(CONSOLE, "Disabling swap.\r\n");
|
||||
waitfor(run( swap_off_cmd, console, FALSE));
|
||||
waitfor( "swapoff -a", console, FALSE);
|
||||
message(CONSOLE, "Unmounting filesystems.\r\n");
|
||||
waitfor(run( umount_cmd, console, FALSE));
|
||||
waitfor("umount -a", console, FALSE);
|
||||
sync();
|
||||
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
|
||||
/* bdflush, kupdate not needed for kernels >2.2.11 */
|
||||
message(CONSOLE, "Flushing buffers.\r\n");
|
||||
bdflush(1, 0);
|
||||
sync();
|
||||
}
|
||||
@@ -417,12 +477,12 @@ static void halt_signal(int sig)
|
||||
message(CONSOLE,
|
||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
if (sig == SIGUSR2)
|
||||
reboot(RB_POWER_OFF);
|
||||
else
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
#endif
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -431,53 +491,175 @@ static void reboot_signal(int sig)
|
||||
shutdown_system();
|
||||
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_AUTOBOOT);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void new_initAction (initActionEnum action,
|
||||
char* process, char* cons)
|
||||
{
|
||||
initAction* newAction;
|
||||
|
||||
/* 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') {
|
||||
return;
|
||||
}
|
||||
|
||||
newAction = calloc ((size_t)(1), sizeof(initAction));
|
||||
if (!newAction) {
|
||||
message(LOG|CONSOLE,"Memory allocation failure\n");
|
||||
while (1) sleep(1);
|
||||
}
|
||||
newAction->nextPtr = initActionList;
|
||||
initActionList = newAction;
|
||||
strncpy( newAction->process, process, 255);
|
||||
newAction->action = action;
|
||||
if (*cons != '\0') {
|
||||
strncpy(newAction->console, cons, 255);
|
||||
} else
|
||||
strncpy(newAction->console, console, 255);
|
||||
newAction->pid = 0;
|
||||
// message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n",
|
||||
// newAction->process, newAction->action, newAction->console);
|
||||
}
|
||||
|
||||
void delete_initAction (initAction *action)
|
||||
{
|
||||
initAction *a, *b=NULL;
|
||||
for( a=initActionList ; a; b=a, a=a->nextPtr) {
|
||||
if (a == action && b != NULL) {
|
||||
b->nextPtr=a->nextPtr;
|
||||
free( a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e runs INIT_SCRIPT and then starts a pair
|
||||
* of "askfirst" shells). If BB_FEATURE_USE_INITTAB
|
||||
* _is_ defined, but /etc/inittab is missing, this
|
||||
* results in the same set of default behaviors.
|
||||
* */
|
||||
void parse_inittab(void)
|
||||
{
|
||||
#ifdef BB_FEATURE_USE_INITTAB
|
||||
FILE* file;
|
||||
char buf[256], lineAsRead[256], tmpConsole[256];
|
||||
char *p, *q, *r, *s;
|
||||
const struct initActionType *a = actions;
|
||||
int foundIt;
|
||||
|
||||
|
||||
file = fopen(INITTAB, "r");
|
||||
if (file == NULL) {
|
||||
/* No inittab file -- set up some default behavior */
|
||||
#endif
|
||||
/* Askfirst shell on tty1 */
|
||||
new_initAction( ASKFIRST, SHELL, console );
|
||||
/* Askfirst shell on tty2 */
|
||||
if (second_console != NULL)
|
||||
new_initAction( ASKFIRST, SHELL, second_console );
|
||||
/* sysinit */
|
||||
new_initAction( SYSINIT, INIT_SCRIPT, console );
|
||||
|
||||
return;
|
||||
#ifdef BB_FEATURE_USE_INITTAB
|
||||
}
|
||||
|
||||
while ( fgets(buf, 255, file) != NULL) {
|
||||
foundIt=FALSE;
|
||||
for(p = buf; *p == ' ' || *p == '\t'; p++);
|
||||
if (*p == '#' || *p == '\n') continue;
|
||||
|
||||
/* Trim the trailing \n */
|
||||
q = strrchr( p, '\n');
|
||||
if (q != NULL)
|
||||
*q='\0';
|
||||
|
||||
/* Keep a copy around for posterity's sake (and error msgs) */
|
||||
strcpy(lineAsRead, buf);
|
||||
|
||||
/* Grab the ID field */
|
||||
s=p;
|
||||
p = strchr( p, ':');
|
||||
if ( p != NULL || *(p+1) != '\0' ) {
|
||||
*p='\0';
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Now peal off the process field from the end
|
||||
* of the string */
|
||||
q = strrchr( p, ':');
|
||||
if ( q == NULL || *(q+1) == '\0' ) {
|
||||
message(LOG|CONSOLE,"Bad inittab entry: %s\n", lineAsRead);
|
||||
continue;
|
||||
} else {
|
||||
*q='\0';
|
||||
++q;
|
||||
}
|
||||
|
||||
/* Now peal off the action field */
|
||||
r = strrchr( p, ':');
|
||||
if ( r == NULL || *(r+1) == '\0') {
|
||||
message(LOG|CONSOLE,"Bad inittab entry: %s\n", lineAsRead);
|
||||
continue;
|
||||
} else {
|
||||
++r;
|
||||
}
|
||||
|
||||
/* Ok, now process it */
|
||||
a = actions;
|
||||
while (a->name != 0) {
|
||||
if (strcmp(a->name, r) == 0) {
|
||||
if (*s != '\0') {
|
||||
struct stat statBuf;
|
||||
strcpy(tmpConsole, "/dev/");
|
||||
strncat(tmpConsole, s, 200);
|
||||
if (stat(tmpConsole, &statBuf) != 0) {
|
||||
message(LOG|CONSOLE, "device '%s' does not exist. Did you read the directions?\n", tmpConsole);
|
||||
break;
|
||||
}
|
||||
s = tmpConsole;
|
||||
}
|
||||
new_initAction( a->action, q, s);
|
||||
foundIt=TRUE;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
if (foundIt==TRUE)
|
||||
continue;
|
||||
else {
|
||||
/* Choke on an unknown action */
|
||||
message(LOG|CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern int init_main(int argc, char **argv)
|
||||
{
|
||||
int run_rc = FALSE;
|
||||
int single = FALSE;
|
||||
int wait_for_enter_tty1 = TRUE;
|
||||
int wait_for_enter_tty2 = TRUE;
|
||||
pid_t pid1 = 0;
|
||||
pid_t pid2 = 0;
|
||||
struct stat statbuf;
|
||||
char which_vt1[30];
|
||||
char which_vt2[30];
|
||||
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const getty1_command[] = { GETTY, GETTY, "38400", which_vt1, 0};
|
||||
const char* const getty2_command[] = { GETTY, GETTY, "38400", which_vt2, 0};
|
||||
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty1_command = shell_command;
|
||||
const char* const* tty2_command = shell_command;
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS",
|
||||
"BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 };
|
||||
#endif
|
||||
initAction *a;
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
char *hello_msg_format =
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
#else
|
||||
char *hello_msg_format =
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 iff we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) {
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
/* from the controlling terminal */
|
||||
setsid();
|
||||
|
||||
/* 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);
|
||||
@@ -485,10 +667,9 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
||||
* SIGINT on CAD so we can shut things down gracefully... */
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_DISABLE_CAD);
|
||||
#endif
|
||||
|
||||
|
||||
/* Figure out where the default console should be */
|
||||
console_init();
|
||||
|
||||
@@ -497,7 +678,6 @@ 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);
|
||||
@@ -505,98 +685,111 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Hello world */
|
||||
#ifndef DEBUG_INIT
|
||||
message(CONSOLE|LOG, hello_msg_format, BB_VER, BB_BT);
|
||||
message(LOG|CONSOLE,
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
BB_VER, BB_BT);
|
||||
#else
|
||||
message(CONSOLE|LOG, hello_msg_format, getpid(), BB_VER, BB_BT);
|
||||
message(LOG|CONSOLE,
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
getpid(), BB_VER, BB_BT);
|
||||
#endif
|
||||
|
||||
|
||||
/* Mount /proc */
|
||||
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
|
||||
message(CONSOLE|LOG, "Mounting /proc: done.\n");
|
||||
message(LOG|CONSOLE, "Mounting /proc: done.\n");
|
||||
kernel_version = get_kernel_revision();
|
||||
} else
|
||||
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
|
||||
message(LOG|CONSOLE, "Mounting /proc: failed!\n");
|
||||
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
single = TRUE;
|
||||
tty1_command = shell_command;
|
||||
tty2_command = shell_command;
|
||||
!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);
|
||||
/* Ask first then start a shell on tty1 */
|
||||
new_initAction( ASKFIRST, SHELL, console);
|
||||
} else {
|
||||
/* Not in single user mode -- see what inittab says */
|
||||
|
||||
/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e runs INIT_SCRIPT and then starts a pair
|
||||
* of "askfirst" shells */
|
||||
parse_inittab();
|
||||
}
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
run_rc = TRUE;
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
tty1_command = rc_script_command;
|
||||
}
|
||||
|
||||
/* Make sure /sbin/getty exists before trying to run it */
|
||||
if (stat(GETTY, &statbuf)==0) {
|
||||
char* where;
|
||||
/* First do tty2 */
|
||||
wait_for_enter_tty2 = FALSE;
|
||||
where = strrchr( second_console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt2, where, sizeof(which_vt2));
|
||||
/* Now run everything that needs to be run */
|
||||
|
||||
/* First run the sysinit command */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == SYSINIT) {
|
||||
waitfor(a->process, a->console, FALSE);
|
||||
/* Now remove the "sysinit" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
tty2_command = getty2_command;
|
||||
}
|
||||
/* Next run anything that wants to block */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == WAIT) {
|
||||
waitfor(a->process, a->console, FALSE);
|
||||
/* Now remove the "wait" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
}
|
||||
/* Next run anything to be run only once */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == ONCE) {
|
||||
run(a->process, a->console, FALSE);
|
||||
/* Now remove the "once" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
}
|
||||
/* If there is nothing else to do, stop */
|
||||
if (initActionList == NULL) {
|
||||
message(LOG|CONSOLE, "No more tasks for init -- sleeping forever.\n");
|
||||
while (1) sleep(1);
|
||||
}
|
||||
|
||||
/* Check on hooking a getty onto tty1 */
|
||||
if (run_rc == FALSE && single==FALSE) {
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
where = strrchr( console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt1, where, sizeof(which_vt1));
|
||||
/* Now run the looping stuff for the rest of forever */
|
||||
while (1) {
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
/* Only run stuff with pid==0. If they have
|
||||
* a pid, that means they are still running */
|
||||
if (a->pid == 0) {
|
||||
switch(a->action) {
|
||||
case RESPAWN:
|
||||
/* run the respawn stuff */
|
||||
a->pid = run(a->process, a->console, FALSE);
|
||||
break;
|
||||
case ASKFIRST:
|
||||
/* run the askfirst stuff */
|
||||
a->pid = run(a->process, a->console, TRUE);
|
||||
break;
|
||||
/* silence the compiler's incessant whining */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
tty1_command = getty1_command;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Ok, now launch the tty1_command and tty2_command */
|
||||
for (;;) {
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
if (pid1 == 0 && tty1_command) {
|
||||
pid1 = run(tty1_command, console, wait_for_enter_tty1);
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (pid2 == 0 && tty2_command && second_console) {
|
||||
pid2 = run(tty2_command, second_console, wait_for_enter_tty2);
|
||||
}
|
||||
#endif
|
||||
/* Wait for a child process to exit */
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
|
||||
}
|
||||
/* Don't respawn init script if it exits */
|
||||
if (wpid == pid1) {
|
||||
if (run_rc == FALSE) {
|
||||
pid1 = 0;
|
||||
/* Find out who died and clean up their corpse */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->pid==wpid) {
|
||||
a->pid=0;
|
||||
message(LOG, "Process '%s' (pid %d) exited. Scheduling it for restart.\n",
|
||||
a->process, wpid);
|
||||
}
|
||||
}
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
else {
|
||||
pid1 = 0;
|
||||
run_rc=FALSE;
|
||||
wait_for_enter_tty1=TRUE;
|
||||
tty1_command=rc_exit_command;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (wpid == pid2) {
|
||||
pid2 = 0;
|
||||
}
|
||||
#endif
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
+359
-166
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
@@ -41,6 +42,7 @@
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/version.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
#endif
|
||||
@@ -49,18 +51,61 @@
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define GETTY "/sbin/getty" /* Default location of getty */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#ifndef INIT_SCRIPT
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#endif
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
|
||||
/* Allowed init action types */
|
||||
typedef enum {
|
||||
SYSINIT=1,
|
||||
RESPAWN,
|
||||
ASKFIRST,
|
||||
WAIT,
|
||||
ONCE
|
||||
} initActionEnum;
|
||||
|
||||
/* And now a list of the actions we support in the version of init */
|
||||
typedef struct initActionType{
|
||||
const char* name;
|
||||
initActionEnum action;
|
||||
} initActionType;
|
||||
|
||||
static const struct initActionType actions[] = {
|
||||
{"sysinit", SYSINIT},
|
||||
{"respawn", RESPAWN},
|
||||
{"askfirst", ASKFIRST},
|
||||
{"wait", WAIT},
|
||||
{"once", ONCE},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* Set up a linked list of initactions, to be read from inittab */
|
||||
typedef struct initActionTag initAction;
|
||||
struct initActionTag {
|
||||
pid_t pid;
|
||||
char process[256];
|
||||
char console[256];
|
||||
initAction *nextPtr;
|
||||
initActionEnum action;
|
||||
};
|
||||
initAction* initActionList = NULL;
|
||||
|
||||
|
||||
static char *console = _PATH_CONSOLE;
|
||||
static char *second_console = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
@@ -90,8 +135,9 @@ int device_open(char *device, int mode)
|
||||
* device may be bitwise-or'd from LOG | CONSOLE */
|
||||
void message(int device, char *fmt, ...)
|
||||
{
|
||||
int fd;
|
||||
va_list arguments;
|
||||
int fd;
|
||||
|
||||
#ifdef BB_SYSLOGD
|
||||
|
||||
/* Log the message to syslogd */
|
||||
@@ -266,7 +312,7 @@ static void console_init()
|
||||
/* 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 2nd virtual terminal.\r\n", console );
|
||||
message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console );
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
@@ -275,49 +321,41 @@ static void console_init()
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
static int waitfor(int pid)
|
||||
{
|
||||
int status, wpid;
|
||||
|
||||
message(LOG, "Waiting for process %d.\n", pid);
|
||||
while ((wpid = wait(&status)) != pid) {
|
||||
if (wpid > 0)
|
||||
message(LOG, "pid %d exited, status=0x%x.\n", wpid, status);
|
||||
}
|
||||
return wpid;
|
||||
}
|
||||
|
||||
|
||||
static pid_t run(const char * const* command,
|
||||
static pid_t run(char* command,
|
||||
char *terminal, int get_enter)
|
||||
{
|
||||
int fd;
|
||||
int i;
|
||||
pid_t pid;
|
||||
const char * const* cmd = command+1;
|
||||
char* tmpCmd;
|
||||
char* cmd[255];
|
||||
static const char press_enter[] =
|
||||
"\nPlease press Enter to activate this console. ";
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
int fd;
|
||||
pid_t shell_pgid = getpid ();
|
||||
|
||||
/* Clean up */
|
||||
close(0);
|
||||
close(1);
|
||||
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, "Bummer, can't open %s\r\n", terminal);
|
||||
exit(-1);
|
||||
}
|
||||
dup(fd);
|
||||
dup(fd);
|
||||
tcsetpgrp(0, getpgrp());
|
||||
set_term(0);
|
||||
|
||||
if (get_enter==TRUE) {
|
||||
/*
|
||||
@@ -330,40 +368,68 @@ static pid_t run(const char * const* command,
|
||||
*/
|
||||
char c;
|
||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||
*cmd, getpid(), terminal );
|
||||
write(1, press_enter, sizeof(press_enter) - 1);
|
||||
read(0, &c, 1);
|
||||
command, shell_pgid, terminal );
|
||||
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
||||
read(fileno(stdin), &c, 1);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
tmpCmd++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
cmd[i] = NULL;
|
||||
|
||||
/* Log the process name and args */
|
||||
message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
|
||||
message(LOG|CONSOLE, "'\r\n");
|
||||
|
||||
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
||||
shell_pgid, terminal, cmd[0]);
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
execvp(*command, (char**)command+1);
|
||||
execvp(cmd[0], cmd);
|
||||
|
||||
message(LOG, "Bummer, could not run '%s'\n", command);
|
||||
/* We're still here? Some error happened. */
|
||||
message(LOG|CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0],
|
||||
strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static int waitfor(char* command,
|
||||
char *terminal, int get_enter)
|
||||
{
|
||||
int status, wpid;
|
||||
int pid = run( command, terminal, get_enter);
|
||||
|
||||
while (1) {
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "Process '%s' (pid %d) exited.\n",
|
||||
command, wpid);
|
||||
break;
|
||||
}
|
||||
if (wpid == pid )
|
||||
break;
|
||||
}
|
||||
return wpid;
|
||||
}
|
||||
|
||||
/* Make sure there is enough memory to do something useful. *
|
||||
* Calls swapon if needed so be sure /proc is mounted. */
|
||||
static void check_memory()
|
||||
{
|
||||
struct stat statbuf;
|
||||
const char* const swap_on_cmd[] =
|
||||
{ "/bin/swapon", "swapon", "-a", 0};
|
||||
struct stat statBuf;
|
||||
|
||||
if (mem_total() > 3500)
|
||||
return;
|
||||
|
||||
if (stat("/etc/fstab", &statbuf) == 0) {
|
||||
if (stat("/etc/fstab", &statBuf) == 0) {
|
||||
/* Try to turn on swap */
|
||||
waitfor(run(swap_on_cmd, log, FALSE));
|
||||
waitfor("/bin/swapon swapon -a", log, FALSE);
|
||||
if (mem_total() < 3500)
|
||||
goto goodnight;
|
||||
} else
|
||||
@@ -375,37 +441,31 @@ goodnight:
|
||||
while (1) sleep(1);
|
||||
}
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
static void shutdown_system(void)
|
||||
{
|
||||
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", 0};
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||
reboot(RB_ENABLE_CAD);
|
||||
#endif
|
||||
message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
|
||||
sync();
|
||||
|
||||
/* Send signals to every process _except_ pid 1 */
|
||||
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
|
||||
#ifndef DEBUG_INIT
|
||||
kill(-1, SIGHUP);
|
||||
#endif
|
||||
sleep(2);
|
||||
sync();
|
||||
|
||||
message(CONSOLE, "Sending SIGKILL to all processes.\r\n");
|
||||
#ifndef DEBUG_INIT
|
||||
kill(-1, SIGKILL);
|
||||
#endif
|
||||
sleep(1);
|
||||
|
||||
message(CONSOLE, "Disabling swap.\r\n");
|
||||
waitfor(run( swap_off_cmd, console, FALSE));
|
||||
waitfor( "swapoff -a", console, FALSE);
|
||||
message(CONSOLE, "Unmounting filesystems.\r\n");
|
||||
waitfor(run( umount_cmd, console, FALSE));
|
||||
waitfor("umount -a", console, FALSE);
|
||||
sync();
|
||||
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
|
||||
/* bdflush, kupdate not needed for kernels >2.2.11 */
|
||||
message(CONSOLE, "Flushing buffers.\r\n");
|
||||
bdflush(1, 0);
|
||||
sync();
|
||||
}
|
||||
@@ -417,12 +477,12 @@ static void halt_signal(int sig)
|
||||
message(CONSOLE,
|
||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
if (sig == SIGUSR2)
|
||||
reboot(RB_POWER_OFF);
|
||||
else
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
#endif
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -431,53 +491,175 @@ static void reboot_signal(int sig)
|
||||
shutdown_system();
|
||||
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_AUTOBOOT);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void new_initAction (initActionEnum action,
|
||||
char* process, char* cons)
|
||||
{
|
||||
initAction* newAction;
|
||||
|
||||
/* 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') {
|
||||
return;
|
||||
}
|
||||
|
||||
newAction = calloc ((size_t)(1), sizeof(initAction));
|
||||
if (!newAction) {
|
||||
message(LOG|CONSOLE,"Memory allocation failure\n");
|
||||
while (1) sleep(1);
|
||||
}
|
||||
newAction->nextPtr = initActionList;
|
||||
initActionList = newAction;
|
||||
strncpy( newAction->process, process, 255);
|
||||
newAction->action = action;
|
||||
if (*cons != '\0') {
|
||||
strncpy(newAction->console, cons, 255);
|
||||
} else
|
||||
strncpy(newAction->console, console, 255);
|
||||
newAction->pid = 0;
|
||||
// message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n",
|
||||
// newAction->process, newAction->action, newAction->console);
|
||||
}
|
||||
|
||||
void delete_initAction (initAction *action)
|
||||
{
|
||||
initAction *a, *b=NULL;
|
||||
for( a=initActionList ; a; b=a, a=a->nextPtr) {
|
||||
if (a == action && b != NULL) {
|
||||
b->nextPtr=a->nextPtr;
|
||||
free( a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e runs INIT_SCRIPT and then starts a pair
|
||||
* of "askfirst" shells). If BB_FEATURE_USE_INITTAB
|
||||
* _is_ defined, but /etc/inittab is missing, this
|
||||
* results in the same set of default behaviors.
|
||||
* */
|
||||
void parse_inittab(void)
|
||||
{
|
||||
#ifdef BB_FEATURE_USE_INITTAB
|
||||
FILE* file;
|
||||
char buf[256], lineAsRead[256], tmpConsole[256];
|
||||
char *p, *q, *r, *s;
|
||||
const struct initActionType *a = actions;
|
||||
int foundIt;
|
||||
|
||||
|
||||
file = fopen(INITTAB, "r");
|
||||
if (file == NULL) {
|
||||
/* No inittab file -- set up some default behavior */
|
||||
#endif
|
||||
/* Askfirst shell on tty1 */
|
||||
new_initAction( ASKFIRST, SHELL, console );
|
||||
/* Askfirst shell on tty2 */
|
||||
if (second_console != NULL)
|
||||
new_initAction( ASKFIRST, SHELL, second_console );
|
||||
/* sysinit */
|
||||
new_initAction( SYSINIT, INIT_SCRIPT, console );
|
||||
|
||||
return;
|
||||
#ifdef BB_FEATURE_USE_INITTAB
|
||||
}
|
||||
|
||||
while ( fgets(buf, 255, file) != NULL) {
|
||||
foundIt=FALSE;
|
||||
for(p = buf; *p == ' ' || *p == '\t'; p++);
|
||||
if (*p == '#' || *p == '\n') continue;
|
||||
|
||||
/* Trim the trailing \n */
|
||||
q = strrchr( p, '\n');
|
||||
if (q != NULL)
|
||||
*q='\0';
|
||||
|
||||
/* Keep a copy around for posterity's sake (and error msgs) */
|
||||
strcpy(lineAsRead, buf);
|
||||
|
||||
/* Grab the ID field */
|
||||
s=p;
|
||||
p = strchr( p, ':');
|
||||
if ( p != NULL || *(p+1) != '\0' ) {
|
||||
*p='\0';
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Now peal off the process field from the end
|
||||
* of the string */
|
||||
q = strrchr( p, ':');
|
||||
if ( q == NULL || *(q+1) == '\0' ) {
|
||||
message(LOG|CONSOLE,"Bad inittab entry: %s\n", lineAsRead);
|
||||
continue;
|
||||
} else {
|
||||
*q='\0';
|
||||
++q;
|
||||
}
|
||||
|
||||
/* Now peal off the action field */
|
||||
r = strrchr( p, ':');
|
||||
if ( r == NULL || *(r+1) == '\0') {
|
||||
message(LOG|CONSOLE,"Bad inittab entry: %s\n", lineAsRead);
|
||||
continue;
|
||||
} else {
|
||||
++r;
|
||||
}
|
||||
|
||||
/* Ok, now process it */
|
||||
a = actions;
|
||||
while (a->name != 0) {
|
||||
if (strcmp(a->name, r) == 0) {
|
||||
if (*s != '\0') {
|
||||
struct stat statBuf;
|
||||
strcpy(tmpConsole, "/dev/");
|
||||
strncat(tmpConsole, s, 200);
|
||||
if (stat(tmpConsole, &statBuf) != 0) {
|
||||
message(LOG|CONSOLE, "device '%s' does not exist. Did you read the directions?\n", tmpConsole);
|
||||
break;
|
||||
}
|
||||
s = tmpConsole;
|
||||
}
|
||||
new_initAction( a->action, q, s);
|
||||
foundIt=TRUE;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
if (foundIt==TRUE)
|
||||
continue;
|
||||
else {
|
||||
/* Choke on an unknown action */
|
||||
message(LOG|CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern int init_main(int argc, char **argv)
|
||||
{
|
||||
int run_rc = FALSE;
|
||||
int single = FALSE;
|
||||
int wait_for_enter_tty1 = TRUE;
|
||||
int wait_for_enter_tty2 = TRUE;
|
||||
pid_t pid1 = 0;
|
||||
pid_t pid2 = 0;
|
||||
struct stat statbuf;
|
||||
char which_vt1[30];
|
||||
char which_vt2[30];
|
||||
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const getty1_command[] = { GETTY, GETTY, "38400", which_vt1, 0};
|
||||
const char* const getty2_command[] = { GETTY, GETTY, "38400", which_vt2, 0};
|
||||
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty1_command = shell_command;
|
||||
const char* const* tty2_command = shell_command;
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS",
|
||||
"BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 };
|
||||
#endif
|
||||
initAction *a;
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
char *hello_msg_format =
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
#else
|
||||
char *hello_msg_format =
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 iff we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) {
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
/* from the controlling terminal */
|
||||
setsid();
|
||||
|
||||
/* 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);
|
||||
@@ -485,10 +667,9 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
||||
* SIGINT on CAD so we can shut things down gracefully... */
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_DISABLE_CAD);
|
||||
#endif
|
||||
|
||||
|
||||
/* Figure out where the default console should be */
|
||||
console_init();
|
||||
|
||||
@@ -497,7 +678,6 @@ 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);
|
||||
@@ -505,98 +685,111 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Hello world */
|
||||
#ifndef DEBUG_INIT
|
||||
message(CONSOLE|LOG, hello_msg_format, BB_VER, BB_BT);
|
||||
message(LOG|CONSOLE,
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
BB_VER, BB_BT);
|
||||
#else
|
||||
message(CONSOLE|LOG, hello_msg_format, getpid(), BB_VER, BB_BT);
|
||||
message(LOG|CONSOLE,
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
getpid(), BB_VER, BB_BT);
|
||||
#endif
|
||||
|
||||
|
||||
/* Mount /proc */
|
||||
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
|
||||
message(CONSOLE|LOG, "Mounting /proc: done.\n");
|
||||
message(LOG|CONSOLE, "Mounting /proc: done.\n");
|
||||
kernel_version = get_kernel_revision();
|
||||
} else
|
||||
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
|
||||
message(LOG|CONSOLE, "Mounting /proc: failed!\n");
|
||||
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
single = TRUE;
|
||||
tty1_command = shell_command;
|
||||
tty2_command = shell_command;
|
||||
!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);
|
||||
/* Ask first then start a shell on tty1 */
|
||||
new_initAction( ASKFIRST, SHELL, console);
|
||||
} else {
|
||||
/* Not in single user mode -- see what inittab says */
|
||||
|
||||
/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e runs INIT_SCRIPT and then starts a pair
|
||||
* of "askfirst" shells */
|
||||
parse_inittab();
|
||||
}
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
run_rc = TRUE;
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
tty1_command = rc_script_command;
|
||||
}
|
||||
|
||||
/* Make sure /sbin/getty exists before trying to run it */
|
||||
if (stat(GETTY, &statbuf)==0) {
|
||||
char* where;
|
||||
/* First do tty2 */
|
||||
wait_for_enter_tty2 = FALSE;
|
||||
where = strrchr( second_console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt2, where, sizeof(which_vt2));
|
||||
/* Now run everything that needs to be run */
|
||||
|
||||
/* First run the sysinit command */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == SYSINIT) {
|
||||
waitfor(a->process, a->console, FALSE);
|
||||
/* Now remove the "sysinit" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
tty2_command = getty2_command;
|
||||
}
|
||||
/* Next run anything that wants to block */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == WAIT) {
|
||||
waitfor(a->process, a->console, FALSE);
|
||||
/* Now remove the "wait" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
}
|
||||
/* Next run anything to be run only once */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->action == ONCE) {
|
||||
run(a->process, a->console, FALSE);
|
||||
/* Now remove the "once" entry from the list */
|
||||
delete_initAction( a);
|
||||
}
|
||||
}
|
||||
/* If there is nothing else to do, stop */
|
||||
if (initActionList == NULL) {
|
||||
message(LOG|CONSOLE, "No more tasks for init -- sleeping forever.\n");
|
||||
while (1) sleep(1);
|
||||
}
|
||||
|
||||
/* Check on hooking a getty onto tty1 */
|
||||
if (run_rc == FALSE && single==FALSE) {
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
where = strrchr( console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt1, where, sizeof(which_vt1));
|
||||
/* Now run the looping stuff for the rest of forever */
|
||||
while (1) {
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
/* Only run stuff with pid==0. If they have
|
||||
* a pid, that means they are still running */
|
||||
if (a->pid == 0) {
|
||||
switch(a->action) {
|
||||
case RESPAWN:
|
||||
/* run the respawn stuff */
|
||||
a->pid = run(a->process, a->console, FALSE);
|
||||
break;
|
||||
case ASKFIRST:
|
||||
/* run the askfirst stuff */
|
||||
a->pid = run(a->process, a->console, TRUE);
|
||||
break;
|
||||
/* silence the compiler's incessant whining */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
tty1_command = getty1_command;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Ok, now launch the tty1_command and tty2_command */
|
||||
for (;;) {
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
if (pid1 == 0 && tty1_command) {
|
||||
pid1 = run(tty1_command, console, wait_for_enter_tty1);
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (pid2 == 0 && tty2_command && second_console) {
|
||||
pid2 = run(tty2_command, second_console, wait_for_enter_tty2);
|
||||
}
|
||||
#endif
|
||||
/* Wait for a child process to exit */
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
|
||||
}
|
||||
/* Don't respawn init script if it exits */
|
||||
if (wpid == pid1) {
|
||||
if (run_rc == FALSE) {
|
||||
pid1 = 0;
|
||||
/* Find out who died and clean up their corpse */
|
||||
for( a=initActionList ; a; a=a->nextPtr) {
|
||||
if (a->pid==wpid) {
|
||||
a->pid=0;
|
||||
message(LOG, "Process '%s' (pid %d) exited. Scheduling it for restart.\n",
|
||||
a->process, wpid);
|
||||
}
|
||||
}
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
else {
|
||||
pid1 = 0;
|
||||
run_rc=FALSE;
|
||||
wait_for_enter_tty1=TRUE;
|
||||
tty1_command=rc_exit_command;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (wpid == pid2) {
|
||||
pid2 = 0;
|
||||
}
|
||||
#endif
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Mini insmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#define _PATH_MODULES "/lib/modules"
|
||||
|
||||
#warning "Danger Will Robinson, Danger!!!"
|
||||
#warning " "
|
||||
#warning "insmod is still under construction. Don't use it."
|
||||
#warning " "
|
||||
#warning " You have been warned!"
|
||||
#warning " "
|
||||
|
||||
|
||||
/* Some firendly syscalls to cheer everyone's day... */
|
||||
_syscall2(int, init_module, const char *, name,
|
||||
const struct module *, info)
|
||||
|
||||
#ifndef BB_RMMOD
|
||||
_syscall1(int, delete_module, const char *, name)
|
||||
#else
|
||||
extern int delete_module(const char *);
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__m68k__) || defined(__arm__)
|
||||
/* Jump through hoops to fixup error return codes */
|
||||
#define __NR__create_module __NR_create_module
|
||||
static inline _syscall2(long, _create_module, const char *, name, size_t, size)
|
||||
unsigned long create_module(const char *name, size_t size)
|
||||
{
|
||||
long ret = _create_module(name, size);
|
||||
if (ret == -1 && errno > 125) {
|
||||
ret = -errno;
|
||||
errno = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
_syscall2(unsigned long, create_module, const char *, name, size_t, size)
|
||||
#endif
|
||||
|
||||
|
||||
static char m_filename[PATH_MAX] = "\0";
|
||||
static char m_fullName[PATH_MAX] ="\0";
|
||||
static const char insmod_usage[] =
|
||||
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
|
||||
"Loads the specified kernel modules into the kernel.\n\n"
|
||||
"Options:\n"
|
||||
"\t-f\tForce module to load into the wrong kernel version.\n"
|
||||
"\t-k\tMake module autoclean-able.\n";
|
||||
|
||||
|
||||
static int findNamedModule(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (m_fullName[0]=='\0')
|
||||
return( FALSE);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, m_fullName) == TRUE) {
|
||||
/* Stop searching if we find a match */
|
||||
memcpy(m_filename, fileName, strlen(fileName));
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int insmod_main(int argc, char **argv)
|
||||
{
|
||||
int len;
|
||||
char *tmp;
|
||||
char m_name[PATH_MAX] ="\0";
|
||||
FILE *fp;
|
||||
|
||||
if (argc<=1) {
|
||||
usage( insmod_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'f':
|
||||
break;
|
||||
case 'k':
|
||||
break;
|
||||
default:
|
||||
usage(insmod_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= 0 )
|
||||
usage(insmod_usage);
|
||||
|
||||
/* Grab the module name */
|
||||
if ((tmp = strrchr(*argv, '/')) != NULL)
|
||||
tmp++;
|
||||
else
|
||||
tmp = *argv;
|
||||
len = strlen(tmp);
|
||||
|
||||
if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
|
||||
len -= 2;
|
||||
memcpy(m_name, tmp, len);
|
||||
strcpy(m_fullName, m_name);
|
||||
strcat(m_fullName, ".o");
|
||||
|
||||
/* Get a filedesc for the module */
|
||||
if ((fp = fopen(*argv, "r")) == NULL) {
|
||||
/* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */
|
||||
if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE,
|
||||
findNamedModule, findNamedModule) == FALSE) {
|
||||
if ( m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) {
|
||||
perror("No module by that name found in " _PATH_MODULES "\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
} else
|
||||
memcpy(m_filename, *argv, strlen(*argv));
|
||||
|
||||
|
||||
fprintf(stderr, "m_filename='%s'\n", m_filename);
|
||||
fprintf(stderr, "m_name='%s'\n", m_name);
|
||||
|
||||
|
||||
/* TODO: do something roughtly like this... */
|
||||
#if 0
|
||||
|
||||
if ((f = obj_load(fp)) == NULL) {
|
||||
perror("Could not load the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* Let the module know about the kernel symbols. */
|
||||
add_kernel_symbols(f);
|
||||
|
||||
if (!create_this_module(f, m_name)) {
|
||||
perror("Could not create the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (!obj_check_undefineds(f, quiet)) {
|
||||
perror("Undefined symbols in the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
obj_allocate_commons(f);
|
||||
|
||||
/* Perse the module's arguments */
|
||||
while (argc-- >0 && *(argv++) != '\0') {
|
||||
if (!process_module_arguments(f, argc - optind, argv + optind)) {
|
||||
perror("Undefined symbols in the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Find current size of the module */
|
||||
m_size = obj_load_size(f);
|
||||
|
||||
|
||||
errno = 0;
|
||||
m_addr = create_module(m_name, m_size);
|
||||
switch (errno) {
|
||||
/* yada yada */
|
||||
default:
|
||||
perror("create_module: %m");
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
fclose( fp);
|
||||
exit( TRUE);
|
||||
}
|
||||
+14
-9
@@ -58,18 +58,20 @@ 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);
|
||||
extern int chvt_main(int argc, char** argv);
|
||||
extern int clear_main(int argc, char** argv);
|
||||
extern int date_main(int argc, char** argv);
|
||||
extern int dd_main(int argc, char** argv);
|
||||
extern int deallocvt_main(int argc, char** argv);
|
||||
extern int df_main(int argc, char** argv);
|
||||
extern int dmesg_main(int argc, char** argv);
|
||||
extern int du_main(int argc, char** argv);
|
||||
extern int dutmp_main(int argc, char** argv);
|
||||
extern int false_main(int argc, char** argv);
|
||||
extern int fbset_main(int argc, char** argv);
|
||||
extern int fdisk_main(int argc, char** argv);
|
||||
extern int fdflush_main(int argc, char **argv);
|
||||
extern int fsck_minix_main(int argc, char **argv);
|
||||
extern int mkfs_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);
|
||||
@@ -77,6 +79,7 @@ extern int halt_main(int argc, char** argv);
|
||||
extern int head_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);
|
||||
@@ -84,11 +87,12 @@ 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 ls_main(int argc, char** argv);
|
||||
extern int chvt_main(int argc, char** argv);
|
||||
extern int deallocvt_main(int argc, char** argv);
|
||||
extern int lsmod_main(int argc, char** argv);
|
||||
extern int makedevs_main(int argc, char** argv);
|
||||
extern int math_main(int argc, char** argv);
|
||||
extern int mkdir_main(int argc, char** argv);
|
||||
extern int mkfifo_main(int argc, char **argv);
|
||||
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);
|
||||
@@ -101,13 +105,15 @@ extern int printf_main(int argc, char** argv);
|
||||
extern int ps_main(int argc, char** argv);
|
||||
extern int pwd_main(int argc, char** argv);
|
||||
extern int reboot_main(int argc, char** argv);
|
||||
extern int rmdir_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 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);
|
||||
@@ -120,10 +126,12 @@ extern int tput_main(int argc, char** argv);
|
||||
extern int true_main(int argc, char** argv);
|
||||
extern int tryopen_main(int argc, char** argv);
|
||||
extern int umount_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);
|
||||
|
||||
|
||||
const char *modeString(int mode);
|
||||
@@ -162,11 +170,8 @@ extern int check_wildcard_match(const char* text, const char* pattern);
|
||||
extern long getNum (const char *cp);
|
||||
extern pid_t findInitPid();
|
||||
|
||||
|
||||
#if defined BB_MTAB
|
||||
#define whine_if_fstab_is_missing() {}
|
||||
#else
|
||||
extern void whine_if_fstab_is_missing();
|
||||
#if (__GLIBC__ < 2) && defined BB_SYSLOGD
|
||||
extern int vdprintf(int d, const char *format, va_list ap);
|
||||
#endif
|
||||
|
||||
#if defined BB_NFSMOUNT
|
||||
|
||||
@@ -183,7 +183,7 @@ extern int kill_main (int argc, char **argv)
|
||||
|
||||
do_it_now:
|
||||
|
||||
while (argc >= 1) {
|
||||
while (--argc >= 0) {
|
||||
int pid;
|
||||
struct stat statbuf;
|
||||
char pidpath[20]="/proc/";
|
||||
@@ -198,6 +198,7 @@ do_it_now:
|
||||
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
|
||||
exit( FALSE);
|
||||
}
|
||||
fprintf(stderr, "sig = %d\n", sig);
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
|
||||
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
* Derived from
|
||||
* mapscrn.c - version 0.92
|
||||
*
|
||||
* Was taken from console-tools and adapted by
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]);
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode);
|
||||
unicode utf8_to_ucs2 (char* buf);
|
||||
int screen_map_load(int fd, FILE *fp);
|
||||
|
||||
int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin))
|
||||
{
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE *fp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed reading binary 16bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode)
|
||||
{
|
||||
if (ioctl(fd,PIO_UNISCRNMAP,wbuf))
|
||||
perror("PIO_UNISCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* rewind... */
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed assuming 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
|
||||
else
|
||||
perror ("fseek for binary 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(buf,E_TABSZ,1,fp) != 1)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ioctl(fd,PIO_SCRNMAP,buf))
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - reads `fp' as a 16-bit ASCII SFM file.
|
||||
* - returns -1 on error.
|
||||
* - returns it in `unicode' in an E_TABSZ-elements array.
|
||||
* - sets `*is_unicode' flagiff there were any non-8-bit
|
||||
* (ie. real 16-bit) mapping.
|
||||
*
|
||||
* FIXME: ignores everything after second word
|
||||
*/
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode)
|
||||
{
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t sigset, old_sigset;
|
||||
|
||||
assert (is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i=0; i<128; i++) buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset (&sigset);
|
||||
sigaddset (&sigset, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigset, &old_sigset);
|
||||
|
||||
do
|
||||
{
|
||||
if (NULL == fgets(buffer, sizeof(buffer),fp))
|
||||
{
|
||||
if (feof (fp))
|
||||
break;
|
||||
else
|
||||
{
|
||||
perror ("uni_screen_map_read_ascii() can't read line");
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL," \t\n");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* restore sig mask */
|
||||
sigprocmask (SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
|
||||
{
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
for (in=0; in<256; in++) buf[in]=in;
|
||||
|
||||
while (fgets(buffer,sizeof(buffer)-1,fp))
|
||||
{
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
q = strtok(NULL," \t\n#");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255) return -1;
|
||||
|
||||
buf[in] = on;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - converts a string into an int.
|
||||
* - supports dec and hex bytes, hex UCS2, single-quoted byte and UTF8 chars.
|
||||
* - returns the converted value
|
||||
* - if `is_unicode != NULL', use it to tell whether it was unicode
|
||||
*
|
||||
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
|
||||
*/
|
||||
long int ctoi(unsigned char *s, int *is_unicode)
|
||||
{
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
ls = strlen(s);
|
||||
if (is_unicode) *is_unicode = 0;
|
||||
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s,"U+",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
{
|
||||
sscanf(s+2,"%x",&i);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
sscanf(s+2,"%x",&i);
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') &&
|
||||
(strspn(s,"01234567") == ls))
|
||||
sscanf(s,"%o",&i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s,"0123456789") == ls)
|
||||
sscanf(s,"%d",&i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i=s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls-1] == '\''))
|
||||
{
|
||||
s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s+1);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
|
||||
return(i);
|
||||
}
|
||||
|
||||
|
||||
void saveoldmap(int fd, char *omfil)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[E_TABSZ];
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
unicode xbuf[E_TABSZ];
|
||||
int is_old_map = 0;
|
||||
|
||||
if (ioctl(fd,GIO_UNISCRNMAP,xbuf))
|
||||
{
|
||||
perror("GIO_UNISCRNMAP ioctl error");
|
||||
#endif
|
||||
if (ioctl(fd,GIO_SCRNMAP,buf))
|
||||
{
|
||||
perror("GIO_SCRNMAP ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
is_old_map = 1;
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(omfil, "w")) == NULL)
|
||||
{
|
||||
perror(omfil);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
if (is_old_map)
|
||||
{
|
||||
#endif
|
||||
if (fwrite(buf,E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
else
|
||||
if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unicode utf8_to_ucs2 (char* buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
unsigned char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = *buf;
|
||||
buf++;
|
||||
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if(c & 0x80)
|
||||
{
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80)
|
||||
{
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else /* Possibly 1st char of a UTF8 sequence */
|
||||
{
|
||||
if ((c & 0xe0) == 0xc0)
|
||||
{
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
}
|
||||
else if ((c & 0xf0) == 0xe0)
|
||||
{
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
}
|
||||
else if ((c & 0xf8) == 0xf0)
|
||||
{
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
}
|
||||
else if ((c & 0xfc) == 0xf8)
|
||||
{
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
}
|
||||
else if ((c & 0xfe) == 0xfc)
|
||||
{
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
}
|
||||
else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
{
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ extern int logger_main(int argc, char **argv)
|
||||
int fd, pri = LOG_USER|LOG_NOTICE;
|
||||
int fromStdinFlag=FALSE;
|
||||
int toStdErrFlag=FALSE;
|
||||
int stopLookingAtMeLikeThat=FALSE;
|
||||
char *message, buf[1024], buf1[1024];
|
||||
time_t now;
|
||||
size_t addrLength;
|
||||
@@ -129,7 +130,8 @@ extern int logger_main(int argc, char **argv)
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromStdinFlag=TRUE;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
stopLookingAtMeLikeThat=FALSE;
|
||||
while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toStdErrFlag = TRUE;
|
||||
@@ -139,10 +141,7 @@ extern int logger_main(int argc, char **argv)
|
||||
usage(logger_usage);
|
||||
}
|
||||
pri = pencode(*(++argv));
|
||||
if (--argc == 0) {
|
||||
usage(logger_usage);
|
||||
}
|
||||
++argv;
|
||||
stopLookingAtMeLikeThat=TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(logger_usage);
|
||||
@@ -152,8 +151,7 @@ extern int logger_main(int argc, char **argv)
|
||||
|
||||
if (fromStdinFlag==TRUE) {
|
||||
/* read from stdin */
|
||||
int i=0;
|
||||
char c;
|
||||
int c, i=0;
|
||||
while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) {
|
||||
buf1[i++]=c;
|
||||
}
|
||||
|
||||
@@ -193,11 +193,13 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
fputs(" ", stdout);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
scratch[0]='\0';
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
@@ -208,20 +210,21 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
tab(16);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
scratch[0]='\0';
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
tab(17);
|
||||
//tab(26);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -230,6 +233,7 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
fputs(" ", stdout);
|
||||
//tab(32);
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Mini lsmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
extern int lsmod_main(int argc, char **argv)
|
||||
{
|
||||
char* cmd[] = { "cat", "/proc/modules", "\0" };
|
||||
exit(cat_main( 3, cmd));
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Mini mkfifo implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@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>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0666;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(mkfifo_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--; argv++;
|
||||
parse_mode(*argv, &mode);
|
||||
break;
|
||||
default:
|
||||
usage (mkfifo_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage (mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
"Options:\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
|
||||
@@ -40,6 +40,9 @@ mknod_main(int argc, char** argv)
|
||||
mode_t mode = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if ( argc != 5 || **(argv+1) == '-' ) {
|
||||
usage (mknod_usage);
|
||||
}
|
||||
switch(argv[2][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Mini insmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#define _PATH_MODULES "/lib/modules"
|
||||
|
||||
#warning "Danger Will Robinson, Danger!!!"
|
||||
#warning " "
|
||||
#warning "insmod is still under construction. Don't use it."
|
||||
#warning " "
|
||||
#warning " You have been warned!"
|
||||
#warning " "
|
||||
|
||||
|
||||
/* Some firendly syscalls to cheer everyone's day... */
|
||||
_syscall2(int, init_module, const char *, name,
|
||||
const struct module *, info)
|
||||
|
||||
#ifndef BB_RMMOD
|
||||
_syscall1(int, delete_module, const char *, name)
|
||||
#else
|
||||
extern int delete_module(const char *);
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__m68k__) || defined(__arm__)
|
||||
/* Jump through hoops to fixup error return codes */
|
||||
#define __NR__create_module __NR_create_module
|
||||
static inline _syscall2(long, _create_module, const char *, name, size_t, size)
|
||||
unsigned long create_module(const char *name, size_t size)
|
||||
{
|
||||
long ret = _create_module(name, size);
|
||||
if (ret == -1 && errno > 125) {
|
||||
ret = -errno;
|
||||
errno = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
_syscall2(unsigned long, create_module, const char *, name, size_t, size)
|
||||
#endif
|
||||
|
||||
|
||||
static char m_filename[PATH_MAX] = "\0";
|
||||
static char m_fullName[PATH_MAX] ="\0";
|
||||
static const char insmod_usage[] =
|
||||
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
|
||||
"Loads the specified kernel modules into the kernel.\n\n"
|
||||
"Options:\n"
|
||||
"\t-f\tForce module to load into the wrong kernel version.\n"
|
||||
"\t-k\tMake module autoclean-able.\n";
|
||||
|
||||
|
||||
static int findNamedModule(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (m_fullName[0]=='\0')
|
||||
return( FALSE);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, m_fullName) == TRUE) {
|
||||
/* Stop searching if we find a match */
|
||||
memcpy(m_filename, fileName, strlen(fileName));
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int insmod_main(int argc, char **argv)
|
||||
{
|
||||
int len;
|
||||
char *tmp;
|
||||
char m_name[PATH_MAX] ="\0";
|
||||
FILE *fp;
|
||||
|
||||
if (argc<=1) {
|
||||
usage( insmod_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'f':
|
||||
break;
|
||||
case 'k':
|
||||
break;
|
||||
default:
|
||||
usage(insmod_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= 0 )
|
||||
usage(insmod_usage);
|
||||
|
||||
/* Grab the module name */
|
||||
if ((tmp = strrchr(*argv, '/')) != NULL)
|
||||
tmp++;
|
||||
else
|
||||
tmp = *argv;
|
||||
len = strlen(tmp);
|
||||
|
||||
if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
|
||||
len -= 2;
|
||||
memcpy(m_name, tmp, len);
|
||||
strcpy(m_fullName, m_name);
|
||||
strcat(m_fullName, ".o");
|
||||
|
||||
/* Get a filedesc for the module */
|
||||
if ((fp = fopen(*argv, "r")) == NULL) {
|
||||
/* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */
|
||||
if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE,
|
||||
findNamedModule, findNamedModule) == FALSE) {
|
||||
if ( m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) {
|
||||
perror("No module by that name found in " _PATH_MODULES "\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
} else
|
||||
memcpy(m_filename, *argv, strlen(*argv));
|
||||
|
||||
|
||||
fprintf(stderr, "m_filename='%s'\n", m_filename);
|
||||
fprintf(stderr, "m_name='%s'\n", m_name);
|
||||
|
||||
|
||||
/* TODO: do something roughtly like this... */
|
||||
#if 0
|
||||
|
||||
if ((f = obj_load(fp)) == NULL) {
|
||||
perror("Could not load the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* Let the module know about the kernel symbols. */
|
||||
add_kernel_symbols(f);
|
||||
|
||||
if (!create_this_module(f, m_name)) {
|
||||
perror("Could not create the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (!obj_check_undefineds(f, quiet)) {
|
||||
perror("Undefined symbols in the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
obj_allocate_commons(f);
|
||||
|
||||
/* Perse the module's arguments */
|
||||
while (argc-- >0 && *(argv++) != '\0') {
|
||||
if (!process_module_arguments(f, argc - optind, argv + optind)) {
|
||||
perror("Undefined symbols in the module\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Find current size of the module */
|
||||
m_size = obj_load_size(f);
|
||||
|
||||
|
||||
errno = 0;
|
||||
m_addr = create_module(m_name, m_size);
|
||||
switch (errno) {
|
||||
/* yada yada */
|
||||
default:
|
||||
perror("create_module: %m");
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
fclose( fp);
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Mini lsmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
extern int lsmod_main(int argc, char **argv)
|
||||
{
|
||||
char* cmd[] = { "cat", "/proc/modules", "\0" };
|
||||
exit(cat_main( 3, cmd));
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Mini rmmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
|
||||
/* And the system call of the day is... */
|
||||
_syscall1(int, delete_module, const char *, name)
|
||||
|
||||
|
||||
static const char rmmod_usage[] =
|
||||
"rmmod [OPTION]... [MODULE]...\n\n"
|
||||
"Unloads the specified kernel modules from the kernel.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tTry to remove all unused kernel modules.\n";
|
||||
|
||||
|
||||
|
||||
extern int rmmod_main(int argc, char **argv)
|
||||
{
|
||||
if (argc<=1) {
|
||||
usage(rmmod_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
/* Unload _all_ unused modules via NULL delete_module() call */
|
||||
if (delete_module(NULL)) {
|
||||
perror("rmmod");
|
||||
exit( FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
default:
|
||||
usage(rmmod_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0 ) {
|
||||
if (delete_module(*argv) < 0) {
|
||||
perror(*argv);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -115,6 +115,18 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
|
||||
#endif
|
||||
|
||||
|
||||
#if defined BB_MTAB
|
||||
#define whine_if_fstab_is_missing() {}
|
||||
#else
|
||||
extern void whine_if_fstab_is_missing()
|
||||
{
|
||||
struct stat statBuf;
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Seperate standard mount options from the nonstandard string options */
|
||||
static void
|
||||
parse_mount_options ( char *options, unsigned long *flags, char *strflags)
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
@@ -35,14 +34,49 @@ static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static const char *skipName;
|
||||
static int dirFlag = FALSE;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, TRUE, TRUE));
|
||||
}
|
||||
|
||||
static int rmfileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
static int rmdirAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int mv_main(int argc, char **argv)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
|
||||
if (argc < 3) {
|
||||
usage (mv_usage);
|
||||
}
|
||||
@@ -50,34 +84,22 @@ extern int mv_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
destName = argv[argc - 1];
|
||||
dirFlag = isDirectory(destName);
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && dirFlag==FALSE) {
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
if (skipName)
|
||||
skipName++;
|
||||
strcpy(newdestName, destName);
|
||||
if (dirFlag==TRUE) {
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(srcName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
fprintf(stderr, "srcName='%s'\n", srcName);
|
||||
fprintf(stderr, "skipName='%s'\n", skipName);
|
||||
fprintf(stderr, "newdestName='%s'\n", newdestName);
|
||||
}
|
||||
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
if (unlink (srcName) < 0) {
|
||||
perror (srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+124
-42
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* $Id: ping.c,v 1.6 1999/12/11 08:41:28 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
@@ -63,28 +63,7 @@
|
||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||
#define TST(bit) (A(bit) & B(bit))
|
||||
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void pingstats(int);
|
||||
static void sendping(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
static void ping(char *);
|
||||
static int in_cksum(unsigned short *, int);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
/* common routines */
|
||||
static int in_cksum(unsigned short *buf, int sz)
|
||||
{
|
||||
int nleft = sz;
|
||||
@@ -108,6 +87,114 @@ static int in_cksum(unsigned short *buf, int sz)
|
||||
return(ans);
|
||||
}
|
||||
|
||||
/* simple version */
|
||||
#ifdef BB_SIMPLE_PING
|
||||
static const char* ping_usage = "ping host\n\n";
|
||||
|
||||
static char* hostname = NULL;
|
||||
|
||||
static void noresp(int ign)
|
||||
{
|
||||
printf("No response from %s\n", hostname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int ping(const char *host)
|
||||
{
|
||||
struct hostent *h;
|
||||
struct sockaddr_in pingaddr;
|
||||
struct icmp *pkt;
|
||||
int pingsock, c;
|
||||
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
|
||||
if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */
|
||||
perror("ping");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* drop root privs if running setuid */
|
||||
setuid(getuid());
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
hostname = h->h_name;
|
||||
|
||||
pkt = (struct icmp *)packet;
|
||||
memset(pkt, 0, sizeof(packet));
|
||||
pkt->icmp_type = ICMP_ECHO;
|
||||
pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
|
||||
|
||||
c = sendto(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (c < 0 || c != sizeof(packet)) {
|
||||
if (c < 0) perror("ping");
|
||||
fprintf(stderr, "ping: write incomplete\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGALRM, noresp);
|
||||
alarm(5); /* give the host 5000ms to respond */
|
||||
/* listen for replies */
|
||||
while (1) {
|
||||
struct sockaddr_in from;
|
||||
size_t fromlen = sizeof(from);
|
||||
|
||||
if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&from, &fromlen)) < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
perror("ping");
|
||||
continue;
|
||||
}
|
||||
if (c >= 76) { /* ip + icmp */
|
||||
struct iphdr *iphdr = (struct iphdr *)packet;
|
||||
pkt = (struct icmp *)(packet + (iphdr->ihl << 2)); /* skip ip hdr */
|
||||
if (pkt->icmp_type == ICMP_ECHOREPLY) break;
|
||||
}
|
||||
}
|
||||
printf("%s is alive!\n", hostname);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
extern int ping_main(int argc, char **argv)
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) usage(ping_usage);
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
#else
|
||||
/* full(er) version */
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void sendping(int);
|
||||
static void pingstats(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
|
||||
static void ping(char *);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static void pingstats(int ign) {
|
||||
signal(SIGINT, SIG_IGN);
|
||||
|
||||
@@ -249,25 +336,21 @@ static void ping(char *host)
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (inet_aton(host, &pingaddr.sin_addr)) {
|
||||
hostname = host;
|
||||
} else {
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
|
||||
/* enable broadcast pings */
|
||||
sockopt = 1;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *)&sockopt, sizeof(sockopt));
|
||||
@@ -331,6 +414,7 @@ extern int ping_main(int argc, char **argv)
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
@@ -367,5 +451,3 @@ extern int ping_main(int argc, char **argv)
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* $Id: ping.c,v 1.6 1999/12/11 08:41:28 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
@@ -63,28 +63,7 @@
|
||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||
#define TST(bit) (A(bit) & B(bit))
|
||||
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void pingstats(int);
|
||||
static void sendping(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
static void ping(char *);
|
||||
static int in_cksum(unsigned short *, int);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
/* common routines */
|
||||
static int in_cksum(unsigned short *buf, int sz)
|
||||
{
|
||||
int nleft = sz;
|
||||
@@ -108,6 +87,114 @@ static int in_cksum(unsigned short *buf, int sz)
|
||||
return(ans);
|
||||
}
|
||||
|
||||
/* simple version */
|
||||
#ifdef BB_SIMPLE_PING
|
||||
static const char* ping_usage = "ping host\n\n";
|
||||
|
||||
static char* hostname = NULL;
|
||||
|
||||
static void noresp(int ign)
|
||||
{
|
||||
printf("No response from %s\n", hostname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int ping(const char *host)
|
||||
{
|
||||
struct hostent *h;
|
||||
struct sockaddr_in pingaddr;
|
||||
struct icmp *pkt;
|
||||
int pingsock, c;
|
||||
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
|
||||
if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */
|
||||
perror("ping");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* drop root privs if running setuid */
|
||||
setuid(getuid());
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
hostname = h->h_name;
|
||||
|
||||
pkt = (struct icmp *)packet;
|
||||
memset(pkt, 0, sizeof(packet));
|
||||
pkt->icmp_type = ICMP_ECHO;
|
||||
pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
|
||||
|
||||
c = sendto(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (c < 0 || c != sizeof(packet)) {
|
||||
if (c < 0) perror("ping");
|
||||
fprintf(stderr, "ping: write incomplete\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGALRM, noresp);
|
||||
alarm(5); /* give the host 5000ms to respond */
|
||||
/* listen for replies */
|
||||
while (1) {
|
||||
struct sockaddr_in from;
|
||||
size_t fromlen = sizeof(from);
|
||||
|
||||
if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&from, &fromlen)) < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
perror("ping");
|
||||
continue;
|
||||
}
|
||||
if (c >= 76) { /* ip + icmp */
|
||||
struct iphdr *iphdr = (struct iphdr *)packet;
|
||||
pkt = (struct icmp *)(packet + (iphdr->ihl << 2)); /* skip ip hdr */
|
||||
if (pkt->icmp_type == ICMP_ECHOREPLY) break;
|
||||
}
|
||||
}
|
||||
printf("%s is alive!\n", hostname);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
extern int ping_main(int argc, char **argv)
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) usage(ping_usage);
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
#else
|
||||
/* full(er) version */
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void sendping(int);
|
||||
static void pingstats(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
|
||||
static void ping(char *);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static void pingstats(int ign) {
|
||||
signal(SIGINT, SIG_IGN);
|
||||
|
||||
@@ -249,25 +336,21 @@ static void ping(char *host)
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (inet_aton(host, &pingaddr.sin_addr)) {
|
||||
hostname = host;
|
||||
} else {
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
|
||||
/* enable broadcast pings */
|
||||
sockopt = 1;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *)&sockopt, sizeof(sockopt));
|
||||
@@ -331,6 +414,7 @@ extern int ping_main(int argc, char **argv)
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
@@ -367,5 +451,3 @@ extern int ping_main(int argc, char **argv)
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
+2
-1
@@ -183,7 +183,7 @@ extern int kill_main (int argc, char **argv)
|
||||
|
||||
do_it_now:
|
||||
|
||||
while (argc >= 1) {
|
||||
while (--argc >= 0) {
|
||||
int pid;
|
||||
struct stat statbuf;
|
||||
char pidpath[20]="/proc/";
|
||||
@@ -198,6 +198,7 @@ do_it_now:
|
||||
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
|
||||
exit( FALSE);
|
||||
}
|
||||
fprintf(stderr, "sig = %d\n", sig);
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
|
||||
Executable
+138
@@ -0,0 +1,138 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
|
||||
rm -rf testdir
|
||||
./busybox cp tar.c testdir
|
||||
|
||||
if ! eval diff -u tar.c testdir ; then
|
||||
echo "Bummer. File copy failed."
|
||||
exit 0
|
||||
else
|
||||
echo "Cool. File copy is ok."
|
||||
fi
|
||||
|
||||
rm -rf testdir
|
||||
mkdir -p testdir/foo
|
||||
./busybox cp tar.c testdir/foo
|
||||
|
||||
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."
|
||||
fi
|
||||
|
||||
|
||||
rm -rf testdir
|
||||
mkdir -p testdir/foo
|
||||
./busybox cp tar.c testdir/foo/
|
||||
|
||||
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."
|
||||
fi
|
||||
|
||||
|
||||
rm -rf testdir X11
|
||||
cp -a /etc/X11 .
|
||||
./busybox cp -a X11 testdir
|
||||
|
||||
if ! eval diff -ur X11 testdir ; then
|
||||
echo "Bummer. Local dir copy failed."
|
||||
exit 0
|
||||
else
|
||||
echo "Cool. Local dir copy is ok."
|
||||
fi
|
||||
|
||||
rm -rf testdir X11
|
||||
cp -a /etc/X11 .
|
||||
./busybox cp -a X11 testdir/
|
||||
|
||||
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."
|
||||
fi
|
||||
|
||||
rm -rf testdir X11
|
||||
cp -a /etc/X11 .
|
||||
./busybox cp -a X11/ testdir
|
||||
|
||||
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."
|
||||
fi
|
||||
|
||||
rm -rf testdir X11
|
||||
cp -a /etc/X11 .
|
||||
./busybox cp -a X11/ testdir/
|
||||
|
||||
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."
|
||||
fi
|
||||
|
||||
rm -rf testdir X11
|
||||
./busybox cp -a /etc/X11 testdir
|
||||
if ! eval diff -ur /etc/X11 testdir ; then
|
||||
echo "Bummer. Remote dir copy failed."
|
||||
exit 0
|
||||
else
|
||||
echo "Cool. Remote dir copy is ok."
|
||||
fi
|
||||
|
||||
|
||||
rm -rf testdir X11
|
||||
mkdir -p testdir/foo
|
||||
|
||||
./busybox cp -a /etc/X11 testdir/foo
|
||||
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."
|
||||
fi
|
||||
|
||||
|
||||
rm -rf testdir X11
|
||||
mkdir -p testdir/foo
|
||||
|
||||
./busybox cp -a /etc/X11 testdir/foo/
|
||||
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."
|
||||
fi
|
||||
|
||||
rm -rf testdir
|
||||
|
||||
|
||||
rm -rf foo bar
|
||||
mkdir foo
|
||||
mkdir bar
|
||||
|
||||
if ! eval ./busybox cp README foo ; then
|
||||
echo "Bummer. cp README foo failed."
|
||||
exit 0
|
||||
else
|
||||
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."
|
||||
fi
|
||||
|
||||
rm -rf foo bar
|
||||
|
||||
@@ -385,11 +385,14 @@ static int match1(regexp* re, char ch, int token, int ignoreCase)
|
||||
if (re->program[1 + 32 * (token - M_CLASS(0)) + (ch >> 3)] & (1 << (ch & 7)))
|
||||
return 0;
|
||||
}
|
||||
else if (ch == token
|
||||
|| (ignoreCase==TRUE && isupper(ch) && tolower(ch) == token))
|
||||
//fprintf(stderr, "match1: ch='%c' token='%c': ", ch, token);
|
||||
if (ch == token
|
||||
|| (ignoreCase==TRUE && tolower(ch) == tolower(token)))
|
||||
{
|
||||
//fprintf(stderr, "match\n");
|
||||
return 0;
|
||||
}
|
||||
//fprintf(stderr, "no match\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Mini rmmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
|
||||
/* And the system call of the day is... */
|
||||
_syscall1(int, delete_module, const char *, name)
|
||||
|
||||
|
||||
static const char rmmod_usage[] =
|
||||
"rmmod [OPTION]... [MODULE]...\n\n"
|
||||
"Unloads the specified kernel modules from the kernel.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tTry to remove all unused kernel modules.\n";
|
||||
|
||||
|
||||
|
||||
extern int rmmod_main(int argc, char **argv)
|
||||
{
|
||||
if (argc<=1) {
|
||||
usage(rmmod_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
/* Unload _all_ unused modules via NULL delete_module() call */
|
||||
if (delete_module(NULL)) {
|
||||
perror("rmmod");
|
||||
exit( FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
default:
|
||||
usage(rmmod_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0 ) {
|
||||
if (delete_module(*argv) < 0) {
|
||||
perror(*argv);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
# /etc/inittab init(8) configuration for BusyBox
|
||||
#
|
||||
# Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen
|
||||
# <andersen@lineo.com>, <andersee@debian.org>
|
||||
#
|
||||
#
|
||||
# Note, BusyBox init doesn't support runlevels. The runlevels field is
|
||||
# completely ignored by BusyBox init. If you want runlevels, use sysvinit.
|
||||
#
|
||||
#
|
||||
# Format for each entry: <id>:<runlevels>:<action>:<process>
|
||||
#
|
||||
# <id>: WARNING: This field has a non-traditional meaning for BusyBox init!
|
||||
#
|
||||
# The id field is used by BusyBox init to specify the controlling tty for
|
||||
# the specified process to run on. The contents of this field are
|
||||
# appended to "/dev/" and used as-is. There is no need for this field to
|
||||
# be unique, although if it isn't you may have strange results. If this
|
||||
# field is left blank, it is completely ignored. Also note that if
|
||||
# BusyBox detects that a serial console is in use, then all entries
|
||||
# containing non-empty id fields will _not_ be run. BusyBox init does
|
||||
# nothing with utmp. We don't need no stinkin' utmp.
|
||||
#
|
||||
# <runlevels>: The runlevels field is completely ignored.
|
||||
#
|
||||
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, and once.
|
||||
#
|
||||
# Note: askfirst acts just like respawn, but before running the specified
|
||||
# process it displays the line "Please press Enter to activate this
|
||||
# console." and then waits for the user to press enter before starting
|
||||
# the specified process.
|
||||
#
|
||||
# Note: unrecognised actions (like initdefault) will cause init to emit
|
||||
# an error message, and then go along with its business.
|
||||
#
|
||||
# <process>: Specifies the process to be executed and it's command line.
|
||||
#
|
||||
# Note: BusyBox init works just fine without an inittab. If no inittab
|
||||
# is found, it has the following default behavior:
|
||||
# ::sysinit:/etc/init.d/rcS
|
||||
# ::askfirst:/bin/sh
|
||||
# if it detects that /dev/console is _not_ a serial console, it will also run:
|
||||
# tty2::askfirst:/bin/sh
|
||||
#
|
||||
|
||||
|
||||
# Boot-time system configuration/initialization script.
|
||||
# This is run first except when booting in single-user mode.
|
||||
#
|
||||
::sysinit:/etc/init.d/rcS
|
||||
|
||||
# /bin/sh invocations on selected ttys
|
||||
#
|
||||
# Start an "askfirst" shell on the console (whatever that may be)
|
||||
::askfirst:/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2
|
||||
tty2::askfirst:/bin/sh
|
||||
|
||||
# /sbin/getty invocations for selected ttys
|
||||
#
|
||||
tty4::respawn:/sbin/getty 38400 tty4
|
||||
tty5::respawn:/sbin/getty 38400 tty5
|
||||
|
||||
|
||||
# Example of how to put a getty on a serial line (for a terminal)
|
||||
#
|
||||
#ttyS0::respawn:/sbin/getty -L ttyS0 9600 vt100
|
||||
#ttyS1::respawn:/sbin/getty -L ttyS1 9600 vt100
|
||||
#
|
||||
# Example how to put a getty on a modem line.
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
|
||||
# Not currently supported, but may be sometime in the future...
|
||||
#::ctrlaltdel:/sbin/reboot
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* Modifications for addresses and append command have been
|
||||
* written by Marco Pantaleoni <panta@prosa.it>, <panta@elasticworld.org>
|
||||
* and are:
|
||||
* Copyright (C) 1999 Marco Pantaleoni.
|
||||
*
|
||||
* 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
|
||||
@@ -31,48 +36,144 @@
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] [-e script] [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t's/regexp/replacement/[gp]'\n"
|
||||
"which attempt to match regexp against the pattern space\n"
|
||||
"and if successful replaces the matched portion with replacement.\n\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] -e script [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
/* Flags & variables */
|
||||
|
||||
typedef enum { f_none, f_replace, f_append } sed_function;
|
||||
|
||||
#define NO_LINE -2
|
||||
#define LAST_LINE -1
|
||||
static int addr_line = NO_LINE;
|
||||
static char *addr_pattern = NULL;
|
||||
static int negated = 0;
|
||||
|
||||
#define SKIPSPACES(p) do { while (isspace(*(p))) (p)++; } while (0)
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
static inline int at_last(FILE * fp)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
int res = 0;
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
char ch;
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void do_sed_repl(FILE * fp, char *needle, char *newNeedle,
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
static void do_sed_append(FILE * fp, char *appendline, int quietFlag)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle=NULL, *newNeedle=NULL;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -83,68 +184,119 @@ extern int sed_main (int argc, char **argv)
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
usage( sed_usage);
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if ( *++cp != 's')
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
*pos=0;
|
||||
newNeedle=++pos;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag=TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -153,30 +305,48 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose (fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Mini sort implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] =
|
||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
||||
;
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
/* line node */
|
||||
typedef struct Line {
|
||||
char *data; /* line data */
|
||||
struct Line *next; /* pointer to next line node */
|
||||
} Line;
|
||||
|
||||
/* singly-linked list of lines */
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
|
||||
/* comparison function */
|
||||
typedef int (Compare)(const void *, const void *);
|
||||
|
||||
|
||||
/* methods ________________________________________________________________ */
|
||||
|
||||
static const int max = 1024;
|
||||
|
||||
/* mallocate Line */
|
||||
static Line *
|
||||
line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Initialize Line with string */
|
||||
static Line *
|
||||
line_init(Line *self, const char *string)
|
||||
{
|
||||
self->data = malloc((strlen(string) + 1) * sizeof(char));
|
||||
if (self->data == NULL) { return NULL; }
|
||||
strcpy(self->data, string);
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *
|
||||
line_newFromFile(FILE *src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) { return NULL; }
|
||||
line_init(self, buffer);
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Line destructor */
|
||||
static Line *
|
||||
line_release(Line *self)
|
||||
{
|
||||
if (self->data) {
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/* Comparison */
|
||||
|
||||
/* ascii order */
|
||||
static int
|
||||
compare_ascii(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
static int
|
||||
compare_numeric(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
int xint, yint;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
}
|
||||
|
||||
|
||||
/* List */
|
||||
|
||||
/* */
|
||||
static List *
|
||||
list_init(List *self)
|
||||
{
|
||||
self->len = 0;
|
||||
self->sorted = NULL;
|
||||
self->head = NULL;
|
||||
self->current = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* for simplicity, the List gains ownership of the line */
|
||||
static List *
|
||||
list_insert(List *self, Line *line)
|
||||
{
|
||||
if (line == NULL) { return NULL; }
|
||||
|
||||
/* first insertion */
|
||||
if (self->head == NULL) {
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
}
|
||||
self->len++;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* order the list according to compare() */
|
||||
static List *
|
||||
list_sort(List *self, Compare *compare)
|
||||
{
|
||||
int i;
|
||||
Line *line;
|
||||
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line*));
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
line = self->head;
|
||||
while (line) {
|
||||
self->sorted[i++] = line;
|
||||
line = line->next;
|
||||
}
|
||||
|
||||
/* apply qsort */
|
||||
qsort(self->sorted, self->len, sizeof(Line*), compare);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* precondition: list must be sorted */
|
||||
static List *
|
||||
list_writeToFile(List *self, FILE* dst)
|
||||
{
|
||||
int i;
|
||||
Line **line = self->sorted;
|
||||
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
for (i = 0; i < self->len; i++) {
|
||||
fprintf(dst, "%s", line[i]->data);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/* deallocate */
|
||||
static void
|
||||
list_release(List *self)
|
||||
{
|
||||
Line *i;
|
||||
Line *die;
|
||||
|
||||
i = self->head;
|
||||
while (i) {
|
||||
die = i;
|
||||
i = die->next;
|
||||
line_release(die);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* I need a list
|
||||
* to insert lines into
|
||||
* then I need to sort this list
|
||||
* and finally print it
|
||||
*/
|
||||
|
||||
int
|
||||
sort_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
List list;
|
||||
Line *l;
|
||||
Compare *compare;
|
||||
|
||||
/* init */
|
||||
compare = compare_ascii;
|
||||
list_init(&list);
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'r':
|
||||
/* reverse */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* this could be factored better */
|
||||
|
||||
/* work w/ stdin */
|
||||
if (i >= argc) {
|
||||
while ( (l = line_newFromFile(stdin))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
|
||||
/* work w/ what's left in argv[] */
|
||||
} else {
|
||||
FILE *src;
|
||||
|
||||
for ( ; i < argc; i++) {
|
||||
src = fopen(argv[i], "r");
|
||||
if (src == NULL) { break; }
|
||||
while ( (l = line_newFromFile(src))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
||||
+5
-7
@@ -120,6 +120,7 @@ extern int logger_main(int argc, char **argv)
|
||||
int fd, pri = LOG_USER|LOG_NOTICE;
|
||||
int fromStdinFlag=FALSE;
|
||||
int toStdErrFlag=FALSE;
|
||||
int stopLookingAtMeLikeThat=FALSE;
|
||||
char *message, buf[1024], buf1[1024];
|
||||
time_t now;
|
||||
size_t addrLength;
|
||||
@@ -129,7 +130,8 @@ extern int logger_main(int argc, char **argv)
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromStdinFlag=TRUE;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
stopLookingAtMeLikeThat=FALSE;
|
||||
while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toStdErrFlag = TRUE;
|
||||
@@ -139,10 +141,7 @@ extern int logger_main(int argc, char **argv)
|
||||
usage(logger_usage);
|
||||
}
|
||||
pri = pencode(*(++argv));
|
||||
if (--argc == 0) {
|
||||
usage(logger_usage);
|
||||
}
|
||||
++argv;
|
||||
stopLookingAtMeLikeThat=TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(logger_usage);
|
||||
@@ -152,8 +151,7 @@ extern int logger_main(int argc, char **argv)
|
||||
|
||||
if (fromStdinFlag==TRUE) {
|
||||
/* read from stdin */
|
||||
int i=0;
|
||||
char c;
|
||||
int c, i=0;
|
||||
while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) {
|
||||
buf1[i++]=c;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,6 @@ static void domark(int sig)
|
||||
{
|
||||
if (MarkInterval > 0) {
|
||||
logMessage(LOG_SYSLOG|LOG_INFO, "-- MARK --");
|
||||
signal(SIGALRM, domark);
|
||||
alarm(MarkInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,6 @@ static void domark(int sig)
|
||||
{
|
||||
if (MarkInterval > 0) {
|
||||
logMessage(LOG_SYSLOG|LOG_INFO, "-- MARK --");
|
||||
signal(SIGALRM, domark);
|
||||
alarm(MarkInterval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
@@ -106,8 +107,12 @@ static int warnedRoot;
|
||||
static int eofFlag;
|
||||
static long dataCc;
|
||||
static int outFd;
|
||||
static char outName[TAR_NAME_SIZE];
|
||||
static const char *outName;
|
||||
|
||||
static int mode;
|
||||
static int uid;
|
||||
static int gid;
|
||||
static time_t mtime;
|
||||
|
||||
/*
|
||||
* Static data associated with the tar file.
|
||||
@@ -364,8 +369,9 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
* message is required on errors.
|
||||
*/
|
||||
if (tostdoutFlag == FALSE) {
|
||||
if (outFd >= 0)
|
||||
(void) close (outFd);
|
||||
if (outFd >= 0) {
|
||||
close (outFd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,29 +384,25 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
static void
|
||||
readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
{
|
||||
int mode;
|
||||
int uid;
|
||||
int gid;
|
||||
int checkSum;
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
long size;
|
||||
time_t mtime;
|
||||
const char *name;
|
||||
int cc;
|
||||
int hardLink;
|
||||
int softLink;
|
||||
int devFileFlag;
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
long size;
|
||||
struct utimbuf utb;
|
||||
|
||||
/*
|
||||
* If the block is completely empty, then this is the end of the
|
||||
* archive file. If the name is null, then just skip this header.
|
||||
*/
|
||||
name = hp->name;
|
||||
outName = hp->name;
|
||||
|
||||
if (*name == '\0') {
|
||||
if (*outName == '\0') {
|
||||
for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) {
|
||||
if (*name++)
|
||||
if (*outName++)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -447,16 +449,16 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
/*
|
||||
* Check for a directory.
|
||||
*/
|
||||
if (name[strlen (name) - 1] == '/')
|
||||
if (outName[strlen (outName) - 1] == '/')
|
||||
mode |= S_IFDIR;
|
||||
|
||||
/*
|
||||
* Check for absolute paths in the file.
|
||||
* If we find any, then warn the user and make them relative.
|
||||
*/
|
||||
if (*name == '/') {
|
||||
while (*name == '/')
|
||||
name++;
|
||||
if (*outName == '/') {
|
||||
while (*outName == '/')
|
||||
outName++;
|
||||
|
||||
if (warnedRoot==FALSE) {
|
||||
fprintf (stderr,
|
||||
@@ -470,7 +472,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* See if we want this file to be restored.
|
||||
* If not, then set up to skip it.
|
||||
*/
|
||||
if (wantFileName (name, fileCount, fileTable) == FALSE) {
|
||||
if (wantFileName (outName, fileCount, fileTable) == FALSE) {
|
||||
if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
|
||||
|| S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
@@ -494,7 +496,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
else
|
||||
printf ("%9ld %s ", size, timeString (mtime));
|
||||
}
|
||||
printf ("%s", name);
|
||||
printf ("%s", outName);
|
||||
|
||||
if (hardLink)
|
||||
printf (" (link to \"%s\")", hp->linkName);
|
||||
@@ -515,22 +517,35 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* We really want to extract the file.
|
||||
*/
|
||||
if (verboseFlag==TRUE)
|
||||
printf ("x %s\n", name);
|
||||
printf ("x %s\n", outName);
|
||||
|
||||
if (hardLink) {
|
||||
if (link (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
if (link (hp->linkName, outName) < 0)
|
||||
perror (outName);
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (softLink) {
|
||||
#ifdef S_ISLNK
|
||||
if (symlink (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
if (symlink (hp->linkName, outName) < 0)
|
||||
perror (outName);
|
||||
/* Try to change ownership of the symlink.
|
||||
* If libs doesn't support that, don't bother.
|
||||
* Changing the pointed-to file is the Wrong Thing(tm).
|
||||
*/
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
lchown(outName, uid, gid);
|
||||
#endif
|
||||
|
||||
/* Do not change permissions or date on symlink,
|
||||
* since it changes the pointed to file instead. duh. */
|
||||
#else
|
||||
fprintf (stderr, "Cannot create symbolic links\n");
|
||||
#endif
|
||||
@@ -545,10 +560,14 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* If the file is a directory, then just create the path.
|
||||
*/
|
||||
if (S_ISDIR (mode)) {
|
||||
createPath (name, mode);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
|
||||
createPath (outName, mode);
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -556,7 +575,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* There is a file to write.
|
||||
* First create the path to it if necessary with default permissions.
|
||||
*/
|
||||
createPath (name, 0777);
|
||||
createPath (outName, 0777);
|
||||
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
dataCc = size;
|
||||
@@ -569,31 +588,34 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
else {
|
||||
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mknod (name, mode, makedev(major, minor) );
|
||||
outFd = mknod (outName, mode, makedev(major, minor) );
|
||||
}
|
||||
else if (S_ISFIFO(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mkfifo(name, mode);
|
||||
outFd = mkfifo(outName, mode);
|
||||
} else {
|
||||
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
outFd = open (outName, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
if (outFd < 0) {
|
||||
perror (outName);
|
||||
skipFileFlag = TRUE;
|
||||
return;
|
||||
}
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
}
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (name);
|
||||
skipFileFlag = TRUE;
|
||||
return;
|
||||
}
|
||||
if (tostdoutFlag == FALSE) {
|
||||
fchmod(outFd, mode);
|
||||
fchown(outFd, uid, gid);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the file is empty, then that's all we need to do.
|
||||
*/
|
||||
if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
|
||||
(void) close (outFd);
|
||||
close (outFd);
|
||||
outFd = -1;
|
||||
}
|
||||
}
|
||||
@@ -627,7 +649,7 @@ static void readData (const char *cp, int count)
|
||||
if (fullWrite (outFd, cp, count) < 0) {
|
||||
perror (outName);
|
||||
if (tostdoutFlag == FALSE) {
|
||||
(void) close (outFd);
|
||||
close (outFd);
|
||||
outFd = -1;
|
||||
}
|
||||
skipFileFlag = TRUE;
|
||||
@@ -635,13 +657,21 @@ static void readData (const char *cp, int count)
|
||||
}
|
||||
|
||||
/*
|
||||
* If the write failed, close the file and disable further
|
||||
* writes to this file.
|
||||
* Check if we are done writing to the file now.
|
||||
*/
|
||||
if (dataCc <= 0 && tostdoutFlag == FALSE) {
|
||||
struct utimbuf utb;
|
||||
if (close (outFd))
|
||||
perror (outName);
|
||||
|
||||
/* Set the file time */
|
||||
utb.actime = mtime;
|
||||
utb.modtime = mtime;
|
||||
utime (outName, &utb);
|
||||
/* Set the file permissions */
|
||||
chown(outName, uid, gid);
|
||||
chmod(outName, mode);
|
||||
|
||||
outFd = -1;
|
||||
}
|
||||
}
|
||||
@@ -722,7 +752,6 @@ static void writeTarFile (int fileCount, char **fileTable)
|
||||
static void saveFile (const char *fileName, int seeLinks)
|
||||
{
|
||||
int status;
|
||||
int mode;
|
||||
struct stat statbuf;
|
||||
|
||||
if (verboseFlag==TRUE)
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Mini uniq implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n"
|
||||
;
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
|
||||
typedef void (Print)(FILE *, const char *);
|
||||
|
||||
typedef int (Decide)(const char *, const char *);
|
||||
|
||||
/* container for two lines to be compared */
|
||||
typedef struct {
|
||||
char *a;
|
||||
char *b;
|
||||
int recurrence;
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
void *func;
|
||||
} Subject;
|
||||
|
||||
/* set up all the variables of a uniq operation */
|
||||
static Subject *
|
||||
subject_init(Subject *self, FILE *in, FILE *out, void *func)
|
||||
{
|
||||
self->a = NULL;
|
||||
self->b = NULL;
|
||||
self->in = in;
|
||||
self->out = out;
|
||||
self->func = func;
|
||||
self->recurrence = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* point a and b to the appropriate lines;
|
||||
* count the recurrences (if any) of a string;
|
||||
*/
|
||||
static Subject *
|
||||
subject_next(Subject *self)
|
||||
{
|
||||
/* tmp line holders */
|
||||
static char line[2][UNIQ_MAX];
|
||||
static int alternator = 0;
|
||||
|
||||
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
|
||||
self->a = self->b;
|
||||
self->b = line[alternator];
|
||||
alternator ^= 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_last(Subject *self)
|
||||
{
|
||||
self->a = self->b;
|
||||
self->b = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_study(Subject *self)
|
||||
{
|
||||
if (self->a == NULL) {
|
||||
return self;
|
||||
}
|
||||
if (self->b == NULL) {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
return self;
|
||||
}
|
||||
if (strcmp(self->a, self->b) == 0) {
|
||||
self->recurrence++;
|
||||
} else {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
self->recurrence = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static int
|
||||
set_file_pointers(int schema, FILE **in, FILE **out, char **argv)
|
||||
{
|
||||
switch (schema) {
|
||||
case 0:
|
||||
*in = stdin;
|
||||
*out = stdout;
|
||||
break;
|
||||
case 1:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = stdout;
|
||||
break;
|
||||
case 2:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = fopen(argv[1], "w");
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* one variable is the decision algo */
|
||||
/* another variable is the printing algo */
|
||||
|
||||
/* I don't think I have to have more than a 1 line memory
|
||||
this is the one constant */
|
||||
|
||||
/* it seems like GNU/uniq only takes one or two files as an option */
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
int
|
||||
uniq_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
FILE *in, *out;
|
||||
Subject s;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(uniq_usage);
|
||||
default:
|
||||
usage(uniq_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 0 src: stdin; dst: stdout */
|
||||
/* 1 src: file; dst: stdout */
|
||||
/* 2 src: file; dst: file */
|
||||
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
subject_init(&s, in, out, NULL);
|
||||
while (subject_next(&s)) {
|
||||
subject_study(&s);
|
||||
}
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
||||
+13
-5
@@ -44,10 +44,15 @@ int dmesg_main( int argc, char** argv )
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
while (*++(*argv))
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
@@ -57,19 +62,22 @@ int dmesg_main( int argc, char** argv )
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi (*(++argv));
|
||||
--argc;
|
||||
++argv;
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi (*(++argv));
|
||||
--argc;
|
||||
++argv;
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Mini fbset implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@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
|
||||
*
|
||||
* This is a from-scratch implementation of fbset; but the de facto fbset
|
||||
* implementation was a good reference. fbset (original) is released under
|
||||
* the GPL, and is (c) 1995-1999 by:
|
||||
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/version.h>
|
||||
|
||||
#define PERROR(ctx) do { perror(ctx); exit(1); } while(0)
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#define DEFAULTFBDEV "/dev/fb0"
|
||||
#define DEFAULTFBMODE "/etc/fb.modes"
|
||||
|
||||
#define OPT_CHANGE 1
|
||||
#define OPT_INFO (1 << 1)
|
||||
#define OPT_READMODE (1 << 2)
|
||||
|
||||
#define CMD_HELP 0
|
||||
#define CMD_FB 1
|
||||
#define CMD_DB 2
|
||||
#define CMD_GEOMETRY 3
|
||||
#define CMD_TIMING 4
|
||||
#define CMD_ACCEL 5
|
||||
#define CMD_HSYNC 6
|
||||
#define CMD_VSYNC 7
|
||||
#define CMD_LACED 8
|
||||
#define CMD_DOUBLE 9
|
||||
/* #define CMD_XCOMPAT 10 */
|
||||
#define CMD_ALL 11
|
||||
#define CMD_INFO 12
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#define CMD_XRES 13
|
||||
#define CMD_YRES 14
|
||||
#define CMD_VXRES 15
|
||||
#define CMD_VYRES 16
|
||||
#define CMD_DEPTH 17
|
||||
#define CMD_MATCH 18
|
||||
#define CMD_PIXCLOCK 19
|
||||
#define CMD_LEFT 20
|
||||
#define CMD_RIGHT 21
|
||||
#define CMD_UPPER 22
|
||||
#define CMD_LOWER 23
|
||||
#define CMD_HSLEN 24
|
||||
#define CMD_VSLEN 25
|
||||
#define CMD_CSYNC 26
|
||||
#define CMD_GSYNC 27
|
||||
#define CMD_EXTSYNC 28
|
||||
#define CMD_BCAST 29
|
||||
#define CMD_RGBA 30
|
||||
#define CMD_STEP 31
|
||||
#define CMD_MOVE 32
|
||||
#endif
|
||||
|
||||
static unsigned int g_options = 0;
|
||||
|
||||
struct cmdoptions_t {
|
||||
char *name;
|
||||
unsigned char param_count;
|
||||
unsigned char code;
|
||||
} g_cmdoptions[] = {
|
||||
{ "-h", 0, CMD_HELP },
|
||||
{ "-fb", 1, CMD_FB },
|
||||
{ "-db", 1, CMD_DB },
|
||||
{ "-a", 0, CMD_ALL },
|
||||
{ "-i", 0, CMD_INFO },
|
||||
{ "-g", 5, CMD_GEOMETRY },
|
||||
{ "-t", 7, CMD_TIMING },
|
||||
{ "-accel", 1, CMD_ACCEL },
|
||||
{ "-hsync", 1, CMD_HSYNC },
|
||||
{ "-vsync", 1, CMD_VSYNC },
|
||||
{ "-laced", 1, CMD_LACED },
|
||||
{ "-double", 1, CMD_DOUBLE },
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
{ "--help", 0, CMD_HELP },
|
||||
{ "-all", 0, CMD_ALL },
|
||||
{ "-xres", 1, CMD_XRES },
|
||||
{ "-yres", 1, CMD_YRES },
|
||||
{ "-vxres", 1, CMD_VXRES },
|
||||
{ "-vyres", 1, CMD_VYRES },
|
||||
{ "-depth", 1, CMD_DEPTH },
|
||||
{ "-match", 0, CMD_MATCH },
|
||||
{ "--geometry", 5, CMD_GEOMETRY },
|
||||
|
||||
{ "-pixclock", 1, CMD_PIXCLOCK },
|
||||
{ "-left", 1, CMD_LEFT },
|
||||
{ "-right", 1, CMD_RIGHT },
|
||||
{ "-upper", 1, CMD_UPPER },
|
||||
{ "-lower", 1, CMD_LOWER },
|
||||
{ "-hslen", 1, CMD_HSLEN },
|
||||
{ "-vslen", 1, CMD_VSLEN },
|
||||
{ "--timings", 7, CMD_TIMING },
|
||||
|
||||
{ "-csync", 1, CMD_CSYNC },
|
||||
{ "-gsync", 1, CMD_GSYNC },
|
||||
{ "-extsync", 1, CMD_EXTSYNC },
|
||||
{ "-bcast", 1, CMD_BCAST },
|
||||
{ "-rgba", 1, CMD_RGBA },
|
||||
{ "-step", 1, CMD_STEP },
|
||||
{ "-move", 1, CMD_MOVE },
|
||||
#endif
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
const char *mode)
|
||||
{
|
||||
#ifdef BB_FBSET_READMODE
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *p = buf;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL) PERROR("readmode(fopen)");
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
|
||||
p += 5;
|
||||
if ((p = strstr(buf, mode))) {
|
||||
p += strlen(mode);
|
||||
if (!isspace(*p) && (*p != 0) && (*p != '"') && (*p != '\r')
|
||||
&& (*p != '\n')) continue; /* almost, but not quite */
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if (!strstr(buf, "endmode")) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "W: mode reading was disabled on this copy of fbset; ignoring request\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setmode(struct fb_var_screeninfo *base,
|
||||
struct fb_var_screeninfo *set)
|
||||
{
|
||||
if ((int)set->xres > 0) base->xres = set->xres;
|
||||
if ((int)set->yres > 0) base->yres = set->yres;
|
||||
if ((int)set->xres_virtual > 0) base->xres_virtual = set->xres_virtual;
|
||||
if ((int)set->yres_virtual > 0) base->yres_virtual = set->yres_virtual;
|
||||
if ((int)set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel;
|
||||
}
|
||||
|
||||
static void showmode(struct fb_var_screeninfo *v)
|
||||
{
|
||||
double drate = 0, hrate = 0, vrate = 0;
|
||||
if (v->pixclock) {
|
||||
drate = 1e12 / v->pixclock;
|
||||
hrate = drate / (v->left_margin+v->xres+v->right_margin+v->hsync_len);
|
||||
vrate = hrate / (v->upper_margin+v->yres+v->lower_margin+v->vsync_len);
|
||||
}
|
||||
printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int)(vrate+0.5));
|
||||
#ifdef BB_FBSET_FANCY
|
||||
printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate/1e6, hrate/1e3,
|
||||
vrate);
|
||||
#endif
|
||||
printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
|
||||
v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
|
||||
#else
|
||||
printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
#endif
|
||||
printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, v->red.offset,
|
||||
v->green.length, v->green.offset, v->blue.length, v->blue.offset,
|
||||
v->transp.length, v->transp.offset);
|
||||
printf("endmode\n");
|
||||
}
|
||||
|
||||
static void fbset_usage(void)
|
||||
{
|
||||
int i;
|
||||
#ifndef STANDALONE
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
|
||||
#endif
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n");
|
||||
fprintf(stderr, "\tThe following options are recognized:\n");
|
||||
for (i = 0; g_cmdoptions[i].name; i++)
|
||||
fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
int main(int argc, char **argv)
|
||||
#else
|
||||
extern int fbset_main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
struct fb_var_screeninfo var, varset;
|
||||
int fh, i;
|
||||
char *fbdev = DEFAULTFBDEV;
|
||||
char *modefile = DEFAULTFBMODE;
|
||||
char *thisarg, *mode = NULL;
|
||||
|
||||
memset(&varset, 0xFF, sizeof(varset));
|
||||
|
||||
/* parse cmd args.... why do they have to make things so difficult? */
|
||||
argv++; argc--;
|
||||
for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
|
||||
for (i = 0; g_cmdoptions[i].name; i++) {
|
||||
if (!strcmp(thisarg, g_cmdoptions[i].name)) {
|
||||
if (argc - 1 < g_cmdoptions[i].param_count) fbset_usage();
|
||||
switch (g_cmdoptions[i].code) {
|
||||
case CMD_HELP: fbset_usage();
|
||||
case CMD_FB: fbdev = argv[1]; break;
|
||||
case CMD_DB: modefile = argv[1]; break;
|
||||
case CMD_GEOMETRY:
|
||||
varset.xres = strtoul(argv[1],0,0);
|
||||
varset.yres = strtoul(argv[2],0,0);
|
||||
varset.xres_virtual = strtoul(argv[3],0,0);
|
||||
varset.yres_virtual = strtoul(argv[4],0,0);
|
||||
varset.bits_per_pixel = strtoul(argv[5],0,0);
|
||||
break;
|
||||
case CMD_TIMING:
|
||||
varset.pixclock = strtoul(argv[1],0,0);
|
||||
varset.left_margin = strtoul(argv[2],0,0);
|
||||
varset.right_margin = strtoul(argv[3],0,0);
|
||||
varset.upper_margin = strtoul(argv[4],0,0);
|
||||
varset.lower_margin = strtoul(argv[5],0,0);
|
||||
varset.hsync_len = strtoul(argv[6],0,0);
|
||||
varset.vsync_len = strtoul(argv[7],0,0);
|
||||
break;
|
||||
#ifdef BB_FBSET_FANCY
|
||||
case CMD_XRES: varset.xres = strtoul(argv[1],0,0); break;
|
||||
case CMD_YRES: varset.yres = strtoul(argv[1],0,0); break;
|
||||
#endif
|
||||
}
|
||||
argc -= g_cmdoptions[i].param_count;
|
||||
argv += g_cmdoptions[i].param_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!g_cmdoptions[i].name) {
|
||||
if (argc == 1) {
|
||||
mode = *argv;
|
||||
g_options |= OPT_READMODE;
|
||||
} else {
|
||||
fbset_usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((fh = open(fbdev, O_RDONLY)) < 0) PERROR("fbset(open)");
|
||||
if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
if (g_options & OPT_READMODE) {
|
||||
if (!readmode(&var, modefile, mode)) {
|
||||
fprintf(stderr, "Unknown video mode `%s'\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
setmode(&var, &varset);
|
||||
if (g_options & OPT_CHANGE)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
close(fh);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
@@ -115,6 +115,18 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
|
||||
#endif
|
||||
|
||||
|
||||
#if defined BB_MTAB
|
||||
#define whine_if_fstab_is_missing() {}
|
||||
#else
|
||||
extern void whine_if_fstab_is_missing()
|
||||
{
|
||||
struct stat statBuf;
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Seperate standard mount options from the nonstandard string options */
|
||||
static void
|
||||
parse_mount_options ( char *options, unsigned long *flags, char *strflags)
|
||||
|
||||
@@ -151,7 +151,8 @@ copyFile( const char *srcName, const char *destName,
|
||||
if (S_ISDIR(srcStatBuf.st_mode)) {
|
||||
//fprintf(stderr, "copying directory %s to %s\n", srcName, destName);
|
||||
/* Make sure the directory is writable */
|
||||
if (mkdir(destName, 0777777 ^ umask(0))) {
|
||||
result = mkdir(destName, 0777777 ^ umask(0));
|
||||
if (result < 0 && errno != EEXIST) {
|
||||
perror(destName);
|
||||
return (FALSE);
|
||||
}
|
||||
@@ -217,10 +218,12 @@ copyFile( const char *srcName, const char *destName,
|
||||
if (setModes == TRUE) {
|
||||
//fprintf(stderr, "Setting permissions for %s\n", destName);
|
||||
chmod(destName, srcStatBuf.st_mode);
|
||||
if (followLinks == TRUE)
|
||||
chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
|
||||
else
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
if (followLinks == FALSE)
|
||||
lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
|
||||
else
|
||||
#endif
|
||||
chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
|
||||
|
||||
times.actime = srcStatBuf.st_atime;
|
||||
times.modtime = srcStatBuf.st_mtime;
|
||||
@@ -376,7 +379,7 @@ int fullRead(int fd, char *buf, int len)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (BB_CHOWN) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS)
|
||||
#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS) || defined (BB_INSMOD)
|
||||
/*
|
||||
* Walk down all the directories under the specified
|
||||
* location, and do something (something specified
|
||||
@@ -966,7 +969,7 @@ check_wildcard_match(const char* text, const char* pattern)
|
||||
|
||||
|
||||
|
||||
#if defined BB_DF | defined BB_MTAB
|
||||
#if defined BB_DF || defined BB_MTAB
|
||||
/*
|
||||
* Given a block device, find the mount table entry if that block device
|
||||
* is mounted.
|
||||
@@ -1005,21 +1008,10 @@ extern struct mntent *findMountPoint(const char *name, const char *table)
|
||||
endmntent(mountTable);
|
||||
return mountEntry;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined BB_MTAB && (defined BB_MOUNT || defined BB_DF )
|
||||
extern void whine_if_fstab_is_missing()
|
||||
{
|
||||
struct stat statBuf;
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined BB_DD || defined BB_TAIL
|
||||
/*
|
||||
* Read a number with a possible multiplier.
|
||||
@@ -1108,4 +1100,15 @@ findInitPid()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
|
||||
extern int vdprintf(int d, const char *format, va_list ap)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
int len;
|
||||
|
||||
len = vsprintf(buf, format, ap);
|
||||
return write(d, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* END CODE */
|
||||
Reference in new issue
Block a user