-Erik
This commit is contained in:
Erik Andersen 2000-02-11 21:55:04 +00:00
parent 5e1b2ca116
commit 9ffdaa647e
24 changed files with 483 additions and 414 deletions

357
Changelog
View File

@ -1,17 +1,15 @@
0.42 0.42
* changed fsck_minix.c to reduce its .bss size significantly
-beppu -piptigger
* Fairly massive restructuring of umount.c to deal with remounting * Fairly massive restructuring of umount.c to deal with remounting
busy devices read-only. Adds a -r option to control that; it is busy devices read-only. Adds a -r option to control that; it is
optionally compiled in with BB_FEATURE_REMOUNT optionally compiled in with BB_FEATURE_REMOUNT
* Added a bunch of functions to mtab.c to interact with the * Added a bunch of functions to mtab.c to interact with the
{get,set,end}mntent interface; as it turns out, those functions do {get,set,end}mntent interface; as it turns out, those functions do
not appear to be re-entrant, and that causes a lot of problems with not appear to be re-entrant, and that causes a lot of problems with
the way umount was originally written. the way umount was originally written.
* Makes init send TERM and KILL (instead of HUP and KILL) on reboot * Makes init send TERM and KILL (instead of HUP and KILL) on reboot
to be more consistent with sysvinit to be more consistent with sysvinit
* Changes to init.c to use the new -r option to umount. Also increased * Changes to init.c to use the new -r option to umount. Also increased
the sleep time between the time the TERM and KILL signals are sent the sleep time between the time the TERM and KILL signals are sent
- Randolph Chung - Randolph Chung
@ -19,17 +17,19 @@
* cp.c, mv.c: removed, replaced by cp_mv.c which has been * cp.c, mv.c: removed, replaced by cp_mv.c which has been
extensively rewritten from the original cp.c. extensively rewritten from the original cp.c.
* Fixed cp and mv so if the source and destination are a the
same directory it will print an error and continue.
* Also added a warning message to the `mv' usage string saying that * Also added a warning message to the `mv' usage string saying that
this is not GNU mv, and it will break hard links. cp also breaks this is not GNU mv, and it will break hard links. cp also breaks
hard links. hard links.
* ln.c: implemented `-n' switch, no-deref symlinks. * ln.c: implemented `-n' switch, no-deref symlinks.
* include<sys/param.h>: and use PATH_MAX everywhere. * include<sys/param.h>: and use PATH_MAX everywhere. busybox: File
* busybox: File name buffer overrun guards to prevent future crashes. * name buffer overrun guards to prevent future crashes.
- Always check exit status. - Always check exit status.
- Purge all use of `creat()', replace with `open()'. - Purge all use of `creat()', replace with `open()'.
* utility.c * utility.c
- recursiveAction was overriding the value of - recursiveAction was overriding the value of followLinks thus
followLinks thus ignoring it. ignoring it.
- isDirectory now takes a followLinks boolean, updated all callers - isDirectory now takes a followLinks boolean, updated all callers
- copyFile had the followLinks logic reversed. - copyFile had the followLinks logic reversed.
* messages.c: New file. Put common error message strings all in * messages.c: New file. Put common error message strings all in
@ -38,9 +38,11 @@
-Karl M. Hegbloom -Karl M. Hegbloom
* Made tar creation support in busybox tar optional. * changed fsck_minix.c to reduce its .bss size significantly
* You no longer _have_ to put a "-" in front of tar options. -beppu -piptigger
* Tar could inadvertently change permissions and ownership on * Made tar creation support in busybox tar optional. You no longer
* _have_ to put a "-" in front of tar options. Tar could inadvertently
* change permissions and ownership on
certain directories pointed to by symlinks. certain directories pointed to by symlinks.
* Made grep and grep -h do the right thing wrt printing * Made grep and grep -h do the right thing wrt printing
the file name (it failed to print files names in many cases). the file name (it failed to print files names in many cases).
@ -59,8 +61,8 @@
* Fixed a bug where init could have reference already freed memory. * Fixed a bug where init could have reference already freed memory.
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp> Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de> * Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
* Added (and documented) "-n" option for head - * Added (and documented) "-n" option for head - Cleanup for a number of
* Cleanup for a number of usage messages -- also * usage messages -- also
contributed Friedrich Vedder <fwv@myrtle.lahn.de> contributed Friedrich Vedder <fwv@myrtle.lahn.de>
* Cosmetic fix to busybox.c (Don't print a comma at the * Cosmetic fix to busybox.c (Don't print a comma at the
end of line if there are no more application names). end of line if there are no more application names).
@ -69,9 +71,9 @@
* Moved commonly used functions "xmalloc()" and "exit()" * Moved commonly used functions "xmalloc()" and "exit()"
to utility.c (with proper #ifdef's). to utility.c (with proper #ifdef's).
* Created a tiny tail implementation, removing -c, -q, -v, and making * Created a tiny tail implementation, removing -c, -q, -v, and making
tail -f work only with a single file. This reduced tail tail -f work only with a single file. This reduced tail from 6k to
from 6k to 2.4k. The bigger/more featured tail can still be 2.4k. The bigger/more featured tail can still be had by disabling
had by disabling BB_FEATURE_SIMPLE_TAIL in dusybox.defs.h BB_FEATURE_SIMPLE_TAIL in dusybox.defs.h
* Ping now falls back to doing the right thing if /etc/protocols * Ping now falls back to doing the right thing if /etc/protocols
turns up missing. turns up missing.
* Fixed mount and umount. Previously they could leak loop device * Fixed mount and umount. Previously they could leak loop device
@ -83,15 +85,24 @@
files pointed to by the symlinks. files pointed to by the symlinks.
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>: * Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
- `chown' with 1 argument displayed the error incorrectly - `chown' with 1 argument displayed the error incorrectly
- `fdflush', `length' and `printf' crashed when run without arguments - `fdflush', `length' and `printf' crashed if run without arguments
- `fdflush' tried to flush itself using *argv - `fdflush' tried to flush itself using *argv
- added "skip" and "seek" to dd. - added "skip" and "seek" to dd.
* swapoff -a was not working. Now it is. - ls no longer messus up output when combining files and
* init did not cleanly unmount filesystems on reboot. Now it does. directories on the command line
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't. * swapoff -a was not working. Now it is. init did not cleanly unmount
* filesystems on reboot. Now it does. "sed -ne s/foo/bar/" worked but
* "sed -n -e s/foo/bar/" didn't.
Now both work. Now both work.
* Some architectures (PowerPc) assume chars are unsigned, so they could * Some architectures (PowerPc) assume chars are unsigned, so they could
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints. not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
* Began converting error handling to use some common routines
in utility.c
* syslogd now has better message handling and ignores SIGHUP.
* install.sh had a bug preventing installation to the specified
target directory. Fix from Gilbert Coville <gilbert@mvista.com>
* You can now spefify alternative strip commands -- change
also from Gilbert Coville.
-Erik Andersen -Erik Andersen
@ -100,48 +111,49 @@
* New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed * New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
by Edward Betts <edward@debian.org> by Edward Betts <edward@debian.org>
* Fixed a bug in both cp and mv preventing 'cp foo/README bar' * Fixed a bug in both cp and mv preventing 'cp foo/README bar'
type commands (file in a directory to another directory) type commands (file in a directory to another directory) from
from working. working.
* Fixed a logger bug that caused garbage to be written to the syslog * Fixed a logger bug that caused garbage to be written to the syslog
(unless you used busybox syslog, which hid the bug). Thanks (unless you used busybox syslog, which hid the bug). Thanks to
to Alex Holden <alex@linuxhacker.org> for the fix. Alex Holden <alex@linuxhacker.org> for the fix.
* /bin/true and /bin/false were echoing a blank line when run. Now fixed. * /bin/true and /bin/false were echoing a blank line when run.
Now fixed.
* mkdir -p would print an error when asked to mkdir an existing dir * mkdir -p would print an error when asked to mkdir an existing dir
with no interveining subdirectories. with no interveining subdirectories.
* Fixed "syslogd -O" so that it works. * Fixed "syslogd -O" so that it works. Added -o loop option for mount,
* Added -o loop option for mount, and support in umount for loop * and support in umount for loop
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
<bcollins@debian.org> <bcollins@debian.org>
* Several fixes from Marco Pantaleoni <panta@prosa.it> * Several fixes from Marco Pantaleoni <panta@prosa.it> compile in
* compile in fullWrite() not only if BB_TAR is defined, but also * fullWrite() not only if BB_TAR is defined, but also
if BB_CP or BB_MV are (fullWrite() is referenced by copyFile()) if BB_CP or BB_MV are (fullWrite() is referenced by copyFile())
* add some compiler optimizations to further reduce executable size * add some compiler optimizations to further reduce executable size
(as a side note, on my machines the largest code is generated by (as a side note, on my machines the largest code is generated
gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with -O2 by gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with
-m386 ...) -O2 -m386 ...)
* Compile no longer fails if busybox.def.h defines BB_FEATURE_LINUXRC * Compile now won't fail if busybox.def.h defines
but not BB_INIT. (init_main used to be referenced, but not compiled) BB_FEATURE_LINUXRC but not BB_INIT. (init_main used to be
referenced, but not compiled)
* Fixed a bug in setting TERM for serial console support. TERM now * Fixed a bug in setting TERM for serial console support. TERM now
defaults to "ansi" for serial consoles. defaults to "ansi" for serial consoles.
* Fixed a bug in handling the CONSOLE env. variable for serial consoles. * Fixed a bug in handling the CONSOLE env. variable for serial
* consoles.
-Erik Andersen, Jan 15, 2000 -Erik Andersen, Jan 15, 2000
0.40 0.40
* New Apps: sort, uniq. -beppu * New Apps: sort, uniq. -beppu New Apps: lsmod, rmmod -erik New Apps:
* New Apps: lsmod, rmmod -erik * fbset contributed by Randolph Chung <tausq@debian.org>. New App::
* New Apps: fbset contributed by Randolph Chung <tausq@debian.org>. * loadacm contributed by Peter Novodvorsky <petya@logic.ru>
* New App:: loadacm contributed by Peter Novodvorsky <petya@logic.ru>
for loading application character maps for Unicode fonts. for loading application character maps for Unicode fonts.
* Major init re-work. init now supports inittab (slightly different * Major init re-work. init now supports inittab (slightly different
but similar to sysvinit), allowing me to get all the policy out but similar to sysvinit), allowing me to get all the policy out of
of init and into the conf file. It works just fine without inittab init and into the conf file. It works just fine without inittab
being present, but if you dont like the defautl behavior you can being present, but if you dont like the defautl behavior you can
now do something about it. Init is much cleaner as a result. 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 bug in syslogd causing it to stop after 20 minutes. -erik
* Fixed an embarrasing segfault in head -beppu * Fixed an embarrasing segfault in head -beppu Fixed the embarrasing
* Fixed the embarrasing failure of 'logger -p'. -erik * failure of 'logger -p'. -erik Added the -s option to du -beppu
* Added the -s option to du -beppu
* Re-worked the source tree a bit so it will compile under glibc 2.0.7 * Re-worked the source tree a bit so it will compile under glibc 2.0.7
with the 2.0.x Linux kernel. with the 2.0.x Linux kernel.
* Added 'grep -q' thanks to a patch from "Konstantin Boldyshev" * Added 'grep -q' thanks to a patch from "Konstantin Boldyshev"
@ -151,8 +163,8 @@
* Fixed a bug where tar would set, and then clear SGID and SUID bits. * 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 * Fixed a bug where tar would not set the user and group on device
special files. special files.
* Fixed a bug where tar would not restore the time to files. * Fixed a bug where tar would not restore the time to files. Fixed a
* Fixed a major security problem with tar -- it changed ownership * major security problem with tar -- it changed ownership
of any file pointed to by a symlink to 777 (like say libc....) of any file pointed to by a symlink to 777 (like say libc....)
Ouch!!! Ouch!!!
* cp and mv were very broken when moving directories. I have rewritten * cp and mv were very broken when moving directories. I have rewritten
@ -162,8 +174,8 @@
* Fixed dmesg. It wasn't parsing its options (-n or -s) properly. * Fixed dmesg. It wasn't parsing its options (-n or -s) properly.
* Some cosmetic fixes to ls output formatting to make it behave more * Some cosmetic fixes to ls output formatting to make it behave more
like GNU ls. like GNU ls.
* Fixed a stupid segfault in kill. * Fixed a stupid segfault in kill. Several fixes from Friedrich Vedder
* Several fixes from Friedrich Vedder <fwv@myrtle.lahn.de>: * <fwv@myrtle.lahn.de>:
- Added gunzip -t, removed gunzip.c dead code, - Added gunzip -t, removed gunzip.c dead code,
- fixed several typos - fixed several typos
- Glibc 2.0.7 and libc5 compile fixes - Glibc 2.0.7 and libc5 compile fixes
@ -175,25 +187,27 @@
0.39 0.39
* New Apps: ping, hostname, and mkfifo contributed by Randolph Chung * New Apps: ping, hostname, and mkfifo contributed by Randolph Chung
<tausq@debian.org>. 3 items off the TODO list! <tausq@debian.org>. 3 items off the TODO list!
* I wrote free (just calls "cat /proc/meminfo"). * I wrote free (just calls "cat /proc/meminfo"). Added tail, based on
* Added tail, based on tail from GNU textutils-1.19, but adjusted * tail from GNU textutils-1.19, but adjusted
to suit my evil purposes. Costs 6k. I'll make it smaller sometime. to suit my evil purposes. Costs 6k. I'll make it smaller
sometime.
* on reboot, init called 'umount -a -n', which caused errors * on reboot, init called 'umount -a -n', which caused errors
when BB_MTAB was not enabled. Changed to 'umount -a', when BB_MTAB was not enabled. Changed to 'umount -a', which does
which does the right thing. the right thing.
* init will now try to run /sbin/getty if it is present (for easy * init will now try to run /sbin/getty if it is present (for easy
integration with the about-to-be-released tinylogin.) integration with the about-to-be-released tinylogin.)
* kill now behaves itself properly, added 'kill -l' to list signals * kill now behaves itself properly, added 'kill -l' to list signals 'ls
* 'ls -l' was failing on long directories, since my_getid was leaking * -l' was failing on long directories, since my_getid was leaking
one file descriptor per file. Oops. one file descriptor per file. Oops.
* Fixed rebooting from init. I'd accidently left some debugging code in * Fixed rebooting from init. I'd accidently left some debugging code
* in
which blocked reboots. which blocked reboots.
* Fixed reboot, halt (and added poweroff) such that they handle it when * Fixed reboot, halt (and added poweroff) such that they handle it when
init is not at PID 1 (like when running in an initrd). init is not at PID 1 (like when running in an initrd).
* Added a prelinary du implementation. Some parameter parsing * Added a prelinary du implementation. Some parameter parsing
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>) stuff still needs to be added. -beppu (John Beppu
* Implemented tee. -beppu <beppu@lineo.com>)
* Implemented head. -beppu * Implemented tee. -beppu Implemented head. -beppu
-Erik Andersen, Dec 10, 1999 -Erik Andersen, Dec 10, 1999
@ -201,7 +215,8 @@
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab * Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
file existed. file existed.
* df will not exit on error, but will stat all mounted filesystems. * df will not exit on error, but will stat all mounted filesystems.
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct. * Fixed tar so uid/gid/permissions on extracted tarballs will be
correct.
* Fixed find -name so it properly uses shell wildcard patterns * Fixed find -name so it properly uses shell wildcard patterns
(i.e. `*', `?', and `[]') instead of regular expressions, which (i.e. `*', `?', and `[]') instead of regular expressions, which
was causing some confusing and unexpected behavior. was causing some confusing and unexpected behavior.
@ -219,20 +234,25 @@
0.37 0.37
* Wrote a micro syslogd, and a logger util (to log things to the syslog * Wrote a micro syslogd, and a logger util (to log things to the syslog
from the command line or scripts) With both compiled in, costs 4k. from the command line or scripts) With both compiled in, costs 4k.
* Fixed 'make install' so symlinks are installed in their proper locations. * Fixed 'make install' so symlinks are installed in their proper
* Changed the build system slightly so that features can now be enabled * locations. Changed the build system slightly so that features can
* now be enabled
or disabled from the busybox.defs.h header file, without trying to or disabled from the busybox.defs.h header file, without trying to
compile in a source file named after that featue (unless that file exists). compile in a source file named after that featue (unless that file
* Several options are now moved into busybox.defs.h exists).
* Now 'rm -R' and 'rm -r' both work. * Several options are now moved into busybox.defs.h Now 'rm -R' and 'rm
* dd now properly handles input beyond 1 block from stdin. * -r' both work. dd now properly handles input beyond 1 block from
* Fixed a bug where tar unpacked everything a directories. Moved some code * stdin. Fixed a bug where tar unpacked everything a directories.
from createPath into mkdir where it belonged, thereby making tar work properly. * Moved some code
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat out the from createPath into mkdir where it belonged, thereby making tar
work properly.
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat
* out the
last file in the list. last file in the list.
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed 'ls -l' * Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid are * 'ls -l'
presented properly. so when uid/gid is not in /etc/{passwd,group} the numeric group/uid
are presented properly.
* Also added a TODO. * Also added a TODO.
@ -241,46 +261,53 @@
0.36 0.36
* fixed dd so it properly defaults to stdin and stdout when no * fixed dd so it properly defaults to stdin and stdout when no
if= and of= are set (fix thanks to Eric Delaunay). if= and of= are set (fix thanks to Eric Delaunay).
* Don't try to close the file descriptor of a pipein tar. (fix also from * Don't try to close the file descriptor of a pipein tar. (fix also
* from
Eric Delaunay). Eric Delaunay).
* Made createPath be quiet (again thanks to Eric Delaunay). * Made createPath be quiet (again thanks to Eric Delaunay). If
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever * BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
command you define it as will be run if the init script exits. command you define it as will be run if the init script exits.
* Updated install.sh to make it more robust (thanks to Adam Di Carlo) * Updated install.sh to make it more robust (thanks to Adam Di Carlo)
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled * NFS support added to mount by Eric Delaunay. It costs 10k when
* compiled
in, but that is still a big win for those that use NFS. in, but that is still a big win for those that use NFS.
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay). * Made 'rm -f' be silent for non-existant files (thanks to Eric
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise * Delaunay). changed zcat.c to gunzip.c. It now obeys the principle
and acts as god intended gunzip and zcat to act. They answer --help and * of least surprise
obey the '-c' flag. and acts as god intended gunzip and zcat to act. They answer
* Fixed a bug in mv which caused it to not move files when the destination --help and obey the '-c' flag.
* Fixed a bug in mv which caused it to not move files when the
* destination
was a directory. was a directory.
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories * Fixed a decimal-instead-of-octal bug causing mkdir to make
* directories
with very wrong permissions. with very wrong permissions.
* chmod would overwrite file permissions instead of modifying them. * chmod would overwrite file permissions instead of modifying them.
Now it properly modifies permissions. Now it properly modifies permissions.
* Init now sends warnings destined for the console to /dev/console to ensure * Init now sends warnings destined for the console to /dev/console to
they show up on whatever the active console it. Otherwise important * ensure
messages (for example that the system is rebooting) were not seen when they show up on whatever the active console it. Otherwise
switched to a different VT. important messages (for example that the system is rebooting) were
not seen when switched to a different VT.
-Erik Andersen, Nov 17, 1999 -Erik Andersen, Nov 17, 1999
0.35 0.35
* gzip now obeys the principle of least surprise and acts like god intended * gzip now obeys the principle of least surprise and acts like god
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag * intended
and only then outputs to stdout). (i.e. it accepts a file name, answers --help, and obeys the '-c'
flag and only then outputs to stdout).
* Fixed more.c to compile autowidth on sparc and set initial winsize * Fixed more.c to compile autowidth on sparc and set initial winsize
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay. to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric
Delaunay.
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards) * Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
* tar now accepts --help * tar now accepts --help chmod, chown, and chgrp usage now works
* chmod, chown, and chgrp usage now works * General usage (i.e. --help) cleanups for most apps umount now parses
* General usage (i.e. --help) cleanups for most apps * options correctly tar can now unpack tarballs containing device
* umount now parses options correctly * special files,
* tar can now unpack tarballs containing device special files, sockets, and fifos (though it can't pack them up) thanks to Matt
sockets, and fifos (though it can't pack them up) thanks Porter. Creating archives containing these is still left to the
to Matt Porter. Creating archives containing these is still interested student.
left to the interested student.
* fixed up the license in more.c to properly point to Bruce Perens. * fixed up the license in more.c to properly point to Bruce Perens.
-Erik Andersen, Nov 11, 1999 -Erik Andersen, Nov 11, 1999
@ -290,17 +317,17 @@
Patch thanks to Eric Delaunay Patch thanks to Eric Delaunay
* init now properly handles sparc serial consoles and does a * init now properly handles sparc serial consoles and does a
better job of finding the real console device rather than using better job of finding the real console device rather than using
/dev/console which doesn't support job control. Patch also /dev/console which doesn't support job control. Patch also thanks
thanks to Eric Delaunay. to Eric Delaunay.
* more started to read from stdin after the last file was finished, and * more started to read from stdin after the last file was finished, and
options were not parsed correctly (fix thanks to Eric Delaunay). options were not parsed correctly (fix thanks to Eric Delaunay).
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on. * more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
* rm wouldn't remove a symlink unless the symlink was valid. This was * rm wouldn't remove a symlink unless the symlink was valid. This was
a side effect of the busybox 0.32 recursiveAction() fix. Things a side effect of the busybox 0.32 recursiveAction() fix. Things
should now work correctly. should now work correctly.
* grep wouldn't grep stdin. Now it does. * grep wouldn't grep stdin. Now it does. sed wouldn't sed stdin. Now
* sed wouldn't sed stdin. Now it does. * it does. sed was appending a \n to the end of lines with
* sed was appending a \n to the end of lines with replacements. * replacements.
Now it doesn't do that. Now it doesn't do that.
* ls -l now bypasses libc6 nss when displaying user/group names. * ls -l now bypasses libc6 nss when displaying user/group names.
Now uses my_getpwuid and my_getgrgid. Now uses my_getpwuid and my_getgrgid.
@ -321,45 +348,45 @@
0.32 0.32
* More changes -- many thanks to Lineo for paying me to work on * More changes -- many thanks to Lineo for paying me to work on
busybox. If you have any problems please let me know ASAP busybox. If you have any problems please let me know ASAP at
at andersen@lineo.com or andersee@debian.org andersen@lineo.com or andersee@debian.org
* usage() now prints the BusyBox version. This will help folks * usage() now prints the BusyBox version. This will help folks
realize that they are not in Kansas anymore. realize that they are not in Kansas anymore.
* Fixed mkdir -m option so that it works. * Fixed mkdir -m option so that it works. kill segfaulted w/o any
* kill segfaulted w/o any arguments. Now it doesn't do that. * arguments. Now it doesn't do that. kill wasn't properly accepting
* kill wasn't properly accepting signal names. It does now. * signal names. It does now. Added new apps chvt and deallocvt (I
* Added new apps chvt and deallocvt (I should probably add open) * should probably add open) Major rewrite of init.c. Code is now
* Major rewrite of init.c. Code is now readable by mere mortals IMHO. * readable by mere mortals IMHO. Wrote sed -- weighs only 1.8k (5.8k
* Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!). * with full regular expressions!). Fixed a stupid seg-fault in sync
* Fixed a stupid seg-fault in sync * Fixed mount -- mount -a failed to parse and apply mount options Fixed
* Fixed mount -- mount -a failed to parse and apply mount options * umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
* Fixed umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>) * umount -a no longer umounts /proc Added BB_MTAB, allowing (at the
* umount -a no longer umounts /proc * cost of ~1.5k and the need for a rw /etc)
* Added BB_MTAB, allowing (at the cost of ~1.5k and the need for a rw /etc) folks to use a real /etc/mtab file instead of a symlink to
folks to use a real /etc/mtab file instead of a symlink to /proc/mounts. /proc/mounts. mount, and umount will add/remove entries and df
mount, and umount will add/remove entries and df will now use /etc/mtab will now use /etc/mtab if BB_MTAB is defined.
if BB_MTAB is defined.
* Fixed a nice bug in recursiveAction() which caused it to infinitely * Fixed a nice bug in recursiveAction() which caused it to infinitely
hunt through /proc/../fd/* creating new file descriptors if it hunt through /proc/../fd/* creating new file descriptors if it
followed the /dev/fd link over to /proc. recursiveAction() now followed the /dev/fd link over to /proc. recursiveAction() now
lstat's the file when followLinks==FALSE so it won't follow links lstat's the file when followLinks==FALSE so it won't follow links
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>. as the name suggests. Fix thanks to Matt Porter
<porter@debian.org>.
-Erik Andersen, Nov 4, 1999 -Erik Andersen, Nov 4, 1999
0.31 0.31
* I added a changelog for version 0.30. * I added a changelog for version 0.30. adjusted find internals to
* adjusted find internals to make it smaller, and removed * make it smaller, and removed
some redundancy. some redundancy.
* Fixed a segfault in ps when /etc/passwd or /etc/group * Fixed a segfault in ps when /etc/passwd or /etc/group
are absent. Now will warn you and carry on. are absent. Now will warn you and carry on.
* Added in optional _real_ regular expression support (to be * Added in optional _real_ regular expression support (to be
the basis for a future sed utility). When compiled in the basis for a future sed utility). When compiled in it adds
it adds 3.9k, but makes grep much more capable. 3.9k, but makes grep much more capable.
* Checked out using nftw(3) for recursive stuff, but unfortunatly * Checked out using nftw(3) for recursive stuff, but unfortunatly
it wasn't supported before GNU libc 2.1, and some folks use it wasn't supported before GNU libc 2.1, and some folks use glibc
glibc 2.0.7 since it is much smaller than that latest and greatest. 2.0.7 since it is much smaller than that latest and greatest.
-Erik Andersen, Oct 21, 1999 -Erik Andersen, Oct 21, 1999
@ -373,8 +400,8 @@
* busybox can now invoke apps in two ways: via symlinks to the * busybox can now invoke apps in two ways: via symlinks to the
busybox binary, and as 'busybox [function] [arguments]...' busybox binary, and as 'busybox [function] [arguments]...'
* When invoked as busybox, the list of currently compiled in * When invoked as busybox, the list of currently compiled in
functions is printed out (no this is not bloat -- the list functions is printed out (no this is not bloat -- the list has
has to be there anyway to map invocation name to function). to be there anyway to map invocation name to function).
* busybox no longer parses command lines for apps or displays their * busybox no longer parses command lines for apps or displays their
usage info. Each app gets to handle (or not handle) this for usage info. Each app gets to handle (or not handle) this for
itself. itself.
@ -385,9 +412,9 @@
* All shared code now lives in utility.c, and is properly * All shared code now lives in utility.c, and is properly
ifdef'ed to be only included for those apps requiring it. ifdef'ed to be only included for those apps requiring it.
* Eliminated struct FileInfo (the basis of monadic, dyadic, etc) * Eliminated struct FileInfo (the basis of monadic, dyadic, etc)
so now each app has the function prototype of (da-dum): so now each app has the function prototype of (da-dum): extern
extern int foo_main(int argc, char** argv); int foo_main(int argc, char** argv); which speeds integration
which speeds integration of new apps. of new apps.
* Adjusted the Makefile to make it easier to * Adjusted the Makefile to make it easier to
{en|dis}able debugging. {en|dis}able debugging.
* Changed default compiler optimization to -Os * Changed default compiler optimization to -Os
@ -396,39 +423,43 @@
App Changes: App Changes:
* To cope with the new app function prototype and the removal of * To cope with the new app function prototype and the removal of
monadic, dyadic, etc, the following apps were re-written: monadic, dyadic, etc, the following apps were re-written:
* cat - Works same as always. * cat - Works same as always. chgrp, chmod, chown -
* chgrp, chmod, chown - rewrite. Combined into a single * rewrite. Combined into a single
source file. Absorbed patches from Enrique Zanardi <ezanard@debian.org> source file. Absorbed patches from Enrique Zanardi
that removes the dependency on libc6 libnss* libraries. <ezanard@debian.org> that removes the dependency on
libc6 libnss* libraries.
* cp - Can now do 'cp -a' can can copy devices, * cp - Can now do 'cp -a' can can copy devices,
pipes, symlinks, as well as recursive or non-recursive dir copies. pipes, symlinks, as well as recursive or non-recursive
* fdflush - adjusted to remove dependancy on struct FileInfo. dir copies.
* find - Now includes some basic regexp matching * fdflush - adjusted to remove dependancy on struct
* FileInfo. find - Now includes some basic regexp matching
which will be the basic of a future mini-sed. which will be the basic of a future mini-sed.
* ln - Same functionality. * ln - Same functionality. mkdir - Added -p flag to
* mkdir - Added -p flag to feature set. * feature set. mv - rewrite. rm - Added -f flag to
* mv - rewrite. * feature set. rmdir - Same functionality. swapon,
* rm - Added -f flag to feature set. * swapoff - Combined into a single binary. No longer
* rmdir - Same functionality. uses /etc/swaps. swap{on|off} -a uses /etc/fstab
* swapon, swapoff - Combined into a single binary. No longer instead.
uses /etc/swaps. swap{on|off} -a uses /etc/fstab instead. * touch - Same functionality. date - adjusted with a patch
* touch - Same functionality. * from Matthew Grant <grantma@anathoth.gen.nz>
* date - adjusted with a patch from Matthew Grant <grantma@anathoth.gen.nz> to accomodate glibc timezone support. I then ripped out GNU
to accomodate glibc timezone support. I then ripped out GNU getopt. getopt.
* mkswap -- new version merged from util-linux. Can now make >128Meg swaps. * mkswap -- new version merged from util-linux. Can now make
* Replaced the old and star, unstar, and tarcat with the tar * >128Meg swaps. Replaced the old and star, unstar, and tarcat
implementation from sash. Now tar behaves as god intended * with the tar
it to (i.e. tar -xvf <file> and tar -cf <file> <dir> work). implementation from sash. Now tar behaves as god intended it
* dd -- rewritten. Can with with files, stdin, stdout. to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
* Added the following new apps: * dd -- rewritten. Can with with files, stdin, stdout. Added the
* loadfont -- added from debian boot floppies * following new apps: loadfont -- added from debian boot floppies
* chroot -- added based on a patch from Paolo Molaro <lupus@lettere.unipd.it> * chroot -- added based on a patch from Paolo Molaro
* grep -- I just wrote it. Only matches simple strings * <lupus@lettere.unipd.it> grep -- I just wrote it. Only matches
* ps -- I just wrote it. Has _no_ options at all, but works. * simple strings ps -- I just wrote it. Has _no_ options at all,
* fsck_minix, mkfs_minix -- added from util-linux, but I ripped out * but works. fsck_minix, mkfs_minix -- added from util-linux, but
* I ripped out
internationalization and such to make them smaller. internationalization and such to make them smaller.
* sfdisk -- Added from util-linux (minus internationalization and such). * sfdisk -- Added from util-linux (minus
* Probably some other changes that I forgot to document... * internationalization and such). Probably some other
* changes that I forgot to document...
-Erik Andersen, Oct 20, 1999 -Erik Andersen, Oct 20, 1999

View File

@ -1,5 +1,8 @@
# Makefile for busybox # Makefile for busybox
# #
# Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org>
#
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -15,13 +18,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
PROG := busybox # PROG := busybox
VERSION := 0.42 VERSION := 0.42
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M") BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
# Set the following to `true' to make a debuggable build. # Set the following to `true' to make a debuggable build.
# Leave this set to `false' for production use. # Leave this set to `false' for production use.
# eg: `make DODEBUG=true' # eg: `make DODEBUG=true tests'
DODEBUG = false DODEBUG = false
# If you want a static binary, turn this on. I can't think # If you want a static binary, turn this on. I can't think
@ -60,15 +63,21 @@ else
OPTIMIZATION = -O2 OPTIMIZATION = -O2
endif endif
# Allow alternative stripping tools to be used...
ifndef $(STRIPTOOL)
STRIPTOOL = strip
endif
# -D_GNU_SOURCE is needed because environ is used in init.c # -D_GNU_SOURCE is needed because environ is used in init.c
ifeq ($(DODEBUG),true) ifeq ($(DODEBUG),true)
CFLAGS += -Wall -g -D_GNU_SOURCE CFLAGS += -Wall -g -D_GNU_SOURCE
STRIP =
LDFLAGS = LDFLAGS =
STRIP =
else else
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS = -s LDFLAGS = -s
STRIP = strip --remove-section=.note --remove-section=.comment $(PROG) STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
#Only staticly link when _not_ debugging #Only staticly link when _not_ debugging
ifeq ($(DOSTATIC),true) ifeq ($(DOSTATIC),true)
LDFLAGS += --static LDFLAGS += --static
@ -84,33 +93,43 @@ OBJECTS = $(shell ./busybox.sh) messages.o utility.o
CFLAGS += -DBB_VER='"$(VERSION)"' CFLAGS += -DBB_VER='"$(VERSION)"'
CFLAGS += -DBB_BT='"$(BUILDTIME)"' CFLAGS += -DBB_BT='"$(BUILDTIME)"'
ifdef BB_INIT_SCRIPT ifdef BB_INIT_SCRIPT
CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT} CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
endif endif
all: busybox busybox.links all: busybox busybox.links
.PHONY: all
busybox: $(OBJECTS) busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES) $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
$(STRIP) $(STRIP) $@
busybox.links: busybox.def.h busybox.links: busybox.def.h
- ./busybox.mkll | sort >$@ - ./busybox.mkll | sort >$@
regexp.o nfsmount.o: %.o: %.h
$(OBJECTS): %.o: busybox.def.h internal.h %.c
.PHONY: test tests
test tests:
cd tests && $(MAKE) all
.PHONY: clean
clean: clean:
- rm -f $(PROG) busybox.links *~ *.o core - rm -f busybox.links *~ *.o core
- rm -rf _install - rm -rf _install
- cd tests && $(MAKE) clean
.PHONY: distclean
distclean: clean distclean: clean
- rm -f $(PROG) - rm -f busybox
- cd tests && $(MAKE) distclean
$(OBJECTS): %.o: %.c busybox.def.h internal.h Makefile messages.c
.PHONY: install
install: busybox busybox.links install: busybox busybox.links
./install.sh $(PREFIX) ./install.sh $(PREFIX)
dist: release .PHONY: dist release
dist release: distclean
release: distclean
cd ..; \ cd ..; \
rm -rf busybox-$(VERSION); \ rm -rf busybox-$(VERSION); \
cp -a busybox busybox-$(VERSION); \ cp -a busybox busybox-$(VERSION); \

6
TODO
View File

@ -10,10 +10,6 @@ around to it some time. If you have any good ideas, please let me know.
separate package (named perhaps tiny-netkit?). This currently includes separate package (named perhaps tiny-netkit?). This currently includes
hostid, hostname, mnc, and ping. hostid, hostname, mnc, and ping.
* init's waitfor() calls wait() which can catch and ignore the wrong pid
exiting. That other process is then not restarted.
-Erik -Erik
@ -22,7 +18,7 @@ around to it some time. If you have any good ideas, please let me know.
* Allow tar to create archives with sockets, devices, and other special files * Allow tar to create archives with sockets, devices, and other special files
* Make insmod actually work * Make insmod actually work
* dnsdomainname * dnsdomainname
* traceroute/nslookup/netstat * traceroute/netstat
* rdate * rdate
* hwclock * hwclock
* killall * killall

View File

@ -2,7 +2,7 @@
set -e set -e
if [ "$1" == "" ]; then if [ "$1" = "" ]; then
echo "No installation directory, aborting." echo "No installation directory, aborting."
exit 1; exit 1;
fi fi

View File

@ -194,7 +194,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array # define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \ # define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) error("insufficient memory"); \ if (array == NULL) errorMsg("insufficient memory"); \
} }
# define FREE(array) {if (array != NULL) free(array), array=NULL;} # define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else #else
@ -311,7 +311,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);} # define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x # define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;} # define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;} # define Tracevv(x) {if (verbose>1) fprintf x ;}
@ -367,8 +367,6 @@ extern void write_buf OF((int fd, voidp buf, unsigned cnt));
#ifndef __linux__ #ifndef __linux__
extern char *basename OF((char *fname)); extern char *basename OF((char *fname));
#endif /* not __linux__ */ #endif /* not __linux__ */
extern void error OF((char *m));
extern void warn OF((char *a, char *b));
extern void read_error OF((void)); extern void read_error OF((void));
extern void write_error OF((void)); extern void write_error OF((void));
@ -1045,13 +1043,13 @@ int in, out; /* input and output file descriptors */
int res = inflate(); int res = inflate();
if (res == 3) { if (res == 3) {
error("out of memory"); errorMsg("out of memory");
} else if (res != 0) { } else if (res != 0) {
error("invalid compressed data--format violated"); errorMsg("invalid compressed data--format violated");
} }
} else { } else {
error("internal error, invalid method"); errorMsg("internal error, invalid method");
} }
/* Get the crc and original length */ /* Get the crc and original length */
@ -1080,10 +1078,10 @@ int in, out; /* input and output file descriptors */
/* Validate decompression */ /* Validate decompression */
if (orig_crc != updcrc(outbuf, 0)) { if (orig_crc != updcrc(outbuf, 0)) {
error("invalid compressed data--crc error"); errorMsg("invalid compressed data--crc error");
} }
if (orig_len != (ulg) bytes_out) { if (orig_len != (ulg) bytes_out) {
error("invalid compressed data--length error"); errorMsg("invalid compressed data--length error");
} }
/* Check if there are more entries in a pkzip file */ /* Check if there are more entries in a pkzip file */

View File

@ -125,7 +125,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * near array # define DECLARE(type, array, size) type * near array
# define ALLOC(type, array, size) { \ # define ALLOC(type, array, size) { \
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) error("insufficient memory"); \ if (array == NULL) errorMsg("insufficient memory"); \
} }
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;} # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
#else #else
@ -262,7 +262,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);} # define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x # define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;} # define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;} # define Tracevv(x) {if (verbose>1) fprintf x ;}
@ -327,8 +327,6 @@ extern void flush_window OF((void));
extern void write_buf OF((int fd, voidp buf, unsigned cnt)); extern void write_buf OF((int fd, voidp buf, unsigned cnt));
extern char *strlwr OF((char *s)); extern char *strlwr OF((char *s));
extern char *add_envopt OF((int *argcp, char ***argvp, char *env)); extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
extern void error OF((char *m));
extern void warn OF((char *a, char *b));
extern void read_error OF((void)); extern void read_error OF((void));
extern void write_error OF((void)); extern void write_error OF((void));
extern void display_ratio OF((long num, long den, FILE * file)); extern void display_ratio OF((long num, long den, FILE * file));
@ -1396,7 +1394,7 @@ int length;
(char *) window + start, length) != EQUAL) { (char *) window + start, length) != EQUAL) {
fprintf(stderr, fprintf(stderr,
" start %d, match %d, length %d\n", start, match, length); " start %d, match %d, length %d\n", start, match, length);
error("invalid match"); errorMsg("invalid match");
} }
if (verbose > 1) { if (verbose > 1) {
fprintf(stderr, "\\[%d,%d]", start - match, length); fprintf(stderr, "\\[%d,%d]", start - match, length);
@ -2916,7 +2914,7 @@ int eof; /* true if this is the last block for a file */
#endif #endif
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
if (buf == (char *) 0) if (buf == (char *) 0)
error("block vanished"); errorMsg("block vanished");
copy_block(buf, (unsigned) stored_len, 0); /* without header */ copy_block(buf, (unsigned) stored_len, 0); /* without header */
compressed_len = stored_len << 3; compressed_len = stored_len << 3;
@ -3099,7 +3097,7 @@ local void set_file_type()
bin_freq += dyn_ltree[n++].Freq; bin_freq += dyn_ltree[n++].Freq;
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
if (*file_type == BINARY && translate_eol) { if (*file_type == BINARY && translate_eol) {
warn("-l used on binary file", ""); errorMsg("-l used on binary file", "");
} }
} }
@ -3259,13 +3257,13 @@ char *env; /* name of environment variable */
nargv = (char **) calloc(*argcp + 1, sizeof(char *)); nargv = (char **) calloc(*argcp + 1, sizeof(char *));
if (nargv == NULL) if (nargv == NULL)
error("out of memory"); errorMsg("out of memory");
oargv = *argvp; oargv = *argvp;
*argvp = nargv; *argvp = nargv;
/* Copy the program name first */ /* Copy the program name first */
if (oargc-- < 0) if (oargc-- < 0)
error("argc<=0"); errorMsg("argc<=0");
*(nargv++) = *(oargv++); *(nargv++) = *(oargv++);
/* Then copy the environment args */ /* Then copy the environment args */

View File

@ -81,9 +81,7 @@ static int fileAction(const char *fileName, struct stat *statbuf)
case CHMOD_APP: case CHMOD_APP:
/* Parse the specified modes */ /* Parse the specified modes */
if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) { if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
fprintf(stderr, "%s: unknown mode: %s\n", invocationName, fatalError( "%s: unknown mode: %s\n", invocationName, theMode);
theMode);
exit(FALSE);
} }
if (chmod(fileName, statbuf->st_mode) == 0) if (chmod(fileName, statbuf->st_mode) == 0)
return (TRUE); return (TRUE);
@ -101,14 +99,13 @@ int chmod_chown_chgrp_main(int argc, char **argv)
const char *appUsage; const char *appUsage;
whichApp = whichApp =
(strcmp(*argv, "chown") == (strcmp(*argv, "chown") == 0)?
0) ? CHOWN_APP : (strcmp(*argv, CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
"chmod") == 0) ? CHMOD_APP : CHGRP_APP; CHMOD_APP : CHGRP_APP;
appUsage = appUsage =
(whichApp == CHOWN_APP) ? chown_usage : (whichApp == (whichApp == CHOWN_APP)?
CHMOD_APP) ? chmod_usage : chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
chgrp_usage;
if (argc < 2) if (argc < 2)
usage(appUsage); usage(appUsage);
@ -163,17 +160,15 @@ int chmod_chown_chgrp_main(int argc, char **argv)
if (*argv == p) if (*argv == p)
uid = my_getpwnam(*argv); uid = my_getpwnam(*argv);
if (uid == -1) { if (uid == -1) {
fprintf(stderr, "%s: unknown user name: %s\n", fatalError( "%s: unknown user name: %s\n",
invocationName, *argv); invocationName, *argv);
exit(FALSE);
} }
} }
} }
/* Ok, ready to do the deed now */ /* Ok, ready to do the deed now */
if (argc <= 1) { if (argc <= 1) {
fprintf(stderr, "%s: too few arguments\n", invocationName); fatalError( "%s: too few arguments\n", invocationName);
exit(FALSE);
} }
while (argc-- > 1) { while (argc-- > 1) {
if (recursiveAction if (recursiveAction
@ -184,7 +179,5 @@ int chmod_chown_chgrp_main(int argc, char **argv)
exit(TRUE); exit(TRUE);
bad_group: bad_group:
fprintf(stderr, "%s: unknown group name: %s\n", invocationName, fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
groupName);
exit(FALSE);
} }

View File

@ -72,6 +72,10 @@ static long du(char *filename)
du_depth++; du_depth++;
sum = statbuf.st_blocks; sum = statbuf.st_blocks;
/* Don't add in stuff pointed to by links */
if (S_ISLNK(statbuf.st_mode)) {
return 0;
}
if (S_ISDIR(statbuf.st_mode)) { if (S_ISDIR(statbuf.st_mode)) {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
@ -140,7 +144,7 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) { for (; i < argc; i++) {
sum = du(argv[i]); sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE))) { if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
print_normal(sum, argv[i]); print_normal(sum, argv[i]);
} }
} }
@ -149,4 +153,4 @@ int du_main(int argc, char **argv)
exit(0); exit(0);
} }
/* $Id: du.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */ /* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */

View File

@ -84,7 +84,7 @@ extern int ln_main(int argc, char **argv)
exit FALSE; exit FALSE;
} }
linkIntoDirFlag = isDirectory(linkName, TRUE); linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
if ((argc > 3) && !linkIntoDirFlag) { if ((argc > 3) && !linkIntoDirFlag) {
fprintf(stderr, not_a_directory, "ln", linkName); fprintf(stderr, not_a_directory, "ln", linkName);

View File

@ -29,10 +29,10 @@
* it more portable. * it more portable.
* *
* KNOWN BUGS: * KNOWN BUGS:
* 1. messy output if you mix files and directories on the command line * 1. ls -l of a directory doesn't give "total <blocks>" header
* 2. ls -l of a directory doesn't give "total <blocks>" header * 2. ls of a symlink to a directory doesn't list directory contents
* 3. ls of a symlink to a directory doesn't list directory contents * 3. hidden files can make column width too large
* 4. hidden files can make column width too large *
* NON-OPTIMAL BEHAVIOUR: * NON-OPTIMAL BEHAVIOUR:
* 1. autowidth reads directories twice * 1. autowidth reads directories twice
* 2. if you do a short directory listing without filetype characters * 2. if you do a short directory listing without filetype characters
@ -100,7 +100,9 @@ static unsigned short opts = 0;
static unsigned short column = 0; static unsigned short column = 0;
#ifdef BB_FEATURE_AUTOWIDTH #ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0; static unsigned short terminal_width = 0;
static unsigned short column_width = 0;
static unsigned short toplevel_column_width = 0;
#else #else
#define terminal_width TERMINAL_WIDTH #define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH #define column_width COLUMN_WIDTH
@ -349,6 +351,9 @@ static int list_item(const char *name)
goto listerr; goto listerr;
if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) { if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) {
#ifdef BB_FEATURE_AUTOWIDTH
column_width = toplevel_column_width;
#endif
list_single(name, &info, name); list_single(name, &info, name);
return 0; return 0;
} }
@ -407,6 +412,15 @@ static int list_item(const char *name)
list_single(entry->d_name, &info, fullname); list_single(entry->d_name, &info, fullname);
} }
closedir(dir); closedir(dir);
if (opts & DISP_DIRNAME) { /* separate the directory */
if (column) {
wr("\n", 1);
}
wr("\n", 1);
column = 0;
}
return 0; return 0;
direrr: direrr:
@ -530,8 +544,8 @@ extern int ls_main(int argc, char **argv)
for (i = argi; i < argc; i++) { for (i = argi; i < argc; i++) {
int len = strlen(argv[i]); int len = strlen(argv[i]);
if (column_width < len) if (toplevel_column_width < len)
column_width = len; toplevel_column_width = len;
} }
#endif #endif

View File

@ -1,5 +1,6 @@
/* vi: set sw=4 ts=4: */ /* vi: set sw=4 ts=4: */
#include "internal.h" #include "internal.h"
/* This file contains _two_ implementations of tail. One is /* This file contains _two_ implementations of tail. One is
* a bit more full featured, but costs 6k. The other (i.e. the * a bit more full featured, but costs 6k. The other (i.e. the
* SIMPLE_TAIL one) is less capable, but is good enough for about * SIMPLE_TAIL one) is less capable, but is good enough for about
@ -51,7 +52,7 @@
#define XWRITE(fd, buffer, n_bytes) \ #define XWRITE(fd, buffer, n_bytes) \
do { \ do { \
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \ if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
error("write error"); \ errorMsg("write error"); \
} while (0) } while (0)
/* Number of items to tail. */ /* Number of items to tail. */
@ -117,7 +118,7 @@ file_lines(const char *filename, int fd, long int n_lines, off_t pos)
lseek(fd, pos, SEEK_SET); lseek(fd, pos, SEEK_SET);
bytes_read = fullRead(fd, buffer, bytes_read); bytes_read = fullRead(fd, buffer, bytes_read);
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
/* Count the incomplete line on files that don't end with a newline. */ /* Count the incomplete line on files that don't end with a newline. */
if (bytes_read && buffer[bytes_read - 1] != '\n') if (bytes_read && buffer[bytes_read - 1] != '\n')
@ -147,7 +148,7 @@ file_lines(const char *filename, int fd, long int n_lines, off_t pos)
} }
while ((bytes_read = fullRead(fd, buffer, BUFSIZ)) > 0); while ((bytes_read = fullRead(fd, buffer, BUFSIZ)) > 0);
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
return 0; return 0;
} }
@ -209,7 +210,7 @@ static int pipe_lines(const char *filename, int fd, long int n_lines)
} }
} }
if (tmp->nbytes == -1) if (tmp->nbytes == -1)
error("read error"); errorMsg("read error");
free((char *) tmp); free((char *) tmp);
@ -272,7 +273,7 @@ static long dump_remainder(const char *filename, int fd)
total += bytes_read; total += bytes_read;
} }
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
if (forever) { if (forever) {
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
@ -294,7 +295,7 @@ static int tail_lines(const char *filename, int fd, long int n_lines)
write_header(filename); write_header(filename);
if (fstat(fd, &stats)) if (fstat(fd, &stats))
error("fstat error"); errorMsg("fstat error");
/* Use file_lines only if FD refers to a regular file with /* Use file_lines only if FD refers to a regular file with
its file pointer positioned at beginning of file. */ its file pointer positioned at beginning of file. */
@ -329,7 +330,7 @@ static int tail_file(const char *filename, off_t n_units)
/* Not standard input. */ /* Not standard input. */
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd == -1) if (fd == -1)
error("open error"); errorMsg("open error");
errors = tail_lines(filename, fd, (long) n_units); errors = tail_lines(filename, fd, (long) n_units);
close(fd); close(fd);

26
cp_mv.c
View File

@ -69,10 +69,12 @@ extern int cp_mv_main(int argc, char **argv)
const char *baseSrcName; const char *baseSrcName;
int srcDirFlag; int srcDirFlag;
struct stat srcStatBuf;
char baseDestName[PATH_MAX + 1]; char baseDestName[PATH_MAX + 1];
size_t baseDestLen; size_t baseDestLen;
int destDirFlag; int destDirFlag;
struct stat destStatBuf;
void fill_baseDest_buf(char *_buf, size_t * _buflen) { void fill_baseDest_buf(char *_buf, size_t * _buflen) {
const char *srcBasename; const char *srcBasename;
@ -91,7 +93,6 @@ extern int cp_mv_main(int argc, char **argv)
} }
int fileAction(const char *fileName, struct stat *statbuf) { int fileAction(const char *fileName, struct stat *statbuf) {
__label__ return_false;
char destName[PATH_MAX + 1]; char destName[PATH_MAX + 1];
size_t destLen; size_t destLen;
const char *srcBasename; const char *srcBasename;
@ -109,7 +110,7 @@ extern int cp_mv_main(int argc, char **argv)
if (destLen + strlen(srcBasename) > PATH_MAX) { if (destLen + strlen(srcBasename) > PATH_MAX) {
fprintf(stderr, name_too_long, "cp"); fprintf(stderr, name_too_long, "cp");
goto return_false; return FALSE;
} }
strcat(destName, srcBasename); strcat(destName, srcBasename);
} else if (destDirFlag == TRUE) { } else if (destDirFlag == TRUE) {
@ -118,9 +119,6 @@ extern int cp_mv_main(int argc, char **argv)
srcBasename = baseSrcName; srcBasename = baseSrcName;
} }
return copyFile(fileName, destName, preserveFlag, followLinks); return copyFile(fileName, destName, preserveFlag, followLinks);
return_false:
return FALSE;
} }
int rmfileAction(const char *fileName, struct stat *statbuf) { int rmfileAction(const char *fileName, struct stat *statbuf) {
@ -180,7 +178,6 @@ extern int cp_mv_main(int argc, char **argv)
argv++; argv++;
} }
} else { /* (dz_i == is_mv) */ } else { /* (dz_i == is_mv) */
recursiveFlag = preserveFlag = TRUE; recursiveFlag = preserveFlag = TRUE;
followLinks = FALSE; followLinks = FALSE;
} }
@ -194,7 +191,7 @@ extern int cp_mv_main(int argc, char **argv)
if (baseDestLen == 0) if (baseDestLen == 0)
goto exit_false; goto exit_false;
destDirFlag = isDirectory(baseDestName, TRUE); destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf);
if ((argc > 3) && destDirFlag == FALSE) { if ((argc > 3) && destDirFlag == FALSE) {
fprintf(stderr, not_a_directory, "cp", baseDestName); fprintf(stderr, not_a_directory, "cp", baseDestName);
goto exit_false; goto exit_false;
@ -212,11 +209,18 @@ extern int cp_mv_main(int argc, char **argv)
if (srcLen == 0) if (srcLen == 0)
continue; continue;
srcDirFlag = isDirectory(baseSrcName, followLinks); srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
if ((flags_memo = (recursiveFlag == TRUE && if ((flags_memo = (recursiveFlag == TRUE &&
srcDirFlag == TRUE && destDirFlag == TRUE))) { srcDirFlag == TRUE && destDirFlag == TRUE))) {
fill_baseDest_buf(&baseDestName[0], &baseDestLen); if ((destStatBuf.st_ino == srcStatBuf.st_ino) &&
(destStatBuf.st_rdev == srcStatBuf.st_rdev)) {
fprintf(stderr,
"%s: Cannot %s `%s' into a subdirectory of itself, `%s/%s'\n",
dz, dz, baseSrcName, baseDestName, baseSrcName);
continue;
}
fill_baseDest_buf(baseDestName, &baseDestLen);
} }
if (recursiveAction(baseSrcName, if (recursiveAction(baseSrcName,
recursiveFlag, followLinks, FALSE, recursiveFlag, followLinks, FALSE,
@ -242,6 +246,6 @@ extern int cp_mv_main(int argc, char **argv)
} }
// Local Variables: // Local Variables:
// c-file-style: "k&r" // c-file-style: "linux"
// c-basic-offset: 4 // tab-width: 4
// End: // End:

8
du.c
View File

@ -72,6 +72,10 @@ static long du(char *filename)
du_depth++; du_depth++;
sum = statbuf.st_blocks; sum = statbuf.st_blocks;
/* Don't add in stuff pointed to by links */
if (S_ISLNK(statbuf.st_mode)) {
return 0;
}
if (S_ISDIR(statbuf.st_mode)) { if (S_ISDIR(statbuf.st_mode)) {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
@ -140,7 +144,7 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) { for (; i < argc; i++) {
sum = du(argv[i]); sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE))) { if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
print_normal(sum, argv[i]); print_normal(sum, argv[i]);
} }
} }
@ -149,4 +153,4 @@ int du_main(int argc, char **argv)
exit(0); exit(0);
} }
/* $Id: du.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */ /* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */

View File

@ -194,7 +194,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array # define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \ # define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) error("insufficient memory"); \ if (array == NULL) errorMsg("insufficient memory"); \
} }
# define FREE(array) {if (array != NULL) free(array), array=NULL;} # define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else #else
@ -311,7 +311,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);} # define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x # define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;} # define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;} # define Tracevv(x) {if (verbose>1) fprintf x ;}
@ -367,8 +367,6 @@ extern void write_buf OF((int fd, voidp buf, unsigned cnt));
#ifndef __linux__ #ifndef __linux__
extern char *basename OF((char *fname)); extern char *basename OF((char *fname));
#endif /* not __linux__ */ #endif /* not __linux__ */
extern void error OF((char *m));
extern void warn OF((char *a, char *b));
extern void read_error OF((void)); extern void read_error OF((void));
extern void write_error OF((void)); extern void write_error OF((void));
@ -1045,13 +1043,13 @@ int in, out; /* input and output file descriptors */
int res = inflate(); int res = inflate();
if (res == 3) { if (res == 3) {
error("out of memory"); errorMsg("out of memory");
} else if (res != 0) { } else if (res != 0) {
error("invalid compressed data--format violated"); errorMsg("invalid compressed data--format violated");
} }
} else { } else {
error("internal error, invalid method"); errorMsg("internal error, invalid method");
} }
/* Get the crc and original length */ /* Get the crc and original length */
@ -1080,10 +1078,10 @@ int in, out; /* input and output file descriptors */
/* Validate decompression */ /* Validate decompression */
if (orig_crc != updcrc(outbuf, 0)) { if (orig_crc != updcrc(outbuf, 0)) {
error("invalid compressed data--crc error"); errorMsg("invalid compressed data--crc error");
} }
if (orig_len != (ulg) bytes_out) { if (orig_len != (ulg) bytes_out) {
error("invalid compressed data--length error"); errorMsg("invalid compressed data--length error");
} }
/* Check if there are more entries in a pkzip file */ /* Check if there are more entries in a pkzip file */

16
gzip.c
View File

@ -125,7 +125,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * near array # define DECLARE(type, array, size) type * near array
# define ALLOC(type, array, size) { \ # define ALLOC(type, array, size) { \
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) error("insufficient memory"); \ if (array == NULL) errorMsg("insufficient memory"); \
} }
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;} # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
#else #else
@ -262,7 +262,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);} # define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x # define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;} # define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;} # define Tracevv(x) {if (verbose>1) fprintf x ;}
@ -327,8 +327,6 @@ extern void flush_window OF((void));
extern void write_buf OF((int fd, voidp buf, unsigned cnt)); extern void write_buf OF((int fd, voidp buf, unsigned cnt));
extern char *strlwr OF((char *s)); extern char *strlwr OF((char *s));
extern char *add_envopt OF((int *argcp, char ***argvp, char *env)); extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
extern void error OF((char *m));
extern void warn OF((char *a, char *b));
extern void read_error OF((void)); extern void read_error OF((void));
extern void write_error OF((void)); extern void write_error OF((void));
extern void display_ratio OF((long num, long den, FILE * file)); extern void display_ratio OF((long num, long den, FILE * file));
@ -1396,7 +1394,7 @@ int length;
(char *) window + start, length) != EQUAL) { (char *) window + start, length) != EQUAL) {
fprintf(stderr, fprintf(stderr,
" start %d, match %d, length %d\n", start, match, length); " start %d, match %d, length %d\n", start, match, length);
error("invalid match"); errorMsg("invalid match");
} }
if (verbose > 1) { if (verbose > 1) {
fprintf(stderr, "\\[%d,%d]", start - match, length); fprintf(stderr, "\\[%d,%d]", start - match, length);
@ -2916,7 +2914,7 @@ int eof; /* true if this is the last block for a file */
#endif #endif
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
if (buf == (char *) 0) if (buf == (char *) 0)
error("block vanished"); errorMsg("block vanished");
copy_block(buf, (unsigned) stored_len, 0); /* without header */ copy_block(buf, (unsigned) stored_len, 0); /* without header */
compressed_len = stored_len << 3; compressed_len = stored_len << 3;
@ -3099,7 +3097,7 @@ local void set_file_type()
bin_freq += dyn_ltree[n++].Freq; bin_freq += dyn_ltree[n++].Freq;
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
if (*file_type == BINARY && translate_eol) { if (*file_type == BINARY && translate_eol) {
warn("-l used on binary file", ""); errorMsg("-l used on binary file", "");
} }
} }
@ -3259,13 +3257,13 @@ char *env; /* name of environment variable */
nargv = (char **) calloc(*argcp + 1, sizeof(char *)); nargv = (char **) calloc(*argcp + 1, sizeof(char *));
if (nargv == NULL) if (nargv == NULL)
error("out of memory"); errorMsg("out of memory");
oargv = *argvp; oargv = *argvp;
*argvp = nargv; *argvp = nargv;
/* Copy the program name first */ /* Copy the program name first */
if (oargc-- < 0) if (oargc-- < 0)
error("argc<=0"); errorMsg("argc<=0");
*(nargv++) = *(oargv++); *(nargv++) = *(oargv++);
/* Then copy the environment args */ /* Then copy the environment args */

View File

@ -2,7 +2,7 @@
set -e set -e
if [ "$1" == "" ]; then if [ "$1" = "" ]; then
echo "No installation directory, aborting." echo "No installation directory, aborting."
exit 1; exit 1;
fi fi

View File

@ -144,9 +144,13 @@ extern int whoami_main(int argc, char** argv);
extern int yes_main(int argc, char** argv); extern int yes_main(int argc, char** argv);
extern void usage(const char *usage) __attribute__ ((noreturn));
extern void errorMsg(char *s, ...);
extern void fatalError(char *s, ...) __attribute__ ((noreturn));
const char *modeString(int mode); const char *modeString(int mode);
const char *timeString(time_t timeVal); const char *timeString(time_t timeVal);
int isDirectory(const char *name, const int followLinks); int isDirectory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name); int isDevice(const char *name);
int copyFile(const char *srcName, const char *destName, int setModes, int copyFile(const char *srcName, const char *destName, int setModes,
int followLinks); int followLinks);
@ -164,7 +168,6 @@ const char* timeString(time_t timeVal);
extern int createPath (const char *name, int mode); extern int createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode); extern int parse_mode( const char* s, mode_t* theMode);
extern void usage(const char *usage) __attribute__ ((noreturn));
extern uid_t my_getpwnam(char *name); extern uid_t my_getpwnam(char *name);
extern gid_t my_getgrnam(char *name); extern gid_t my_getgrnam(char *name);
@ -184,6 +187,7 @@ extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern); extern int check_wildcard_match(const char* text, const char* pattern);
extern long getNum (const char *cp); extern long getNum (const char *cp);
extern pid_t findInitPid(); extern pid_t findInitPid();
extern void *xmalloc (size_t size);
#if defined BB_INIT || defined BB_SYSLOGD #if defined BB_INIT || defined BB_SYSLOGD
extern int device_open(char *device, int mode); extern int device_open(char *device, int mode);
#endif #endif
@ -195,10 +199,6 @@ extern int set_loop(const char *device, const char *file, int offset, int *loopr
extern char *find_unused_loop_device (void); extern char *find_unused_loop_device (void);
#endif #endif
#if defined BB_GUNZIP || defined BB_GZIP || defined BB_PRINTF || defined BB_TAIL
extern void *xmalloc (size_t size);
extern void error(char *msg);
#endif
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap); extern int vdprintf(int d, const char *format, va_list ap);

2
ln.c
View File

@ -84,7 +84,7 @@ extern int ln_main(int argc, char **argv)
exit FALSE; exit FALSE;
} }
linkIntoDirFlag = isDirectory(linkName, TRUE); linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
if ((argc > 3) && !linkIntoDirFlag) { if ((argc > 3) && !linkIntoDirFlag) {
fprintf(stderr, not_a_directory, "ln", linkName); fprintf(stderr, not_a_directory, "ln", linkName);

28
ls.c
View File

@ -29,10 +29,10 @@
* it more portable. * it more portable.
* *
* KNOWN BUGS: * KNOWN BUGS:
* 1. messy output if you mix files and directories on the command line * 1. ls -l of a directory doesn't give "total <blocks>" header
* 2. ls -l of a directory doesn't give "total <blocks>" header * 2. ls of a symlink to a directory doesn't list directory contents
* 3. ls of a symlink to a directory doesn't list directory contents * 3. hidden files can make column width too large
* 4. hidden files can make column width too large *
* NON-OPTIMAL BEHAVIOUR: * NON-OPTIMAL BEHAVIOUR:
* 1. autowidth reads directories twice * 1. autowidth reads directories twice
* 2. if you do a short directory listing without filetype characters * 2. if you do a short directory listing without filetype characters
@ -100,7 +100,9 @@ static unsigned short opts = 0;
static unsigned short column = 0; static unsigned short column = 0;
#ifdef BB_FEATURE_AUTOWIDTH #ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0; static unsigned short terminal_width = 0;
static unsigned short column_width = 0;
static unsigned short toplevel_column_width = 0;
#else #else
#define terminal_width TERMINAL_WIDTH #define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH #define column_width COLUMN_WIDTH
@ -349,6 +351,9 @@ static int list_item(const char *name)
goto listerr; goto listerr;
if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) { if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) {
#ifdef BB_FEATURE_AUTOWIDTH
column_width = toplevel_column_width;
#endif
list_single(name, &info, name); list_single(name, &info, name);
return 0; return 0;
} }
@ -407,6 +412,15 @@ static int list_item(const char *name)
list_single(entry->d_name, &info, fullname); list_single(entry->d_name, &info, fullname);
} }
closedir(dir); closedir(dir);
if (opts & DISP_DIRNAME) { /* separate the directory */
if (column) {
wr("\n", 1);
}
wr("\n", 1);
column = 0;
}
return 0; return 0;
direrr: direrr:
@ -530,8 +544,8 @@ extern int ls_main(int argc, char **argv)
for (i = argi; i < argc; i++) { for (i = argi; i < argc; i++) {
int len = strlen(argv[i]); int len = strlen(argv[i]);
if (column_width < len) if (toplevel_column_width < len)
column_width = len; toplevel_column_width = len;
} }
#endif #endif

View File

@ -219,29 +219,6 @@ static void warn(char *s, ...)
va_end(p); va_end(p);
} }
static void error(char *s, ...)
{
va_list p;
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n" PROGNAME ": ");
vfprintf(stderr, s, p);
va_end(p);
}
static void fatal(char *s, ...)
{
va_list p;
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n" PROGNAME ": ");
vfprintf(stderr, s, p);
va_end(p);
exit(1);
}
/* /*
* A. About seeking * A. About seeking
*/ */
@ -273,12 +250,12 @@ static int sseek(char *dev, unsigned int fd, unsigned long s)
if ((out = lseek(fd, in, SEEK_SET)) != in) { if ((out = lseek(fd, in, SEEK_SET)) != in) {
#endif #endif
perror("llseek"); perror("llseek");
error("seek error on %s - cannot seek to %lu\n", dev, s); errorMsg("seek error on %s - cannot seek to %lu\n", dev, s, FALSE);
return 0; return 0;
} }
if (in != out) { if (in != out) {
error("seek error: wanted 0x%08x%08x, got 0x%08x%08x\n", errorMsg("seek error: wanted 0x%08x%08x, got 0x%08x%08x\n",
(uint) (in >> 32), (uint) (in & 0xffffffff), (uint) (in >> 32), (uint) (in & 0xffffffff),
(uint) (out >> 32), (uint) (out & 0xffffffff)); (uint) (out >> 32), (uint) (out & 0xffffffff));
return 0; return 0;
@ -324,11 +301,11 @@ static struct sector *get_sector(char *dev, int fd, unsigned long sno)
return 0; return 0;
if (!(s = (struct sector *) malloc(sizeof(struct sector)))) if (!(s = (struct sector *) malloc(sizeof(struct sector))))
fatal("out of memory - giving up\n"); fatalError("out of memory - giving up\n");
if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) { if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
perror("read"); perror("read");
error("read error on %s - cannot read sector %lu\n", dev, sno); errorMsg("read error on %s - cannot read sector %lu\n", dev, sno);
free(s); free(s);
return 0; return 0;
} }
@ -344,7 +321,7 @@ static struct sector *get_sector(char *dev, int fd, unsigned long sno)
static int msdos_signature(struct sector *s) static int msdos_signature(struct sector *s)
{ {
if (*(unsigned short *) (s->data + 0x1fe) != 0xaa55) { if (*(unsigned short *) (s->data + 0x1fe) != 0xaa55) {
error("ERROR: sector %lu does not have an msdos signature\n", errorMsg("ERROR: sector %lu does not have an msdos signature\n",
s->sectornumber); s->sectornumber);
return 0; return 0;
} }
@ -361,7 +338,7 @@ static int write_sectors(char *dev, int fd)
return 0; return 0;
if (write(fd, s->data, sizeof(s->data)) != sizeof(s->data)) { if (write(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
perror("write"); perror("write");
error("write error on %s - cannot write sector %lu\n", errorMsg("write error on %s - cannot write sector %lu\n",
dev, s->sectornumber); dev, s->sectornumber);
return 0; return 0;
} }
@ -399,7 +376,7 @@ static int save_sectors(char *dev, int fdin)
fdout = open(save_sector_file, O_WRONLY | O_CREAT, 0444); fdout = open(save_sector_file, O_WRONLY | O_CREAT, 0444);
if (fdout < 0) { if (fdout < 0) {
perror(save_sector_file); perror(save_sector_file);
error("cannot open partition sector save file (%s)\n", errorMsg("cannot open partition sector save file (%s)\n",
save_sector_file); save_sector_file);
return 0; return 0;
} }
@ -411,13 +388,13 @@ static int save_sectors(char *dev, int fdin)
return 0; return 0;
if (read(fdin, ss + 4, 512) != 512) { if (read(fdin, ss + 4, 512) != 512) {
perror("read"); perror("read");
error("read error on %s - cannot read sector %lu\n", errorMsg("read error on %s - cannot read sector %lu\n",
dev, s->sectornumber); dev, s->sectornumber);
return 0; return 0;
} }
if (write(fdout, ss, sizeof(ss)) != sizeof(ss)) { if (write(fdout, ss, sizeof(ss)) != sizeof(ss)) {
perror("write"); perror("write");
error("write error on %s\n"), save_sector_file; errorMsg("write error on %s\n"), save_sector_file;
return 0; return 0;
} }
} }
@ -435,35 +412,35 @@ static int restore_sectors(char *dev)
if (stat(restore_sector_file, &statbuf) < 0) { if (stat(restore_sector_file, &statbuf) < 0) {
perror(restore_sector_file); perror(restore_sector_file);
error("cannot stat partition restore file (%s)\n", errorMsg("cannot stat partition restore file (%s)\n",
restore_sector_file); restore_sector_file);
return 0; return 0;
} }
if (statbuf.st_size % 516) { if (statbuf.st_size % 516) {
error("partition restore file has wrong size - not restoring\n"); errorMsg("partition restore file has wrong size - not restoring\n");
return 0; return 0;
} }
if (!(ss = (char *) malloc(statbuf.st_size))) { if (!(ss = (char *) malloc(statbuf.st_size))) {
error("out of memory?\n"); errorMsg("out of memory?\n");
return 0; return 0;
} }
fdin = open(restore_sector_file, O_RDONLY); fdin = open(restore_sector_file, O_RDONLY);
if (fdin < 0) { if (fdin < 0) {
perror(restore_sector_file); perror(restore_sector_file);
error("cannot open partition restore file (%s)\n", errorMsg("cannot open partition restore file (%s)\n",
restore_sector_file); restore_sector_file);
return 0; return 0;
} }
if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) { if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) {
perror("read"); perror("read");
error("error reading %s\n"), restore_sector_file; errorMsg("error reading %s\n"), restore_sector_file;
return 0; return 0;
} }
fdout = open(dev, O_WRONLY); fdout = open(dev, O_WRONLY);
if (fdout < 0) { if (fdout < 0) {
perror(dev); perror(dev);
error("cannot open device %s for writing\n"), dev; errorMsg("cannot open device %s for writing\n"), dev;
return 0; return 0;
} }
@ -475,7 +452,7 @@ static int restore_sectors(char *dev)
return 0; return 0;
if (write(fdout, ss + 4, 512) != 512) { if (write(fdout, ss + 4, 512) != 512) {
perror(dev); perror(dev);
error("error writing sector %lu on %s\n", sno, dev); errorMsg("error writing sector %lu on %s\n", sno, dev);
return 0; return 0;
} }
ss += 516; ss += 516;
@ -905,7 +882,7 @@ static int asc_to_index(char *pnam, struct disk_desc *z)
pno = linux_to_index(pnum, z); pno = linux_to_index(pnum, z);
} }
if (!(pno >= 0 && pno < z->partno)) if (!(pno >= 0 && pno < z->partno))
fatal("%s: no such partition\n"), pnam; fatalError("%s: no such partition\n"), pnam;
return pno; return pno;
} }
@ -1233,9 +1210,9 @@ static int partitions_ok(struct disk_desc *z)
/* Have at least 4 partitions been defined? */ /* Have at least 4 partitions been defined? */
if (partno < 4) { if (partno < 4) {
if (!partno) if (!partno)
fatal("no partition table present.\n"); fatalError("no partition table present.\n");
else else
fatal("strange, only %d partitions defined.\n"), partno; fatalError("strange, only %d partitions defined.\n"), partno;
return 0; return 0;
} }
@ -1680,12 +1657,12 @@ static int write_partitions(char *dev, int fd, struct disk_desc *z)
} }
if (save_sector_file) { if (save_sector_file) {
if (!save_sectors(dev, fd)) { if (!save_sectors(dev, fd)) {
fatal("Failed saving the old sectors - aborting\n"); fatalError("Failed saving the old sectors - aborting\n");
return 0; return 0;
} }
} }
if (!write_sectors(dev, fd)) { if (!write_sectors(dev, fd)) {
error("Failed writing the partition on %s\n"), dev; errorMsg("Failed writing the partition on %s\n"), dev;
return 0; return 0;
} }
return 1; return 1;
@ -1765,7 +1742,7 @@ read_stdin(unsigned char **fields, unsigned char *line, int fieldssize,
return RD_EOF; return RD_EOF;
} }
if (!(lp = index(lp, '\n'))) if (!(lp = index(lp, '\n')))
fatal("long or incomplete input line - quitting\n"); fatalError("long or incomplete input line - quitting\n");
*lp = 0; *lp = 0;
/* remove comments, if any */ /* remove comments, if any */
@ -1801,21 +1778,21 @@ read_stdin(unsigned char **fields, unsigned char *line, int fieldssize,
while (isalnum(*ip)) /* 0x07FF */ while (isalnum(*ip)) /* 0x07FF */
ip++; ip++;
} else } else
fatal("input error: `=' expected after %s field\n", fatalError("input error: `=' expected after %s field\n",
d->fldname); d->fldname);
if (fno <= d->fldno) if (fno <= d->fldno)
fno = d->fldno + 1; fno = d->fldno + 1;
if (*ip == 0) if (*ip == 0)
return fno; return fno;
if (*ip != ',' && *ip != ';') if (*ip != ',' && *ip != ';')
fatal fatalError
("input error: unexpected character %c after %s field\n", ("input error: unexpected character %c after %s field\n",
*ip, d->fldname); *ip, d->fldname);
*ip = 0; *ip = 0;
goto nxtfld; goto nxtfld;
} }
} }
fatal("unrecognized input: %s\n"), ip; fatalError("unrecognized input: %s\n"), ip;
} }
/* split line into fields */ /* split line into fields */
@ -2251,7 +2228,7 @@ read_partition(char *dev, int interactive, int pno, struct part_desc *ep,
while (!(i = read_line(pno, ep, dev, interactive, z))) while (!(i = read_line(pno, ep, dev, interactive, z)))
if (!interactive) if (!interactive)
fatal("bad input\n"); fatalError("bad input\n");
if (i < 0) { if (i < 0) {
p->ep = ep; p->ep = ep;
return 0; return 0;
@ -2612,19 +2589,19 @@ extern int sfdisk_main(int argc, char **argv)
} }
if (do_id) { if (do_id) {
if ((do_id & PRINT_ID) != 0 && optind != argc - 2) if ((do_id & PRINT_ID) != 0 && optind != argc - 2)
fatal("usage: sfdisk --print-id device partition-number\n"); fatalError("usage: sfdisk --print-id device partition-number\n");
else if ((do_id & CHANGE_ID) != 0 && optind != argc - 3) else if ((do_id & CHANGE_ID) != 0 && optind != argc - 3)
fatal fatalError
("usage: sfdisk --change-id device partition-number Id\n"); ("usage: sfdisk --change-id device partition-number Id\n");
else if (optind != argc - 3 && optind != argc - 2) else if (optind != argc - 3 && optind != argc - 2)
fatal("usage: sfdisk --id device partition-number [Id]\n"); fatalError("usage: sfdisk --id device partition-number [Id]\n");
do_change_id(argv[optind], argv[optind + 1], do_change_id(argv[optind], argv[optind + 1],
(optind == argc - 2) ? 0 : argv[optind + 2]); (optind == argc - 2) ? 0 : argv[optind + 2]);
exit(exit_status); exit(exit_status);
} }
if (optind != argc - 1) if (optind != argc - 1)
fatal("can specify only one device (except with -l or -s)\n"); fatalError("can specify only one device (except with -l or -s)\n");
dev = argv[optind]; dev = argv[optind];
if (opt_reread) if (opt_reread)
@ -2649,7 +2626,7 @@ static int my_open(char *dev, int rw, int silent)
fd = open(dev, mode); fd = open(dev, mode);
if (fd < 0 && !silent) { if (fd < 0 && !silent) {
perror(dev); perror(dev);
fatal("cannot open %s %s\n", dev, fatalError("cannot open %s %s\n", dev,
rw ? "read-write" : "for reading"); rw ? "read-write" : "for reading");
} }
return fd; return fd;
@ -2711,7 +2688,7 @@ static void do_size(char *dev, int silent)
if (ioctl(fd, BLKGETSIZE, &size)) { if (ioctl(fd, BLKGETSIZE, &size)) {
if (!silent) { if (!silent) {
perror(dev); perror(dev);
fatal("BLKGETSIZE ioctl failed for %s\n"), dev; fatalError("BLKGETSIZE ioctl failed for %s\n"), dev;
} }
return; return;
} }
@ -2831,7 +2808,7 @@ static void set_unhidden(struct disk_desc *z, char *pnam)
if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17) if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17)
id -= 0x10; id -= 0x10;
else else
fatal("partition %s has id %x and is not hidden\n", pnam, id); fatalError("partition %s has id %x and is not hidden\n", pnam, id);
z->partitions[pno].p.sys_type = id; z->partitions[pno].p.sys_type = id;
} }
@ -2889,7 +2866,7 @@ static void do_change_id(char *dev, char *pnam, char *id)
} }
i = strtoul(id, NULL, 16); i = strtoul(id, NULL, 16);
if (i > 255) if (i > 255)
fatal("Bad Id %x\n"), i; fatalError("Bad Id %x\n"), i;
z->partitions[pno].p.sys_type = i; z->partitions[pno].p.sys_type = i;
if (write_partitions(dev, fd, z)) if (write_partitions(dev, fd, z))
@ -2921,7 +2898,7 @@ static void do_fdisk(char *dev)
if (stat(dev, &statbuf) < 0) { if (stat(dev, &statbuf) < 0) {
perror(dev); perror(dev);
fatal("Fatal error: cannot find %s\n"), dev; fatalError("Fatal error: cannot find %s\n"), dev;
} }
if (!S_ISBLK(statbuf.st_mode)) { if (!S_ISBLK(statbuf.st_mode)) {
warn("Warning: %s is not a block device\n"), dev; warn("Warning: %s is not a block device\n"), dev;
@ -2954,7 +2931,7 @@ static void do_fdisk(char *dev)
out_partitions(dev, z); out_partitions(dev, z);
if (one_only && (one_only_pno = linux_to_index(one_only, z)) < 0) if (one_only && (one_only_pno = linux_to_index(one_only, z)) < 0)
fatal("Partition %d does not exist, cannot change it\n"), one_only; fatalError("Partition %d does not exist, cannot change it\n"), one_only;
z = &newp; z = &newp;
@ -2967,7 +2944,7 @@ static void do_fdisk(char *dev)
if (!partitions_ok(z) && !force) { if (!partitions_ok(z) && !force) {
if (!interactive) if (!interactive)
fatal("I don't like these partitions - nothing changed.\n" fatalError("I don't like these partitions - nothing changed.\n"
"(If you really want this, use the --force option.)\n"); "(If you really want this, use the --force option.)\n");
else else
printf printf
@ -2985,7 +2962,7 @@ static void do_fdisk(char *dev)
if (c == EOF) if (c == EOF)
printf("\nsfdisk: premature end of input\n"); printf("\nsfdisk: premature end of input\n");
if (c == EOF || answer == 'q' || answer == 'Q') { if (c == EOF || answer == 'q' || answer == 'Q') {
fatal("Quitting - nothing changed\n"); fatalError("Quitting - nothing changed\n");
} else if (answer == 'n' || answer == 'N') { } else if (answer == 'n' || answer == 'N') {
continue; continue;
} else if (answer == 'y' || answer == 'Y') { } else if (answer == 'y' || answer == 'Y') {

View File

@ -110,17 +110,19 @@ static void logMessage(int pri, char *msg)
{ {
time_t now; time_t now;
char *timestamp; char *timestamp;
static char res[20]; static char res[20] = "";
CODE *c_pri, *c_fac; CODE *c_pri, *c_fac;
for (c_fac = facilitynames; if (pri != 0) {
c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++); for (c_fac = facilitynames;
for (c_pri = prioritynames; c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++); for (c_pri = prioritynames;
if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0') c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
snprintf(res, sizeof(res), "<%d>", pri); if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
else snprintf(res, sizeof(res), "<%d>", pri);
snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name); else
snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
}
if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' || if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
@ -141,17 +143,11 @@ static void logMessage(int pri, char *msg)
static void quit_signal(int sig) static void quit_signal(int sig)
{ {
logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); logMessage(0, "System log daemon exiting.");
unlink(_PATH_LOG); unlink(_PATH_LOG);
exit(TRUE); exit(TRUE);
} }
static void restart_signal(int sig)
{
/* pretend to restart */
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd restarting");
}
static void domark(int sig) static void domark(int sig)
{ {
if (MarkInterval > 0) { if (MarkInterval > 0) {
@ -173,8 +169,8 @@ static void doSyslogd(void)
signal(SIGINT, quit_signal); signal(SIGINT, quit_signal);
signal(SIGTERM, quit_signal); signal(SIGTERM, quit_signal);
signal(SIGQUIT, quit_signal); signal(SIGQUIT, quit_signal);
signal(SIGHUP, restart_signal);
signal(SIGALRM, domark); signal(SIGALRM, domark);
signal(SIGHUP, SIG_IGN);
alarm(MarkInterval); alarm(MarkInterval);
/* Remove any preexisting socket/file */ /* Remove any preexisting socket/file */
@ -201,8 +197,7 @@ static void doSyslogd(void)
exit(FALSE); exit(FALSE);
} }
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " logMessage(0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
"BusyBox v" BB_VER " (" BB_BT ")");
while ((conn = accept(fd, (struct sockaddr *) &sunx, while ((conn = accept(fd, (struct sockaddr *) &sunx,
@ -251,7 +246,7 @@ static void klogd_signal(int sig)
{ {
ksyslog(7, NULL, 0); ksyslog(7, NULL, 0);
ksyslog(0, 0, 0); ksyslog(0, 0, 0);
logMessage(LOG_SYSLOG | LOG_INFO, "Kernel log daemon exiting."); logMessage(0, "Kernel log daemon exiting.");
exit(TRUE); exit(TRUE);
} }
@ -265,8 +260,8 @@ static void doKlogd(void)
signal(SIGINT, klogd_signal); signal(SIGINT, klogd_signal);
signal(SIGKILL, klogd_signal); signal(SIGKILL, klogd_signal);
signal(SIGTERM, klogd_signal); signal(SIGTERM, klogd_signal);
signal(SIGHUP, klogd_signal); signal(SIGHUP, SIG_IGN);
logMessage(LOG_SYSLOG | LOG_INFO, "klogd started: " logMessage(0, "klogd started: "
"BusyBox v" BB_VER " (" BB_BT ")"); "BusyBox v" BB_VER " (" BB_BT ")");
ksyslog(1, NULL, 0); ksyslog(1, NULL, 0);

View File

@ -110,17 +110,19 @@ static void logMessage(int pri, char *msg)
{ {
time_t now; time_t now;
char *timestamp; char *timestamp;
static char res[20]; static char res[20] = "";
CODE *c_pri, *c_fac; CODE *c_pri, *c_fac;
for (c_fac = facilitynames; if (pri != 0) {
c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++); for (c_fac = facilitynames;
for (c_pri = prioritynames; c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++); for (c_pri = prioritynames;
if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0') c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
snprintf(res, sizeof(res), "<%d>", pri); if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
else snprintf(res, sizeof(res), "<%d>", pri);
snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name); else
snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
}
if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' || if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
@ -141,17 +143,11 @@ static void logMessage(int pri, char *msg)
static void quit_signal(int sig) static void quit_signal(int sig)
{ {
logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); logMessage(0, "System log daemon exiting.");
unlink(_PATH_LOG); unlink(_PATH_LOG);
exit(TRUE); exit(TRUE);
} }
static void restart_signal(int sig)
{
/* pretend to restart */
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd restarting");
}
static void domark(int sig) static void domark(int sig)
{ {
if (MarkInterval > 0) { if (MarkInterval > 0) {
@ -173,8 +169,8 @@ static void doSyslogd(void)
signal(SIGINT, quit_signal); signal(SIGINT, quit_signal);
signal(SIGTERM, quit_signal); signal(SIGTERM, quit_signal);
signal(SIGQUIT, quit_signal); signal(SIGQUIT, quit_signal);
signal(SIGHUP, restart_signal);
signal(SIGALRM, domark); signal(SIGALRM, domark);
signal(SIGHUP, SIG_IGN);
alarm(MarkInterval); alarm(MarkInterval);
/* Remove any preexisting socket/file */ /* Remove any preexisting socket/file */
@ -201,8 +197,7 @@ static void doSyslogd(void)
exit(FALSE); exit(FALSE);
} }
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " logMessage(0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
"BusyBox v" BB_VER " (" BB_BT ")");
while ((conn = accept(fd, (struct sockaddr *) &sunx, while ((conn = accept(fd, (struct sockaddr *) &sunx,
@ -251,7 +246,7 @@ static void klogd_signal(int sig)
{ {
ksyslog(7, NULL, 0); ksyslog(7, NULL, 0);
ksyslog(0, 0, 0); ksyslog(0, 0, 0);
logMessage(LOG_SYSLOG | LOG_INFO, "Kernel log daemon exiting."); logMessage(0, "Kernel log daemon exiting.");
exit(TRUE); exit(TRUE);
} }
@ -265,8 +260,8 @@ static void doKlogd(void)
signal(SIGINT, klogd_signal); signal(SIGINT, klogd_signal);
signal(SIGKILL, klogd_signal); signal(SIGKILL, klogd_signal);
signal(SIGTERM, klogd_signal); signal(SIGTERM, klogd_signal);
signal(SIGHUP, klogd_signal); signal(SIGHUP, SIG_IGN);
logMessage(LOG_SYSLOG | LOG_INFO, "klogd started: " logMessage(0, "klogd started: "
"BusyBox v" BB_VER " (" BB_BT ")"); "BusyBox v" BB_VER " (" BB_BT ")");
ksyslog(1, NULL, 0); ksyslog(1, NULL, 0);

15
tail.c
View File

@ -1,5 +1,6 @@
/* vi: set sw=4 ts=4: */ /* vi: set sw=4 ts=4: */
#include "internal.h" #include "internal.h"
/* This file contains _two_ implementations of tail. One is /* This file contains _two_ implementations of tail. One is
* a bit more full featured, but costs 6k. The other (i.e. the * a bit more full featured, but costs 6k. The other (i.e. the
* SIMPLE_TAIL one) is less capable, but is good enough for about * SIMPLE_TAIL one) is less capable, but is good enough for about
@ -51,7 +52,7 @@
#define XWRITE(fd, buffer, n_bytes) \ #define XWRITE(fd, buffer, n_bytes) \
do { \ do { \
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \ if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
error("write error"); \ errorMsg("write error"); \
} while (0) } while (0)
/* Number of items to tail. */ /* Number of items to tail. */
@ -117,7 +118,7 @@ file_lines(const char *filename, int fd, long int n_lines, off_t pos)
lseek(fd, pos, SEEK_SET); lseek(fd, pos, SEEK_SET);
bytes_read = fullRead(fd, buffer, bytes_read); bytes_read = fullRead(fd, buffer, bytes_read);
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
/* Count the incomplete line on files that don't end with a newline. */ /* Count the incomplete line on files that don't end with a newline. */
if (bytes_read && buffer[bytes_read - 1] != '\n') if (bytes_read && buffer[bytes_read - 1] != '\n')
@ -147,7 +148,7 @@ file_lines(const char *filename, int fd, long int n_lines, off_t pos)
} }
while ((bytes_read = fullRead(fd, buffer, BUFSIZ)) > 0); while ((bytes_read = fullRead(fd, buffer, BUFSIZ)) > 0);
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
return 0; return 0;
} }
@ -209,7 +210,7 @@ static int pipe_lines(const char *filename, int fd, long int n_lines)
} }
} }
if (tmp->nbytes == -1) if (tmp->nbytes == -1)
error("read error"); errorMsg("read error");
free((char *) tmp); free((char *) tmp);
@ -272,7 +273,7 @@ static long dump_remainder(const char *filename, int fd)
total += bytes_read; total += bytes_read;
} }
if (bytes_read == -1) if (bytes_read == -1)
error("read error"); errorMsg("read error");
if (forever) { if (forever) {
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
@ -294,7 +295,7 @@ static int tail_lines(const char *filename, int fd, long int n_lines)
write_header(filename); write_header(filename);
if (fstat(fd, &stats)) if (fstat(fd, &stats))
error("fstat error"); errorMsg("fstat error");
/* Use file_lines only if FD refers to a regular file with /* Use file_lines only if FD refers to a regular file with
its file pointer positioned at beginning of file. */ its file pointer positioned at beginning of file. */
@ -329,7 +330,7 @@ static int tail_file(const char *filename, off_t n_units)
/* Not standard input. */ /* Not standard input. */
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd == -1) if (fd == -1)
error("open error"); errorMsg("open error");
errors = tail_lines(filename, fd, (long) n_units); errors = tail_lines(filename, fd, (long) n_units);
close(fd); close(fd);

View File

@ -77,6 +77,30 @@ extern void usage(const char *usage)
exit FALSE; exit FALSE;
} }
extern void errorMsg(char *s, ...)
{
va_list p;
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n");
vfprintf(stderr, s, p);
fprintf(stderr, "\n");
va_end(p);
}
extern void fatalError(char *s, ...)
{
va_list p;
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n");
vfprintf(stderr, s, p);
fprintf(stderr, "\n");
va_end(p);
exit( FALSE);
}
#if defined (BB_INIT) || defined (BB_PS) #if defined (BB_INIT) || defined (BB_PS)
@ -110,21 +134,31 @@ int get_kernel_revision()
* Return TRUE if a fileName is a directory. * Return TRUE if a fileName is a directory.
* Nonexistant files return FALSE. * Nonexistant files return FALSE.
*/ */
int isDirectory(const char *fileName, const int followLinks) int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf)
{ {
struct stat statBuf;
int status; int status;
int didMalloc = 0;
if (statBuf == NULL) {
statBuf = (struct stat *)xmalloc(sizeof(struct stat));
++didMalloc;
}
if (followLinks == TRUE) if (followLinks == TRUE)
status = stat(fileName, &statBuf); status = stat(fileName, statBuf);
else else
status = lstat(fileName, &statBuf); status = lstat(fileName, statBuf);
if (status < 0) if (status < 0 || !(S_ISDIR(statBuf->st_mode))) {
return FALSE; status = FALSE;
if (S_ISDIR(statBuf.st_mode)) }
return TRUE; else status = TRUE;
return FALSE;
if (didMalloc) {
free(statBuf);
statBuf = NULL;
}
return status;
} }
#endif #endif
@ -1189,16 +1223,11 @@ extern void *xmalloc(size_t size)
void *cp = malloc(size); void *cp = malloc(size);
if (cp == NULL) { if (cp == NULL) {
error("out of memory"); errorMsg("out of memory");
} }
return cp; return cp;
} }
extern void error(char *msg)
{
fprintf(stderr, "\n%s\n", msg);
exit(1);
}
#endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)