-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

371
Changelog
View File

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

View File

@ -1,5 +1,8 @@
# 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
# it under the terms of the GNU General Public License as published by
# 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
#
PROG := busybox
# PROG := busybox
VERSION := 0.42
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
# Set the following to `true' to make a debuggable build.
# Leave this set to `false' for production use.
# eg: `make DODEBUG=true'
# eg: `make DODEBUG=true tests'
DODEBUG = false
# If you want a static binary, turn this on. I can't think
@ -60,15 +63,21 @@ else
OPTIMIZATION = -O2
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
ifeq ($(DODEBUG),true)
CFLAGS += -Wall -g -D_GNU_SOURCE
STRIP =
LDFLAGS =
STRIP =
else
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
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
ifeq ($(DOSTATIC),true)
LDFLAGS += --static
@ -84,33 +93,43 @@ OBJECTS = $(shell ./busybox.sh) messages.o utility.o
CFLAGS += -DBB_VER='"$(VERSION)"'
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
ifdef BB_INIT_SCRIPT
CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
endif
all: busybox busybox.links
.PHONY: all
busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
$(STRIP)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
$(STRIP) $@
busybox.links: busybox.def.h
- ./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:
- rm -f $(PROG) busybox.links *~ *.o core
- rm -f busybox.links *~ *.o core
- rm -rf _install
- cd tests && $(MAKE) clean
.PHONY: distclean
distclean: clean
- rm -f $(PROG)
$(OBJECTS): %.o: %.c busybox.def.h internal.h Makefile messages.c
- rm -f busybox
- cd tests && $(MAKE) distclean
.PHONY: install
install: busybox busybox.links
./install.sh $(PREFIX)
dist: release
release: distclean
.PHONY: dist release
dist release: distclean
cd ..; \
rm -rf 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
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
@ -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
* Make insmod actually work
* dnsdomainname
* traceroute/nslookup/netstat
* traceroute/netstat
* rdate
* hwclock
* killall

View File

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

View File

@ -194,7 +194,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \
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;}
#else
@ -311,7 +311,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) 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__
extern char *basename OF((char *fname));
#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 write_error OF((void));
@ -1045,13 +1043,13 @@ int in, out; /* input and output file descriptors */
int res = inflate();
if (res == 3) {
error("out of memory");
errorMsg("out of memory");
} else if (res != 0) {
error("invalid compressed data--format violated");
errorMsg("invalid compressed data--format violated");
}
} else {
error("internal error, invalid method");
errorMsg("internal error, invalid method");
}
/* Get the crc and original length */
@ -1080,10 +1078,10 @@ int in, out; /* input and output file descriptors */
/* Validate decompression */
if (orig_crc != updcrc(outbuf, 0)) {
error("invalid compressed data--crc error");
errorMsg("invalid compressed data--crc error");
}
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 */

View File

@ -125,7 +125,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * near array
# define ALLOC(type, array, size) { \
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;}
#else
@ -262,7 +262,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) 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 char *strlwr OF((char *s));
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 write_error OF((void));
extern void display_ratio OF((long num, long den, FILE * file));
@ -1396,7 +1394,7 @@ int length;
(char *) window + start, length) != EQUAL) {
fprintf(stderr,
" start %d, match %d, length %d\n", start, match, length);
error("invalid match");
errorMsg("invalid match");
}
if (verbose > 1) {
fprintf(stderr, "\\[%d,%d]", start - match, length);
@ -2916,7 +2914,7 @@ int eof; /* true if this is the last block for a file */
#endif
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
if (buf == (char *) 0)
error("block vanished");
errorMsg("block vanished");
copy_block(buf, (unsigned) stored_len, 0); /* without header */
compressed_len = stored_len << 3;
@ -3099,7 +3097,7 @@ local void set_file_type()
bin_freq += dyn_ltree[n++].Freq;
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
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 *));
if (nargv == NULL)
error("out of memory");
errorMsg("out of memory");
oargv = *argvp;
*argvp = nargv;
/* Copy the program name first */
if (oargc-- < 0)
error("argc<=0");
errorMsg("argc<=0");
*(nargv++) = *(oargv++);
/* Then copy the environment args */

View File

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

View File

@ -72,6 +72,10 @@ static long du(char *filename)
du_depth++;
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)) {
DIR *dir;
struct dirent *entry;
@ -140,7 +144,7 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) {
sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE))) {
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
print_normal(sum, argv[i]);
}
}
@ -149,4 +153,4 @@ int du_main(int argc, char **argv)
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;
}
linkIntoDirFlag = isDirectory(linkName, TRUE);
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
if ((argc > 3) && !linkIntoDirFlag) {
fprintf(stderr, not_a_directory, "ln", linkName);

View File

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

View File

@ -1,5 +1,6 @@
/* vi: set sw=4 ts=4: */
#include "internal.h"
/* This file contains _two_ implementations of tail. One is
* 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
@ -51,7 +52,7 @@
#define XWRITE(fd, buffer, n_bytes) \
do { \
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
error("write error"); \
errorMsg("write error"); \
} while (0)
/* 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);
bytes_read = fullRead(fd, buffer, bytes_read);
if (bytes_read == -1)
error("read error");
errorMsg("read error");
/* Count the incomplete line on files that don't end with a newline. */
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);
if (bytes_read == -1)
error("read error");
errorMsg("read error");
return 0;
}
@ -209,7 +210,7 @@ static int pipe_lines(const char *filename, int fd, long int n_lines)
}
}
if (tmp->nbytes == -1)
error("read error");
errorMsg("read error");
free((char *) tmp);
@ -272,7 +273,7 @@ static long dump_remainder(const char *filename, int fd)
total += bytes_read;
}
if (bytes_read == -1)
error("read error");
errorMsg("read error");
if (forever) {
fflush(stdout);
sleep(1);
@ -294,7 +295,7 @@ static int tail_lines(const char *filename, int fd, long int n_lines)
write_header(filename);
if (fstat(fd, &stats))
error("fstat error");
errorMsg("fstat error");
/* Use file_lines only if FD refers to a regular file with
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. */
fd = open(filename, O_RDONLY);
if (fd == -1)
error("open error");
errorMsg("open error");
errors = tail_lines(filename, fd, (long) n_units);
close(fd);

26
cp_mv.c
View File

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

8
du.c
View File

@ -72,6 +72,10 @@ static long du(char *filename)
du_depth++;
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)) {
DIR *dir;
struct dirent *entry;
@ -140,7 +144,7 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) {
sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE))) {
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
print_normal(sum, argv[i]);
}
}
@ -149,4 +153,4 @@ int du_main(int argc, char **argv)
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 ALLOC(type, array, size) { \
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;}
#else
@ -311,7 +311,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) 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__
extern char *basename OF((char *fname));
#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 write_error OF((void));
@ -1045,13 +1043,13 @@ int in, out; /* input and output file descriptors */
int res = inflate();
if (res == 3) {
error("out of memory");
errorMsg("out of memory");
} else if (res != 0) {
error("invalid compressed data--format violated");
errorMsg("invalid compressed data--format violated");
}
} else {
error("internal error, invalid method");
errorMsg("internal error, invalid method");
}
/* Get the crc and original length */
@ -1080,10 +1078,10 @@ int in, out; /* input and output file descriptors */
/* Validate decompression */
if (orig_crc != updcrc(outbuf, 0)) {
error("invalid compressed data--crc error");
errorMsg("invalid compressed data--crc error");
}
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 */

16
gzip.c
View File

@ -125,7 +125,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * near array
# define ALLOC(type, array, size) { \
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;}
#else
@ -262,7 +262,7 @@ extern int save_orig_name; /* set if original name must be saved */
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Assert(cond,msg) {if(!(cond)) errorMsg(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) 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 char *strlwr OF((char *s));
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 write_error OF((void));
extern void display_ratio OF((long num, long den, FILE * file));
@ -1396,7 +1394,7 @@ int length;
(char *) window + start, length) != EQUAL) {
fprintf(stderr,
" start %d, match %d, length %d\n", start, match, length);
error("invalid match");
errorMsg("invalid match");
}
if (verbose > 1) {
fprintf(stderr, "\\[%d,%d]", start - match, length);
@ -2916,7 +2914,7 @@ int eof; /* true if this is the last block for a file */
#endif
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
if (buf == (char *) 0)
error("block vanished");
errorMsg("block vanished");
copy_block(buf, (unsigned) stored_len, 0); /* without header */
compressed_len = stored_len << 3;
@ -3099,7 +3097,7 @@ local void set_file_type()
bin_freq += dyn_ltree[n++].Freq;
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
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 *));
if (nargv == NULL)
error("out of memory");
errorMsg("out of memory");
oargv = *argvp;
*argvp = nargv;
/* Copy the program name first */
if (oargc-- < 0)
error("argc<=0");
errorMsg("argc<=0");
*(nargv++) = *(oargv++);
/* Then copy the environment args */

View File

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

View File

@ -144,9 +144,13 @@ extern int whoami_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 *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 copyFile(const char *srcName, const char *destName, int setModes,
int followLinks);
@ -164,7 +168,6 @@ const char* timeString(time_t timeVal);
extern int createPath (const char *name, int mode);
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 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 long getNum (const char *cp);
extern pid_t findInitPid();
extern void *xmalloc (size_t size);
#if defined BB_INIT || defined BB_SYSLOGD
extern int device_open(char *device, int mode);
#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);
#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)
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;
}
linkIntoDirFlag = isDirectory(linkName, TRUE);
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
if ((argc > 3) && !linkIntoDirFlag) {
fprintf(stderr, not_a_directory, "ln", linkName);

28
ls.c
View File

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

View File

@ -219,29 +219,6 @@ static void warn(char *s, ...)
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
*/
@ -273,12 +250,12 @@ static int sseek(char *dev, unsigned int fd, unsigned long s)
if ((out = lseek(fd, in, SEEK_SET)) != in) {
#endif
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;
}
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) (out >> 32), (uint) (out & 0xffffffff));
return 0;
@ -324,11 +301,11 @@ static struct sector *get_sector(char *dev, int fd, unsigned long sno)
return 0;
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)) {
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);
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)
{
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);
return 0;
}
@ -361,7 +338,7 @@ static int write_sectors(char *dev, int fd)
return 0;
if (write(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
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);
return 0;
}
@ -399,7 +376,7 @@ static int save_sectors(char *dev, int fdin)
fdout = open(save_sector_file, O_WRONLY | O_CREAT, 0444);
if (fdout < 0) {
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);
return 0;
}
@ -411,13 +388,13 @@ static int save_sectors(char *dev, int fdin)
return 0;
if (read(fdin, ss + 4, 512) != 512) {
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);
return 0;
}
if (write(fdout, ss, sizeof(ss)) != sizeof(ss)) {
perror("write");
error("write error on %s\n"), save_sector_file;
errorMsg("write error on %s\n"), save_sector_file;
return 0;
}
}
@ -435,35 +412,35 @@ static int restore_sectors(char *dev)
if (stat(restore_sector_file, &statbuf) < 0) {
perror(restore_sector_file);
error("cannot stat partition restore file (%s)\n",
errorMsg("cannot stat partition restore file (%s)\n",
restore_sector_file);
return 0;
}
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;
}
if (!(ss = (char *) malloc(statbuf.st_size))) {
error("out of memory?\n");
errorMsg("out of memory?\n");
return 0;
}
fdin = open(restore_sector_file, O_RDONLY);
if (fdin < 0) {
perror(restore_sector_file);
error("cannot open partition restore file (%s)\n",
errorMsg("cannot open partition restore file (%s)\n",
restore_sector_file);
return 0;
}
if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) {
perror("read");
error("error reading %s\n"), restore_sector_file;
errorMsg("error reading %s\n"), restore_sector_file;
return 0;
}
fdout = open(dev, O_WRONLY);
if (fdout < 0) {
perror(dev);
error("cannot open device %s for writing\n"), dev;
errorMsg("cannot open device %s for writing\n"), dev;
return 0;
}
@ -475,7 +452,7 @@ static int restore_sectors(char *dev)
return 0;
if (write(fdout, ss + 4, 512) != 512) {
perror(dev);
error("error writing sector %lu on %s\n", sno, dev);
errorMsg("error writing sector %lu on %s\n", sno, dev);
return 0;
}
ss += 516;
@ -905,7 +882,7 @@ static int asc_to_index(char *pnam, struct disk_desc *z)
pno = linux_to_index(pnum, z);
}
if (!(pno >= 0 && pno < z->partno))
fatal("%s: no such partition\n"), pnam;
fatalError("%s: no such partition\n"), pnam;
return pno;
}
@ -1233,9 +1210,9 @@ static int partitions_ok(struct disk_desc *z)
/* Have at least 4 partitions been defined? */
if (partno < 4) {
if (!partno)
fatal("no partition table present.\n");
fatalError("no partition table present.\n");
else
fatal("strange, only %d partitions defined.\n"), partno;
fatalError("strange, only %d partitions defined.\n"), partno;
return 0;
}
@ -1680,12 +1657,12 @@ static int write_partitions(char *dev, int fd, struct disk_desc *z)
}
if (save_sector_file) {
if (!save_sectors(dev, fd)) {
fatal("Failed saving the old sectors - aborting\n");
fatalError("Failed saving the old sectors - aborting\n");
return 0;
}
}
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 1;
@ -1765,7 +1742,7 @@ read_stdin(unsigned char **fields, unsigned char *line, int fieldssize,
return RD_EOF;
}
if (!(lp = index(lp, '\n')))
fatal("long or incomplete input line - quitting\n");
fatalError("long or incomplete input line - quitting\n");
*lp = 0;
/* remove comments, if any */
@ -1801,21 +1778,21 @@ read_stdin(unsigned char **fields, unsigned char *line, int fieldssize,
while (isalnum(*ip)) /* 0x07FF */
ip++;
} else
fatal("input error: `=' expected after %s field\n",
fatalError("input error: `=' expected after %s field\n",
d->fldname);
if (fno <= d->fldno)
fno = d->fldno + 1;
if (*ip == 0)
return fno;
if (*ip != ',' && *ip != ';')
fatal
fatalError
("input error: unexpected character %c after %s field\n",
*ip, d->fldname);
*ip = 0;
goto nxtfld;
}
}
fatal("unrecognized input: %s\n"), ip;
fatalError("unrecognized input: %s\n"), ip;
}
/* 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)))
if (!interactive)
fatal("bad input\n");
fatalError("bad input\n");
if (i < 0) {
p->ep = ep;
return 0;
@ -2612,19 +2589,19 @@ extern int sfdisk_main(int argc, char **argv)
}
if (do_id) {
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)
fatal
fatalError
("usage: sfdisk --change-id device partition-number Id\n");
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],
(optind == argc - 2) ? 0 : argv[optind + 2]);
exit(exit_status);
}
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];
if (opt_reread)
@ -2649,7 +2626,7 @@ static int my_open(char *dev, int rw, int silent)
fd = open(dev, mode);
if (fd < 0 && !silent) {
perror(dev);
fatal("cannot open %s %s\n", dev,
fatalError("cannot open %s %s\n", dev,
rw ? "read-write" : "for reading");
}
return fd;
@ -2711,7 +2688,7 @@ static void do_size(char *dev, int silent)
if (ioctl(fd, BLKGETSIZE, &size)) {
if (!silent) {
perror(dev);
fatal("BLKGETSIZE ioctl failed for %s\n"), dev;
fatalError("BLKGETSIZE ioctl failed for %s\n"), dev;
}
return;
}
@ -2831,7 +2808,7 @@ static void set_unhidden(struct disk_desc *z, char *pnam)
if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17)
id -= 0x10;
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;
}
@ -2889,7 +2866,7 @@ static void do_change_id(char *dev, char *pnam, char *id)
}
i = strtoul(id, NULL, 16);
if (i > 255)
fatal("Bad Id %x\n"), i;
fatalError("Bad Id %x\n"), i;
z->partitions[pno].p.sys_type = i;
if (write_partitions(dev, fd, z))
@ -2921,7 +2898,7 @@ static void do_fdisk(char *dev)
if (stat(dev, &statbuf) < 0) {
perror(dev);
fatal("Fatal error: cannot find %s\n"), dev;
fatalError("Fatal error: cannot find %s\n"), dev;
}
if (!S_ISBLK(statbuf.st_mode)) {
warn("Warning: %s is not a block device\n"), dev;
@ -2954,7 +2931,7 @@ static void do_fdisk(char *dev)
out_partitions(dev, z);
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;
@ -2967,7 +2944,7 @@ static void do_fdisk(char *dev)
if (!partitions_ok(z) && !force) {
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");
else
printf
@ -2985,7 +2962,7 @@ static void do_fdisk(char *dev)
if (c == EOF)
printf("\nsfdisk: premature end of input\n");
if (c == EOF || answer == 'q' || answer == 'Q') {
fatal("Quitting - nothing changed\n");
fatalError("Quitting - nothing changed\n");
} else if (answer == 'n' || answer == 'N') {
continue;
} else if (answer == 'y' || answer == 'Y') {

View File

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

View File

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

15
tail.c
View File

@ -1,5 +1,6 @@
/* vi: set sw=4 ts=4: */
#include "internal.h"
/* This file contains _two_ implementations of tail. One is
* 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
@ -51,7 +52,7 @@
#define XWRITE(fd, buffer, n_bytes) \
do { \
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
error("write error"); \
errorMsg("write error"); \
} while (0)
/* 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);
bytes_read = fullRead(fd, buffer, bytes_read);
if (bytes_read == -1)
error("read error");
errorMsg("read error");
/* Count the incomplete line on files that don't end with a newline. */
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);
if (bytes_read == -1)
error("read error");
errorMsg("read error");
return 0;
}
@ -209,7 +210,7 @@ static int pipe_lines(const char *filename, int fd, long int n_lines)
}
}
if (tmp->nbytes == -1)
error("read error");
errorMsg("read error");
free((char *) tmp);
@ -272,7 +273,7 @@ static long dump_remainder(const char *filename, int fd)
total += bytes_read;
}
if (bytes_read == -1)
error("read error");
errorMsg("read error");
if (forever) {
fflush(stdout);
sleep(1);
@ -294,7 +295,7 @@ static int tail_lines(const char *filename, int fd, long int n_lines)
write_header(filename);
if (fstat(fd, &stats))
error("fstat error");
errorMsg("fstat error");
/* Use file_lines only if FD refers to a regular file with
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. */
fd = open(filename, O_RDONLY);
if (fd == -1)
error("open error");
errorMsg("open error");
errors = tail_lines(filename, fd, (long) n_units);
close(fd);

View File

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