Compare commits

...
130 Commits
Author SHA1 Message Date
Eric Andersen 0958093be6 Doc update for the 0.51 release.
-Erik
2001-04-10 20:10:55 +00:00
Eric Andersen 3c3430502a Fix up changelog for 0.51 release 2001-04-10 20:10:14 +00:00
Eric Andersen b04d744a47 Bring Debian config files into sync with the master one. 2001-04-10 20:07:19 +00:00
Eric Andersen e703f7ed42 Ha. Regression testing found a bug with uClibc support. Fixed.
-Erik
2001-04-10 19:03:03 +00:00
Eric Andersen b9af894264 Fix up the uClibc compiler name (its format was recently changed slightly) 2001-04-10 18:35:02 +00:00
Eric Andersen 6d7fa438a7 This patch from Laurence Anderson <laurence@zxmail.com> fixes
wget HTTP 1.1 support and addes chunked encoding so bb wget
is now fully RFC compliant.
2001-04-10 18:17:05 +00:00
Eric Andersen fd402941a7 Patch from Valdimir to reduce stack usage, since recursive_action
is (as the name implies) is recursive, reducing stack memory usage
is important to avoid exhausting available stack memory.
2001-04-10 17:53:49 +00:00
Matt Kraai 4e853560f5 Fix double quote handling. 2001-04-10 00:00:05 +00:00
Eric Andersen 2f2da90fd4 "I will always compile before I commit" x 100 2001-04-09 23:54:15 +00:00
Eric Andersen b6b519b416 Update how we detect if libc5 is in use.
-Erik
2001-04-09 23:52:18 +00:00
Matt Kraai d3f97f1971 Fix warning generated by pod2html about unterminated list. 2001-04-09 23:27:51 +00:00
Eric Andersen 303dd28bb0 Make 'grep -l' work 2001-04-09 23:26:31 +00:00
Mark Whitley 4391a16c92 Fixed option parsing. Grep would continue grepping, even when given a bad /
invalid option. Closes bug #1146.
2001-04-09 23:00:07 +00:00
Eric Andersen e5dfced23a Apply Vladimir's latest cleanup patch.
-Erik
2001-04-09 22:48:12 +00:00
Eric Andersen a75e286743 Bump version number to 0.51 2001-04-09 22:18:14 +00:00
Eric Andersen 59aa5703ae Enable freeramdisk and pivot_root, disable lash for the Debian .udeb
-Erik
2001-04-09 22:17:10 +00:00
Eric Andersen fc994d1cb4 make sure we auto-close debian bug #91758
-Erik
2001-04-09 22:15:27 +00:00
Eric Andersen 7cf9fed83f update the changelog, prepatory to the 0.51 release. Please review
for correctness!
 -Erik
2001-04-09 22:09:41 +00:00
Eric Andersen 3f8688b406 Update changelog 2001-04-09 19:00:29 +00:00
Eric Andersen 5d6f3440e6 use 'USE_SYSTEM_PWD_GRP=false' for the Debian packages so the boot-floppies
do not need any of the nss crap installed.  As was, things like 'id' would
fail.  Fixed now (with thanks to Matt Kraai for his help).
 -Erik
2001-04-09 18:42:52 +00:00
Glenn L McGrath 305fdfa755 Reorganise status field to use 3 chars instead of one bit shifted long int.
Generates status file properly now, not compatable with full dpkg yet.
2001-04-08 13:27:39 +00:00
Glenn L McGrath 37849f3320 Use create_path instead of mkdir 2001-04-08 07:23:53 +00:00
Glenn L McGrath 13e9c7ad82 It now correctly backs up the (still corrupt) status file 2001-04-08 07:18:08 +00:00
Glenn L McGrath 0e757a2f3f Some fixes, but still broken... (cont)
Make better use of some libbb functions
New remove dir code to avoid depending on the rm applet
dont use copy_file() it doesnt fail elegantly
Use getopt.
Generate correct /var/lib/dpkg/info/ files
Status file is broken, working on it now
2001-04-08 05:27:18 +00:00
Glenn L McGrath f608da4288 Ignore SIGTERM prior to gz_close() 2001-04-07 02:40:59 +00:00
Glenn L McGrath e5f3957665 Fix warning 2001-04-07 02:17:36 +00:00
Eric Andersen 8a9b2c6448 Note that insmod now also supports powerpc and mips. Thanks Larry. 2001-04-06 22:02:49 +00:00
Eric Andersen aa21e0f913 An optimization from Vladimir 2001-04-06 16:02:22 +00:00
Eric Andersen 250a221768 more FILE_OFFSET_BITS == 64 adjustments. 2001-04-05 23:26:44 +00:00
Eric Andersen 83f173b61e A first pass at making D_FILE_OFFSET_BITS=64 work, from
Jari Ruusu <jari.ruusu@pp.inet.fi>
2001-04-05 23:07:25 +00:00
Eric Andersen c270ec1fa2 Add support of /W prompts
-Erik
2001-04-05 23:00:47 +00:00
Eric Andersen 831ed16efc Handle glibc 2.0.7 as well 2001-04-05 22:38:32 +00:00
Eric Andersen 79757c9c37 A patch from Dmitry Zakharov <dmit@crp.bank.gov.ua> which adds
- support for ftp downloads
- HTTP basic authentication support (as an optional feature)
- handling of http redirections
- protocol version changed to 1.0 (to stop servers from requesting
chunked encoding)
- bugfix: in the case when content-length not given, wget didn't
download anything
- when attempting to continue an aborted download but server doesn't
support restarts, reopen output file in write mode
- changed assumption that existing file should restart an aborted
    download.  Now the user must explicitly specify this with -c
2001-04-05 21:45:54 +00:00
Eric Andersen ea9065072c Some cleanups/fixes for the syslogd circular buffer code
from Gennady Feldman.
2001-04-05 20:55:17 +00:00
John Beppu 79359d87e8 - autodocifier.pl :: continuation() was modified such that '#'
is handled correctly.
2001-04-05 20:03:33 +00:00
John Beppu 94e505485e - use docs/autodocifier.pl to merge POD together 2001-04-05 19:42:03 +00:00
John Beppu 5bca0afb31 - split busybox.pod into a header and footer.
the body will be generated by docs/autodocifier.pl
2001-04-05 19:41:23 +00:00
John Beppu 9a1395b9fd - documentation updates and a minor tweak to POD generation 2001-04-05 19:35:17 +00:00
Eric Andersen 4e2439ad27 It seems all the stdout munging was useless anyways, since
deb_extract and all its called functions do nothing with
stdout anyways.  Axe that stuff.
 -Erik
2001-04-05 18:30:38 +00:00
Eric Andersen 911af57ff8 Be more generic for libc5. We don't need to know struct definitions
to make the syscall finction -- use a generic pointer instead.
2001-04-05 07:41:51 +00:00
Eric Andersen 64c8b1762c Another iteration -- adjust the init_module syscall a bit.
-Erik
2001-04-05 07:33:10 +00:00
Eric Andersen acc7757312 *** empty log message *** 2001-04-05 06:24:28 +00:00
Eric Andersen a2a978ae23 Some further syscall adjustments. Split the module syscalls out of
insmod and into libbb. Only enable them for libc5.  glibc and
uClibc don't need them.
 -Erik
2001-04-05 06:08:14 +00:00
Eric Andersen fdefbbbe85 dpkg_deb had not been updated for the new gunzip interface. Fix it.
-Erik
2001-04-05 06:04:11 +00:00
Eric Andersen e76c3b08e1 A number of cleanups. Now compiles with libc5, glibc, and uClibc. Fix a few
shadowed variables.  Move (almost) all syscalls to libbb/syscalls.c, so I can
handle them sanely and all at once.
 -Erik
2001-04-05 03:14:39 +00:00
Eric Andersen 3c0364f391 Patch from Larry Doolittle to eliminate needless thrashing
about when trimming long strings with lots of trailing white
space.
2001-04-04 22:49:01 +00:00
Eric Andersen 4fd382ea29 Remove unused optarg variable 2001-04-04 19:33:32 +00:00
Eric Andersen 06070532ba Failed to name "Electric-fence" explicitly 2001-04-04 19:32:00 +00:00
Eric Andersen d402edfd63 Some cleanups for libc5 support 2001-04-04 19:29:48 +00:00
Eric Andersen 14fe392dde Fix a warning with libc5.
-Erik
2001-04-04 19:26:22 +00:00
Eric Andersen b2e3e9b0c9 Seems that stupid libc5 doesn't implement daemon(), so conditionally
inclde that here.
 -Erik
2001-04-04 19:25:57 +00:00
Matt Kraai 2129f97cd9 Avoid segfault when export is invoked with no arguments. Thanks to
Gennady Feldman.
2001-04-04 17:50:04 +00:00
Eric Andersen 3f98040554 I said no new features till after the 0.51 release. Well, I lied. This is a
vi editor for busybox, contributed by Sterling Huxley <sterling@europa.com>.
It adds 22k to the busybox binary when enabled.  Quite impressive!
2001-04-04 17:31:15 +00:00
Eric Andersen 91c9388715 Place a temporary bandaid on the ls/du/df human-readable issue. This method is
not going to scale up as well as I would like, and Matt Kraai and I have
discussed a better long term solution.  But for now this will at least make all
the human-readable apps give correct answers.

Please test the human readable/non-human readable options on your systems!!!
 -Erik
2001-04-03 23:14:29 +00:00
Eric Andersen 24073c7665 Add in easy-to-use electric-fence support.
-Erik
2001-04-03 22:53:19 +00:00
Eric Andersen 60b2d8d2c8 if strlen(s) was 0, it would then end up using s[-1] as an array index. Bad,
bad, bad.  This was crashing the shell on powerpc boxes, though all other archs
seem to have a much more forgiving malloc implementations.  I finally found
this bug using electric-fence on a powerpc box.
 -Erik
2001-04-03 22:50:52 +00:00
Eric Andersen c97ec34370 A patch from Matt Kraai that adds a new 'shutdown' action to busybox init. Now
you can specify an arbitrary behavior for 'ctrlaltdel' without that behavior
needing to be a reboot.
2001-04-03 18:01:51 +00:00
Eric Andersen 0f0c0b41ce Make 'busybox --help' work as expected, closing bug #1139
-Erik
2001-04-03 17:05:01 +00:00
Eric Andersen c0c502e172 Fix for bug 1143 from Larry Doolittle
-Erik
2001-04-03 16:38:37 +00:00
Eric Andersen c4cef5ab06 Move the mtab support stuff into libbb
-Erik
2001-04-01 16:01:11 +00:00
Eric Andersen f77d88641d Formatting change 2001-04-01 04:49:41 +00:00
Glenn L McGrath 1e117b4752 Dont try and automount devfs, rename some variables 2001-03-30 01:28:13 +00:00
Eric Andersen 84e229cfbe Add in a new standalone env applet for fixing up app's environments
-Erik
2001-03-29 22:48:33 +00:00
Eric Andersen e5c24dfd01 Use daemon() to spawn syslogd and klogd daemons.
-Erik
2001-03-29 21:58:33 +00:00
Eric Andersen 3a6da8c183 gz_open and gz_close were left in, even when BB_FEATURE_TAR_GZIP was disabled.
Fix that.
2001-03-29 14:22:45 +00:00
Glenn L McGrath 5f2ef46d6d Fix zcat 2001-03-29 01:07:54 +00:00
Glenn L McGrath ed7a776538 gunzip -c works again 2001-03-29 00:57:20 +00:00
Glenn L McGrath ae8ad35590 Fixes from Robert Kaiser 2001-03-28 23:57:51 +00:00
Mark Whitley e0a7f917c2 Applied patch from David Douthitt to re-add -print option to find.
Closes bug #1144.
2001-03-28 22:04:42 +00:00
Eric Andersen c835567914 Fix ls so it uses make_human_readable_str() the same way already
used by 'du' and 'df'.  Now we just need to fix make_human_readable_str
so it behaves they way it used to before Matt fixed it.
2001-03-28 20:26:51 +00:00
Matt Kraai d98e574d41 Patch bass ackwards behavior of hr flag. 2001-03-28 20:10:25 +00:00
Matt Kraai 7cd0cfeab6 Rewrite to fix bug #1140 and make it slightly smaller. 2001-03-28 16:42:27 +00:00
Glenn L McGrath f957c77910 Enable tar -z support again by default 2001-03-28 07:48:10 +00:00
Glenn L McGrath 02cebebc3b Remove cruft 2001-03-28 07:37:48 +00:00
Glenn L McGrath 9233959940 Remove tar_unzip_init() not needed any more, uses gz_open instead 2001-03-28 07:31:37 +00:00
Glenn L McGrath 018e9e6799 Fix tar -z, calls gz_open now 2001-03-28 07:27:26 +00:00
Glenn L McGrath ee79ca1ba6 Disable tar -z for now 2001-03-28 06:13:15 +00:00
Glenn L McGrath 0cbc8cf4c9 Gunzip changes broke tar -z support (woops) 2001-03-28 05:47:26 +00:00
Glenn L McGrath 58e42d5356 Major cleanup to better adhere to style guide and use standard busybox functions 2001-03-28 05:38:24 +00:00
Glenn L McGrath f58efb57d1 Add functions that were shared with gunzip.c, gunzip about to change. 2001-03-28 05:35:16 +00:00
Matt Kraai a2e68fc233 Change BB_FEATURE_TRIVIAL_HELP to BB_FEATURE_VERBOSE_USAGE (per bug #1130). 2001-03-27 21:57:29 +00:00
Mark Whitley 5b8939b147 Some more words on sending patches to the bug-tracker. 2001-03-27 21:20:05 +00:00
Mark Whitley 9a2144663a Applied patch from David Douthitt to fix problem where ls reports half the
file size. Should close bug #1140.
2001-03-27 20:59:14 +00:00
Mark Whitley cc7b4f39fc Some more tests for cut. Craig Matsuura said he saw some problems along these
lines. "Works for me", but we'll keep these tests around for regression.
2001-03-27 20:48:01 +00:00
Mark Whitley bff6b18bf9 Applied patch from Gennady Feldman to fix a single-threaded syslogd bug that
turned up. This code needs to be tested on an embedded system, since that's
where the bug turned up in the first place.
2001-03-27 20:17:58 +00:00
Mark Whitley 2b549c3be0 Fixed the Makefile so busybox can link against libc5 again. Putting libbb.a at
the end broke it.
2001-03-27 18:22:41 +00:00
Mark Whitley 5cd2a2d53e In fact, socklen_t *is* defined by libc5. 2001-03-27 18:22:00 +00:00
Mark Whitley a82a00397f Fix to last patch: locale code should be 9, not 7. 2001-03-27 17:07:15 +00:00
Mark Whitley 1c6581a865 Applied patch from Vladimir N. Oleynik to add locale support to the shell per
bug report from Ralph Jones.
2001-03-27 16:35:16 +00:00
Mark Whitley af633757d3 Applied patch from Anthony Towns that he posted to Debian bug tracking. 2001-03-26 16:47:57 +00:00
Manuel Novoa III 049dc25fe7 Fix in_ether bug regarding hex digits reported by Jonas Holmberg <jonas.holmberg@axis.com>. 2001-03-26 16:26:16 +00:00
Eric Andersen 36eff9ac55 Bump version number to 0.51pre 2001-03-24 06:34:59 +00:00
Eric Andersen 6f3240abf9 xstrdup xargs cleanup from Jeff Garzik 2001-03-23 17:11:22 +00:00
Eric Andersen 6b2c23d847 xstrdup tftp cleanup from Jeff Garzik 2001-03-23 17:10:19 +00:00
Eric Andersen 21af752b04 Patch to use xfopen from Jeff Garzik 2001-03-23 17:09:15 +00:00
Eric Andersen f6aa13d403 -Wshadow tr fix from Jeff Garzik 2001-03-23 17:08:21 +00:00
Eric Andersen 82ab8da245 -Wshadow sh fix from Jeff Garzik 2001-03-23 17:06:01 +00:00
Eric Andersen 8ffaf8d139 -Wshadow logread fix from Jeff Garzik 2001-03-23 17:04:47 +00:00
Eric Andersen c54f9530ee -Wshadow loadacm fix from Jeff Garzik 2001-03-23 17:03:28 +00:00
Eric Andersen 08ff8a49ba includes cleanup from Jeff Garzik 2001-03-23 17:02:05 +00:00
Mark Whitley 0b4d73a53c Some minor wordsmithing, an extra item in the list of "things Busybox doesn't
need", example of a testcase, more janitorial items, and a whole new section
with guidelines on committing changes to CVS.
2001-03-22 22:59:33 +00:00
Eric Andersen 82bb8a2bf8 Patch from Dirk Behme <dirk.behme@de.bosch.com> to
add EM_MIPS_RS3_LE for mips
 -Erik
2001-03-22 19:01:16 +00:00
Eric Andersen 851895ab80 Clean up more local vars which shadow globals
-Erik
2001-03-21 21:52:25 +00:00
Eric Andersen 1ca20a7747 A nice patch from Larry Doolittle that adds -Wshadow and
cleans up most of the now-revealed problems.
2001-03-21 07:34:27 +00:00
Mark Whitley 7447642a47 Added a section on the available Busybox boot-floppy image. Also provided some
linkes to a Wired article on Midori Linux.
2001-03-20 19:57:30 +00:00
Mark Whitley 6f93277f56 Added adjtimex applet from Larry Doolittle. 2001-03-20 19:18:10 +00:00
Eric Andersen ba372620c2 Force applet_name to be "sh" when command prefaced by "-" 2001-03-20 17:39:53 +00:00
Eric Andersen 7ef1a5beb2 Fix up command line munging in init. Postpone the askfirst thing till
a bit later in run().
2001-03-20 17:39:08 +00:00
Eric Andersen 4ef37d0c17 chown was missing a ] in its usage msg 2001-03-20 01:06:14 +00:00
Eric Andersen 92d23245c9 Another cleanup patch from Jeff Garzik <jgarzik@mandrakesoft.com> 2001-03-19 23:49:41 +00:00
Eric Andersen 40eaa9f0bb Size optimization for rdate from Vladimir 2001-03-19 19:41:54 +00:00
Eric Andersen 8269396491 Simpify detection of no options. 2001-03-19 19:40:43 +00:00
Eric Andersen 2ccfef2004 Patch from Vladimir to move struct applet from busybox.c to applets.c,
which looks like the right place for such things to live.
2001-03-19 19:30:24 +00:00
Eric Andersen 23c1a18126 Per suggestion from Vladimir, no need to initialize these -- let the bss
do it.
 -Erik
2001-03-19 19:28:24 +00:00
Eric Andersen 7ef54de672 locale correction patch from Vladimir 2001-03-19 19:25:49 +00:00
Eric Andersen b183dfad2d Split error messages into separate files.
Update libbb.h, per suggestion from Vladimir, to include __attribute__((format
(printf ...))) stuff
 -Erik
2001-03-19 19:24:06 +00:00
Eric Andersen cc165b9083 Should exclude "i" option when not enabled. 2001-03-19 18:59:01 +00:00
Eric Andersen 00b0496e69 Doesn't need a "-" option -- getopt does that for us. 2001-03-19 18:57:08 +00:00
Eric Andersen 16f7015722 Patch from Vladimir to force interactiveFlag=FALSE when forceFlag=TRUE 2001-03-19 18:54:38 +00:00
Eric Andersen 7c25441792 getopt-ify rm so that BB_FEATURE_RM_INTERACTIVE will work 2001-03-19 18:52:37 +00:00
Eric Andersen c75586e06d Split libbb/pwd_grp_wrappers.c into 5 different libbb/my_* files.
-Erik
2001-03-19 18:37:42 +00:00
Eric Andersen 61173a5371 Fix to cmdedit.c from Vladimir 2001-03-19 17:48:55 +00:00
Eric Andersen fa513aab48 Some configuration adjustments from Vladimir 2001-03-19 17:25:21 +00:00
Eric Andersen 8b96032139 Fix a bug pointed out by Rob Landley <rlandley@austin.rr.com>, where
setup_sockaddr_in was zeroing the sizeof a pointer, not the sizeof the struct,
which was obviously what was intended.  Thanks Rob,
 -Erik
2001-03-17 05:43:39 +00:00
Eric Andersen 341744781a Patch from Larry and Vladimir to clean up sh.c and fix
shell expansion to work in non POSIX locales.
2001-03-17 00:20:10 +00:00
Eric Andersen 1a6f8cfadf update .cvsignore files to note new location of loop.h 2001-03-17 00:15:02 +00:00
Eric Andersen 8a6dbf6709 Patch from Pierre PEIFFER <pierre.peiffer@sxb.bsf.alcatel.fr>
that copes with the fact that processes may have been swapped
out.
2001-03-17 00:05:42 +00:00
Eric Andersen e2a3cd15a8 Stupid thinko. egrep tried to call init. Sigh. Fix from Christophe Boyanique 2001-03-16 23:49:20 +00:00
Eric Andersen aad1a88c76 Convert utility.c into libbb.a. It is now a whole pile of .c
files.  Clean up the resulting damage and fix up the makefile.
 -Erik
2001-03-16 22:47:14 +00:00
Eric Andersen dfba13d199 A few minor touchups. 2001-03-16 08:30:00 +00:00
202 changed files with 18018 additions and 7098 deletions

No files matched your search

-1
View File
@@ -1,5 +1,4 @@
busybox
busybox.links
_install
loop.h
applet_source_list
+3
View File
@@ -73,3 +73,6 @@ Charles P. Wright <cpwright@villagenet.com>
Enrique Zanardi <ezanardi@ull.es>
tarcat (since removed), loadkmap, various fixes, Debian maintenance
Vladimir Oleynik <dzo@simtreas.ru>
cmdedit, stty-port, locale, various fixes
and irreconcilable critic of everything not perfect.
+76 -2
View File
@@ -1,11 +1,85 @@
0.51
Critical Bugfixes:
* Erik Andersen -- Fixed a bug that could crash the shell in 0.50
when pressing <Enter> on an empty line.
* Gennady Feldman -- Fixed a bug that could crash the shell in 0.50
when performing an 'export' in the shell.
* Gennady Feldman -- fixed a syslogd bug where syslogd could cause
the init process to block (which can break systems badly).
New Applets:
* Sterling Huxley -- contributed a new vi applet! This is a very
functional vi implementation in Only 22k.
* Erik Andersen -- added env applet
Other changes:
* Erik Andersen -- Split utility.c into libbb, which provides a
much cleaner was for us to include shared functionality.
* Erik Andersen -- Reorganized how and when busybox includes
syscalls, aiding portability and (in this case) making the
busybox work on ia64 systems.
* Erik Andersen -- dpkg.c cleanup to use the updated gunzip interface.
* Erik Andersen -- Cleanups for libc5, glibc, and uClibc.
* Erik Andersen and Matt Kraai -- Cleanups for the human-readable
output from ls, du, and df.
* Laurence Anderson <laurence@zxmail.com> -- Fixed wget HTTP 1.1
support and added chunked encoding so it is now RFC compliant.
* John Beppu -- The busybox.pod documentation is now automagically
generated from the source code. This makes it _much_ simpler.
Now to update the docs, just update the usage message...
* Dirk Behme <dirk.behme@de.bosch.com> -- Adjusted MIPS insmod
support a bit for Mips RS3.
* Christophe Boyanique -- egrep invoked the "init" applet in 0.50!
* Larry Doolittle -- Added -Wshadow and fixed a number of shadowed
variables
* David Douthitt -- fixed 'find -print'
* Gennady Feldman -- fixes for the syslogd circular buffer code
* Jeff Garzik -- a number of structural cleanups, fixes for -Wshadow
bugs, and similar problems.
* Matt Kraai -- Added a new 'shutdown' action to busybox init. Now
you can specify arbitrary behavior for 'ctrlaltdel' so now
pressing CTL-ALT-DEL can do something else (or nothing).
* Andreas Neuhaus <andy@fasta.fh-dortmund.de> -- fix for merging
kernel command line environment variables into child environment
for init.c
* Glenn McGrath -- Fixed problems with dpkg and dpkg-deb applets
* Glenn McGrath -- Don't try to automount devfs
* Vladimir Oleynik -- optimizations for more.c
* Vladimir Oleynik -- Added locale support to the shell, and fixed
locale support in several other places
* Vladimir Oleynik -- moved struct applet from busybox.c to applets.c
* Vladimir Oleynik -- A size optimization for rdate
* Vladimir Oleynik -- Fixed printf applets's locale handling
* Vladimir Oleynik -- More cmdedit updates
* Vladimir Oleynik -- Fixed `du' applet so it continues running
after permission errors.
* Vladimir Oleynik -- Reduced stack usage in recursive_action()
* Pierre Peiffer <pierre.peiffer@sxb.bsf.alcatel.fr> -- made
find_pid_by_name() cope with swapped out processes.
* Jari Ruusu <jari.ruusu@pp.inet.fi> -- updates so that setting
D_FILE_OFFSET_BITS=64 now works as expected.
* Anthony Towns <aj@azure.humbug.org.au> -- fixed a bug with
sed address range handling
* Dmitry Zakharov <dmit@crp.bank.gov.ua> -- a number of updates
to wget: support for ftp downloads, basic HTTP basic auth, handling
of http redirects, when attempting to continue an aborted download
but server doesn't support restarts then reopen output file in
write mode, bugfix: when content-length not given, wget didn't
download anything, if -c is not specified, it no longer default to
restarting an aborted download.
-Erik Andersen, not yet released
0.50
* Erik Andersen -- added ifconfig interface status reporting
* Erik Andersen -- Debian packaging updates
* Erik Andersen -- lash environment variable expansion rewritten,
with lots of help/fixes/testing from Larry Doolittle.
* Erik Andersen -- Fix use of busybox with dmalloc debugging lib
* Erik Andersen -- fixed ls behavior for broken or very narrow terminals.
* Erik Andersen -- stub umount2 and pivot_root if they are not available.
* Erik Andersen -- fixed ls behavior for broken or very narrow terminals
* Erik Andersen -- stub umount2 and pivot_root if they are not available
* Erik Andersen -- libc5 fixes
* Erik Andersen -- make init work with devfsd
* Erik Andersen -- fixed df for nfs and dos where blksize = 512
+24 -17
View File
@@ -7,6 +7,7 @@
//
//
// BusyBox Applications
//#define BB_ADJTIMEX
//#define BB_AR
#define BB_BASENAME
#define BB_CAT
@@ -31,6 +32,7 @@
#define BB_DU
//#define BB_DUMPKMAP
#define BB_ECHO
#define BB_ENV
//#define BB_EXPR
//#define BB_FBSET
//#define BB_FDFLUSH
@@ -118,6 +120,7 @@
//#define BB_UPDATE
#define BB_UPTIME
//#define BB_USLEEP
//#define BB_VI
//#define BB_WATCHDOG
#define BB_WC
//#define BB_WGET
@@ -152,12 +155,11 @@
// I emailed Linus and this patch will not be going into the stock kernel.
//#define BB_FEATURE_USE_DEVPS_PATCH
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
#define BB_FEATURE_TRIVIAL_HELP
// show verbose usage messages
//#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
//#define BB_FEATURE_USE_TERMIOS
//
// calculate terminal & column widths (for more and ls)
#define BB_FEATURE_AUTOWIDTH
@@ -209,7 +211,7 @@
#define BB_FEATURE_MOUNT_LOOP
//
// Enable support for a real /etc/mtab file instead of /proc/mounts
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
//#define BB_FEATURE_MTAB_SUPPORT
//
// Enable support for mounting remote NFS volumes.
// You may need to mount with "-o nolock" if you are
@@ -306,6 +308,9 @@
// Enable a nifty progress meter in wget (adds just under 2k)
#define BB_FEATURE_WGET_STATUSBAR
//
// Enable HTTP authentication in wget
#define BB_FEATURE_WGET_AUTHENTICATION
//
// Clean up all memory before exiting -- usually not needed
// as the OS can clean up... Don't enable this unless you
// have a really good reason for cleaning things up manually.
@@ -333,6 +338,20 @@
#define BB_FEATURE_TFTP_PUT
#define BB_FEATURE_TFTP_GET
//
// features for vi
#define BB_FEATURE_VI_COLON // ":" colon commands, no "ex" mode
#define BB_FEATURE_VI_YANKMARK // Yank/Put commands and Mark cmds
#define BB_FEATURE_VI_SEARCH // search and replace cmds
#define BB_FEATURE_VI_USE_SIGNALS // catch signals
#define BB_FEATURE_VI_DOT_CMD // remember previous cmd and "." cmd
#define BB_FEATURE_VI_READONLY // vi -R and "view" mode
#define BB_FEATURE_VI_SETOPTS // set-able options, ai ic showmatch
#define BB_FEATURE_VI_SET // :set
#define BB_FEATURE_VI_WIN_RESIZE // handle window resize
//
// Enable a if you system have setuped locale
//#define BB_LOCALE_SUPPORT
//
// End of Features List
//
//
@@ -344,20 +363,9 @@
// Nothing beyond this point should ever be touched by
// mere mortals so leave this stuff alone.
//
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
#define BB_MTAB
#endif
#else
#undef BB_MTAB
#endif
//
#if defined BB_SH
#if defined BB_FEATURE_COMMAND_EDITING
#define BB_CMDEDIT
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
#endif
#else
#undef BB_FEATURE_COMMAND_EDITING
#undef BB_FEATURE_COMMAND_TAB_COMPLETION
@@ -365,7 +373,6 @@
#define BB_FEATURE_SH_SIMPLE_PROMPT
#endif
#else
#undef BB_FEATURE_COMMAND_EDITING
#undef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
#undef BB_FEATURE_SH_STANDALONE_SHELL
#undef BB_FEATURE_SH_SIMPLE_PROMPT
+2 -3
View File
@@ -144,9 +144,8 @@
// at the same time...
#define BB_FEATURE_USE_PROCFS
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
//#define BB_FEATURE_TRIVIAL_HELP
// show verbose usage messages
#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
+56 -11
View File
@@ -18,7 +18,7 @@
#
PROG := busybox
VERSION := 0.50
VERSION := 0.51
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
export VERSION
@@ -60,6 +60,10 @@ USE_SYSTEM_PWD_GRP = true
# Do not enable this for production builds...
DODMALLOC = false
# Electric-fence is another very useful malloc debugging library.
# Do not enable this for production builds...
DOEFENCE = false
# If you want large file summit support, turn this on.
# This has no effect if you don't have a kernel with lfs
# support, and a system with libc-2.1.3 or later.
@@ -84,7 +88,7 @@ STRIPTOOL = $(CROSS)strip
# To compile vs uClibc, just use the compiler wrapper built by uClibc...
# This make things very easy? Everything should compile and work as
# expected these days...
#CC = ../uClibc/extra/gcc-uClibc/gcc-uClibc-i386
#CC = ../uClibc/extra/gcc-uClibc/i386-uclibc-gcc
# To compile vs some other alternative libc, you may need to use/adjust
# the following lines to meet your needs...
@@ -108,7 +112,9 @@ STRIPTOOL = $(CROSS)strip
OPTIMIZATION := $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
then echo "-Os"; else echo "-O2" ; fi)
WARNINGS = -Wall
WARNINGS = -Wall -Wshadow
ARFLAGS = -r
#
#--------------------------------------------------------
@@ -129,6 +135,12 @@ ifeq ($(strip $(DODMALLOC)),true)
LIBRARIES = -ldmalloc
# Force debug=true, since this is useless when not debugging...
DODEBUG = true
else
ifeq ($(strip $(DOEFENCE)),true)
LIBRARIES = -lefence
# Force debug=true, since this is useless when not debugging...
DODEBUG = true
endif
endif
ifeq ($(strip $(DODEBUG)),true)
CFLAGS += $(WARNINGS) -g -D_GNU_SOURCE
@@ -200,7 +212,7 @@ endif
# And option 4:
-include applet_source_list
OBJECTS = $(APPLET_SOURCES:.c=.o) busybox.o messages.o usage.o utility.o
OBJECTS = $(APPLET_SOURCES:.c=.o) busybox.o messages.o usage.o applets.o
CFLAGS += $(CROSS_CFLAGS)
CFLAGS += -DBB_VER='"$(VERSION)"'
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
@@ -220,6 +232,27 @@ ifneq ($(strip $(USE_SYSTEM_PWD_GRP)),true)
else
CFLAGS += -DUSE_SYSTEM_PWD_GRP
endif
LIBBB = libbb
LIBBB_LIB = libbb.a
LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c copy_file.c \
copy_file_chunk.c create_path.c daemon.c device_open.c error_msg.c \
find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
full_write.c get_console.c get_last_path_component.c get_line_from_file.c \
human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \
mode_string.c parse_mode.c parse_number.c print_file.c process_escape_sequence.c \
my_getgrgid.c my_getpwnamegid.c my_getpwuid.c my_getgrnam.c my_getpwnam.c \
recursive_action.c safe_read.c safe_strncpy.c syscalls.c module_syscalls.c \
syslog_msg_with_name.c time_string.c trim.c vdprintf.c wfopen.c xfuncs.c \
xregcomp.c error_msg_and_die.c perror_msg.c perror_msg_and_die.c \
verror_msg.c vperror_msg.c mtab.c mtab_file.c xgetcwd.c concat_path_file.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
LIBBB_CFLAGS = -I$(LIBBB)
ifneq ($(strip $(BB_SRC_DIR)),)
LIBBB_CFLAGS += -I$(BB_SRC_DIR)/$(LIBBB)
endif
# Put user-supplied flags at the end, where they
# have a chance of winning.
@@ -235,7 +268,12 @@ applet_source_list: busybox.sh Config.h
doc: olddoc
# Old Docs...
olddoc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
docs/busybox.pod : docs/busybox_header.pod usage.h docs/busybox_footer.pod
- ( cat docs/busybox_header.pod; \
docs/autodocifier.pl usage.h; \
cat docs/busybox_footer.pod ) > docs/busybox.pod
docs/BusyBox.txt: docs/busybox.pod
@echo
@@ -288,8 +326,8 @@ docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
busybox: $(PWD_LIB) $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) $(PWD_LIB)
busybox: $(PWD_LIB) $(LIBBB_LIB) $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(PWD_LIB) $(LIBBB_LIB) $(LIBRARIES)
$(STRIP)
# Without VPATH, rule expands to "/bin/sh busybox.mkll Config.h applets.h"
@@ -307,14 +345,21 @@ $(PWD_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile
- mkdir -p $(PWD_GRP)
$(CC) $(CFLAGS) $(PWD_CFLAGS) -c $< -o $*.o
$(LIBBB_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile libbb/libbb.h
- mkdir -p $(LIBBB)
$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -c $< -o $*.o
libpwd.a: $(PWD_OBJS)
$(AR) $(ARFLAGS) $@ $^
libbb.a: $(LIBBB_OBJS)
$(AR) $(ARFLAGS) $@ $^
usage.o: usage.h
utility.o: loop.h
libbb/loop.o: libbb/loop.h
loop.h: mk_loop_h.sh
libbb/loop.h: mk_loop_h.sh
@ $(SHELL) $< > $@
test tests:
@@ -330,8 +375,8 @@ clean:
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
docs/busybox.pdf docs/busybox.lineo.com/busybox.html
- rm -f multibuild.log Config.h.orig
- rm -rf docs/busybox _install libpwd.a
- rm -f busybox.links loop.h *~ slist.mk core applet_source_list
- rm -rf docs/busybox _install libpwd.a libbb.a
- rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list
- find -name \*.o -exec rm -f {} \;
distclean: clean
+6 -5
View File
@@ -11,9 +11,9 @@ the expected functionality and behave very much like their GNU counterparts.
BusyBox has been written with size-optimization and limited resources in mind.
It is also extremely modular so you can easily include or exclude commands (or
features) at compile time. This makes it easy to customize your embedded
systems. To create a working system, just add /dev, a kernel, and an editor,
such as nano, e3, or elvis-tiny. For a really minimal system, you can even use
the busybox shell (not Bourne compatible, but very small and quite usable).
systems. To create a working system, just add /dev, a shell, and a kernel. For
a really minimal system, you can even use the busybox shell (not Bourne
compatible, but very small and quite usable) and the busybox vi editor.
BusyBox was originally written to support the Debian Rescue/Install disks, but
it also makes an excellent environment for any small or embedded system.
@@ -36,7 +36,7 @@ Supported architectures:
Busybox in general will build on any architecture supported by gcc. It has
a few specialized features added for __sparc__ and __alpha__. insmod
functionality is currently limited to x86, ARM, and SH3/4.
functionality is currently limited to x86, ARM, SH3/4, powerpc, and MIPS.
Supported libcs:
@@ -71,7 +71,7 @@ to submit@bugs.lineo.com. Bug reports should look something like this:
Subject: /bin/true doesn't work
Package: busybox
Version: 0.48
Version: 0.51
When I invoke '/bin/true' it doesn't work. I expected it to return
a "0" but it returned a "1" instead. Here is the transcript:
@@ -115,6 +115,7 @@ Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@debian.org>
<andersee@codepoet.org>
<blatant plug>
Many thanks to go to Lineo for paying me to work on busybox.
+9 -8
View File
@@ -11,13 +11,14 @@ around to it some time. If you have any good ideas, please let me know.
to happen. False alarm. Sorry about the confusion.
* The busybox shell, lash, is really too weak for serious use, although it is
possible to run simple systems with it. BusyBox 0.49 was supposed to have
a new shell, updated to understand full Bourne grammer. Well, that simply
didn't happen in time for the release. A rewrite is in progress that will
result in a new shell that understands the full Bourne grammar. This new
shell is being championed by Larry Doolittle <ldoolitt@recycle.lbl.gov>, and
could use your help. Please see the work in progress at
http://doolittle.faludi.com/~larry/parser.html
possible to run many simple systems with it. BusyBox 0.49 was supposed to
have a new shell, updated to understand full Bourne grammer. Well, that
simply didn't happen in time for the release. A rewrite is in progress
that will result in a new shell that understands the full Bourne grammar.
This new shell is being championed by Larry Doolittle
<ldoolitt@recycle.lbl.gov>, and could use your help. Please see the work
in progress at http://doolittle.faludi.com/~larry/parser.html and help
us out.
-Erik
@@ -31,7 +32,7 @@ Possible apps to include some time:
-----------
Write a fixup_globals function to do just that right before calling
non-forking applets. Or, just always fork...
non-forking applets. Or, just always fork in the shell...
-----------------------
+176
View File
@@ -0,0 +1,176 @@
/*
* adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
*
* Originally written: October 1997
* Last hack: March 2001
* Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (Version 2,
* June 1991) as published by the Free Software Foundation. At the
* time of writing, that license was published by the FSF with the URL
* http://www.gnu.org/copyleft/gpl.html, and is incorporated herein by
* reference.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This adjtimex(1) is very similar in intent to adjtimex(8) by Steven
* Dick <ssd@nevets.oau.org> and Jim Van Zandt <jrv@vanzandt.mv.com>
* (see http://metalab.unc.edu/pub/Linux/system/admin/time/adjtimex*).
* That version predates this one, and is _much_ bigger and more
* featureful. My independently written version was very similar to
* Steven's from the start, because they both follow the kernel timex
* structure. I further tweaked this version to be equivalent to Steven's
* where possible, but I don't like getopt_long, so the actual usage
* syntax is incompatible.
*
* Amazingly enough, my Red Hat 5.2 sys/timex (and sub-includes)
* don't actually give a prototype for adjtimex(2), so building
* this code (with -Wall) gives a warning. Later versions of
* glibc fix this issue.
*
* This program is too simple for a Makefile, just build with:
* gcc -Wall -O adjtimex.c -o adjtimex
*
* busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov>
* It will autosense if it is built in a busybox environment, based
* on the BB_VER preprocessor macro.
*/
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#if __GNU_LIBRARY__ < 5
#include <sys/timex.h>
extern int adjtimex(struct timex *buf);
#else
#include <sys/timex.h>
#endif
#ifdef BB_VER
#include "busybox.h"
#endif
static struct {int bit; char *name;} statlist[] = {
{ STA_PLL, "PLL" },
{ STA_PPSFREQ, "PPSFREQ" },
{ STA_PPSTIME, "PPSTIME" },
{ STA_FLL, "FFL" },
{ STA_INS, "INS" },
{ STA_DEL, "DEL" },
{ STA_UNSYNC, "UNSYNC" },
{ STA_FREQHOLD, "FREQHOLD" },
{ STA_PPSSIGNAL, "PPSSIGNAL" },
{ STA_PPSJITTER, "PPSJITTER" },
{ STA_PPSWANDER, "PPSWANDER" },
{ STA_PPSERROR, "PPSERROR" },
{ STA_CLOCKERR, "CLOCKERR" },
{ 0, NULL } };
static char *ret_code_descript[] = {
"clock synchronized",
"insert leap second",
"delete leap second",
"leap second in progress",
"leap second has occurred",
"clock not synchronized" };
#ifdef BB_VER
#define main adjtimex_main
#else
void usage(char *prog)
{
fprintf(stderr,
"Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n",
prog);
}
#define show_usage() usage(argv[0])
#endif
int main(int argc, char ** argv)
{
struct timex txc;
int quiet=0;
int c, i, ret, sep;
char *descript;
txc.modes=0;
for (;;) {
c = getopt( argc, argv, "qo:f:p:t:");
if (c == EOF) break;
switch (c) {
case 'q':
quiet=1;
break;
case 'o':
txc.offset = atoi(optarg);
txc.modes |= ADJ_OFFSET_SINGLESHOT;
break;
case 'f':
txc.freq = atoi(optarg);
txc.modes |= ADJ_FREQUENCY;
break;
case 'p':
txc.constant = atoi(optarg);
txc.modes |= ADJ_TIMECONST;
break;
case 't':
txc.tick = atoi(optarg);
txc.modes |= ADJ_TICK;
break;
default:
show_usage();
exit(1);
}
}
if (argc != optind) { /* no valid non-option parameters */
show_usage();
exit(1);
}
ret = adjtimex(&txc);
if (ret < 0) perror("adjtimex");
if (!quiet && ret>=0) {
printf(
" mode: %d\n"
"-o offset: %ld\n"
"-f frequency: %ld\n"
" maxerror: %ld\n"
" esterror: %ld\n"
" status: %d ( ",
txc.modes, txc.offset, txc.freq, txc.maxerror,
txc.esterror, txc.status);
/* representative output of next code fragment:
"PLL | PPSTIME" */
sep=0;
for (i=0; statlist[i].name; i++) {
if (txc.status & statlist[i].bit) {
if (sep) fputs(" | ",stdout);
fputs(statlist[i].name,stdout);
sep=1;
}
}
descript = "error";
if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
printf(" )\n"
"-p timeconstant: %ld\n"
" precision: %ld\n"
" tolerance: %ld\n"
"-t tick: %ld\n"
" time.tv_sec: %ld\n"
" time.tv_usec: %ld\n"
" return value: %d (%s)\n",
txc.constant,
txc.precision, txc.tolerance, txc.tick,
(long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);
}
return (ret<0);
}
+108
View File
@@ -0,0 +1,108 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "busybox.h"
#undef APPLET
#undef APPLET_NOUSAGE
#undef PROTOTYPES
#include "applets.h"
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
struct BB_applet *applet_using;
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
extern void show_usage(void)
{
const char *format_string;
const char *usage_string = usage_messages;
int i;
/* From busybox.c */
extern int been_there_done_that;
if (strcmp(applet_using->name, "busybox")==0) {
been_there_done_that=1;
busybox_main(0, NULL);
}
for (i = applet_using - applets; i > 0; ) {
if (!*usage_string++) {
--i;
}
}
format_string = "%s\n\nUsage: %s %s\n\n";
if(*usage_string == 0)
format_string = "%s\n\nNo help available.\n\n";
fprintf(stderr, format_string,
full_version, applet_using->name, usage_string);
exit(EXIT_FAILURE);
}
static int applet_name_compare(const void *x, const void *y)
{
const char *name = x;
const struct BB_applet *applet = y;
return strcmp(name, applet->name);
}
extern size_t NUM_APPLETS;
struct BB_applet *find_applet_by_name(const char *name)
{
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
applet_name_compare);
}
void run_applet_by_name(const char *name, int argc, char **argv)
{
/* Do a binary search to find the applet entry given the name. */
if ((applet_using = find_applet_by_name(name)) != NULL) {
applet_name = applet_using->name;
if (argv[1] && strcmp(argv[1], "--help") == 0)
show_usage();
exit((*(applet_using->main)) (argc, argv));
}
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+15 -9
View File
@@ -21,14 +21,14 @@
#define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
extern const char usage_messages[];
#elif defined(MAKE_USAGE)
#ifdef BB_FEATURE_TRIVIAL_HELP
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#else
#ifdef BB_FEATURE_VERBOSE_USAGE
#define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#else
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#endif
#elif defined(MAKE_LINKS)
# define APPLET(a,b,c) LINK c a
@@ -46,6 +46,9 @@
#ifdef BB_TEST
APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_ADJTIMEX
APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
#endif
#ifdef BB_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN)
#endif
@@ -126,7 +129,10 @@
APPLET(echo, echo_main, _BB_DIR_BIN)
#endif
#if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP)
APPLET_NOUSAGE("egrep", init_main, _BB_DIR_BIN)
APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN)
#endif
#ifdef BB_ENV
APPLET(env, env_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_EXPR
APPLET(expr, expr_main, _BB_DIR_USR_BIN)
@@ -407,6 +413,9 @@
#ifdef BB_UUENCODE
APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_VI
APPLET(vi, vi_main, _BB_DIR_BIN)
#endif
#ifdef BB_WATCHDOG
APPLET(watchdog, watchdog_main, _BB_DIR_SBIN)
#endif
@@ -436,7 +445,4 @@
{ 0,NULL,0 }
};
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
#endif
+108
View File
@@ -0,0 +1,108 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "busybox.h"
#undef APPLET
#undef APPLET_NOUSAGE
#undef PROTOTYPES
#include "applets.h"
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
struct BB_applet *applet_using;
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
extern void show_usage(void)
{
const char *format_string;
const char *usage_string = usage_messages;
int i;
/* From busybox.c */
extern int been_there_done_that;
if (strcmp(applet_using->name, "busybox")==0) {
been_there_done_that=1;
busybox_main(0, NULL);
}
for (i = applet_using - applets; i > 0; ) {
if (!*usage_string++) {
--i;
}
}
format_string = "%s\n\nUsage: %s %s\n\n";
if(*usage_string == 0)
format_string = "%s\n\nNo help available.\n\n";
fprintf(stderr, format_string,
full_version, applet_using->name, usage_string);
exit(EXIT_FAILURE);
}
static int applet_name_compare(const void *x, const void *y)
{
const char *name = x;
const struct BB_applet *applet = y;
return strcmp(name, applet->name);
}
extern size_t NUM_APPLETS;
struct BB_applet *find_applet_by_name(const char *name)
{
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
applet_name_compare);
}
void run_applet_by_name(const char *name, int argc, char **argv)
{
/* Do a binary search to find the applet entry given the name. */
if ((applet_using = find_applet_by_name(name)) != NULL) {
applet_name = applet_using->name;
if (argv[1] && strcmp(argv[1], "--help") == 0)
show_usage();
exit((*(applet_using->main)) (argc, argv));
}
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+18 -14
View File
@@ -6,16 +6,15 @@
#include <stdlib.h>
#include "busybox.h"
#undef APPLET
#undef APPLET_NOUSAGE
#undef PROTOTYPES
#include "applets.h"
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
static int been_there_done_that = 0;
#ifdef BB_LOCALE_SUPPORT
#include <locale.h>
#endif
int been_there_done_that = 0; /* Also used in applets.c */
const char *applet_name;
#ifdef BB_FEATURE_INSTALLER
@@ -65,7 +64,7 @@ static void install_links(const char *busybox, int use_symbolic_links)
{
__link_f Link = link;
char command[256];
char *fpc;
int i;
int rc;
@@ -73,13 +72,13 @@ static void install_links(const char *busybox, int use_symbolic_links)
Link = symlink;
for (i = 0; applets[i].name != NULL; i++) {
sprintf ( command, "%s/%s",
install_dir[applets[i].location], applets[i].name);
rc = Link(busybox, command);
if (rc) {
perror_msg("%s", command);
fpc = concat_path_file(
install_dir[applets[i].location], applets[i].name);
rc = Link(busybox, fpc);
if (rc!=0 && errno!=EEXIST) {
perror_msg("%s", fpc);
}
free(fpc);
}
}
@@ -98,10 +97,15 @@ int main(int argc, char **argv)
/* Add in a special case hack -- whenever **argv == '-'
* (i.e. '-su' or '-sh') always invoke the shell */
if (**argv == '-' && *(*argv+1)!= '-') {
exit(((*(shell_main)) (argc, argv)));
applet_name = "sh";
}
#endif
#ifdef BB_LOCALE_SUPPORT
if(getpid()!=1) /* Do not set locale for `init' */
setlocale(LC_ALL, "");
#endif
run_applet_by_name(applet_name, argc, argv);
error_msg_and_die("applet not found");
}
+50 -9
View File
@@ -1,3 +1,16 @@
#define adjtimex_trivial_usage \
"[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]"
#define adjtimex_full_usage \
"Reads and optionally sets system timebase parameters.\n" \
"See adjtimex(2).\n\n" \
"Options:\n" \
"\t-q\t\tquiet mode - do not print\n" \
"\t-o offset\ttime offset, microseconds\n" \
"\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \
"\t\t\t(positive values make the system clock run fast)\n" \
"\t-t tick\t\tmicroseconds per tick, usually 10000\n" \
"\t-p timeconstant\n"
#define ar_trivial_usage \
"-[ovR]{ptx} archive filenames"
#define ar_full_usage \
@@ -62,7 +75,7 @@
"-r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo\n"
#define chown_trivial_usage \
"[OPTION]... OWNER[<.|:>[GROUP] FILE..."
"[OPTION]... OWNER[<.|:>[GROUP]] FILE..."
#define chown_full_usage \
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" \
"\nOptions:\n" \
@@ -330,6 +343,15 @@
"$ echo "Erik\nis\ncool"\n" \
"Erik\nis\ncool\n"
#define env_trivial_usage \
"[-] [-iu] [name=value ...] [command]"
#define env_full_usage \
"Prints the current environment or runs a program after setting\n" \
"up the specified environment.\n\n" \
"Options:\n" \
"\t-, -i\tstart with an empty environment\n" \
"\t-u\tremove variable from the environment\n"
#define expr_trivial_usage \
"EXPRESSION"
#define expr_full_usage \
@@ -416,6 +438,7 @@
"\nEXPRESSION may consist of:\n" \
"\t-follow\t\tDereference symbolic links.\n" \
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN." \
"\t-print\t\tPrint (default and assumed).\n" \
USAGE_FIND_TYPE( \
"\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \
) USAGE_FIND_PERM( \
@@ -499,6 +522,7 @@
"\t-H\tprefix output lines with filename where match was found\n" \
"\t-h\tsuppress the prefixing filename on output\n" \
"\t-i\tignore case distinctions\n" \
"\t-l\tlist names of files that match\n" \
"\t-n\tprint line number with output lines\n" \
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n" \
"\t-v\tselect non-matching lines\n" \
@@ -640,10 +664,15 @@
"\n" \
" ::sysinit:/etc/init.d/rcS\n" \
" ::askfirst:/bin/sh\n" \
" ::ctrlaltdel:/sbin/reboot\n" \
" ::shutdown:/sbin/swapoff -a\n" \
" ::shutdown:/bin/umount -a -r\n" \
"\n" \
"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
"\n" \
" tty2::askfirst:/bin/sh\n" \
" tty3::askfirst:/bin/sh\n" \
" tty4::askfirst:/bin/sh\n" \
"\n" \
"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
"\n" \
@@ -669,7 +698,7 @@
" <action>: \n" \
"\n" \
" Valid actions include: sysinit, respawn, askfirst, wait, \n" \
" once, and ctrlaltdel.\n" \
" once, ctrlaltdel, and shutdown.\n" \
"\n" \
" The available actions can be classified into two groups: actions\n" \
" that are run only once, and actions that are re-run when the specified\n" \
@@ -683,9 +712,12 @@
" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \
" the specified task completes. 'once' actions are asyncronous,\n" \
" therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \
" actions are run immediately before init causes the system to reboot\n" \
" (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
" idea).\n" \
" actions are run when the system detects that someone on the system\n" \
" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \
" wants to run 'reboot' at this point to cause the system to reboot.\n" \
" Finally the 'shutdown' action specifies the actions to taken when\n" \
" init is told to reboot. Unmounting filesystems and disabling swap\n" \
" is a very good here\n" \
"\n" \
" Run repeatedly actions:\n" \
"\n" \
@@ -736,8 +768,9 @@
" #::respawn:/sbin/getty 57600 ttyS2\n" \
" \n" \
" # Stuff to do before rebooting\n" \
" ::ctrlaltdel:/bin/umount -a -r\n" \
" ::ctrlaltdel:/sbin/swapoff -a\n"
" ::ctrlaltdel:/sbin/reboot\n" \
" ::shutdown:/bin/umount -a -r\n" \
" ::shutdown:/sbin/swapoff -a\n"
#define insmod_trivial_usage \
"[OPTION]... MODULE [symbol=value]..."
@@ -1044,7 +1077,7 @@
#else
#define USAGE_MOUNT_LOOP(a)
#endif
#ifdef BB_MTAB
#ifdef BB_FEATURE_MTAB_SUPPORT
#define USAGE_MTAB(a) a
#else
#define USAGE_MTAB(a)
@@ -1657,6 +1690,13 @@
"$ uudecode busybox busybox > busybox.uu\n" \
"$\n"
#define vi_trivial_usage \
"[OPTION] [FILE]..."
#define vi_full_usage \
"edit FILE.\n\n" \
"Options:\n" \
"\t-R\tRead-only- do not write to the file."
#define watchdog_trivial_usage \
"DEV"
#define watchdog_full_usage \
@@ -1679,9 +1719,10 @@
#define wget_trivial_usage \
"[-c] [-O file] url"
#define wget_full_usage \
"wget retrieves files via HTTP\n\n" \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
"\t-c\tcontinue retrieval of aborted transfers\n" \
"\t-q\tquiet mode - do not print\n" \
"\t-O\tsave to filename ('-' for stdout)"
#define which_trivial_usage \
+4 -4
View File
@@ -31,7 +31,7 @@
typedef struct ar_headers_s {
char *name;
size_t size;
off_t size;
uid_t uid;
gid_t gid;
mode_t mode;
@@ -90,7 +90,7 @@ extern ar_headers_t get_ar_headers(int srcFd)
/* dont worry about adding the last '\n', we dont need it now */
}
entry->size = (size_t) atoi(raw_ar_header.size);
entry->size = (off_t) atoi(raw_ar_header.size);
/* long filenames have '/' as the first character */
if (raw_ar_header.name[0] == '/') {
if (raw_ar_header.name[1] == '/') {
@@ -211,12 +211,12 @@ extern int ar_main(int argc, char **argv)
}
if ((funct & extract_to_file) || (funct & extract_to_stdout)) {
lseek(srcFd, extract_list->offset, SEEK_SET);
copy_file_chunk(srcFd, dstFd, (size_t) extract_list->size);
copy_file_chunk(srcFd, dstFd, (off_t) extract_list->size);
}
if (funct & verbose) {
printf("%s %d/%d %8d %s ", mode_string(extract_list->mode),
extract_list->uid, extract_list->gid,
extract_list->size, time_string(extract_list->mtime));
(int) extract_list->size, time_string(extract_list->mtime));
}
if ((funct & display) || (funct & verbose)){
printf("%s\n", extract_list->name);
+4 -4
View File
@@ -31,7 +31,7 @@
typedef struct ar_headers_s {
char *name;
size_t size;
off_t size;
uid_t uid;
gid_t gid;
mode_t mode;
@@ -90,7 +90,7 @@ extern ar_headers_t get_ar_headers(int srcFd)
/* dont worry about adding the last '\n', we dont need it now */
}
entry->size = (size_t) atoi(raw_ar_header.size);
entry->size = (off_t) atoi(raw_ar_header.size);
/* long filenames have '/' as the first character */
if (raw_ar_header.name[0] == '/') {
if (raw_ar_header.name[1] == '/') {
@@ -211,12 +211,12 @@ extern int ar_main(int argc, char **argv)
}
if ((funct & extract_to_file) || (funct & extract_to_stdout)) {
lseek(srcFd, extract_list->offset, SEEK_SET);
copy_file_chunk(srcFd, dstFd, (size_t) extract_list->size);
copy_file_chunk(srcFd, dstFd, (off_t) extract_list->size);
}
if (funct & verbose) {
printf("%s %d/%d %8d %s ", mode_string(extract_list->mode),
extract_list->uid, extract_list->gid,
extract_list->size, time_string(extract_list->mtime));
(int) extract_list->size, time_string(extract_list->mtime));
}
if ((funct & display) || (funct & verbose)){
printf("%s\n", extract_list->name);
+278 -285
View File
@@ -1,3 +1,5 @@
#include <dirent.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -12,21 +14,13 @@
#include "busybox.h"
/* Stupid libc doesn't have a reliable way for use to know
* that libc5 is being used. Assume this is good enough */
#if !defined __GLIBC__ && !defined __UCLIBC__
#error It looks like you are using libc5, which does not support
#error tfind(). tfind() is used by busybox dpkg.
#error Please disable BB_DPKG. Sorry.
#endif
#define DEPENDSMAX 64 /* maximum number of depends we can handle */
/* Should we do full dependency checking? */
#define DODEPENDS 1
/* Should we do debugging? */
#define DODEBUG 1
//#define DODEBUG 1
#ifdef DODEBUG
#define SYSTEM(x) do_system(x)
@@ -54,39 +48,30 @@ static const char dpkgcidir[] = "/var/lib/dpkg/tmp.ci/";
static const char infodir[] = "/var/lib/dpkg/info/";
static const char udpkg_quiet[] = "UDPKG_QUIET";
//static const int status_wantstart = 0;
//static const int status_wantunknown = (1 << 0);
static const int status_wantinstall = (1 << 1);
//static const int status_wanthold = (1 << 2);
//static const int status_wantdeinstall = (1 << 3);
//static const int status_wantpurge = (1 << 4);
static const int status_wantmask = 31;
//static const int status_want_unknown = 1;
static const int status_want_install = 2;
//static const int status_want_hold = 3;
//static const int status_want_deinstall = 4;
//static const int status_want_purge = 5;
//static const int status_flagstart = 5;
static const int status_flagok = (1 << 5); /* 32 */
//static const int status_flagreinstreq = (1 << 6);
//static const int status_flaghold = (1 << 7);
//static const int status_flagholdreinstreq = (1 << 8);
static const int status_flagmask = 480;
static const int status_flag_ok = 1;
//static const int status_flag_reinstreq = 2;
//static const int status_flag_hold = 3;
//static const int status_flag_holdreinstreq = 4;
//static const int status_statusstart = 9;
//static const int status_statusnoninstalled = (1 << 9); /* 512 */
static const int status_statusunpacked = (1 << 10);
static const int status_statushalfconfigured = (1 << 11);
static const int status_statusinstalled = (1 << 12);
static const int status_statushalfinstalled = (1 << 13);
//static const int status_statusconfigfiles = (1 << 14);
//static const int status_statuspostinstfailed = (1 << 15);
//static const int status_statusremovalfailed = (1 << 16);
static const int status_statusmask = 130560; /* i assume status_statusinstalled is supposed to be included */
//static const int status_statusnoninstalled = 1;
static const int status_status_unpacked = 2;
static const int status_status_halfconfigured = 3;
static const int status_status_installed = 4;
static const int status_status_halfinstalled = 5;
//static const int status_statusconfigfiles = 6;
//static const int status_statuspostinstfailed = 7;
//static const int status_statusremovalfailed = 8;
static const char *statuswords[][10] = {
{ (char *) 0, "unknown", "install", "hold", "deinstall", "purge", 0 },
{ (char *) 5, "ok", "reinstreq", "hold", "hold-reinstreq", 0 },
{ (char *) 9, "not-installed", "unpacked", "half-configured",
"installed", "half-installed", "config-files",
"post-inst-failed", "removal-failed", 0 }
};
static const char *status_words_want[] = { "unknown", "install", "hold", "deinstall", "purge", 0 };
static const char *status_words_flag[] = { "ok", "reinstreq", "hold", "hold-reinstreq", 0 };
static const char *status_words_status[] = { "not-installed", "unpacked", "half-configured", "installed",
"half-installed", "config-files", "post-inst-failed", "removal-failed", 0 };
static const int color_white = 0;
static const int color_grey = 1;
@@ -101,7 +86,9 @@ typedef struct package_s {
char *provides;
char *description;
int installer_menu_item;
unsigned long status;
unsigned char status_want;
unsigned char status_flag;
unsigned char status_status;
char color; /* for topo-sort */
struct package_s *requiredfor[DEPENDSMAX];
unsigned short requiredcount;
@@ -124,18 +111,34 @@ static int package_compare(const void *p1, const void *p2)
((package_t *)p2)->package);
}
static int remove_dpkgcidir()
/*
* NOTE: this was handled by a "rm -rf" shell command
* Maybe theis behaviour should be integrated into the rm applet
* (i dont appreciate the rm applets recursive action fn)-bug1
*/
static int remove_dir(const char *dirname)
{
char *rm_dpkgcidir = NULL;
struct dirent *fp;
DIR *dp = opendir(dirname);
while ((fp = readdir(dp)) != NULL) {
struct stat statbuf;
char *filename;
rm_dpkgcidir = (char *) xmalloc(strlen(dpkgcidir) + 8);
strcpy(rm_dpkgcidir, "rm -rf ");
strcat(rm_dpkgcidir, dpkgcidir);
filename = (char *) xcalloc(1, strlen(dirname) + strlen(fp->d_name) + 2);
strcpy(filename, dirname);
strcat(filename, fp->d_name);
lstat(filename, &statbuf);
if (SYSTEM(rm_dpkgcidir) != 0) {
perror("mkdir ");
return EXIT_FAILURE;
if ((strcmp(fp->d_name, ".") != 0) && (strcmp(fp->d_name, "..") != 0)) {
if (S_ISDIR(statbuf.st_mode)) {
remove_dir(strcat(filename, "/"));
}
else if (remove(filename) == -1) {
perror_msg(filename);
}
}
}
remove(dirname);
return EXIT_SUCCESS;
}
@@ -153,7 +156,7 @@ static char **depends_split(const char *dependsstr)
goto end;
}
p = strdup(dependsstr);
p = xstrdup(dependsstr);
while (*p != 0 && *p != '\n') {
if (*p != ' ') {
if (*p == ',') {
@@ -261,10 +264,9 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
while (dependsvec[i] != 0) {
/* Check for dependencies; first look for installed packages */
dependpkg.package = dependsvec[i];
if ((found = tfind(&dependpkg, &status, package_compare)) == 0 ||
((chk = *(package_t **)found) &&
(chk->status & (status_flagok | status_statusinstalled)) !=
(status_flagok | status_statusinstalled))) {
if (((found = tfind(&dependpkg, &status, package_compare)) == 0) ||
((chk = *(package_t **)found) && (chk->status_flag & status_flag_ok) &&
(chk->status_status & status_status_installed))) {
/* if it fails, we look through the list of packages we are going to
* install */
@@ -272,7 +274,7 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
if (strcmp(chk->package, dependsvec[i]) == 0 || (chk->provides &&
strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) {
if (chk->requiredcount >= DEPENDSMAX) {
fprintf(stderr, "Too many dependencies for %s\n", chk->package);
error_msg("Too many dependencies for %s", chk->package);
return 0;
}
if (chk != pkg) {
@@ -282,7 +284,7 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
}
}
if (chk == 0) {
fprintf(stderr, "%s depends on %s, but it is not going to be installed\n", pkg->package, dependsvec[i]);
error_msg("%s depends on %s, but it is not going to be installed", pkg->package, dependsvec[i]);
return 0;
}
}
@@ -308,58 +310,21 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
* replacing any pre-existing entries. when a merge happens, status info
* read using the status_read function is written back to the status file
*/
static unsigned long status_parse(const char *line)
static unsigned char status_parse(const char *line, const char **status_words)
{
char *p;
int i, j;
unsigned long l = 0;
unsigned char status_num;
int i = 0;
for (i = 0; i < 3; i++) {
if ((p = strchr(line, ' ')) != NULL) {
*p = 0;
while (status_words[i] != 0) {
if (strncmp(line, status_words[i], strlen(status_words[i])) == 0) {
status_num = (char)i;
return(status_num);
}
j = 1;
while (statuswords[i][j] != 0) {
if (strcmp(line, statuswords[i][j]) == 0) {
l |= (1 << ((int)statuswords[i][0] + j - 1));
break;
}
j++;
}
/* parse error */
if (statuswords[i][j] == 0) {
return 0;
}
line = p+1;
i++;
}
return l;
}
static const char *status_print(unsigned long flags)
{
/* this function returns a static buffer... */
static char buf[256];
int i, j;
buf[0] = 0;
for (i = 0; i < 3; i++) {
j = 1;
while (statuswords[i][j] != 0) {
if ((flags & (1 << ((int)statuswords[i][0] + j - 1))) != 0) {
strcat(buf, statuswords[i][j]);
if (i < 2) strcat(buf, " ");
break;
}
j++;
}
if (statuswords[i][j] == 0) {
fprintf(stderr, "corrupted status flag!!\n");
return NULL;
}
}
return buf;
/* parse error */
error_msg("Invalid status word");
return(0);
}
/*
@@ -371,28 +336,34 @@ static int control_read(FILE *file, package_t *p)
char *line;
while ((line = get_line_from_file(file)) != NULL) {
line[strlen(line)] = 0;
line[strlen(line) - 1] = '\0';
if (strlen(line) == 0) {
break;
} else
if (strstr(line, "Package: ") == line) {
p->package = strdup(line + 9);
} else
if (strstr(line, "Status: ") == line) {
p->status = status_parse(line + 8);
} else
if (strstr(line, "Depends: ") == line) {
p->depends = strdup(line + 9);
} else
if (strstr(line, "Provides: ") == line) {
p->provides = strdup(line + 10);
} else
if (strstr(line, "Description: ") == line) {
p->description = strdup(line + 13);
}
else if (strstr(line, "Package: ") == line) {
p->package = xstrdup(line + 9);
}
else if (strstr(line, "Status: ") == line) {
char *word_pointer;
word_pointer = strchr(line, ' ') + 1;
p->status_want = status_parse(word_pointer, status_words_want);
word_pointer = strchr(word_pointer, ' ') + 1;
p->status_flag = status_parse(word_pointer, status_words_flag);
word_pointer = strchr(word_pointer, ' ') + 1;
p->status_status = status_parse(word_pointer, status_words_status);
}
else if (strstr(line, "Depends: ") == line) {
p->depends = xstrdup(line + 9);
}
else if (strstr(line, "Provides: ") == line) {
p->provides = xstrdup(line + 10);
}
else if (strstr(line, "Description: ") == line) {
p->description = xstrdup(line + 13);
/* This is specific to the Debian Installer. Ifdef? */
} else
if (strstr(line, "installer-menu-item: ") == line) {
}
else if (strstr(line, "installer-menu-item: ") == line) {
p->installer_menu_item = atoi(line + 21);
}
/* TODO: localized descriptions */
@@ -407,18 +378,16 @@ static void *status_read(void)
void *status = 0;
package_t *m = 0, *p = 0, *t = 0;
if ((f = fopen(statusfile, "r")) == NULL) {
perror(statusfile);
return 0;
}
if (getenv(udpkg_quiet) == NULL) {
printf("(Reading database...)\n");
}
if ((f = wfopen(statusfile, "r")) == NULL) {
return(NULL);
}
while (!feof(f)) {
m = (package_t *)xmalloc(sizeof(package_t));
memset(m, 0, sizeof(package_t));
m = (package_t *)xcalloc(1, sizeof(package_t));
control_read(f, m);
if (m->package) {
/*
@@ -434,25 +403,24 @@ static void *status_read(void)
* of a pseudo package into the status
* binary-tree.
*/
p = (package_t *)xmalloc(sizeof(package_t));
memset(p, 0, sizeof(package_t));
p->package = strdup(m->provides);
p = (package_t *)xcalloc(1, sizeof(package_t));
p->package = xstrdup(m->provides);
t = *(package_t **)tsearch(p, &status, package_compare);
if (t != p) {
free(p->package);
free(p);
}
else {
} else {
/*
* Pseudo package status is the
* same as the status of the
* package providing it
* FIXME: (not quite right, if 2
* packages of different statuses
* provide it).
*/
t->status = m->status;
* provide it).
*/
t->status_want = m->status_want;
t->status_flag = m->status_flag;
t->status_status = m->status_status;
}
}
}
@@ -467,64 +435,67 @@ static void *status_read(void)
static int status_merge(void *status, package_t *pkgs)
{
FILE *fin, *fout;
char *line;
char *line = NULL;
package_t *pkg = 0, *statpkg = 0;
package_t locpkg;
int r = 0;
if ((fin = fopen(statusfile, "r")) == NULL) {
perror(statusfile);
return 0;
}
if ((fout = fopen(new_statusfile, "w")) == NULL) {
perror(new_statusfile);
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
return 0;
}
if (getenv(udpkg_quiet) == NULL) {
printf("(Updating database...)\n");
}
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
line[strlen(line)] = 0; /* trim newline */
/* If we see a package header, find out if it's a package
* that we have processed. if so, we skip that block for
* now (write it at the end).
*
* we also look at packages in the status cache and update
* their status fields
*/
if (strstr(line, "Package: ") == line) {
for (pkg = pkgs; pkg != 0 && strncmp(line + 9,
pkg->package, strlen(line) - 9) != 0;
pkg = pkg->next) ;
/*
* Dont use wfopen here, handle errors ourself
*/
if ((fin = fopen(statusfile, "r")) != NULL) {
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
line[strlen(line) - 1] = '\0'; /* trim newline */
/* If we see a package header, find out if it's a package
* that we have processed. if so, we skip that block for
* now (write it at the end).
*
* we also look at packages in the status cache and update
* their status fields
*/
if (strstr(line, "Package: ") == line) {
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
pkg->package) != 0; pkg = pkg->next) ;
locpkg.package = line + 9;
statpkg = tfind(&locpkg, &status, package_compare);
/* note: statpkg should be non-zero, unless the status
* file was changed while we are processing (no locking
* is currently done...
*/
if (statpkg != 0) {
statpkg = *(package_t **)statpkg;
locpkg.package = line + 9;
statpkg = tfind(&locpkg, &status, package_compare);
/* note: statpkg should be non-zero, unless the status
* file was changed while we are processing (no locking
* is currently done...
*/
if (statpkg != 0) {
statpkg = *(package_t **)statpkg;
}
}
if (pkg != 0) {
continue;
}
if (strstr(line, "Status: ") == line && statpkg != 0) {
snprintf(line, sizeof(line), "Status: %s %s %s",
status_words_want[statpkg->status_want - 1],
status_words_flag[statpkg->status_flag - 1],
status_words_status[statpkg->status_status - 1]);
}
fprintf(fout, "%s\n", line);
}
if (pkg != 0) {
continue;
}
if (strstr(line, "Status: ") == line && statpkg != 0) {
snprintf(line, sizeof(line), "Status: %s",
status_print(statpkg->status));
}
fputs(line, fout);
fputc('\n', fout);
fclose(fin);
}
free(line);
// Print out packages we processed.
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
fprintf(fout, "Package: %s\nStatus: %s\n",
pkg->package, status_print(pkg->status));
fprintf(fout, "Package: %s\nStatus: %s %s %s\n",
pkg->package, status_words_want[pkg->status_want - 1],
status_words_flag[pkg->status_flag - 1],
status_words_status[pkg->status_status - 1]);
if (pkg->depends)
fprintf(fout, "Depends: %s\n", pkg->depends);
if (pkg->provides)
@@ -535,16 +506,25 @@ static int status_merge(void *status, package_t *pkgs)
fprintf(fout, "Description: %s\n", pkg->description);
fputc('\n', fout);
}
fclose(fin);
fclose(fout);
r = rename(statusfile, bak_statusfile);
if (r == 0) {
r = rename(new_statusfile, statusfile);
/*
* Its ok if renaming statusfile fails becasue it doesnt exist
*/
if (rename(statusfile, bak_statusfile) == -1) {
struct stat stat_buf;
if (stat(statusfile, &stat_buf) == 0) {
error_msg("Couldnt create backup status file");
return(EXIT_FAILURE);
}
error_msg("No status file found, creating new one");
}
return 0;
if (rename(new_statusfile, statusfile) == -1) {
error_msg("Couldnt create status file");
return(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}
static int is_file(const char *fn)
@@ -564,18 +544,18 @@ static int dpkg_doconfigure(package_t *pkg)
char buf[1024];
DPRINTF("Configuring %s\n", pkg->package);
pkg->status &= status_statusmask;
pkg->status_status = 0;
snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);
if (is_file(postinst)) {
snprintf(buf, sizeof(buf), "%s configure", postinst);
if ((r = do_system(buf)) != 0) {
fprintf(stderr, "postinst exited with status %d\n", r);
pkg->status |= status_statushalfconfigured;
error_msg("postinst exited with status %d\n", r);
pkg->status_status = status_status_halfconfigured;
return 1;
}
}
pkg->status |= status_statusinstalled;
pkg->status_status = status_status_installed;
return 0;
}
@@ -583,66 +563,74 @@ static int dpkg_doconfigure(package_t *pkg)
static int dpkg_dounpack(package_t *pkg)
{
int r = 0, i;
char *cwd;
FILE *outfp;
int status = TRUE;
char *cwd = xgetcwd(0);
char *src_file = NULL;
char *dst_file = NULL;
char *lst_file = NULL;
char *adminscripts[] = { "/prerm", "/postrm", "/preinst", "/postinst",
"/conffiles", "/md5sums", "/shlibs", "/templates" };
char buf[1024], buf2[1024];
// char *lst_file = NULL;
char *adminscripts[] = { "prerm", "postrm", "preinst", "postinst",
"conffiles", "md5sums", "shlibs", "templates" };
DPRINTF("Unpacking %s\n", pkg->package);
cwd = getcwd(0, 0);
if(cwd==NULL)
exit(EXIT_FAILURE);
chdir("/");
deb_extract(dpkg_deb_extract, "/", pkg->file);
/* Installs the package scripts into the info directory */
for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) {
struct stat src_stat_buf;
int src_fd = 0, dst_fd = 0;
/* The full path of the current location of the admin file */
src_file = xrealloc(src_file, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
strcpy(src_file, dpkgcidir);
strcat(src_file, pkg->package);
strcat(src_file, adminscripts[i]);
sprintf(src_file, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]);
/* the full path of where we want the file to be copied to */
dst_file = xrealloc(dst_file, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
strcpy(dst_file, infodir);
strcat(dst_file, pkg->package);
strcat(dst_file, adminscripts[i]);
sprintf(dst_file, "%s%s.%s", infodir, pkg->package, adminscripts[i]);
/* copy admin file to permanent home */
if (copy_file(src_file, dst_file, TRUE, FALSE, FALSE) < 0) {
error_msg_and_die("Cannot copy %s to %s ", buf, buf2);
/*
* copy admin file to permanent home
* NOTE: Maybe merge this behaviour into libb/copy_file.c
*/
if (lstat(src_file, &src_stat_buf) == 0) {
if ((src_fd = open(src_file, O_RDONLY)) != -1) {
if ((dst_fd = open(dst_file, O_WRONLY | O_CREAT, 0644)) == -1) {
status = FALSE;
perror_msg("Opening %s", dst_file);
}
copy_file_chunk(src_fd, dst_fd, src_stat_buf.st_size);
close(src_fd);
close(dst_fd);
} else {
status = FALSE;
error_msg("couldnt open [%s]\n", src_file);
}
}
/* create the list file */
lst_file = (char *) xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
strcpy(lst_file, infodir);
strcat(lst_file, pkg->package);
strcat(lst_file, ".list");
outfp = freopen(lst_file, "w", stdout);
deb_extract(dpkg_deb_list, NULL, pkg->file);
stdout = freopen(NULL, "w", outfp);
printf("done\n");
getchar();
fclose(outfp);
}
pkg->status &= status_wantmask;
pkg->status |= status_wantinstall;
pkg->status &= status_flagmask;
pkg->status |= status_flagok;
pkg->status &= status_statusmask;
/*
* create the list file
* FIXME: currently this dumps the lst to stdout instead of a file
*/
/* lst_file = (char *) xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
strcpy(lst_file, infodir);
strcat(lst_file, pkg->package);
strcat(lst_file, ".list");
deb_extract(dpkg_deb_list, NULL, pkg->file);
*/
if (r == 0) {
pkg->status |= status_statusunpacked;
pkg->status_want = status_want_install;
pkg->status_flag = status_flag_ok;
if (status == TRUE) {
pkg->status_status = status_status_unpacked;
} else {
pkg->status |= status_statushalfinstalled;
pkg->status_status = status_status_halfinstalled;
}
chdir(cwd);
return r;
}
@@ -657,9 +645,8 @@ static int dpkg_unpackcontrol(package_t *pkg)
int length;
/* clean the temp directory (dpkgcidir) be recreating it */
remove_dpkgcidir();
if (mkdir(dpkgcidir, S_IRWXU) != 0) {
perror("mkdir");
remove_dir(dpkgcidir);
if (create_path(dpkgcidir, S_IRWXU) == FALSE) {
return EXIT_FAILURE;
}
@@ -674,13 +661,12 @@ static int dpkg_unpackcontrol(package_t *pkg)
}
/* now remove trailing version numbers etc */
length = strcspn(tmp_name, "_.");
pkg->package = (char *) xmalloc(length + 1);
pkg->package = (char *) xcalloc(1, length + 1);
/* store the package name */
strncpy(pkg->package, tmp_name, length);
/* work out the full extraction path */
tmp_name = (char *) xmalloc(strlen(dpkgcidir) + strlen(pkg->package) + 9);
memset(tmp_name, 0, strlen(dpkgcidir) + strlen(pkg->package) + 9);
tmp_name = (char *) xcalloc(1, strlen(dpkgcidir) + strlen(pkg->package) + 9);
strcpy(tmp_name, dpkgcidir);
strcat(tmp_name, pkg->package);
@@ -689,7 +675,7 @@ static int dpkg_unpackcontrol(package_t *pkg)
/* parse the extracted control file */
strcat(tmp_name, "/control");
if ((file = fopen(tmp_name, "r")) == NULL) {
if ((file = wfopen(tmp_name, "r")) == NULL) {
return EXIT_FAILURE;
}
if (control_read(file, pkg) == EXIT_FAILURE) {
@@ -713,7 +699,7 @@ static int dpkg_unpack(package_t *pkgs, void *status)
}
}
status_merge(status, pkgs);
remove_dpkgcidir();
remove_dir(dpkgcidir);
return r;
}
@@ -728,7 +714,7 @@ static int dpkg_configure(package_t *pkgs, void *status)
found = tfind(pkg, &status, package_compare);
if (found == 0) {
fprintf(stderr, "Trying to configure %s, but it is not installed\n", pkg->package);
error_msg("Trying to configure %s, but it is not installed", pkg->package);
r = 1;
}
/* configure the package listed in the status file;
@@ -750,8 +736,7 @@ static int dpkg_install(package_t *pkgs, void *status)
/* Stage 1: parse all the control information */
for (p = pkgs; p != 0; p = p->next) {
if (dpkg_unpackcontrol(p) == EXIT_FAILURE) {
perror(p->file);
return EXIT_FAILURE;
return(EXIT_FAILURE);
}
}
@@ -764,32 +749,34 @@ static int dpkg_install(package_t *pkgs, void *status)
/* Stage 3: install */
for (p = ordered; p != 0; p = p->next) {
p->status &= status_wantmask;
p->status |= status_wantinstall;
p->status_want = status_want_install;
/* for now the flag is always set to ok... this is probably
* not what we want
*/
p->status &= status_flagmask;
p->status |= status_flagok;
p->status_flag = status_flag_ok;
DPRINTF("Installing %s\n", p->package);
if (dpkg_dounpack(p) != 0) {
perror(p->file);
perror_msg(p->file);
}
if (dpkg_doconfigure(p) != 0) {
perror(p->file);
perror_msg(p->file);
}
}
if (ordered != 0) {
status_merge(status, pkgs);
}
remove_dpkgcidir();
remove_dir(dpkgcidir);
return 0;
}
/*
* Not implemented yet
*
static int dpkg_remove(package_t *pkgs, void *status)
{
package_t *p;
@@ -801,55 +788,61 @@ static int dpkg_remove(package_t *pkgs, void *status)
return 0;
}
*/
extern int dpkg_main(int argc, char **argv)
{
char opt = 0;
char *s;
const int arg_install = 1;
const int arg_unpack = 2;
const int arg_configure = 4;
package_t *p, *packages = NULL;
char *cwd = getcwd(0, 0);
void *status = NULL;
char opt = 0;
int optflag = 0;
while (*++argv) {
if (**argv == '-') {
/* Nasty little hack to "parse" long options. */
s = *argv;
while (*s == '-') {
s++;
}
opt=s[0];
} else {
p = (package_t *)xmalloc(sizeof(package_t));
memset(p, 0, sizeof(package_t));
if (**argv == '/') {
p->file = *argv;
} else
if (opt != 'c') {
p->file = xmalloc(strlen(cwd) + strlen(*argv) + 2);
sprintf(p->file, "%s/%s", cwd, *argv);
} else {
p->package = strdup(*argv);
}
p->next = packages;
packages = p;
}
while ((opt = getopt(argc, argv, "iruc")) != -1) {
switch (opt) {
case 'i':
optflag |= arg_install;
break;
case 'u':
optflag |= arg_unpack;
break;
case 'c':
optflag |= arg_configure;
break;
default:
show_usage();
}
}
while (optind < argc) {
p = (package_t *) xcalloc(1, sizeof(package_t));
if (optflag & arg_configure) {
p->package = xstrdup(argv[optind]);
} else {
p->file = xstrdup(argv[optind]);
}
p->next = packages;
packages = p;
optind++;
}
create_path(dpkgcidir, S_IRWXU);
create_path(infodir, S_IRWXU);
status = status_read();
switch (opt) {
case 'i':
return dpkg_install(packages, status);
case 'r':
return dpkg_remove(packages, status);
case 'u':
return dpkg_unpack(packages, status);
case 'c':
return dpkg_configure(packages, status);
default :
show_usage();
return EXIT_FAILURE;
if (optflag & arg_install) {
return dpkg_install(packages, status);
}
else if (optflag & arg_unpack) {
return dpkg_unpack(packages, status);
}
else if (optflag & arg_configure) {
return dpkg_configure(packages, status);
}
return(EXIT_FAILURE);
}
+20 -2
View File
@@ -24,8 +24,13 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include "busybox.h"
/* From gunzip.c */
extern int gz_open(FILE *compressed_file, int *pid);
extern void gz_close(int gunzip_pid);
typedef struct ar_headers_s {
char *name;
size_t size;
@@ -60,6 +65,8 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
int extract_to_stdout = FALSE;
int srcFd = 0;
int status;
pid_t pid;
FILE *comp_file = NULL;
if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
strcpy(ar_filename, "data.tar.gz");
@@ -99,7 +106,11 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
ar_headers = ar_headers->next;
}
lseek(srcFd, ar_headers->offset, SEEK_SET);
srcFd = tar_unzip_init(srcFd);
/* Uncompress the file */
comp_file = fdopen(srcFd, "r");
if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
error_msg_and_die("Couldnt unzip file");
}
if ( dir_name != NULL) {
if (is_directory(dir_name, TRUE, NULL)==FALSE) {
mkdir(dir_name, 0755);
@@ -108,7 +119,14 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
error_msg_and_die("Cannot change to dir %s", dir_name);
}
}
status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
status = readTarFile(srcFd, extract_flag, list_flag,
extract_to_stdout, verbose_flag, NULL, extract_list);
/* we are deliberately terminating the child so we can safely ignore this */
signal(SIGTERM, SIG_IGN);
gz_close(pid);
close(srcFd);
fclose(comp_file);
return status;
}
+746 -927
View File
File diff suppressed because it is too large. Load diff
+125 -10
View File
@@ -42,6 +42,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
@@ -72,7 +73,7 @@ typedef unsigned long ulg;
/* methods 4 to 7 reserved */
#define DEFLATED 8
#define MAX_METHODS 9
extern int method; /* compression method */
static int method; /* compression method */
/* To save memory for 16 bit systems, some arrays are overlaid between
* the various modules:
@@ -143,7 +144,7 @@ EXTERN(ush, tab_prefix1); /* prefix for odd codes */
#endif
extern unsigned insize; /* valid bytes in inbuf */
extern unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned inptr; /* index of next byte to be processed in inbuf */
extern unsigned outcnt; /* bytes in output buffer */
extern long bytes_in; /* number of input bytes */
@@ -294,7 +295,7 @@ void lm_init (ush * flags);
ulg deflate (void);
/* in trees.c */
void ct_init (ush * attr, int *method);
void ct_init (ush * attr, int *methodp);
int ct_tally (int dist, int lc);
ulg flush_block (char *buf, ulg stored_len, int eof);
@@ -308,16 +309,16 @@ extern int (*read_buf) (char *buf, unsigned size);
/* in util.c: */
extern int copy (int in, int out);
extern ulg updcrc (uch * s, unsigned n);
extern void clear_bufs (void);
//extern ulg updcrc (uch * s, unsigned n);
//extern void clear_bufs (void);
extern int fill_inbuf (int eof_ok);
extern void flush_outbuf (void);
extern void flush_window (void);
extern void write_buf (int fd, void * buf, unsigned cnt);
//extern void write_buf (int fd, void * buf, unsigned cnt);
extern char *strlwr (char *s);
extern char *add_envopt (int *argcp, char ***argvp, char *env);
extern void read_error_msg (void);
extern void write_error_msg (void);
//extern void read_error_msg (void);
//extern void write_error_msg (void);
extern void display_ratio (long num, long den, FILE * file);
/* in inflate.c */
@@ -704,6 +705,120 @@ extern void _expand_args(int *argc, char ***argv);
#ifndef put_char
# define put_char(c) put_byte(c)
#endif
int crc_table_empty = 1;
/* ========================================================================
* Signal and error handler.
*/
void abort_gzip()
{
exit(ERROR);
}
/* ===========================================================================
* Clear input and output buffers
*/
static void clear_bufs(void)
{
outcnt = 0;
insize = inptr = 0;
bytes_in = bytes_out = 0L;
}
static void write_error_msg()
{
fprintf(stderr, "\n");
perror("");
abort_gzip();
}
/* ===========================================================================
* Does the same as write(), but also handles partial pipe writes and checks
* for error return.
*/
static void write_buf(fd, buf, cnt)
int fd;
void * buf;
unsigned cnt;
{
unsigned n;
while ((n = write(fd, buf, cnt)) != cnt) {
if (n == (unsigned) (-1)) {
write_error_msg();
}
cnt -= n;
buf = (void *) ((char *) buf + n);
}
}
/* ========================================================================
* Error handlers.
*/
static void read_error_msg()
{
fprintf(stderr, "\n");
if (errno != 0) {
perror("");
} else {
fprintf(stderr, "unexpected end of file\n");
}
abort_gzip();
}
/* ===========================================================================
* Run a set of bytes through the crc shift register. If s is a NULL
* pointer, then initialize the crc shift register contents instead.
* Return the current crc in either case.
*/
static ulg updcrc(s, n)
uch *s; /* pointer to bytes to pump through */
unsigned n; /* number of bytes in s[] */
{
static ulg crc = (ulg) 0xffffffffL; /* shift register contents */
register ulg c; /* temporary variable */
static unsigned long crc_32_tab[256];
if (crc_table_empty) {
unsigned long csr; /* crc shift register */
unsigned long e; /* polynomial exclusive-or pattern */
int i; /* counter for all possible eight bit values */
int k; /* byte being shifted into crc apparatus */
/* terms of polynomial defining this crc (except x^32): */
static int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* Make exclusive-or pattern from polynomial (0xedb88320) */
e = 0;
for (i = 0; i < sizeof(p)/sizeof(int); i++)
e |= 1L << (31 - p[i]);
/* Compute and print table of CRC's, five per line */
crc_32_tab[0] = 0x00000000L;
for (i = 1; i < 256; i++) {
csr = i;
/* The idea to initialize the register with the byte instead of
* zero was stolen from Haruhiko Okumura's ar002
*/
for (k = 8; k; k--)
csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1;
crc_32_tab[i]=csr;
}
}
if (s == NULL) {
c = 0xffffffffL;
} else {
c = crc;
if (n)
do {
c = crc_32_tab[((int) c ^ (*s++)) & 0xff] ^ (c >> 8);
} while (--n);
}
crc = c;
return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
}
/* bits.c -- output variable-length bit strings
* Copyright (C) 1992-1993 Jean-loup Gailly
* This is free software; you can redistribute it and/or modify it under the
@@ -3299,7 +3414,7 @@ long header_bytes; /* number of bytes in gzip header */
int zip(in, out)
int in, out; /* input and output file descriptors */
{
uch flags = 0; /* general purpose bit flags */
uch my_flags = 0; /* general purpose bit flags */
ush attr = 0; /* ascii/binary flag */
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
@@ -3315,7 +3430,7 @@ int in, out; /* input and output file descriptors */
put_byte(GZIP_MAGIC[1]);
put_byte(DEFLATED); /* compression method */
put_byte(flags); /* general flags */
put_byte(my_flags); /* general flags */
put_long(time_stamp);
/* Write deflated file to zip file */
+17 -40
View File
@@ -58,7 +58,8 @@
#ifdef BB_FEATURE_TAR_GZIP
extern int unzip(int in, int out);
extern int gunzip_init();
extern int gz_open(FILE *compressed_file, int *pid);
extern void gz_close(int gunzip_pid);
#endif
/* Tar file constants */
@@ -148,43 +149,6 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
char** excludeList);
#endif
#ifdef BB_FEATURE_TAR_GZIP
/* Signal handler for when child gzip process dies... */
static void child_died()
{
fflush(stdout);
fflush(stderr);
exit(EXIT_FAILURE);
}
extern int tar_unzip_init(int tarFd)
{
int child_pid;
static int unzip_pipe[2];
/* Cope if child dies... Otherwise we block forever in read()... */
signal(SIGCHLD, child_died);
if (pipe(unzip_pipe)!=0)
error_msg_and_die("pipe error");
if ( (child_pid = fork()) == -1)
error_msg_and_die("fork failure");
if (child_pid==0) {
/* child process */
close(unzip_pipe[0]);
gunzip_init();
unzip(tarFd, unzip_pipe[1]);
exit(EXIT_SUCCESS);
}
else {
/* return fd of uncompressed data to parent process */
close(unzip_pipe[1]);
return(unzip_pipe[0]);
}
}
#endif
#if defined BB_FEATURE_TAR_EXCLUDE
static struct option longopts[] = {
{ "exclude", 1, NULL, 'e' },
@@ -203,6 +167,7 @@ extern int tar_main(int argc, char **argv)
char file[256];
#endif
#if defined BB_FEATURE_TAR_GZIP
FILE *comp_file = NULL;
int unzipFlag = FALSE;
#endif
int listFlag = FALSE;
@@ -212,6 +177,7 @@ extern int tar_main(int argc, char **argv)
int tostdoutFlag = FALSE;
int status = FALSE;
int opt;
pid_t pid;
if (argc <= 1)
show_usage();
@@ -316,11 +282,22 @@ extern int tar_main(int argc, char **argv)
#ifdef BB_FEATURE_TAR_GZIP
/* unzip tarFd in a seperate process */
if (unzipFlag == TRUE)
tarFd = tar_unzip_init(tarFd);
if (unzipFlag == TRUE) {
comp_file = fdopen(tarFd, "r");
if ((tarFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
error_msg_and_die("Couldnt unzip file");
}
}
#endif
status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
verboseFlag, extractList, excludeList);
close(tarFd);
#ifdef BB_FEATURE_TAR_GZIP
if (unzipFlag == TRUE) {
gz_close(pid);
fclose(comp_file);
}
#endif
}
if (status == TRUE)
+18 -14
View File
@@ -6,16 +6,15 @@
#include <stdlib.h>
#include "busybox.h"
#undef APPLET
#undef APPLET_NOUSAGE
#undef PROTOTYPES
#include "applets.h"
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
static int been_there_done_that = 0;
#ifdef BB_LOCALE_SUPPORT
#include <locale.h>
#endif
int been_there_done_that = 0; /* Also used in applets.c */
const char *applet_name;
#ifdef BB_FEATURE_INSTALLER
@@ -65,7 +64,7 @@ static void install_links(const char *busybox, int use_symbolic_links)
{
__link_f Link = link;
char command[256];
char *fpc;
int i;
int rc;
@@ -73,13 +72,13 @@ static void install_links(const char *busybox, int use_symbolic_links)
Link = symlink;
for (i = 0; applets[i].name != NULL; i++) {
sprintf ( command, "%s/%s",
install_dir[applets[i].location], applets[i].name);
rc = Link(busybox, command);
if (rc) {
perror_msg("%s", command);
fpc = concat_path_file(
install_dir[applets[i].location], applets[i].name);
rc = Link(busybox, fpc);
if (rc!=0 && errno!=EEXIST) {
perror_msg("%s", fpc);
}
free(fpc);
}
}
@@ -98,10 +97,15 @@ int main(int argc, char **argv)
/* Add in a special case hack -- whenever **argv == '-'
* (i.e. '-su' or '-sh') always invoke the shell */
if (**argv == '-' && *(*argv+1)!= '-') {
exit(((*(shell_main)) (argc, argv)));
applet_name = "sh";
}
#endif
#ifdef BB_LOCALE_SUPPORT
if(getpid()!=1) /* Do not set locale for `init' */
setlocale(LC_ALL, "");
#endif
run_applet_by_name(applet_name, argc, argv);
error_msg_and_die("applet not found");
}
+14 -187
View File
@@ -36,37 +36,6 @@
#endif
#include <features.h>
/* Stupid libc doesn't have a reliable way for use to know
* that libc5 is being used. Assume this is good enough */
#if ! defined __GLIBC__ && ! defined __UCLIBC__
/* libc5 doesn't define socklen_t */
typedef unsigned int socklen_t;
#endif
/* Some useful definitions */
#define FALSE ((int) 0)
#define TRUE ((int) 1)
#define SKIP ((int) 2)
/* for mtab.c */
#define MTAB_GETMOUNTPT '1'
#define MTAB_GETDEVICE '2'
#define BUF_SIZE 8192
#define EXPAND_ALLOC 1024
static inline int is_decimal(ch) { return ((ch >= '0') && (ch <= '9')); }
static inline int is_octal(ch) { return ((ch >= '0') && (ch <= '7')); }
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
enum Location {
@@ -97,147 +66,15 @@ extern const struct BB_applet applets[];
extern const char *applet_name;
extern void show_usage(void) __attribute__ ((noreturn));
extern void error_msg(const char *s, ...);
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
extern void perror_msg(const char *s, ...);
extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
const char *mode_string(int mode);
const char *time_string(time_t timeVal);
int is_directory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name);
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
char name[1];
} ino_dev_hashtable_bucket_t;
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
int copy_file(const char *srcName, const char *destName,
int setModes, int followLinks, int forceFlag);
int copy_file_chunk(int srcFd, int dstFd, size_t remaining);
char *buildName(const char *dirName, const char *fileName);
int makeString(int argc, const char **argv, char *buf, int bufLen);
char *getChunk(int size);
char *chunkstrdup(const char *str);
void freeChunks(void);
ssize_t safe_read(int fd, void *buf, size_t count);
int full_write(int fd, const char *buf, int len);
int full_read(int fd, char *buf, int len);
int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
void* userData);
extern int create_path (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern int get_kernel_revision(void);
extern int get_console_fd(char* tty_name);
extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern);
extern long atoi_w_units (const char *cp);
extern pid_t* find_pid_by_name( char* pidName);
extern int find_real_root_device_name(char* name);
extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file);
extern int print_file_by_name(char *filename);
extern char process_escape_sequence(char **ptr);
extern char *get_last_path_component(char *path);
extern FILE *wfopen(const char *path, const char *mode);
extern FILE *xfopen(const char *path, const char *mode);
extern void chomp(char *s);
extern void trim(char *s);
extern struct BB_applet *find_applet_by_name(const char *name);
void run_applet_by_name(const char *name, int argc, char **argv);
#ifndef DMALLOC
extern void *xmalloc (size_t size);
extern void *xrealloc(void *old, size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern char *xstrdup (const char *s);
#endif
extern char *xstrndup (const char *s, int n);
extern char * safe_strncpy(char *dst, const char *src, size_t size);
struct suffix_mult {
char *suffix;
int mult;
};
extern unsigned long parse_number(const char *numstr,
const struct suffix_mult *suffixes);
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
#if defined BB_FEATURE_MOUNT_LOOP
extern int del_loop(const char *device);
extern int set_loop(const char *device, const char *file, int offset, int *loopro);
extern char *find_unused_loop_device (void);
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#endif
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap);
#endif
#if defined BB_NFSMOUNT
int nfsmount(const char *spec, const char *node, int *flags,
char **extra_opts, char **mount_opts, int running_bg);
#endif
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
#define RB_POWER_OFF 0x4321fedc
#endif
#if defined(BB_KLOGD) || defined(BB_LOGGER)
void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
void syslog_msg(int facility, int pri, const char *msg);
#endif
/* Include our own copy of struct sysinfo to avoid binary compatability
* problems with Linux 2.4, which changed things. Grumble, grumble. */
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
extern int sysinfo (struct sysinfo* info);
/* Bit map related macros -- libc5 doens't provide these... sigh. */
#ifndef setbit
#define NBBY CHAR_BIT
@@ -247,25 +84,15 @@ extern int sysinfo (struct sysinfo* info);
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#endif
#ifdef BB_FEATURE_HUMAN_READABLE
const char *make_human_readable_str(unsigned long val, unsigned long hr);
#endif
enum {
KILOBYTE = 1024,
MEGABYTE = (KILOBYTE*1024),
GIGABYTE = (MEGABYTE*1024)
};
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
#define RB_POWER_OFF 0x4321fedc
#endif
#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
int ask_confirmation(void);
#endif
/* Pull in the utility routines from libbb */
#include "libbb/libbb.h"
#endif /* _BB_INTERNAL_H_ */
+1 -1
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.50
Version: 0.51
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
+1
View File
@@ -49,6 +49,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
switch (whichApp) {
case CHGRP_APP:
case CHOWN_APP:
/* Don't use lchown for libc5 or glibc older then 2.1.x */
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
if (lchown
(fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
+98 -139
View File
@@ -31,8 +31,6 @@
*/
//#define TEST
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
@@ -43,10 +41,16 @@
#include <signal.h>
#include <limits.h>
#ifndef TEST
#include "busybox.h"
#ifdef BB_LOCALE_SUPPORT
#define Isprint(c) isprint((c))
#else
#define Isprint(c) ( (c) >= ' ' && (c) != ((unsigned char)'\233') )
#endif
#ifndef TEST
#define D(x)
#else
@@ -59,13 +63,6 @@
#define D(x) x
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#endif /* TEST */
#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION
@@ -92,29 +89,6 @@
#endif /* advanced FEATURES */
#ifdef TEST
void *xrealloc(void *old, size_t size)
{
return realloc(old, size);
}
void *xmalloc(size_t size)
{
return malloc(size);
}
char *xstrdup(const char *s)
{
return strdup(s);
}
void *xcalloc(size_t size, size_t se)
{
return calloc(size, se);
}
#define error_msg(s, d) fprintf(stderr, s, d)
#endif
struct history {
char *s;
@@ -238,7 +212,7 @@ static void win_changed(int nsig)
static void cmdedit_reset_term(void)
{
if ((handlers_sets & SET_RESET_TERM) != 0) {
/* sparc and other have broken termios support: use old termio handling. */
/* sparc and other have broken termios support: use old termio handling. */
setTermSettings(fileno(stdin), (void *) &initial_settings);
handlers_sets &= ~SET_RESET_TERM;
}
@@ -270,9 +244,9 @@ static void cmdedit_set_out_char(int next_char)
int c = (int)((unsigned char) command_ps[cursor]);
if (c == 0)
c = ' '; /* destroy end char? */
c = ' '; /* destroy end char? */
#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT
if (!isprint(c)) { /* Inverse put non-printable characters */
if (!Isprint(c)) { /* Inverse put non-printable characters */
if (c >= 128)
c -= 128;
if (c < ' ')
@@ -328,7 +302,7 @@ static void input_backward(int num)
{
if (num > cursor)
num = cursor;
cursor -= num; /* new cursor (in command, not terminal) */
cursor -= num; /* new cursor (in command, not terminal) */
if (cmdedit_x >= num) { /* no to up line */
cmdedit_x -= num;
@@ -369,134 +343,116 @@ static void parse_prompt(const char *prmt_ptr)
put_prompt();
}
#else
static void add_to_prompt(char **prmt_mem_ptr, int *alm,
int *prmt_len, const char *addb)
{
*prmt_len += strlen(addb);
if (*alm < (*prmt_len) + 1) {
*alm = (*prmt_len) + 1;
*prmt_mem_ptr = xrealloc(*prmt_mem_ptr, *alm);
}
strcat(*prmt_mem_ptr, addb);
}
static void parse_prompt(const char *prmt_ptr)
{
int alm = strlen(prmt_ptr) + 1; /* supposedly require memory */
int prmt_len = 0;
int sub_len = 0;
int flg_not_length = '[';
char *prmt_mem_ptr = xstrdup(prmt_ptr);
char pwd_buf[PATH_MAX + 1];
char buf[16];
int c;
pwd_buf[0] = 0;
*prmt_mem_ptr = 0;
char flg_not_length = '[';
char *prmt_mem_ptr = xcalloc(1, 1);
char *pwd_buf = xgetcwd(0);
char buf2[PATH_MAX + 1];
char buf[2];
char c;
char *pbuf;
while (*prmt_ptr) {
pbuf = buf;
pbuf[1] = 0;
c = *prmt_ptr++;
if (c == '\\') {
c = *prmt_ptr;
if (c == 0)
const char *cp = prmt_ptr;
int l;
c = process_escape_sequence(&prmt_ptr);
if(prmt_ptr==cp) {
if (*cp == 0)
break;
prmt_ptr++;
switch (c) {
c = *prmt_ptr++;
switch (c) {
#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR
case 'u':
add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, user_buf);
continue;
case 'u':
pbuf = user_buf;
break;
#endif
case 'h':
if (hostname_buf[0] == 0) {
hostname_buf = xcalloc(256, 1);
if (gethostname(hostname_buf, 255) < 0) {
strcpy(hostname_buf, "?");
case 'h':
pbuf = hostname_buf;
if (*pbuf == 0) {
pbuf = xcalloc(256, 1);
if (gethostname(pbuf, 255) < 0) {
strcpy(pbuf, "?");
} else {
char *s = strchr(hostname_buf, '.');
char *s = strchr(pbuf, '.');
if (s)
*s = 0;
}
hostname_buf = pbuf;
}
add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len,
hostname_buf);
continue;
case '$':
break;
case '$':
c = my_euid == 0 ? '#' : '$';
break;
#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR
case 'w':
if (pwd_buf[0] == 0) {
int l;
getcwd(pwd_buf, PATH_MAX);
l = strlen(home_pwd_buf);
if (home_pwd_buf[0] != 0 &&
strncmp(home_pwd_buf, pwd_buf, l) == 0) {
strcpy(pwd_buf + 1, pwd_buf + l);
pwd_buf[0] = '~';
case 'w':
pbuf = pwd_buf;
l = strlen(home_pwd_buf);
if (home_pwd_buf[0] != 0 &&
strncmp(home_pwd_buf, pbuf, l) == 0 &&
(pbuf[l]=='/' || pbuf[l]=='\0') &&
strlen(pwd_buf+l)<PATH_MAX) {
pbuf = buf2;
*pbuf = '~';
strcpy(pbuf+1, pwd_buf+l);
}
}
add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, pwd_buf);
continue;
break;
#endif
case '!':
snprintf(buf, sizeof(buf), "%d", num_ok_lines);
add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, buf);
continue;
case 'e':
case 'E': /* \e \E = \033 */
case 'W':
pbuf = pwd_buf;
cp = strrchr(pbuf,'/');
if ( (cp != NULL) && (cp != pbuf) )
pbuf += (cp-pbuf)+1;
break;
case '!':
snprintf(pbuf = buf2, sizeof(buf2), "%d", num_ok_lines);
break;
case 'e': case 'E': /* \e \E = \033 */
c = '\033';
break;
case 'x':
case 'X':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':{
int l;
int ho = 0;
char *eho;
if (c == 'X')
c = 'x';
case 'x': case 'X':
for (l = 0; l < 3;) {
buf[l++] = *prmt_ptr;
buf[l] = 0;
ho = strtol(buf, &eho, c == 'x' ? 16 : 8);
if (ho > UCHAR_MAX || (eho - buf) < l) {
int h;
buf2[l++] = *prmt_ptr;
buf2[l] = 0;
h = strtol(buf2, &pbuf, 16);
if (h > UCHAR_MAX || (pbuf - buf2) < l) {
l--;
break;
}
prmt_ptr++;
}
buf[l] = 0;
ho = strtol(buf, 0, c == 'x' ? 16 : 8);
c = ho == 0 ? '?' : (char) ho;
buf2[l] = 0;
c = (char)strtol(buf2, 0, 16);
if(c==0)
c = '?';
pbuf = buf;
break;
}
case '[':
case ']':
case '[': case ']':
if (c == flg_not_length) {
flg_not_length = flg_not_length == '[' ? ']' : '[';
continue;
}
break;
}
}
}
}
buf[0] = c;
buf[1] = 0;
add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, buf);
if(pbuf == buf)
*pbuf = c;
prmt_len += strlen(pbuf);
prmt_mem_ptr = strcat(xrealloc(prmt_mem_ptr, prmt_len+1), pbuf);
if (flg_not_length == ']')
sub_len++;
}
free(pwd_buf);
cmdedit_prompt = prmt_mem_ptr;
cmdedit_prmt_len = prmt_len - sub_len;
put_prompt();
@@ -580,6 +536,7 @@ static void cmdedit_setwidth(int w, int redraw_flg)
extern void cmdedit_init(void)
{
cmdedit_prmt_len = 0;
if ((handlers_sets & SET_WCHG_HANDLERS) == 0) {
/* emulate usage handler to set handler and call yours work */
win_changed(-SIGWINCH);
@@ -775,7 +732,7 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
char **paths = path1;
int npaths;
int i;
char found[BUFSIZ + 4 + PATH_MAX];
char *found;
char *pfind = strrchr(command, '/');
path1[0] = ".";
@@ -808,7 +765,6 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
continue;
while ((next = readdir(dir)) != NULL) {
const char *str_merge = "%s/%s";
char *str_found = next->d_name;
/* matched ? */
@@ -821,25 +777,23 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
else
continue;
}
if (paths[i][strlen(paths[i]) - 1] == '/')
str_merge = "%s%s";
sprintf(found, str_merge, paths[i], str_found);
found = concat_path_file(paths[i], str_found);
/* hmm, remover in progress? */
if (stat(found, &st) < 0)
continue;
if (stat(found, &st) < 0)
goto cont;
/* find with dirs ? */
if (paths[i] != dirbuf)
strcpy(found, next->d_name); /* only name */
if (S_ISDIR(st.st_mode)) {
/* name is directory */
/* algorithmic only "/" ? */
if (*str_found)
strcat(found, "/");
str_found = found;
found = concat_path_file(found, "");
free(str_found);
str_found = add_quote_for_spec_chars(found);
} else {
/* not put found file if search only dirs for cd */
if (type == FIND_DIR_ONLY)
continue;
if (type == FIND_DIR_ONLY)
goto cont;
str_found = add_quote_for_spec_chars(found);
if (type == FIND_FILE_ONLY ||
(type == FIND_EXE_ONLY && is_execute(&st) == TRUE))
@@ -849,6 +803,8 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
matches = xrealloc(matches, (nm + 1) * sizeof(char *));
matches[nm++] = str_found;
cont:
free(found);
}
closedir(dir);
}
@@ -1426,7 +1382,7 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
}
} else
#endif
if (!isprint(c)) /* Skip non-printable characters */
if (!Isprint(c)) /* Skip non-printable characters */
break;
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
@@ -1540,6 +1496,9 @@ extern void cmdedit_terminate(void)
#ifdef TEST
const char *applet_name = "debug stuff usage";
const char *memory_exhausted = "Memory exhausted";
#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT
#include <locale.h>
#endif
+13 -48
View File
@@ -24,10 +24,10 @@
typedef unsigned short unicode;
static long int ctoi(unsigned char *s, int *is_unicode);
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
unicode utf8_to_ucs2(char *buf);
int screen_map_load(int fd, FILE * fp);
static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
static int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
static unicode utf8_to_ucs2(char *buf);
static int screen_map_load(int fd, FILE * fp);
int loadacm_main(int argc, char **argv)
{
@@ -51,7 +51,7 @@ int loadacm_main(int argc, char **argv)
return EXIT_SUCCESS;
}
int screen_map_load(int fd, FILE * fp)
static int screen_map_load(int fd, FILE * fp)
{
struct stat stbuf;
unicode wbuf[E_TABSZ];
@@ -141,7 +141,7 @@ int screen_map_load(int fd, FILE * fp)
*
* FIXME: ignores everything after second word
*/
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
static int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
{
char buffer[256]; /* line buffer reading file */
char *p, *q; /* 1st + 2nd words in line */
@@ -149,7 +149,7 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
int tmp_is_unicode; /* tmp for is_unicode calculation */
int i; /* loop index - result holder */
int ret_code = 0; /* return code */
sigset_t sigset, old_sigset;
sigset_t acmsigset, old_sigset;
assert(is_unicode);
@@ -163,9 +163,9 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
buf[i] = 0xfffd;
/* block SIGCHLD */
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
sigemptyset(&acmsigset);
sigaddset(&acmsigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &acmsigset, &old_sigset);
do {
if (NULL == fgets(buffer, sizeof(buffer), fp)) {
@@ -213,7 +213,7 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
}
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
{
char buffer[256];
int in, on;
@@ -255,7 +255,7 @@ int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
*
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
*/
long int ctoi(unsigned char *s, int *is_unicode)
static long int ctoi(unsigned char *s, int *is_unicode)
{
int i;
size_t ls;
@@ -302,42 +302,7 @@ long int ctoi(unsigned char *s, int *is_unicode)
}
void saveoldmap(int fd, char *omfil)
{
FILE *fp;
char buf[E_TABSZ];
#ifdef GIO_UNISCRNMAP
unicode xbuf[E_TABSZ];
int is_old_map = 0;
if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) {
perror_msg("GIO_UNISCRNMAP ioctl error");
#endif
if (ioctl(fd, GIO_SCRNMAP, buf))
perror_msg_and_die("GIO_SCRNMAP ioctl error");
else
is_old_map = 1;
#ifdef GIO_UNISCRNMAP
}
#endif
fp = xfopen(omfil, "w");
#ifdef GIO_UNISCRNMAP
if (is_old_map) {
#endif
if (fwrite(buf, E_TABSZ, 1, fp) != 1)
perror_msg_and_die("Error writing map to file");
#ifdef GIO_UNISCRNMAP
} else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) {
perror_msg_and_die("Error writing map to file");
}
#endif
fclose(fp);
}
unicode utf8_to_ucs2(char *buf)
static unicode utf8_to_ucs2(char *buf)
{
int utf_count = 0;
long utf_char = 0;
+5 -5
View File
@@ -45,7 +45,7 @@ static const struct suffix_mult dd_suffixes[] = {
int dd_main(int argc, char **argv)
{
int i, ifd, ofd, oflag, sync = FALSE, trunc = TRUE;
int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE;
size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
size_t bs = 512, count = -1;
ssize_t n;
@@ -73,7 +73,7 @@ int dd_main(int argc, char **argv)
trunc = FALSE;
buf += 7;
} else if (strncmp("sync", buf, 4) == 0) {
sync = TRUE;
sync_flag = TRUE;
buf += 4;
} else {
error_msg_and_die("invalid conversion `%s'", argv[i]+5);
@@ -138,7 +138,7 @@ int dd_main(int argc, char **argv)
in_full++;
else
in_part++;
if (sync) {
if (sync_flag) {
memset(buf + n, '\0', bs - n);
n = bs;
}
@@ -151,8 +151,8 @@ int dd_main(int argc, char **argv)
out_part++;
}
fprintf(statusfp, "%d+%d records in\n", in_full, in_part);
fprintf(statusfp, "%d+%d records out\n", out_full, out_part);
fprintf(statusfp, "%ld+%ld records in\n", (long)in_full, (long)in_part);
fprintf(statusfp, "%ld+%ld records out\n", (long)out_full, (long)out_part);
return EXIT_SUCCESS;
}
+6 -11
View File
@@ -83,7 +83,8 @@ static long du(char *filename)
int len;
if ((lstat(filename, &statbuf)) != 0) {
perror_msg_and_die("%s", filename);
perror_msg("%s", filename);
return 0;
}
du_depth++;
@@ -110,22 +111,16 @@ static long du(char *filename)
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[BUFSIZ + 1];
char *newfile;
char *name = entry->d_name;
if ((strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0)) {
continue;
}
if (len + strlen(name) + 1 > BUFSIZ) {
error_msg(name_too_long);
du_depth--;
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
newfile = concat_path_file(filename, name);
sum += du(newfile);
free(newfile);
}
closedir(dir);
print(sum, filename);
@@ -197,7 +192,7 @@ int du_main(int argc, char **argv)
return status;
}
/* $Id: du.c,v 1.43 2001/03/09 14:36:42 andersen Exp $ */
/* $Id: du.c,v 1.44 2001/04/09 22:48:11 andersen Exp $ */
/*
Local Variables:
c-file-style: "linux"
+4 -4
View File
@@ -40,7 +40,7 @@ echo_main(int argc, char** argv)
while (argc > 0 && *argv[0] == '-')
{
register char *temp;
register int index;
register int ix;
/*
* If it appears that we are handling options, then make sure
@@ -49,9 +49,9 @@ echo_main(int argc, char** argv)
*/
temp = argv[0] + 1;
for (index = 0; temp[index]; index++)
for (ix = 0; temp[ix]; ix++)
{
if (strrchr("neE", temp[index]) == 0)
if (strrchr("neE", temp[ix]) == 0)
goto just_echo;
}
@@ -81,7 +81,7 @@ echo_main(int argc, char** argv)
just_echo:
while (argc > 0) {
char *arg = argv[0];
const char *arg = argv[0];
register int c;
while ((c = *arg++)) {
+97
View File
@@ -0,0 +1,97 @@
/* vi: set sw=4 ts=4: */
/*
* env implementation for busybox
*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice is retained at the end of this file.
*
* Modified for BusyBox by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*/
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
extern int env_main(int argc, char** argv)
{
char **ep, *p;
char *cleanenv[1];
int ch;
while ((ch = getopt(argc, argv, "-iu:")) != -1)
switch(ch) {
case '-':
case 'i':
environ = cleanenv;
cleanenv[0] = NULL;
break;
case 'u':
unsetenv(optarg);
break;
default:
show_usage();
}
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
setenv(*argv, ++p, 1);
if (*argv) {
execvp(*argv, argv);
perror_msg_and_die("%s", *argv);
}
for (ep = environ; *ep; ep++)
printf("%s\n", *ep);
exit(EXIT_SUCCESS);
}
/*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
*
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+1 -1
View File
@@ -225,7 +225,7 @@ int name (l, r) VALUE *l; VALUE *r; \
}
#define arithdivf(name, op) \
int name (l, r) VALUE *l; VALUE *r; \
static int name (l, r) VALUE *l; VALUE *r; \
{ \
if (!toarith (l) || !toarith (r)) \
error_msg_and_die ( "non-numeric argument"); \
+10 -7
View File
@@ -626,7 +626,7 @@ static int list_single(struct dnode *dn)
column += 10;
break;
case LIST_NLINKS:
printf("%4d ", dn->dstat.st_nlink);
printf("%4ld ", (long)dn->dstat.st_nlink);
column += 10;
break;
case LIST_ID_NAME:
@@ -648,15 +648,18 @@ static int list_single(struct dnode *dn)
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
} else {
#ifdef BB_FEATURE_HUMAN_READABLE
fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size,
(ls_disp_hr==TRUE)? 0: 1));
#else
if (ls_disp_hr==TRUE) {
fprintf(stdout, "%9s ", make_human_readable_str(
dn->dstat.st_size>>10, 0));
} else
#endif
{
#if _FILE_OFFSET_BITS == 64
printf("%9lld ", dn->dstat.st_size>>1);
printf("%9lld ", (long long)dn->dstat.st_size);
#else
printf("%9ld ", dn->dstat.st_size>>1);
#endif
printf("%9ld ", dn->dstat.st_size);
#endif
}
}
column += 10;
break;
+1 -20
View File
@@ -92,28 +92,9 @@ static const int S_IFMT = 0170000;
#define IN_CTYPE_DOMAIN(c) 1
#ifdef isblank
# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
#else
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
#endif
#ifdef isgraph
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
#else
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
#endif
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
#define ISDIGIT(c) (((unsigned char) (c)) - '0' <= 9)
#define isodigit(c) ((c) >= '0' && (c) <= '7')
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
+9 -7
View File
@@ -32,11 +32,13 @@
extern int pwd_main(int argc, char **argv)
{
char buf[BUFSIZ + 1];
if (getcwd(buf, sizeof(buf)) == NULL)
perror_msg_and_die("getcwd");
puts(buf);
return EXIT_SUCCESS;
static char *buf;
buf = xgetcwd(buf);
if (buf != NULL) {
puts(buf);
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
+31 -35
View File
@@ -33,6 +33,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include "busybox.h"
static int recursiveFlag = FALSE;
@@ -82,52 +83,46 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
extern int rm_main(int argc, char **argv)
{
int opt;
int status = EXIT_SUCCESS;
int stopIt=FALSE;
struct stat statbuf;
argc--;
argv++;
/* Parse any options */
while (argc > 0 && stopIt == FALSE) {
if (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'R':
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
/* do normal option parsing */
while ((opt = getopt(argc, argv, "Rrf-"
#ifdef BB_FEATURE_RM_INTERACTIVE
interactiveFlag = FALSE;
"i"
#endif
break;
case 'i':
)) > 0) {
switch (opt) {
case 'R':
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
#ifdef BB_FEATURE_RM_INTERACTIVE
interactiveFlag = TRUE;
case 'i':
interactiveFlag = TRUE;
#endif
break;
case '-':
stopIt = TRUE;
break;
default:
show_usage();
}
argc--;
argv++;
break;
default:
show_usage();
}
else
break;
}
if (argc < 1 && forceFlag == FALSE) {
if (argc == optind && forceFlag == FALSE) {
show_usage();
}
#ifdef BB_FEATURE_RM_INTERACTIVE
if (forceFlag == TRUE)
interactiveFlag = FALSE;
#endif
while (argc-- > 0) {
srcName = *(argv++);
while (optind < argc) {
srcName = argv[optind];
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0
&& errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
@@ -137,6 +132,7 @@ extern int rm_main(int argc, char **argv)
status = EXIT_FAILURE;
}
}
optind++;
}
return status;
}
+2 -2
View File
@@ -110,10 +110,10 @@ enum token_types {
PAREN
};
struct t_op {
static const struct t_op {
const char *op_text;
short op_num, op_type;
} const ops [] = {
} ops [] = {
{"-r", FILRD, UNOP},
{"-w", FILWR, UNOP},
{"-x", FILEX, UNOP},
+15 -15
View File
@@ -93,7 +93,7 @@ static void map(register unsigned char *string1, unsigned int string1_len,
}
}
static unsigned int expand(char *arg, register unsigned char *buffer)
static unsigned int expand(const char *arg, register unsigned char *buffer)
{
unsigned char *buffer_start = buffer;
int i, ac;
@@ -123,26 +123,26 @@ static unsigned int expand(char *arg, register unsigned char *buffer)
static int complement(unsigned char *buffer, int buffer_len)
{
register short i, j, index;
register short i, j, ix;
char conv[ASCII + 2];
index = 0;
ix = 0;
for (i = 0; i <= ASCII; i++) {
for (j = 0; j < buffer_len; j++)
if (buffer[j] == i)
break;
if (j == buffer_len)
conv[index++] = i & ASCII;
conv[ix++] = i & ASCII;
}
memcpy(buffer, conv, index);
return index;
memcpy(buffer, conv, ix);
return ix;
}
extern int tr_main(int argc, char **argv)
{
register unsigned char *ptr;
int output_length=0, input_length;
int index = 1;
int idx = 1;
int i;
RESERVE_BB_BUFFER(output, BUFSIZ);
RESERVE_BB_BUFFER(input, BUFSIZ);
@@ -157,8 +157,8 @@ extern int tr_main(int argc, char **argv)
pinvec = invec;
poutvec = outvec;
if (argc > 1 && argv[index][0] == '-') {
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
if (argc > 1 && argv[idx][0] == '-') {
for (ptr = (unsigned char *) &argv[idx][1]; *ptr; ptr++) {
switch (*ptr) {
case 'c':
com_fl = TRUE;
@@ -173,21 +173,21 @@ extern int tr_main(int argc, char **argv)
show_usage();
}
}
index++;
idx++;
}
for (i = 0; i <= ASCII; i++) {
vector[i] = i;
invec[i] = outvec[i] = FALSE;
}
if (argv[index] != NULL) {
input_length = expand(argv[index++], input);
if (argv[idx] != NULL) {
input_length = expand(argv[idx++], input);
if (com_fl)
input_length = complement(input, input_length);
if (argv[index] != NULL) {
if (*argv[index] == '\0')
if (argv[idx] != NULL) {
if (*argv[idx] == '\0')
error_msg_and_die("STRING2 cannot be empty");
output_length = expand(argv[index], output);
output_length = expand(argv[idx], output);
map(input, input_length, output, output_length);
}
for (i = 0; i < input_length; i++)
+2
View File
@@ -21,6 +21,8 @@
*
*/
/* getopt not needed */
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
+4 -6
View File
@@ -256,18 +256,16 @@ extern int cp_mv_main(int argc, char **argv)
int state = 0;
char *pushd, *d, *p;
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
perror_msg("getcwd()");
if ((pushd = xgetcwd(0)) == NULL)
continue;
}
if (chdir(baseDestName) < 0) {
perror_msg("chdir(%s)", baseSrcName);
continue;
}
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
perror_msg("getcwd()");
if ((d = xgetcwd(0)) == NULL)
continue;
}
while (!state && *d != '\0') {
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
perror_msg("stat(%s)", d);
+5 -5
View File
@@ -45,7 +45,7 @@ static const struct suffix_mult dd_suffixes[] = {
int dd_main(int argc, char **argv)
{
int i, ifd, ofd, oflag, sync = FALSE, trunc = TRUE;
int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE;
size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
size_t bs = 512, count = -1;
ssize_t n;
@@ -73,7 +73,7 @@ int dd_main(int argc, char **argv)
trunc = FALSE;
buf += 7;
} else if (strncmp("sync", buf, 4) == 0) {
sync = TRUE;
sync_flag = TRUE;
buf += 4;
} else {
error_msg_and_die("invalid conversion `%s'", argv[i]+5);
@@ -138,7 +138,7 @@ int dd_main(int argc, char **argv)
in_full++;
else
in_part++;
if (sync) {
if (sync_flag) {
memset(buf + n, '\0', bs - n);
n = bs;
}
@@ -151,8 +151,8 @@ int dd_main(int argc, char **argv)
out_part++;
}
fprintf(statusfp, "%d+%d records in\n", in_full, in_part);
fprintf(statusfp, "%d+%d records out\n", out_full, out_part);
fprintf(statusfp, "%ld+%ld records in\n", (long)in_full, (long)in_part);
fprintf(statusfp, "%ld+%ld records out\n", (long)out_full, (long)out_part);
return EXIT_SUCCESS;
}
+8 -12
View File
@@ -31,6 +31,7 @@
#define BB_DU
//#define BB_DUMPKMAP
#define BB_ECHO
//#define BB_ENV
//#define BB_EXPR
//#define BB_FBSET
//#define BB_FDFLUSH
@@ -118,6 +119,7 @@
//#define BB_UPDATE
#define BB_UPTIME
//#define BB_USLEEP
//#define BB_VI
//#define BB_WATCHDOG
#define BB_WC
#define BB_WGET
@@ -152,9 +154,8 @@
// I emailed Linus and this patch will not be going into the stock kernel.
//#define BB_FEATURE_USE_DEVPS_PATCH
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
#define BB_FEATURE_TRIVIAL_HELP
// show verbose usage messages
//#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
@@ -209,7 +210,7 @@
#define BB_FEATURE_MOUNT_LOOP
//
// Enable support for a real /etc/mtab file instead of /proc/mounts
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
//#define BB_FEATURE_MTAB_SUPPORT
//
// Enable support for mounting remote NFS volumes.
// You may need to mount with "-o nolock" if you are
@@ -306,6 +307,9 @@
// Enable a nifty progress meter in wget (adds just under 2k)
#define BB_FEATURE_WGET_STATUSBAR
//
// Enable HTTP authentication in wget
#define BB_FEATURE_WGET_AUTHENTICATION
//
// Clean up all memory before exiting -- usually not needed
// as the OS can clean up... Don't enable this unless you
// have a really good reason for cleaning things up manually.
@@ -344,14 +348,6 @@
// Nothing beyond this point should ever be touched by
// mere mortals so leave this stuff alone.
//
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
#define BB_MTAB
#endif
#else
#undef BB_MTAB
#endif
//
#if defined BB_SH
#if defined BB_FEATURE_COMMAND_EDITING
#define BB_CMDEDIT
+8 -12
View File
@@ -31,6 +31,7 @@
#define BB_DU
#define BB_DUMPKMAP
#define BB_ECHO
#define BB_ENV
#define BB_EXPR
#define BB_FBSET
#define BB_FDFLUSH
@@ -118,6 +119,7 @@
#define BB_UPDATE
#define BB_UPTIME
#define BB_USLEEP
#define BB_VI
#define BB_WATCHDOG
#define BB_WC
#define BB_WGET
@@ -152,9 +154,8 @@
// I emailed Linus and this patch will not be going into the stock kernel.
//#define BB_FEATURE_USE_DEVPS_PATCH
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
//#define BB_FEATURE_TRIVIAL_HELP
// show verbose usage messages
#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
@@ -209,7 +210,7 @@
#define BB_FEATURE_MOUNT_LOOP
//
// Enable support for a real /etc/mtab file instead of /proc/mounts
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
//#define BB_FEATURE_MTAB_SUPPORT
//
// Enable support for mounting remote NFS volumes.
// You may need to mount with "-o nolock" if you are
@@ -306,6 +307,9 @@
// Enable a nifty progress meter in wget (adds just under 2k)
#define BB_FEATURE_WGET_STATUSBAR
//
// Enable HTTP authentication in wget
#define BB_FEATURE_WGET_AUTHENTICATION
//
// Clean up all memory before exiting -- usually not needed
// as the OS can clean up... Don't enable this unless you
// have a really good reason for cleaning things up manually.
@@ -344,14 +348,6 @@
// Nothing beyond this point should ever be touched by
// mere mortals so leave this stuff alone.
//
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
#define BB_MTAB
#endif
#else
#undef BB_MTAB
#endif
//
#if defined BB_SH
#if defined BB_FEATURE_COMMAND_EDITING
#define BB_CMDEDIT
+11 -15
View File
@@ -31,12 +31,13 @@
#define BB_DU
//#define BB_DUMPKMAP
#define BB_ECHO
//#define BB_ENV
//#define BB_EXPR
//#define BB_FBSET
//#define BB_FDFLUSH
#define BB_FIND
#define BB_FREE
//#define BB_FREERAMDISK
#define BB_FREERAMDISK
//#define BB_FSCK_MINIX
//#define BB_GETOPT
#define BB_GREP
@@ -76,7 +77,7 @@
//#define BB_MT
//#define BB_NSLOOKUP
//#define BB_PING
//#define BB_PIVOT_ROOT
#define BB_PIVOT_ROOT
#define BB_POWEROFF
//#define BB_PRINTF
#define BB_PS
@@ -93,7 +94,7 @@
//#define BB_RPMUNPACK
#define BB_SED
//#define BB_SETKEYCODES
#define BB_SH
//#define BB_SH
#define BB_SLEEP
#define BB_SORT
//#define BB_STTY
@@ -118,6 +119,7 @@
//#define BB_UPDATE
#define BB_UPTIME
//#define BB_USLEEP
//#define BB_VI
//#define BB_WATCHDOG
#define BB_WC
//#define BB_WGET
@@ -152,9 +154,8 @@
// I emailed Linus and this patch will not be going into the stock kernel.
//#define BB_FEATURE_USE_DEVPS_PATCH
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
#define BB_FEATURE_TRIVIAL_HELP
// show verbose usage messages
//#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
@@ -209,7 +210,7 @@
#define BB_FEATURE_MOUNT_LOOP
//
// Enable support for a real /etc/mtab file instead of /proc/mounts
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
//#define BB_FEATURE_MTAB_SUPPORT
//
// Enable support for mounting remote NFS volumes.
// You may need to mount with "-o nolock" if you are
@@ -306,6 +307,9 @@
// Enable a nifty progress meter in wget (adds just under 2k)
#define BB_FEATURE_WGET_STATUSBAR
//
// Enable HTTP authentication in wget
#define BB_FEATURE_WGET_AUTHENTICATION
//
// Clean up all memory before exiting -- usually not needed
// as the OS can clean up... Don't enable this unless you
// have a really good reason for cleaning things up manually.
@@ -344,14 +348,6 @@
// Nothing beyond this point should ever be touched by
// mere mortals so leave this stuff alone.
//
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
#define BB_MTAB
#endif
#else
#undef BB_MTAB
#endif
//
#if defined BB_SH
#if defined BB_FEATURE_COMMAND_EDITING
#define BB_CMDEDIT
+30 -4
View File
@@ -1,3 +1,33 @@
busybox (0.51-1) unstable; urgency=low
* Fixes several critical bugs (see the busybox changelog
for complete details)
* Force USE_SYSTEM_PWD_GRP=false, so busybox bypasses
the glibc NSS libraries. (closes: #93362)
* Fixed a bug in sed's address range handling (closes: #91758)
* Removed irrelevant cruft from the bottem of debian/changelog
-- Erik Andersen <andersee@debian.org> Tue, 10 Apr 2001 14:07:29 -0600
busybox (0.50-2) unstable; urgency=low
* Enabled freeramdisk and pivot_root in the udeb (closes: #91336)
* Disabled lash (the busybox shell) in the udeb (closes: #91337)
* fixed a bug in syslog, a problem with rebooting when booted as
an initrd, and a few other minor problems.
-- Erik Andersen <andersee@debian.org> Sun, 25 Mar 2001 20:59:44 -0700
busybox (0.50-2) unstable; urgency=low
* Enabled freeramdisk and pivot_root in the udeb (closes: #91336)
* Disabled lash (the busybox shell) in the udeb (closes: #91337)
* fixed a bug in syslog, a problem with rebooting when booted as
an initrd, and a few other minor problems.
-- Erik Andersen <andersee@debian.org> Sun, 25 Mar 2001 20:59:44 -0700
busybox (0.50-1) unstable; urgency=low
* Tons on improvements all around -- See changelog for details.
@@ -50,7 +80,3 @@ busybox (0.45-1) unstable; urgency=low
-- Erik Andersen <andersee@debian.org> Tue, 27 Jun 2000 12:26:41 -0600
Local variables:
mode: debian-changelog
add-log-mailing-address: "andersee@debian.org"
End:
+3 -3
View File
@@ -29,7 +29,7 @@ debian/build-stamp-busybox:
cp Makefile $(bbbd)
cp debian/Config.h-deb $(bbbd)/Config.h
-(cd $(bbbd); $(MAKE) "BB_SRC_DIR=../../" applet_source_list)
(cd $(bbbd); $(MAKE) "BB_SRC_DIR=../../")
(cd $(bbbd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
touch debian/build-stamp-busybox
install: build
@@ -54,7 +54,7 @@ debian/build-stamp-busybox-static:
mkdir -p $(bbsbd)
cp Makefile $(bbsbd)
cp debian/Config.h-static $(bbsbd)/Config.h
(cd $(bbsbd); $(MAKE) DOSTATIC=true "BB_SRC_DIR=../../")
(cd $(bbsbd); $(MAKE) DOSTATIC=true USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
touch debian/build-stamp-busybox-static
install-static: build
@@ -95,7 +95,7 @@ debian/build-stamp-busybox-udeb:
mkdir -p $(bbubd)
cp Makefile $(bbubd)
cp debian/Config.h-udeb $(bbubd)/Config.h
(cd $(bbubd); $(MAKE) "BB_SRC_DIR=../../")
(cd $(bbubd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
touch debian/build-stamp-busybox-udeb
install-udeb: build
+4 -9
View File
@@ -20,18 +20,13 @@
#include <getopt.h>
#if __GNU_LIBRARY__ < 5
#include <sys/syscall.h>
#include <linux/unistd.h>
#ifndef __alpha__
# define __NR_klogctl __NR_syslog
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
#else /* __alpha__ */
#define klogctl syslog
#endif
# ifdef __alpha__
# define klogctl syslog
# endif
#else
# include <sys/klog.h>
#endif
#include "busybox.h"
int dmesg_main(int argc, char **argv)
+59 -10
View File
@@ -11,7 +11,7 @@ sub continuation {
while (<$fh>) {
my $s = $_;
$s =~ s/\\\s*$//;
$s =~ s/#.*$//;
#$s =~ s/#.*$//;
push @line, $s;
last unless (/\\\s*$/);
}
@@ -27,11 +27,11 @@ sub beautify {
my @line = split("\n", $text);
$text = join('',
map {
s/^\s*//;
s/"//g;
s/^\s*"//;
s/"\s*$//;
s/%/%%/g;
s/\$/\\\$/g;
eval qq[ sprintf(qq#$_#) ]
eval qq[ sprintf(qq{$_}) ]
} @line
);
return $text;
@@ -77,7 +77,7 @@ sub pod_for_usage {
: "";
return
"=item I<$name>".
"=item B<$name>".
"\n\n" .
"$name $trivial".
"\n\n" .
@@ -192,24 +192,73 @@ This script was based on a script by Erik Andersen (andersen@lineo.com).
=over 4
=item --help
=item B<--help>
This displays the help message.
=item --pod
=item B<--pod>
Generate POD (this is the default)
=item --sgml
=item B<--sgml>
Generate SGML
=item --verbose
=item B<--verbose>
Be verbose (not implemented)
=back
=head1 FORMAT
The following is an example of some data this script might parse.
#define length_trivial_usage \
"STRING"
#define length_full_usage \
"Prints out the length of the specified STRING."
#define length_example_usage \
"$ length "Hello"\n" \
"5\n"
Each entry is a cpp macro that defines a string. The macros are
named systematically in the form:
$name_$type_usage
$name is the name of the applet. $type can be "trivial", "full", "notes",
or "example". Every documentation macro must end with "_usage".
The definition of the types is as follows:
=over 4
=item B<trivial>
This should be a brief, one-line description of parameters that
the command expects. This will be displayed when B<-h> is issued to
a command. I<REQUIRED>
=item B<full>
This should contain descriptions of each option. This will also
be displayed along with the trivial help if BB_FEATURE_TRIVIAL_HELP
is disabled. I<REQUIRED>
=item B<notes>
This is documentation that is intended to go in the POD or SGML, but
not be output when a B<-h> is given to a command. To see an example
of notes being used, see init_notes_usage. I<OPTIONAL>
=item B<example>
This should be an example of how the command is acutally used.
I<OPTIONAL>
=back
=head1 FILES
F<usage.h>
@@ -226,4 +275,4 @@ John BEPPU <beppu@lineo.com>
=cut
# $Id: autodocifier.pl,v 1.17 2001/03/15 21:08:01 beppu Exp $
# $Id: autodocifier.pl,v 1.20 2001/04/10 00:00:05 kraai Exp $
+76 -7
View File
@@ -45,9 +45,8 @@ the expected functionality and behave very much like their GNU counterparts.
BusyBox has been written with size-optimization and limited resources in mind.
It is also extremely modular so you can easily include or exclude commands (or
features) at compile time. This makes it easy to customize your embedded
systems. To create a working system, just add /dev, a kernel, and an editor,
such as nano, e3, or elvis-tiny. For a really minimal system, you can even use
the busybox shell (not Bourne compatible, but very small and quite usable).
systems. To create a working system, just add /dev, a kernel, and a shell.
For a really minimal system, you can even use the busybox shell (not Bourne compatible, but very small and quite usable), and the busybox vi editor.
<p>
BusyBox is now maintained by
@@ -59,11 +58,13 @@ BusyBox is licensed under the
<a href="http://www.gnu.org/copyleft/gpl.html">GNU GENERAL PUBLIC LICENSE</a>
<p>
<h3> Screenshot </h3>
<p> Because everybody loves screenshots, a screenshot of BusyBox
is now available <a href="screenshot.html"> right here</a>
<H3>Mailing List Information</h3>
BusyBox now has a <a href="http://opensource.lineo.com/lists/busybox/">mailing list</a>!
To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo/busybox">this page</a>.
@@ -81,6 +82,65 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
<ul>
<li> <b>10 April 2001 -- BusyBox 0.51 released</b>
<br>
BusyBox 0.51 (the "rock-solid release") is now out there. This
release adds only 2 new applets: env and vi. The vi applet,
contributed by Sterling Huxley, is very functional, and is only
22k. This release fixes 3 critical bugs in the 0.50 release.
There were 2 potential segfaults in lash (the busybox shell) in
the 0.50 release which are now fixed. Another critical bug in
0.50 which is now fixed: syslogd from 0.50 could potentially
deadlock the init process and thereby break your entire system.
<p>
There are a number of improvements in this release as well. For
one thing, the wget applet is greatly improved. Dmitry Zakharov
added FTP support, and Laurence Anderson make wget fully RFC
compliant for HTTP 1.1. The mechanism for including utility
functions in previous releases was clumsy and error prone. Now
all utility functions are part of a new libbb library, which makes
maintaining utility functions much simpler. And BusyBox now
compiles on itanium systems (thanks to the Debian itanium porters
for letting me use their system!).
<p>
You can read the
<a href="ftp://oss.lineo.com/busybox/Changelog">changelog</a> for
complete details. BusyBox 0.51 can be downloaded from
<a href="ftp://oss.lineo.com/busybox">ftp://oss.lineo.com/busybox</a>.
<p>Have Fun!
<p>
<li> <b>Busybox Boot-Floppy Image</b>
<p>Because you asked for it, we have made available a <a href=
"ftp://opensource.lineo.com/busybox/busybox.floppy.img"> Busybox boot floppy
image</a>. Here's how you use it:
<ol>
<li> <a href= "ftp://opensource.lineo.com/busybox/busybox.floppy.img">
Download the image</a>
<li> dd it onto a floppy like so: <tt> dd if=busybox.floppy.img
of=/dev/fd0 ; sync </tt>
<li> Pop it in a machine and boot up.
</ol>
<p> If you want to look at the contents of the initrd image, do this:
<pre>
mount ./busybox.floppy.img /mnt -o loop -t msdos
cp /mnt/initrd.gz /tmp
umount /mnt
gunzip /tmp/initrd.gz
mount /tmp/initrd /mnt -o loop -t minix
</pre>
<li> <b>15 March 2001 -- BusyBox 0.50 released</b>
<br>
@@ -101,6 +161,7 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
business as we begin working on the next BusyBox release will be to merge in the new shell
currently in progress at
<a href="http://doolittle.faludi.com/~larry/parser.html">Larry Doolittle's website</a>.
<p>
<li> <b>27 January 2001 -- BusyBox 0.49 released</b>
@@ -126,6 +187,7 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
progress on <a href="http://doolittle.faludi.com/~larry/parser.html">Larry's website</a>
and help out if you can. This shell will be included in the next
release of BusyBox.
<p>
<li> <b>13 December 2000 -- BusyBox 0.48 released</b>
<br>
@@ -144,6 +206,7 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
<p>
Many thanks go out to the many many people that have contributed to
this release, especially Matt Kraai, Larry Doolittle, and Kent Robotti.
<p>
<li> <b>Old News</b>
@@ -231,11 +294,11 @@ Current documentation for BusyBox includes:
and similar tasks which nicely complements BusyBox.
<p>
<li><a href="http://cvs.uclinux.org/uClibc.html">uCLibc</a>
<li><a href="http://cvs.uclinux.org/uClibc.html">uClibc</a>
is a C library for embedded systems. You can actually statically link
a "Hello World" application under x86 that only takes 4k (as opposed to
200k under GNU libc). It can do dynamic linking too and works nicely with
BusyBox. to create very small embedded systems.
BusyBox to create very small embedded systems.
<p>
<li> <a href="http://opensource.lineo.com/software.html">Other cool embedded software</a>.
@@ -281,7 +344,13 @@ listed in the order I happen to add them to the web page:
<li> <a href="http://mkcdrec.ota.be/">mkCDrec - make CD-ROM recovery</a>
<li> <a href="http://recycle.lbl.gov/~ldoolitt/bse/">Linux on nanoEngine</a>
<li> <a href="http://www.zelow.no/floppyfw/"> Floppyfw</a>
<li> <a href="http://midori.transmeta.com/"> Midori Linux</a>
<li> <a href="http://midori.transmeta.com/"> Midori Linux</a> - <a href=
"http://www.wired.com/news/technology/0,1282,42399,00.html"> Article on
Midori Linux</a> on <a href= "http://www.wired.com"> Wired</a>. Quote from
Erik at the top of <a href=
"http://www.wired.com/news/technology/0,1282,42399-2,00.html"> this
page</a>
</ul>
@@ -305,7 +374,7 @@ you.
<font size="-1" face="arial, helvetica, sans-serif">
Mail all comments, insults, suggestions and bribes to
<a href="mailto:andersen@lineo.com">Erik Andersen</a><BR>
The Busybox logo is copyright 1999,2000, Erik Andersen.
The Busybox logo is copyright 1999,2000,2001, Erik Andersen.
</font>
</TD>
+290 -229
View File
File diff suppressed because it is too large. Load diff
+156
View File
@@ -0,0 +1,156 @@
=back
=head1 LIBC NSS
GNU Libc uses the Name Service Switch (NSS) to configure the behavior of the C
library for the local environment, and to configure how it reads system data,
such as passwords and group information. BusyBox has made it Policy that it
will never use NSS, and will never use and libc calls that make use of NSS.
This allows you to run an embedded system without the need for installing an
/etc/nsswitch.conf file and without and /lib/libnss_* libraries installed.
If you are using a system that is using a remote LDAP server for authentication
via GNU libc NSS, and you want to use BusyBox, then you will need to adjust the
BusyBox source. Chances are though, that if you have enough space to install
of that stuff on your system, then you probably want the full GNU utilities.
=head1 SEE ALSO
textutils(1), shellutils(1), etc...
=head1 MAINTAINER
Erik Andersen <andersee@debian.org> <andersen@lineo.com>
=head1 AUTHORS
The following people have contributed code to BusyBox whether
they know it or not.
=for html <br>
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
Tons of new stuff, major rewrite of most of the
core apps, tons of new apps as noted in header files.
=for html <br>
Edward Betts <edward@debian.org>
expr, hostid, logname, tty, wc, whoami, yes
=for html <br>
John Beppu <beppu@lineo.com>
du, head, nslookup, sort, tee, uniq
=for html <br>
Brian Candler <B.Candler@pobox.com>
tiny-ls(ls)
=for html <br>
Randolph Chung <tausq@debian.org>
fbset, ping, hostname, and mkfifo
=for html <br>
Dave Cinege <dcinege@psychosis.com>
more(v2), makedevs, dutmp, modularization, auto links file,
various fixes, Linux Router Project maintenance
=for html <br>
Karl M. Hegbloom <karlheg@debian.org>
cp_mv.c, the test suite, various fixes to utility.c, &c.
=for html <br>
Daniel Jacobowitz <dan@debian.org>
mktemp.c
=for html <br>
Matt Kraai <kraai@alumni.carnegiemellon.edu>
documentation, bugfixes
=for html <br>
John Lombardo <john@deltanet.com>
dirname, tr
=for html <br>
Glenn McGrath <bug1@netconnect.com.au>
ar.c
=for html <br>
Vladimir Oleynik <dzo@simtreas.ru>
cmdedit, stty-port, locale, various fixes
and irreconcilable critic of everything not perfect.
=for html <br>
Bruce Perens <bruce@pixar.com>
Original author of BusyBox. His code is still in many apps.
=for html <br>
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
wget - Contributed by permission of Covad Communications
=for html <br>
Pavel Roskin <proski@gnu.org>
Lots of bugs fixes and patches.
=for html <br>
Gyepi Sam <gyepi@praxis-sw.com>
Remote logging feature for syslogd
=for html <br>
Linus Torvalds <torvalds@transmeta.com>
mkswap, fsck.minix, mkfs.minix
=for html <br>
Mark Whitley <markw@lineo.com>
sed remix, bug fixes, style-guide, etc.
=for html <br>
Charles P. Wright <cpwright@villagenet.com>
gzip, mini-netcat(nc)
=for html <br>
Enrique Zanardi <ezanardi@ull.es>
tarcat (since removed), loadkmap, various fixes, Debian maintenance
=cut
# $Id: busybox_footer.pod,v 1.3 2001/04/09 23:27:51 kraai Exp $
+72
View File
@@ -0,0 +1,72 @@
# vi: set sw=4 ts=4:
=head1 NAME
BusyBox - The Swiss Army Knife of Embedded Linux
=head1 SYNTAX
BusyBox <function> [arguments...] # or
<function> [arguments...] # if symlinked
=head1 DESCRIPTION
BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides minimalist replacements for most of the utilities
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
tar, etc. BusyBox provides a fairly complete POSIX environment for any small
or embedded system. The utilities in BusyBox generally have fewer options than
their full-featured GNU cousins; however, the options that are included provide
the expected functionality and behave very much like their GNU counterparts.
BusyBox has been written with size-optimization and limited resources in mind.
It is also extremely modular so you can easily include or exclude commands (or
features) at compile time. This makes it easy to customize your embedded
systems. To create a working system, just add a kernel, a shell (such as ash),
and an editor (such as elvis-tiny or ae).
=head1 USAGE
When you create a link to BusyBox for the function you wish to use, when BusyBox
is called using that link it will behave as if the command itself has been invoked.
For example, entering
ln -s ./BusyBox ls
./ls
will cause BusyBox to behave as 'ls' (if the 'ls' command has been compiled
into BusyBox).
You can also invoke BusyBox by issuing the command as an argument on the
command line. For example, entering
./BusyBox ls
will also cause BusyBox to behave as 'ls'.
=head1 COMMON OPTIONS
Most BusyBox commands support the B<--help> option to provide a
terse runtime description of their behavior.
=head1 COMMANDS
Currently defined functions include:
ar, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt, clear, cmp, cp,
cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, dpkg, dpkg-deb, du,
dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find, free, freeramdisk,
fsck.minix, getopt, grep, gunzip, gzip, halt, head, hostid, hostname, id,
ifconfig, init, insmod, kill, killall, klogd, length, ln, loadacm, loadfont,
loadkmap, logger, logname, ls, lsmod, makedevs, md5sum, mkdir, mkfifo,
mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc, nslookup, ping,
pivot_root, poweroff, printf, ps, pwd, rdate, readlink, reboot, renice, reset,
rm, rmdir, rmmod, route, rpmunpack, sed, setkeycodes, sh, sleep, sort, stty,
swapoff, swapon, sync, syslogd, tail, tar, tee, telnet, test, tftp, touch, tr,
true, tty, umount, uname, uniq, unix2dos, update, uptime, usleep, uudecode,
uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat, [
=over 4
+90 -12
View File
@@ -21,8 +21,9 @@ Checkout the Latest Code from CVS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a necessary first step. Please do not try to work with the last
released version, as there is a good chance that somebody has already worked
on the area you had in mind and your patch might already be obsolete.
released version, as there is a good chance that somebody has already fixed
the bug you found. Somebody might have even added the feature you had in mind.
Don't make your work obsolete before you start!
For information on how to check out Busybox from CVS, please look at the
following links:
@@ -45,7 +46,8 @@ Archives can be found here:
http://opensource.lineo.com/lists/busybox/
If you have a serious interest in Busybox, i.e. you are using it day-to-day or
as part of an embedded project, it's a good idea to join the mailing list.
as part of an embedded project, it would be a good idea to join the mailing
list.
A web-based sign-up form can be found here:
@@ -58,7 +60,7 @@ Coordinate with the Applet Maintainer
Some (not all) of the applets in Busybox are "owned" by a maintainer who has
put significant effort into it and is probably more familiar with it than
others. To find the maintainer of an applet, look at the top of the .c file
for a name following the word 'Copyright' or 'Written by'.
for a name following the word 'Copyright' or 'Written by' or 'Maintainer'.
Before plunging ahead, it's a good idea to send a message to the mailing list
that says: "Hey, I was thinking about adding the 'transmogrify' feature to the
@@ -84,8 +86,8 @@ Knife" of embedded Linux, there are some applets that will not be accepted:
- Any filesystem manipulation tools: Busybox is filesystem independent and
we do not want to start adding mkfs/fsck tools for every (or any)
filesystem under the sun. (fsck_minix.c and mkfs_minix.c are living on
borrowed time.) There are far too many of these tools out there. Use
the upstream version. Not everything has to be part of Busybox.
borrowed time.) There are far too many of these tools out there. Use
the upstream version. Not everything has to be part of Busybox.
- Any partitioning tools: Partitioning a device is typically done once and
only once, and tools which do this generally do not need to reside on the
@@ -101,6 +103,12 @@ Knife" of embedded Linux, there are some applets that will not be accepted:
independent. Do not send us tools that cannot be used across multiple
platforms / arches.
- Any daemons that are not essential to basic system operation. To date, only
syslogd and klogd meet this requirement. We do not need a web server, an
ftp daemon, a dhcp server, a mail transport agent or a dns resolver. If you
need one of those, you are welcome to ask the folks on the mailing list for
recommendations, but please don't bloat up Busybox with any of these.
Bug Reporting
~~~~~~~~~~~~~
@@ -113,9 +121,19 @@ report to the tracking system can be found at:
The README file that comes with Busybox also describes how to submit a bug.
A well-written bug report will include a transcript of a shell session that
A well-written bug report should include a transcript of a shell session that
demonstrates the bad behavior and enables anyone else to duplicate the bug on
their own machine.
their own machine. The following is such an example:
When I execute Busybox 'date' it produces unexpected results.
This is using GNU date:
$ date
Wed Mar 21 14:19:41 MST 2001
This is using Busybox date:
$ date
codswaddle
Bug Triage
@@ -219,6 +237,10 @@ These are dirty jobs, but somebody's gotta do 'em.
- Where appropriate, replace preprocessor defined macros and values with
compile-time equivalents.
- Style guide compliance. See: docs/style-guide.txt
- Add testcases to tests/testcases.
- Makefile improvements:
http://www.canb.auug.org.au/~millerp/rmch/recu-make-cons-harm.html
(I think the recursive problems are pretty much taken care of at this point, non?)
@@ -310,6 +332,12 @@ Detailed instructions on how to submit a bug to the tracking system are at:
http://bugs.lineo.com/Reporting.html
If you have a patch that will fix and close a reported bug, please send a
message to [bugnumber]@bugs.lineo.com with your patch attached. It will catch
people's attention if you have a subject line like the following:
[PATCH INCLUDED] - Fix attached, please apply and close this bug
Improving Your Chances of Patch Acceptance
@@ -370,6 +398,15 @@ place in the form of mailing lists, the bug tracking system, and CVS. Please
use these resources.
Send Patches to the Bug Tracking System
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This was mentioned above in the "Making Sure Your Patch Doesn't Get Lost"
section, but it is worth mentioning again. A patch sent to the mailing list
might be unnoticed and forgotten. A patch sent to the bug tracking system will
be stored and closely connected to the bug it fixes.
Be Polite
~~~~~~~~~
@@ -382,6 +419,51 @@ opposite effect.
Committing Changes to CVS
-------------------------
If you submit several patches that demonstrate that you are a skilled and wise
coder, you may be invited to become a committer, thus enabling you to commit
changes directly to CVS. This is nice because you don't have to wait for
someone else to commit your change for you, you can just do it yourself.
But note that this is a priviledge that comes with some responsibilities. You
should test your changes before you commit them. You should also talk to an
applet maintainer before you make any kind of sweeping changes to somebody
else's code. Big changes should still go to the mailing list first. Remember,
being wise, polite, and discreet is more important than being clever.
When To Commit
~~~~~~~~~~~~~~
Generally, you should feel free to commit a change if:
- Your changes are small and don't touch many files
- You are fixing a bug
- Somebody has told you that it's okay
- It's obviously the Right Thing
The more of the above are true, the better it is to just commit a change
directly to CVS.
When Not To Commit
~~~~~~~~~~~~~~~~~~
Even if you have commit rights, you should probably still post a patch to the
mailing list if:
- Your changes are broad and touch many different files
- You are adding a feature
- Your changes are speculative or experimental (i.e. trying a new algorithm)
- You are not the maintainer and your changes make the maintainer cringe
The more of the above are true, the better it is to post a patch to the
mailing list instead of committing.
Final Words
-----------
@@ -391,8 +473,4 @@ document don't worry, the folks on the Busybox mailing list are a fairly
good-natured bunch and will work with you to help get your patches into shape
or help you make contributions.
If you submit several patches that demonstrate that you are a skilled and wise
coder, you may be invited to become a committer, thus enabling you to commit
changes directly to CVS.
+278 -285
View File
@@ -1,3 +1,5 @@
#include <dirent.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -12,21 +14,13 @@
#include "busybox.h"
/* Stupid libc doesn't have a reliable way for use to know
* that libc5 is being used. Assume this is good enough */
#if !defined __GLIBC__ && !defined __UCLIBC__
#error It looks like you are using libc5, which does not support
#error tfind(). tfind() is used by busybox dpkg.
#error Please disable BB_DPKG. Sorry.
#endif
#define DEPENDSMAX 64 /* maximum number of depends we can handle */
/* Should we do full dependency checking? */
#define DODEPENDS 1
/* Should we do debugging? */
#define DODEBUG 1
//#define DODEBUG 1
#ifdef DODEBUG
#define SYSTEM(x) do_system(x)
@@ -54,39 +48,30 @@ static const char dpkgcidir[] = "/var/lib/dpkg/tmp.ci/";
static const char infodir[] = "/var/lib/dpkg/info/";
static const char udpkg_quiet[] = "UDPKG_QUIET";
//static const int status_wantstart = 0;
//static const int status_wantunknown = (1 << 0);
static const int status_wantinstall = (1 << 1);
//static const int status_wanthold = (1 << 2);
//static const int status_wantdeinstall = (1 << 3);
//static const int status_wantpurge = (1 << 4);
static const int status_wantmask = 31;
//static const int status_want_unknown = 1;
static const int status_want_install = 2;
//static const int status_want_hold = 3;
//static const int status_want_deinstall = 4;
//static const int status_want_purge = 5;
//static const int status_flagstart = 5;
static const int status_flagok = (1 << 5); /* 32 */
//static const int status_flagreinstreq = (1 << 6);
//static const int status_flaghold = (1 << 7);
//static const int status_flagholdreinstreq = (1 << 8);
static const int status_flagmask = 480;
static const int status_flag_ok = 1;
//static const int status_flag_reinstreq = 2;
//static const int status_flag_hold = 3;
//static const int status_flag_holdreinstreq = 4;
//static const int status_statusstart = 9;
//static const int status_statusnoninstalled = (1 << 9); /* 512 */
static const int status_statusunpacked = (1 << 10);
static const int status_statushalfconfigured = (1 << 11);
static const int status_statusinstalled = (1 << 12);
static const int status_statushalfinstalled = (1 << 13);
//static const int status_statusconfigfiles = (1 << 14);
//static const int status_statuspostinstfailed = (1 << 15);
//static const int status_statusremovalfailed = (1 << 16);
static const int status_statusmask = 130560; /* i assume status_statusinstalled is supposed to be included */
//static const int status_statusnoninstalled = 1;
static const int status_status_unpacked = 2;
static const int status_status_halfconfigured = 3;
static const int status_status_installed = 4;
static const int status_status_halfinstalled = 5;
//static const int status_statusconfigfiles = 6;
//static const int status_statuspostinstfailed = 7;
//static const int status_statusremovalfailed = 8;
static const char *statuswords[][10] = {
{ (char *) 0, "unknown", "install", "hold", "deinstall", "purge", 0 },
{ (char *) 5, "ok", "reinstreq", "hold", "hold-reinstreq", 0 },
{ (char *) 9, "not-installed", "unpacked", "half-configured",
"installed", "half-installed", "config-files",
"post-inst-failed", "removal-failed", 0 }
};
static const char *status_words_want[] = { "unknown", "install", "hold", "deinstall", "purge", 0 };
static const char *status_words_flag[] = { "ok", "reinstreq", "hold", "hold-reinstreq", 0 };
static const char *status_words_status[] = { "not-installed", "unpacked", "half-configured", "installed",
"half-installed", "config-files", "post-inst-failed", "removal-failed", 0 };
static const int color_white = 0;
static const int color_grey = 1;
@@ -101,7 +86,9 @@ typedef struct package_s {
char *provides;
char *description;
int installer_menu_item;
unsigned long status;
unsigned char status_want;
unsigned char status_flag;
unsigned char status_status;
char color; /* for topo-sort */
struct package_s *requiredfor[DEPENDSMAX];
unsigned short requiredcount;
@@ -124,18 +111,34 @@ static int package_compare(const void *p1, const void *p2)
((package_t *)p2)->package);
}
static int remove_dpkgcidir()
/*
* NOTE: this was handled by a "rm -rf" shell command
* Maybe theis behaviour should be integrated into the rm applet
* (i dont appreciate the rm applets recursive action fn)-bug1
*/
static int remove_dir(const char *dirname)
{
char *rm_dpkgcidir = NULL;
struct dirent *fp;
DIR *dp = opendir(dirname);
while ((fp = readdir(dp)) != NULL) {
struct stat statbuf;
char *filename;
rm_dpkgcidir = (char *) xmalloc(strlen(dpkgcidir) + 8);
strcpy(rm_dpkgcidir, "rm -rf ");
strcat(rm_dpkgcidir, dpkgcidir);
filename = (char *) xcalloc(1, strlen(dirname) + strlen(fp->d_name) + 2);
strcpy(filename, dirname);
strcat(filename, fp->d_name);
lstat(filename, &statbuf);
if (SYSTEM(rm_dpkgcidir) != 0) {
perror("mkdir ");
return EXIT_FAILURE;
if ((strcmp(fp->d_name, ".") != 0) && (strcmp(fp->d_name, "..") != 0)) {
if (S_ISDIR(statbuf.st_mode)) {
remove_dir(strcat(filename, "/"));
}
else if (remove(filename) == -1) {
perror_msg(filename);
}
}
}
remove(dirname);
return EXIT_SUCCESS;
}
@@ -153,7 +156,7 @@ static char **depends_split(const char *dependsstr)
goto end;
}
p = strdup(dependsstr);
p = xstrdup(dependsstr);
while (*p != 0 && *p != '\n') {
if (*p != ' ') {
if (*p == ',') {
@@ -261,10 +264,9 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
while (dependsvec[i] != 0) {
/* Check for dependencies; first look for installed packages */
dependpkg.package = dependsvec[i];
if ((found = tfind(&dependpkg, &status, package_compare)) == 0 ||
((chk = *(package_t **)found) &&
(chk->status & (status_flagok | status_statusinstalled)) !=
(status_flagok | status_statusinstalled))) {
if (((found = tfind(&dependpkg, &status, package_compare)) == 0) ||
((chk = *(package_t **)found) && (chk->status_flag & status_flag_ok) &&
(chk->status_status & status_status_installed))) {
/* if it fails, we look through the list of packages we are going to
* install */
@@ -272,7 +274,7 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
if (strcmp(chk->package, dependsvec[i]) == 0 || (chk->provides &&
strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) {
if (chk->requiredcount >= DEPENDSMAX) {
fprintf(stderr, "Too many dependencies for %s\n", chk->package);
error_msg("Too many dependencies for %s", chk->package);
return 0;
}
if (chk != pkg) {
@@ -282,7 +284,7 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
}
}
if (chk == 0) {
fprintf(stderr, "%s depends on %s, but it is not going to be installed\n", pkg->package, dependsvec[i]);
error_msg("%s depends on %s, but it is not going to be installed", pkg->package, dependsvec[i]);
return 0;
}
}
@@ -308,58 +310,21 @@ static package_t *depends_resolve(package_t *pkgs, void *status)
* replacing any pre-existing entries. when a merge happens, status info
* read using the status_read function is written back to the status file
*/
static unsigned long status_parse(const char *line)
static unsigned char status_parse(const char *line, const char **status_words)
{
char *p;
int i, j;
unsigned long l = 0;
unsigned char status_num;
int i = 0;
for (i = 0; i < 3; i++) {
if ((p = strchr(line, ' ')) != NULL) {
*p = 0;
while (status_words[i] != 0) {
if (strncmp(line, status_words[i], strlen(status_words[i])) == 0) {
status_num = (char)i;
return(status_num);
}
j = 1;
while (statuswords[i][j] != 0) {
if (strcmp(line, statuswords[i][j]) == 0) {
l |= (1 << ((int)statuswords[i][0] + j - 1));
break;
}
j++;
}
/* parse error */
if (statuswords[i][j] == 0) {
return 0;
}
line = p+1;
i++;
}
return l;
}
static const char *status_print(unsigned long flags)
{
/* this function returns a static buffer... */
static char buf[256];
int i, j;
buf[0] = 0;
for (i = 0; i < 3; i++) {
j = 1;
while (statuswords[i][j] != 0) {
if ((flags & (1 << ((int)statuswords[i][0] + j - 1))) != 0) {
strcat(buf, statuswords[i][j]);
if (i < 2) strcat(buf, " ");
break;
}
j++;
}
if (statuswords[i][j] == 0) {
fprintf(stderr, "corrupted status flag!!\n");
return NULL;
}
}
return buf;
/* parse error */
error_msg("Invalid status word");
return(0);
}
/*
@@ -371,28 +336,34 @@ static int control_read(FILE *file, package_t *p)
char *line;
while ((line = get_line_from_file(file)) != NULL) {
line[strlen(line)] = 0;
line[strlen(line) - 1] = '\0';
if (strlen(line) == 0) {
break;
} else
if (strstr(line, "Package: ") == line) {
p->package = strdup(line + 9);
} else
if (strstr(line, "Status: ") == line) {
p->status = status_parse(line + 8);
} else
if (strstr(line, "Depends: ") == line) {
p->depends = strdup(line + 9);
} else
if (strstr(line, "Provides: ") == line) {
p->provides = strdup(line + 10);
} else
if (strstr(line, "Description: ") == line) {
p->description = strdup(line + 13);
}
else if (strstr(line, "Package: ") == line) {
p->package = xstrdup(line + 9);
}
else if (strstr(line, "Status: ") == line) {
char *word_pointer;
word_pointer = strchr(line, ' ') + 1;
p->status_want = status_parse(word_pointer, status_words_want);
word_pointer = strchr(word_pointer, ' ') + 1;
p->status_flag = status_parse(word_pointer, status_words_flag);
word_pointer = strchr(word_pointer, ' ') + 1;
p->status_status = status_parse(word_pointer, status_words_status);
}
else if (strstr(line, "Depends: ") == line) {
p->depends = xstrdup(line + 9);
}
else if (strstr(line, "Provides: ") == line) {
p->provides = xstrdup(line + 10);
}
else if (strstr(line, "Description: ") == line) {
p->description = xstrdup(line + 13);
/* This is specific to the Debian Installer. Ifdef? */
} else
if (strstr(line, "installer-menu-item: ") == line) {
}
else if (strstr(line, "installer-menu-item: ") == line) {
p->installer_menu_item = atoi(line + 21);
}
/* TODO: localized descriptions */
@@ -407,18 +378,16 @@ static void *status_read(void)
void *status = 0;
package_t *m = 0, *p = 0, *t = 0;
if ((f = fopen(statusfile, "r")) == NULL) {
perror(statusfile);
return 0;
}
if (getenv(udpkg_quiet) == NULL) {
printf("(Reading database...)\n");
}
if ((f = wfopen(statusfile, "r")) == NULL) {
return(NULL);
}
while (!feof(f)) {
m = (package_t *)xmalloc(sizeof(package_t));
memset(m, 0, sizeof(package_t));
m = (package_t *)xcalloc(1, sizeof(package_t));
control_read(f, m);
if (m->package) {
/*
@@ -434,25 +403,24 @@ static void *status_read(void)
* of a pseudo package into the status
* binary-tree.
*/
p = (package_t *)xmalloc(sizeof(package_t));
memset(p, 0, sizeof(package_t));
p->package = strdup(m->provides);
p = (package_t *)xcalloc(1, sizeof(package_t));
p->package = xstrdup(m->provides);
t = *(package_t **)tsearch(p, &status, package_compare);
if (t != p) {
free(p->package);
free(p);
}
else {
} else {
/*
* Pseudo package status is the
* same as the status of the
* package providing it
* FIXME: (not quite right, if 2
* packages of different statuses
* provide it).
*/
t->status = m->status;
* provide it).
*/
t->status_want = m->status_want;
t->status_flag = m->status_flag;
t->status_status = m->status_status;
}
}
}
@@ -467,64 +435,67 @@ static void *status_read(void)
static int status_merge(void *status, package_t *pkgs)
{
FILE *fin, *fout;
char *line;
char *line = NULL;
package_t *pkg = 0, *statpkg = 0;
package_t locpkg;
int r = 0;
if ((fin = fopen(statusfile, "r")) == NULL) {
perror(statusfile);
return 0;
}
if ((fout = fopen(new_statusfile, "w")) == NULL) {
perror(new_statusfile);
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
return 0;
}
if (getenv(udpkg_quiet) == NULL) {
printf("(Updating database...)\n");
}
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
line[strlen(line)] = 0; /* trim newline */
/* If we see a package header, find out if it's a package
* that we have processed. if so, we skip that block for
* now (write it at the end).
*
* we also look at packages in the status cache and update
* their status fields
*/
if (strstr(line, "Package: ") == line) {
for (pkg = pkgs; pkg != 0 && strncmp(line + 9,
pkg->package, strlen(line) - 9) != 0;
pkg = pkg->next) ;
/*
* Dont use wfopen here, handle errors ourself
*/
if ((fin = fopen(statusfile, "r")) != NULL) {
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
line[strlen(line) - 1] = '\0'; /* trim newline */
/* If we see a package header, find out if it's a package
* that we have processed. if so, we skip that block for
* now (write it at the end).
*
* we also look at packages in the status cache and update
* their status fields
*/
if (strstr(line, "Package: ") == line) {
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
pkg->package) != 0; pkg = pkg->next) ;
locpkg.package = line + 9;
statpkg = tfind(&locpkg, &status, package_compare);
/* note: statpkg should be non-zero, unless the status
* file was changed while we are processing (no locking
* is currently done...
*/
if (statpkg != 0) {
statpkg = *(package_t **)statpkg;
locpkg.package = line + 9;
statpkg = tfind(&locpkg, &status, package_compare);
/* note: statpkg should be non-zero, unless the status
* file was changed while we are processing (no locking
* is currently done...
*/
if (statpkg != 0) {
statpkg = *(package_t **)statpkg;
}
}
if (pkg != 0) {
continue;
}
if (strstr(line, "Status: ") == line && statpkg != 0) {
snprintf(line, sizeof(line), "Status: %s %s %s",
status_words_want[statpkg->status_want - 1],
status_words_flag[statpkg->status_flag - 1],
status_words_status[statpkg->status_status - 1]);
}
fprintf(fout, "%s\n", line);
}
if (pkg != 0) {
continue;
}
if (strstr(line, "Status: ") == line && statpkg != 0) {
snprintf(line, sizeof(line), "Status: %s",
status_print(statpkg->status));
}
fputs(line, fout);
fputc('\n', fout);
fclose(fin);
}
free(line);
// Print out packages we processed.
for (pkg = pkgs; pkg != 0; pkg = pkg->next) {
fprintf(fout, "Package: %s\nStatus: %s\n",
pkg->package, status_print(pkg->status));
fprintf(fout, "Package: %s\nStatus: %s %s %s\n",
pkg->package, status_words_want[pkg->status_want - 1],
status_words_flag[pkg->status_flag - 1],
status_words_status[pkg->status_status - 1]);
if (pkg->depends)
fprintf(fout, "Depends: %s\n", pkg->depends);
if (pkg->provides)
@@ -535,16 +506,25 @@ static int status_merge(void *status, package_t *pkgs)
fprintf(fout, "Description: %s\n", pkg->description);
fputc('\n', fout);
}
fclose(fin);
fclose(fout);
r = rename(statusfile, bak_statusfile);
if (r == 0) {
r = rename(new_statusfile, statusfile);
/*
* Its ok if renaming statusfile fails becasue it doesnt exist
*/
if (rename(statusfile, bak_statusfile) == -1) {
struct stat stat_buf;
if (stat(statusfile, &stat_buf) == 0) {
error_msg("Couldnt create backup status file");
return(EXIT_FAILURE);
}
error_msg("No status file found, creating new one");
}
return 0;
if (rename(new_statusfile, statusfile) == -1) {
error_msg("Couldnt create status file");
return(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}
static int is_file(const char *fn)
@@ -564,18 +544,18 @@ static int dpkg_doconfigure(package_t *pkg)
char buf[1024];
DPRINTF("Configuring %s\n", pkg->package);
pkg->status &= status_statusmask;
pkg->status_status = 0;
snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);
if (is_file(postinst)) {
snprintf(buf, sizeof(buf), "%s configure", postinst);
if ((r = do_system(buf)) != 0) {
fprintf(stderr, "postinst exited with status %d\n", r);
pkg->status |= status_statushalfconfigured;
error_msg("postinst exited with status %d\n", r);
pkg->status_status = status_status_halfconfigured;
return 1;
}
}
pkg->status |= status_statusinstalled;
pkg->status_status = status_status_installed;
return 0;
}
@@ -583,66 +563,74 @@ static int dpkg_doconfigure(package_t *pkg)
static int dpkg_dounpack(package_t *pkg)
{
int r = 0, i;
char *cwd;
FILE *outfp;
int status = TRUE;
char *cwd = xgetcwd(0);
char *src_file = NULL;
char *dst_file = NULL;
char *lst_file = NULL;
char *adminscripts[] = { "/prerm", "/postrm", "/preinst", "/postinst",
"/conffiles", "/md5sums", "/shlibs", "/templates" };
char buf[1024], buf2[1024];
// char *lst_file = NULL;
char *adminscripts[] = { "prerm", "postrm", "preinst", "postinst",
"conffiles", "md5sums", "shlibs", "templates" };
DPRINTF("Unpacking %s\n", pkg->package);
cwd = getcwd(0, 0);
if(cwd==NULL)
exit(EXIT_FAILURE);
chdir("/");
deb_extract(dpkg_deb_extract, "/", pkg->file);
/* Installs the package scripts into the info directory */
for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) {
struct stat src_stat_buf;
int src_fd = 0, dst_fd = 0;
/* The full path of the current location of the admin file */
src_file = xrealloc(src_file, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
strcpy(src_file, dpkgcidir);
strcat(src_file, pkg->package);
strcat(src_file, adminscripts[i]);
sprintf(src_file, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]);
/* the full path of where we want the file to be copied to */
dst_file = xrealloc(dst_file, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
strcpy(dst_file, infodir);
strcat(dst_file, pkg->package);
strcat(dst_file, adminscripts[i]);
sprintf(dst_file, "%s%s.%s", infodir, pkg->package, adminscripts[i]);
/* copy admin file to permanent home */
if (copy_file(src_file, dst_file, TRUE, FALSE, FALSE) < 0) {
error_msg_and_die("Cannot copy %s to %s ", buf, buf2);
/*
* copy admin file to permanent home
* NOTE: Maybe merge this behaviour into libb/copy_file.c
*/
if (lstat(src_file, &src_stat_buf) == 0) {
if ((src_fd = open(src_file, O_RDONLY)) != -1) {
if ((dst_fd = open(dst_file, O_WRONLY | O_CREAT, 0644)) == -1) {
status = FALSE;
perror_msg("Opening %s", dst_file);
}
copy_file_chunk(src_fd, dst_fd, src_stat_buf.st_size);
close(src_fd);
close(dst_fd);
} else {
status = FALSE;
error_msg("couldnt open [%s]\n", src_file);
}
}
/* create the list file */
lst_file = (char *) xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
strcpy(lst_file, infodir);
strcat(lst_file, pkg->package);
strcat(lst_file, ".list");
outfp = freopen(lst_file, "w", stdout);
deb_extract(dpkg_deb_list, NULL, pkg->file);
stdout = freopen(NULL, "w", outfp);
printf("done\n");
getchar();
fclose(outfp);
}
pkg->status &= status_wantmask;
pkg->status |= status_wantinstall;
pkg->status &= status_flagmask;
pkg->status |= status_flagok;
pkg->status &= status_statusmask;
/*
* create the list file
* FIXME: currently this dumps the lst to stdout instead of a file
*/
/* lst_file = (char *) xmalloc(strlen(infodir) + strlen(pkg->package) + 6);
strcpy(lst_file, infodir);
strcat(lst_file, pkg->package);
strcat(lst_file, ".list");
deb_extract(dpkg_deb_list, NULL, pkg->file);
*/
if (r == 0) {
pkg->status |= status_statusunpacked;
pkg->status_want = status_want_install;
pkg->status_flag = status_flag_ok;
if (status == TRUE) {
pkg->status_status = status_status_unpacked;
} else {
pkg->status |= status_statushalfinstalled;
pkg->status_status = status_status_halfinstalled;
}
chdir(cwd);
return r;
}
@@ -657,9 +645,8 @@ static int dpkg_unpackcontrol(package_t *pkg)
int length;
/* clean the temp directory (dpkgcidir) be recreating it */
remove_dpkgcidir();
if (mkdir(dpkgcidir, S_IRWXU) != 0) {
perror("mkdir");
remove_dir(dpkgcidir);
if (create_path(dpkgcidir, S_IRWXU) == FALSE) {
return EXIT_FAILURE;
}
@@ -674,13 +661,12 @@ static int dpkg_unpackcontrol(package_t *pkg)
}
/* now remove trailing version numbers etc */
length = strcspn(tmp_name, "_.");
pkg->package = (char *) xmalloc(length + 1);
pkg->package = (char *) xcalloc(1, length + 1);
/* store the package name */
strncpy(pkg->package, tmp_name, length);
/* work out the full extraction path */
tmp_name = (char *) xmalloc(strlen(dpkgcidir) + strlen(pkg->package) + 9);
memset(tmp_name, 0, strlen(dpkgcidir) + strlen(pkg->package) + 9);
tmp_name = (char *) xcalloc(1, strlen(dpkgcidir) + strlen(pkg->package) + 9);
strcpy(tmp_name, dpkgcidir);
strcat(tmp_name, pkg->package);
@@ -689,7 +675,7 @@ static int dpkg_unpackcontrol(package_t *pkg)
/* parse the extracted control file */
strcat(tmp_name, "/control");
if ((file = fopen(tmp_name, "r")) == NULL) {
if ((file = wfopen(tmp_name, "r")) == NULL) {
return EXIT_FAILURE;
}
if (control_read(file, pkg) == EXIT_FAILURE) {
@@ -713,7 +699,7 @@ static int dpkg_unpack(package_t *pkgs, void *status)
}
}
status_merge(status, pkgs);
remove_dpkgcidir();
remove_dir(dpkgcidir);
return r;
}
@@ -728,7 +714,7 @@ static int dpkg_configure(package_t *pkgs, void *status)
found = tfind(pkg, &status, package_compare);
if (found == 0) {
fprintf(stderr, "Trying to configure %s, but it is not installed\n", pkg->package);
error_msg("Trying to configure %s, but it is not installed", pkg->package);
r = 1;
}
/* configure the package listed in the status file;
@@ -750,8 +736,7 @@ static int dpkg_install(package_t *pkgs, void *status)
/* Stage 1: parse all the control information */
for (p = pkgs; p != 0; p = p->next) {
if (dpkg_unpackcontrol(p) == EXIT_FAILURE) {
perror(p->file);
return EXIT_FAILURE;
return(EXIT_FAILURE);
}
}
@@ -764,32 +749,34 @@ static int dpkg_install(package_t *pkgs, void *status)
/* Stage 3: install */
for (p = ordered; p != 0; p = p->next) {
p->status &= status_wantmask;
p->status |= status_wantinstall;
p->status_want = status_want_install;
/* for now the flag is always set to ok... this is probably
* not what we want
*/
p->status &= status_flagmask;
p->status |= status_flagok;
p->status_flag = status_flag_ok;
DPRINTF("Installing %s\n", p->package);
if (dpkg_dounpack(p) != 0) {
perror(p->file);
perror_msg(p->file);
}
if (dpkg_doconfigure(p) != 0) {
perror(p->file);
perror_msg(p->file);
}
}
if (ordered != 0) {
status_merge(status, pkgs);
}
remove_dpkgcidir();
remove_dir(dpkgcidir);
return 0;
}
/*
* Not implemented yet
*
static int dpkg_remove(package_t *pkgs, void *status)
{
package_t *p;
@@ -801,55 +788,61 @@ static int dpkg_remove(package_t *pkgs, void *status)
return 0;
}
*/
extern int dpkg_main(int argc, char **argv)
{
char opt = 0;
char *s;
const int arg_install = 1;
const int arg_unpack = 2;
const int arg_configure = 4;
package_t *p, *packages = NULL;
char *cwd = getcwd(0, 0);
void *status = NULL;
char opt = 0;
int optflag = 0;
while (*++argv) {
if (**argv == '-') {
/* Nasty little hack to "parse" long options. */
s = *argv;
while (*s == '-') {
s++;
}
opt=s[0];
} else {
p = (package_t *)xmalloc(sizeof(package_t));
memset(p, 0, sizeof(package_t));
if (**argv == '/') {
p->file = *argv;
} else
if (opt != 'c') {
p->file = xmalloc(strlen(cwd) + strlen(*argv) + 2);
sprintf(p->file, "%s/%s", cwd, *argv);
} else {
p->package = strdup(*argv);
}
p->next = packages;
packages = p;
}
while ((opt = getopt(argc, argv, "iruc")) != -1) {
switch (opt) {
case 'i':
optflag |= arg_install;
break;
case 'u':
optflag |= arg_unpack;
break;
case 'c':
optflag |= arg_configure;
break;
default:
show_usage();
}
}
while (optind < argc) {
p = (package_t *) xcalloc(1, sizeof(package_t));
if (optflag & arg_configure) {
p->package = xstrdup(argv[optind]);
} else {
p->file = xstrdup(argv[optind]);
}
p->next = packages;
packages = p;
optind++;
}
create_path(dpkgcidir, S_IRWXU);
create_path(infodir, S_IRWXU);
status = status_read();
switch (opt) {
case 'i':
return dpkg_install(packages, status);
case 'r':
return dpkg_remove(packages, status);
case 'u':
return dpkg_unpack(packages, status);
case 'c':
return dpkg_configure(packages, status);
default :
show_usage();
return EXIT_FAILURE;
if (optflag & arg_install) {
return dpkg_install(packages, status);
}
else if (optflag & arg_unpack) {
return dpkg_unpack(packages, status);
}
else if (optflag & arg_configure) {
return dpkg_configure(packages, status);
}
return(EXIT_FAILURE);
}
+20 -2
View File
@@ -24,8 +24,13 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include "busybox.h"
/* From gunzip.c */
extern int gz_open(FILE *compressed_file, int *pid);
extern void gz_close(int gunzip_pid);
typedef struct ar_headers_s {
char *name;
size_t size;
@@ -60,6 +65,8 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
int extract_to_stdout = FALSE;
int srcFd = 0;
int status;
pid_t pid;
FILE *comp_file = NULL;
if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
strcpy(ar_filename, "data.tar.gz");
@@ -99,7 +106,11 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
ar_headers = ar_headers->next;
}
lseek(srcFd, ar_headers->offset, SEEK_SET);
srcFd = tar_unzip_init(srcFd);
/* Uncompress the file */
comp_file = fdopen(srcFd, "r");
if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
error_msg_and_die("Couldnt unzip file");
}
if ( dir_name != NULL) {
if (is_directory(dir_name, TRUE, NULL)==FALSE) {
mkdir(dir_name, 0755);
@@ -108,7 +119,14 @@ extern int deb_extract(int optflags, const char *dir_name, const char *deb_filen
error_msg_and_die("Cannot change to dir %s", dir_name);
}
}
status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
status = readTarFile(srcFd, extract_flag, list_flag,
extract_to_stdout, verbose_flag, NULL, extract_list);
/* we are deliberately terminating the child so we can safely ignore this */
signal(SIGTERM, SIG_IGN);
gz_close(pid);
close(srcFd);
fclose(comp_file);
return status;
}
+6 -11
View File
@@ -83,7 +83,8 @@ static long du(char *filename)
int len;
if ((lstat(filename, &statbuf)) != 0) {
perror_msg_and_die("%s", filename);
perror_msg("%s", filename);
return 0;
}
du_depth++;
@@ -110,22 +111,16 @@ static long du(char *filename)
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[BUFSIZ + 1];
char *newfile;
char *name = entry->d_name;
if ((strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0)) {
continue;
}
if (len + strlen(name) + 1 > BUFSIZ) {
error_msg(name_too_long);
du_depth--;
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
newfile = concat_path_file(filename, name);
sum += du(newfile);
free(newfile);
}
closedir(dir);
print(sum, filename);
@@ -197,7 +192,7 @@ int du_main(int argc, char **argv)
return status;
}
/* $Id: du.c,v 1.43 2001/03/09 14:36:42 andersen Exp $ */
/* $Id: du.c,v 1.44 2001/04/09 22:48:11 andersen Exp $ */
/*
Local Variables:
c-file-style: "linux"
+4 -5
View File
@@ -41,11 +41,9 @@ extern int dutmp_main(int argc, char **argv)
}
}
/* Kludge around the fact that the binary format for utmp has changed, and the
* fact the stupid libc doesn't have a reliable #define to announce that libc5
* is being used. sigh.
*/
#if ! defined __GLIBC__ || defined __UCLIBC__
/* Kludge around the fact that the binary format for utmp has changed. */
#if __GNU_LIBRARY__ < 5 || defined __UCLIBC__
/* Linux libc5 */
while (read(file, (void*)&ut, sizeof(struct utmp))) {
printf("%d|%d|%s|%s|%s|%s|%s|%lx\n",
ut.ut_type, ut.ut_pid, ut.ut_line,
@@ -54,6 +52,7 @@ extern int dutmp_main(int argc, char **argv)
(long)ut.ut_addr);
}
#else
/* Glibc, uClibc, etc */
while (read(file, (void*)&ut, sizeof(struct utmp))) {
printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
ut.ut_type, ut.ut_pid, ut.ut_line,
+4 -4
View File
@@ -40,7 +40,7 @@ echo_main(int argc, char** argv)
while (argc > 0 && *argv[0] == '-')
{
register char *temp;
register int index;
register int ix;
/*
* If it appears that we are handling options, then make sure
@@ -49,9 +49,9 @@ echo_main(int argc, char** argv)
*/
temp = argv[0] + 1;
for (index = 0; temp[index]; index++)
for (ix = 0; temp[ix]; ix++)
{
if (strrchr("neE", temp[index]) == 0)
if (strrchr("neE", temp[ix]) == 0)
goto just_echo;
}
@@ -81,7 +81,7 @@ echo_main(int argc, char** argv)
just_echo:
while (argc > 0) {
char *arg = argv[0];
const char *arg = argv[0];
register int c;
while ((c = *arg++)) {
+3 -2
View File
@@ -622,9 +622,10 @@ static void process_file(FILE *file)
if (sed_cmds[i].beg_match && sed_cmds[i].end_match) {
if (still_in_range || regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0) {
line_altered += do_sed_command(&sed_cmds[i], line);
still_in_range = 1;
if (regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
if (still_in_range && regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
still_in_range = 0;
else
still_in_range = 1;
}
}
+3674
View File
File diff suppressed because it is too large. Load diff
+97
View File
@@ -0,0 +1,97 @@
/* vi: set sw=4 ts=4: */
/*
* env implementation for busybox
*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice is retained at the end of this file.
*
* Modified for BusyBox by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*/
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
extern int env_main(int argc, char** argv)
{
char **ep, *p;
char *cleanenv[1];
int ch;
while ((ch = getopt(argc, argv, "-iu:")) != -1)
switch(ch) {
case '-':
case 'i':
environ = cleanenv;
cleanenv[0] = NULL;
break;
case 'u':
unsetenv(optarg);
break;
default:
show_usage();
}
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
setenv(*argv, ++p, 1);
if (*argv) {
execvp(*argv, argv);
perror_msg_and_die("%s", *argv);
}
for (ep = environ; *ep; ep++)
printf("%s\n", *ep);
exit(EXIT_SUCCESS);
}
/*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
*
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+1 -1
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.50
Version: 0.51
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
+1 -1
View File
@@ -225,7 +225,7 @@ int name (l, r) VALUE *l; VALUE *r; \
}
#define arithdivf(name, op) \
int name (l, r) VALUE *l; VALUE *r; \
static int name (l, r) VALUE *l; VALUE *r; \
{ \
if (!toarith (l) || !toarith (r)) \
error_msg_and_die ( "non-numeric argument"); \
+3
View File
@@ -143,6 +143,9 @@ int find_main(int argc, char **argv)
for (i = firstopt; i < argc; i++) {
if (strcmp(argv[i], "-follow") == 0)
dereference = TRUE;
else if (strcmp(argv[i], "-print") == 0) {
;
}
else if (strcmp(argv[i], "-name") == 0) {
if (++i == argc)
error_msg_and_die("option `-name' requires an argument");
+3
View File
@@ -143,6 +143,9 @@ int find_main(int argc, char **argv)
for (i = firstopt; i < argc; i++) {
if (strcmp(argv[i], "-follow") == 0)
dereference = TRUE;
else if (strcmp(argv[i], "-print") == 0) {
;
}
else if (strcmp(argv[i], "-name") == 0) {
if (++i == argc)
error_msg_and_die("option `-name' requires an argument");
+18 -5
View File
@@ -41,6 +41,7 @@ static int print_count_only = 0;
static int be_quiet = 0;
static int invert_search = 0;
static int suppress_err_msgs = 0;
static int files_that_match = 0;
#ifdef BB_FEATURE_GREP_CONTEXT
extern char *optarg; /* in getopt.h */
@@ -105,7 +106,7 @@ static void grep_file(FILE *file)
/* otherwise, keep track of matches and print the matched line */
nmatches++;
if (!print_count_only) {
if (print_count_only==0 && files_that_match==0) {
#ifdef BB_FEATURE_GREP_CONTEXT
int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
@@ -163,11 +164,18 @@ static void grep_file(FILE *file)
}
/* special-case post processing */
if (print_count_only) {
if (files_that_match) {
if (nmatches > 0) {
printf("%s", cur_file);
if (nmatches)
printf(":%d", nmatches);
printf("\n");
}
} else if (print_count_only) {
if (print_filename)
printf("%s:", cur_file);
printf("%i\n", nmatches);
}
}
/* remember if we matched */
if (nmatches != 0)
@@ -183,7 +191,7 @@ extern int grep_main(int argc, char **argv)
#endif
/* do normal option parsing */
while ((opt = getopt(argc, argv, "iHhnqvsc"
while ((opt = getopt(argc, argv, "iHhlnqvsc"
#ifdef BB_FEATURE_GREP_CONTEXT
"A:B:C:"
#endif
@@ -192,6 +200,9 @@ extern int grep_main(int argc, char **argv)
case 'i':
ignore_case++;
break;
case 'l':
files_that_match++;
break;
case 'H':
print_filename++;
break;
@@ -232,6 +243,8 @@ extern int grep_main(int argc, char **argv)
before_buf = (char **)calloc(lines_before, sizeof(char *));
break;
#endif /* BB_FEATURE_GREP_CONTEXT */
default:
show_usage();
}
}
@@ -240,7 +253,7 @@ extern int grep_main(int argc, char **argv)
show_usage();
/* sanity check */
if (print_count_only || be_quiet) {
if (print_count_only || be_quiet || files_that_match) {
print_line_num = 0;
#ifdef BB_FEATURE_GREP_CONTEXT
lines_before = 0;
+1 -1
View File
@@ -45,7 +45,7 @@ int xargs_main(int argc, char **argv)
/* Store the command to be executed (taken from the command line) */
if (argc == 1) {
/* default behavior is to echo all the filenames */
cmd_to_be_executed = strdup("/bin/echo ");
cmd_to_be_executed = xstrdup("/bin/echo ");
} else {
/* concatenate all the arguments passed to xargs together */
int i;
+9 -9
View File
@@ -1439,18 +1439,18 @@ extern int fsck_minix_main(int argc, char **argv)
check();
}
if (verbose) {
int i, free;
int i, free_cnt;
for (i = 1, free = 0; i <= INODES; i++)
for (i = 1, free_cnt = 0; i <= INODES; i++)
if (!inode_in_use(i))
free++;
printf("\n%6ld inodes used (%ld%%)\n", (INODES - free),
100 * (INODES - free) / INODES);
for (i = FIRSTZONE, free = 0; i < ZONES; i++)
free_cnt++;
printf("\n%6ld inodes used (%ld%%)\n", (INODES - free_cnt),
100 * (INODES - free_cnt) / INODES);
for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++)
if (!zone_in_use(i))
free++;
printf("%6ld zones used (%ld%%)\n", (ZONES - free),
100 * (ZONES - free) / ZONES);
free_cnt++;
printf("%6ld zones used (%ld%%)\n", (ZONES - free_cnt),
100 * (ZONES - free_cnt) / ZONES);
printf("\n%6d regular files\n"
"%6d directories\n"
"%6d character device files\n"
+18 -5
View File
@@ -41,6 +41,7 @@ static int print_count_only = 0;
static int be_quiet = 0;
static int invert_search = 0;
static int suppress_err_msgs = 0;
static int files_that_match = 0;
#ifdef BB_FEATURE_GREP_CONTEXT
extern char *optarg; /* in getopt.h */
@@ -105,7 +106,7 @@ static void grep_file(FILE *file)
/* otherwise, keep track of matches and print the matched line */
nmatches++;
if (!print_count_only) {
if (print_count_only==0 && files_that_match==0) {
#ifdef BB_FEATURE_GREP_CONTEXT
int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
@@ -163,11 +164,18 @@ static void grep_file(FILE *file)
}
/* special-case post processing */
if (print_count_only) {
if (files_that_match) {
if (nmatches > 0) {
printf("%s", cur_file);
if (nmatches)
printf(":%d", nmatches);
printf("\n");
}
} else if (print_count_only) {
if (print_filename)
printf("%s:", cur_file);
printf("%i\n", nmatches);
}
}
/* remember if we matched */
if (nmatches != 0)
@@ -183,7 +191,7 @@ extern int grep_main(int argc, char **argv)
#endif
/* do normal option parsing */
while ((opt = getopt(argc, argv, "iHhnqvsc"
while ((opt = getopt(argc, argv, "iHhlnqvsc"
#ifdef BB_FEATURE_GREP_CONTEXT
"A:B:C:"
#endif
@@ -192,6 +200,9 @@ extern int grep_main(int argc, char **argv)
case 'i':
ignore_case++;
break;
case 'l':
files_that_match++;
break;
case 'H':
print_filename++;
break;
@@ -232,6 +243,8 @@ extern int grep_main(int argc, char **argv)
before_buf = (char **)calloc(lines_before, sizeof(char *));
break;
#endif /* BB_FEATURE_GREP_CONTEXT */
default:
show_usage();
}
}
@@ -240,7 +253,7 @@ extern int grep_main(int argc, char **argv)
show_usage();
/* sanity check */
if (print_count_only || be_quiet) {
if (print_count_only || be_quiet || files_that_match) {
print_line_num = 0;
#ifdef BB_FEATURE_GREP_CONTEXT
lines_before = 0;
+746 -927
View File
File diff suppressed because it is too large. Load diff
+125 -10
View File
@@ -42,6 +42,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
@@ -72,7 +73,7 @@ typedef unsigned long ulg;
/* methods 4 to 7 reserved */
#define DEFLATED 8
#define MAX_METHODS 9
extern int method; /* compression method */
static int method; /* compression method */
/* To save memory for 16 bit systems, some arrays are overlaid between
* the various modules:
@@ -143,7 +144,7 @@ EXTERN(ush, tab_prefix1); /* prefix for odd codes */
#endif
extern unsigned insize; /* valid bytes in inbuf */
extern unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned inptr; /* index of next byte to be processed in inbuf */
extern unsigned outcnt; /* bytes in output buffer */
extern long bytes_in; /* number of input bytes */
@@ -294,7 +295,7 @@ void lm_init (ush * flags);
ulg deflate (void);
/* in trees.c */
void ct_init (ush * attr, int *method);
void ct_init (ush * attr, int *methodp);
int ct_tally (int dist, int lc);
ulg flush_block (char *buf, ulg stored_len, int eof);
@@ -308,16 +309,16 @@ extern int (*read_buf) (char *buf, unsigned size);
/* in util.c: */
extern int copy (int in, int out);
extern ulg updcrc (uch * s, unsigned n);
extern void clear_bufs (void);
//extern ulg updcrc (uch * s, unsigned n);
//extern void clear_bufs (void);
extern int fill_inbuf (int eof_ok);
extern void flush_outbuf (void);
extern void flush_window (void);
extern void write_buf (int fd, void * buf, unsigned cnt);
//extern void write_buf (int fd, void * buf, unsigned cnt);
extern char *strlwr (char *s);
extern char *add_envopt (int *argcp, char ***argvp, char *env);
extern void read_error_msg (void);
extern void write_error_msg (void);
//extern void read_error_msg (void);
//extern void write_error_msg (void);
extern void display_ratio (long num, long den, FILE * file);
/* in inflate.c */
@@ -704,6 +705,120 @@ extern void _expand_args(int *argc, char ***argv);
#ifndef put_char
# define put_char(c) put_byte(c)
#endif
int crc_table_empty = 1;
/* ========================================================================
* Signal and error handler.
*/
void abort_gzip()
{
exit(ERROR);
}
/* ===========================================================================
* Clear input and output buffers
*/
static void clear_bufs(void)
{
outcnt = 0;
insize = inptr = 0;
bytes_in = bytes_out = 0L;
}
static void write_error_msg()
{
fprintf(stderr, "\n");
perror("");
abort_gzip();
}
/* ===========================================================================
* Does the same as write(), but also handles partial pipe writes and checks
* for error return.
*/
static void write_buf(fd, buf, cnt)
int fd;
void * buf;
unsigned cnt;
{
unsigned n;
while ((n = write(fd, buf, cnt)) != cnt) {
if (n == (unsigned) (-1)) {
write_error_msg();
}
cnt -= n;
buf = (void *) ((char *) buf + n);
}
}
/* ========================================================================
* Error handlers.
*/
static void read_error_msg()
{
fprintf(stderr, "\n");
if (errno != 0) {
perror("");
} else {
fprintf(stderr, "unexpected end of file\n");
}
abort_gzip();
}
/* ===========================================================================
* Run a set of bytes through the crc shift register. If s is a NULL
* pointer, then initialize the crc shift register contents instead.
* Return the current crc in either case.
*/
static ulg updcrc(s, n)
uch *s; /* pointer to bytes to pump through */
unsigned n; /* number of bytes in s[] */
{
static ulg crc = (ulg) 0xffffffffL; /* shift register contents */
register ulg c; /* temporary variable */
static unsigned long crc_32_tab[256];
if (crc_table_empty) {
unsigned long csr; /* crc shift register */
unsigned long e; /* polynomial exclusive-or pattern */
int i; /* counter for all possible eight bit values */
int k; /* byte being shifted into crc apparatus */
/* terms of polynomial defining this crc (except x^32): */
static int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* Make exclusive-or pattern from polynomial (0xedb88320) */
e = 0;
for (i = 0; i < sizeof(p)/sizeof(int); i++)
e |= 1L << (31 - p[i]);
/* Compute and print table of CRC's, five per line */
crc_32_tab[0] = 0x00000000L;
for (i = 1; i < 256; i++) {
csr = i;
/* The idea to initialize the register with the byte instead of
* zero was stolen from Haruhiko Okumura's ar002
*/
for (k = 8; k; k--)
csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1;
crc_32_tab[i]=csr;
}
}
if (s == NULL) {
c = 0xffffffffL;
} else {
c = crc;
if (n)
do {
c = crc_32_tab[((int) c ^ (*s++)) & 0xff] ^ (c >> 8);
} while (--n);
}
crc = c;
return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
}
/* bits.c -- output variable-length bit strings
* Copyright (C) 1992-1993 Jean-loup Gailly
* This is free software; you can redistribute it and/or modify it under the
@@ -3299,7 +3414,7 @@ long header_bytes; /* number of bytes in gzip header */
int zip(in, out)
int in, out; /* input and output file descriptors */
{
uch flags = 0; /* general purpose bit flags */
uch my_flags = 0; /* general purpose bit flags */
ush attr = 0; /* ascii/binary flag */
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
@@ -3315,7 +3430,7 @@ int in, out; /* input and output file descriptors */
put_byte(GZIP_MAGIC[1]);
put_byte(DEFLATED); /* compression method */
put_byte(flags); /* general flags */
put_byte(my_flags); /* general flags */
put_long(time_stamp);
/* Write deflated file to zip file */
+3 -3
View File
@@ -15,7 +15,7 @@
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* $Id: ifconfig.c,v 1.9 2001/03/15 20:48:45 andersen Exp $
* $Id: ifconfig.c,v 1.10 2001/03/26 16:26:16 mjn3 Exp $
*
*/
@@ -472,9 +472,9 @@ in_ether(char *bufp, struct sockaddr *sap)
if (c >= '0' && c <= '9') {
c -= '0';
} else if (c >= 'a' && c <= 'f') {
c -= ('a' + 10);
c -= ('a' - 10);
} else if (c >= 'A' && c <= 'F') {
c -= ('A' + 10);
c -= ('A' - 10);
} else if (j && (c == ':' || c == 0)) {
break;
} else {
+15 -9
View File
@@ -21,14 +21,14 @@
#define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
extern const char usage_messages[];
#elif defined(MAKE_USAGE)
#ifdef BB_FEATURE_TRIVIAL_HELP
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#else
#ifdef BB_FEATURE_VERBOSE_USAGE
#define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#else
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#endif
#elif defined(MAKE_LINKS)
# define APPLET(a,b,c) LINK c a
@@ -46,6 +46,9 @@
#ifdef BB_TEST
APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_ADJTIMEX
APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
#endif
#ifdef BB_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN)
#endif
@@ -126,7 +129,10 @@
APPLET(echo, echo_main, _BB_DIR_BIN)
#endif
#if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP)
APPLET_NOUSAGE("egrep", init_main, _BB_DIR_BIN)
APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN)
#endif
#ifdef BB_ENV
APPLET(env, env_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_EXPR
APPLET(expr, expr_main, _BB_DIR_USR_BIN)
@@ -407,6 +413,9 @@
#ifdef BB_UUENCODE
APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_VI
APPLET(vi, vi_main, _BB_DIR_BIN)
#endif
#ifdef BB_WATCHDOG
APPLET(watchdog, watchdog_main, _BB_DIR_SBIN)
#endif
@@ -436,7 +445,4 @@
{ 0,NULL,0 }
};
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
#endif
+14 -187
View File
@@ -36,37 +36,6 @@
#endif
#include <features.h>
/* Stupid libc doesn't have a reliable way for use to know
* that libc5 is being used. Assume this is good enough */
#if ! defined __GLIBC__ && ! defined __UCLIBC__
/* libc5 doesn't define socklen_t */
typedef unsigned int socklen_t;
#endif
/* Some useful definitions */
#define FALSE ((int) 0)
#define TRUE ((int) 1)
#define SKIP ((int) 2)
/* for mtab.c */
#define MTAB_GETMOUNTPT '1'
#define MTAB_GETDEVICE '2'
#define BUF_SIZE 8192
#define EXPAND_ALLOC 1024
static inline int is_decimal(ch) { return ((ch >= '0') && (ch <= '9')); }
static inline int is_octal(ch) { return ((ch >= '0') && (ch <= '7')); }
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
enum Location {
@@ -97,147 +66,15 @@ extern const struct BB_applet applets[];
extern const char *applet_name;
extern void show_usage(void) __attribute__ ((noreturn));
extern void error_msg(const char *s, ...);
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
extern void perror_msg(const char *s, ...);
extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
const char *mode_string(int mode);
const char *time_string(time_t timeVal);
int is_directory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name);
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
char name[1];
} ino_dev_hashtable_bucket_t;
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
int copy_file(const char *srcName, const char *destName,
int setModes, int followLinks, int forceFlag);
int copy_file_chunk(int srcFd, int dstFd, size_t remaining);
char *buildName(const char *dirName, const char *fileName);
int makeString(int argc, const char **argv, char *buf, int bufLen);
char *getChunk(int size);
char *chunkstrdup(const char *str);
void freeChunks(void);
ssize_t safe_read(int fd, void *buf, size_t count);
int full_write(int fd, const char *buf, int len);
int full_read(int fd, char *buf, int len);
int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
void* userData);
extern int create_path (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern int get_kernel_revision(void);
extern int get_console_fd(char* tty_name);
extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern);
extern long atoi_w_units (const char *cp);
extern pid_t* find_pid_by_name( char* pidName);
extern int find_real_root_device_name(char* name);
extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file);
extern int print_file_by_name(char *filename);
extern char process_escape_sequence(char **ptr);
extern char *get_last_path_component(char *path);
extern FILE *wfopen(const char *path, const char *mode);
extern FILE *xfopen(const char *path, const char *mode);
extern void chomp(char *s);
extern void trim(char *s);
extern struct BB_applet *find_applet_by_name(const char *name);
void run_applet_by_name(const char *name, int argc, char **argv);
#ifndef DMALLOC
extern void *xmalloc (size_t size);
extern void *xrealloc(void *old, size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern char *xstrdup (const char *s);
#endif
extern char *xstrndup (const char *s, int n);
extern char * safe_strncpy(char *dst, const char *src, size_t size);
struct suffix_mult {
char *suffix;
int mult;
};
extern unsigned long parse_number(const char *numstr,
const struct suffix_mult *suffixes);
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
#if defined BB_FEATURE_MOUNT_LOOP
extern int del_loop(const char *device);
extern int set_loop(const char *device, const char *file, int offset, int *loopro);
extern char *find_unused_loop_device (void);
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#endif
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap);
#endif
#if defined BB_NFSMOUNT
int nfsmount(const char *spec, const char *node, int *flags,
char **extra_opts, char **mount_opts, int running_bg);
#endif
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
#define RB_POWER_OFF 0x4321fedc
#endif
#if defined(BB_KLOGD) || defined(BB_LOGGER)
void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
void syslog_msg(int facility, int pri, const char *msg);
#endif
/* Include our own copy of struct sysinfo to avoid binary compatability
* problems with Linux 2.4, which changed things. Grumble, grumble. */
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
extern int sysinfo (struct sysinfo* info);
/* Bit map related macros -- libc5 doens't provide these... sigh. */
#ifndef setbit
#define NBBY CHAR_BIT
@@ -247,25 +84,15 @@ extern int sysinfo (struct sysinfo* info);
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#endif
#ifdef BB_FEATURE_HUMAN_READABLE
const char *make_human_readable_str(unsigned long val, unsigned long hr);
#endif
enum {
KILOBYTE = 1024,
MEGABYTE = (KILOBYTE*1024),
GIGABYTE = (MEGABYTE*1024)
};
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
#define RB_POWER_OFF 0x4321fedc
#endif
#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
int ask_confirmation(void);
#endif
/* Pull in the utility routines from libbb */
#include "libbb/libbb.h"
#endif /* _BB_INTERNAL_H_ */
+218
View File
@@ -0,0 +1,218 @@
/* vi: set sw=4 ts=4: */
/*
* Busybox main internal header file
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#ifndef __LIBBB_H__
#define __LIBBB_H__ 1
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#include <features.h>
#if __GNU_LIBRARY__ < 5
/* libc5 doesn't define socklen_t */
typedef unsigned int socklen_t;
/* libc5 doesn't implement BSD 4.4 daemon() */
extern int daemon (int nochdir, int noclose);
#endif
/* Some useful definitions */
#define FALSE ((int) 0)
#define TRUE ((int) 1)
#define SKIP ((int) 2)
/* for mtab.c */
#define MTAB_GETMOUNTPT '1'
#define MTAB_GETDEVICE '2'
#define BUF_SIZE 8192
#define EXPAND_ALLOC 1024
static inline int is_decimal(ch) { return ((ch >= '0') && (ch <= '9')); }
static inline int is_octal(ch) { return ((ch >= '0') && (ch <= '7')); }
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
extern void show_usage(void) __attribute__ ((noreturn));
extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
extern void perror_msg(const char *s, ...);
extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
/* These two are used internally -- you shouldn't need to use them */
extern void verror_msg(const char *s, va_list p);
extern void vperror_msg(const char *s, va_list p);
const char *mode_string(int mode);
const char *time_string(time_t timeVal);
int is_directory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name);
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
char name[1];
} ino_dev_hashtable_bucket_t;
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
int copy_file(const char *srcName, const char *destName,
int setModes, int followLinks, int forceFlag);
int copy_file_chunk(int srcFd, int dstFd, off_t remaining);
char *buildName(const char *dirName, const char *fileName);
int makeString(int argc, const char **argv, char *buf, int bufLen);
char *getChunk(int size);
char *chunkstrdup(const char *str);
void freeChunks(void);
ssize_t safe_read(int fd, void *buf, size_t count);
int full_write(int fd, const char *buf, int len);
int full_read(int fd, char *buf, int len);
int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
void* userData);
extern int create_path (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern int get_kernel_revision(void);
extern int get_console_fd(char* tty_name);
extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern);
extern long atoi_w_units (const char *cp);
extern pid_t* find_pid_by_name( char* pidName);
extern int find_real_root_device_name(char* name);
extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file);
extern int print_file_by_name(char *filename);
extern char process_escape_sequence(const char **ptr);
extern char *get_last_path_component(char *path);
extern FILE *wfopen(const char *path, const char *mode);
extern FILE *xfopen(const char *path, const char *mode);
extern void chomp(char *s);
extern void trim(char *s);
extern struct BB_applet *find_applet_by_name(const char *name);
void run_applet_by_name(const char *name, int argc, char **argv);
#ifndef DMALLOC
extern void *xmalloc (size_t size);
extern void *xrealloc(void *old, size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern char *xstrdup (const char *s);
#endif
extern char *xstrndup (const char *s, int n);
extern char * safe_strncpy(char *dst, const char *src, size_t size);
struct suffix_mult {
const char *suffix;
int mult;
};
extern unsigned long parse_number(const char *numstr,
const struct suffix_mult *suffixes);
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
extern int del_loop(const char *device);
extern int set_loop(const char *device, const char *file, int offset, int *loopro);
extern char *find_unused_loop_device (void);
#if (__GLIBC__ < 2)
extern int vdprintf(int d, const char *format, va_list ap);
#endif
int nfsmount(const char *spec, const char *node, int *flags,
char **extra_opts, char **mount_opts, int running_bg);
void syslog_msg_with_name(const char *name, int facility, int pri, const char *msg);
void syslog_msg(int facility, int pri, const char *msg);
/* Include our own copy of struct sysinfo to avoid binary compatability
* problems with Linux 2.4, which changed things. Grumble, grumble. */
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
extern int sysinfo (struct sysinfo* info);
const char *make_human_readable_str(unsigned long val, unsigned long not_hr);
enum {
KILOBYTE = 1024,
MEGABYTE = (KILOBYTE*1024),
GIGABYTE = (MEGABYTE*1024)
};
int ask_confirmation(void);
int klogctl(int type, char * b, int len);
char *xgetcwd(char *cwd);
char *concat_path_file(const char *path, const char *filename);
#endif /* __LIBBB_H__ */
+50 -9
View File
@@ -1,3 +1,16 @@
#define adjtimex_trivial_usage \
"[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]"
#define adjtimex_full_usage \
"Reads and optionally sets system timebase parameters.\n" \
"See adjtimex(2).\n\n" \
"Options:\n" \
"\t-q\t\tquiet mode - do not print\n" \
"\t-o offset\ttime offset, microseconds\n" \
"\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \
"\t\t\t(positive values make the system clock run fast)\n" \
"\t-t tick\t\tmicroseconds per tick, usually 10000\n" \
"\t-p timeconstant\n"
#define ar_trivial_usage \
"-[ovR]{ptx} archive filenames"
#define ar_full_usage \
@@ -62,7 +75,7 @@
"-r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo\n"
#define chown_trivial_usage \
"[OPTION]... OWNER[<.|:>[GROUP] FILE..."
"[OPTION]... OWNER[<.|:>[GROUP]] FILE..."
#define chown_full_usage \
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" \
"\nOptions:\n" \
@@ -330,6 +343,15 @@
"$ echo "Erik\nis\ncool"\n" \
"Erik\nis\ncool\n"
#define env_trivial_usage \
"[-] [-iu] [name=value ...] [command]"
#define env_full_usage \
"Prints the current environment or runs a program after setting\n" \
"up the specified environment.\n\n" \
"Options:\n" \
"\t-, -i\tstart with an empty environment\n" \
"\t-u\tremove variable from the environment\n"
#define expr_trivial_usage \
"EXPRESSION"
#define expr_full_usage \
@@ -416,6 +438,7 @@
"\nEXPRESSION may consist of:\n" \
"\t-follow\t\tDereference symbolic links.\n" \
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN." \
"\t-print\t\tPrint (default and assumed).\n" \
USAGE_FIND_TYPE( \
"\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \
) USAGE_FIND_PERM( \
@@ -499,6 +522,7 @@
"\t-H\tprefix output lines with filename where match was found\n" \
"\t-h\tsuppress the prefixing filename on output\n" \
"\t-i\tignore case distinctions\n" \
"\t-l\tlist names of files that match\n" \
"\t-n\tprint line number with output lines\n" \
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n" \
"\t-v\tselect non-matching lines\n" \
@@ -640,10 +664,15 @@
"\n" \
" ::sysinit:/etc/init.d/rcS\n" \
" ::askfirst:/bin/sh\n" \
" ::ctrlaltdel:/sbin/reboot\n" \
" ::shutdown:/sbin/swapoff -a\n" \
" ::shutdown:/bin/umount -a -r\n" \
"\n" \
"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
"\n" \
" tty2::askfirst:/bin/sh\n" \
" tty3::askfirst:/bin/sh\n" \
" tty4::askfirst:/bin/sh\n" \
"\n" \
"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
"\n" \
@@ -669,7 +698,7 @@
" <action>: \n" \
"\n" \
" Valid actions include: sysinit, respawn, askfirst, wait, \n" \
" once, and ctrlaltdel.\n" \
" once, ctrlaltdel, and shutdown.\n" \
"\n" \
" The available actions can be classified into two groups: actions\n" \
" that are run only once, and actions that are re-run when the specified\n" \
@@ -683,9 +712,12 @@
" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \
" the specified task completes. 'once' actions are asyncronous,\n" \
" therefore, init does not wait for them to complete. 'ctrlaltdel'\n" \
" actions are run immediately before init causes the system to reboot\n" \
" (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
" idea).\n" \
" actions are run when the system detects that someone on the system\n" \
" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \
" wants to run 'reboot' at this point to cause the system to reboot.\n" \
" Finally the 'shutdown' action specifies the actions to taken when\n" \
" init is told to reboot. Unmounting filesystems and disabling swap\n" \
" is a very good here\n" \
"\n" \
" Run repeatedly actions:\n" \
"\n" \
@@ -736,8 +768,9 @@
" #::respawn:/sbin/getty 57600 ttyS2\n" \
" \n" \
" # Stuff to do before rebooting\n" \
" ::ctrlaltdel:/bin/umount -a -r\n" \
" ::ctrlaltdel:/sbin/swapoff -a\n"
" ::ctrlaltdel:/sbin/reboot\n" \
" ::shutdown:/bin/umount -a -r\n" \
" ::shutdown:/sbin/swapoff -a\n"
#define insmod_trivial_usage \
"[OPTION]... MODULE [symbol=value]..."
@@ -1044,7 +1077,7 @@
#else
#define USAGE_MOUNT_LOOP(a)
#endif
#ifdef BB_MTAB
#ifdef BB_FEATURE_MTAB_SUPPORT
#define USAGE_MTAB(a) a
#else
#define USAGE_MTAB(a)
@@ -1657,6 +1690,13 @@
"$ uudecode busybox busybox > busybox.uu\n" \
"$\n"
#define vi_trivial_usage \
"[OPTION] [FILE]..."
#define vi_full_usage \
"edit FILE.\n\n" \
"Options:\n" \
"\t-R\tRead-only- do not write to the file."
#define watchdog_trivial_usage \
"DEV"
#define watchdog_full_usage \
@@ -1679,9 +1719,10 @@
#define wget_trivial_usage \
"[-c] [-O file] url"
#define wget_full_usage \
"wget retrieves files via HTTP\n\n" \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
"\t-c\tcontinue retrieval of aborted transfers\n" \
"\t-q\tquiet mode - do not print\n" \
"\t-O\tsave to filename ('-' for stdout)"
#define which_trivial_usage \
+99 -80
View File
@@ -85,13 +85,14 @@ static const int RB_ENABLE_CAD = 0x89abcdef;
static const int RB_DISABLE_CAD = 0;
#define RB_POWER_OFF 0x4321fedc
static const int RB_AUTOBOOT = 0x01234567;
#if defined(__GLIBC__) || defined (__UCLIBC__)
#include <sys/reboot.h>
#endif
#if __GNU_LIBRARY__ > 5
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#endif
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
@@ -112,13 +113,11 @@ static const int RB_AUTOBOOT = 0x01234567;
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
#if __GNU_LIBRARY__ > 5
#include <sys/kdaemon.h>
#else
#include <sys/syscall.h>
#include <linux/unistd.h>
static _syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
extern int bdflush (int func, long int data);
#endif
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
@@ -146,7 +145,8 @@ typedef enum {
ASKFIRST,
WAIT,
ONCE,
CTRLALTDEL
CTRLALTDEL,
SHUTDOWN
} initActionEnum;
/* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +162,7 @@ static const struct initActionType actions[] = {
{"wait", WAIT},
{"once", ONCE},
{"ctrlaltdel", CTRLALTDEL},
{"shutdown", SHUTDOWN},
{0, 0}
};
@@ -188,6 +189,7 @@ static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
static void message(int device, char *fmt, ...)
@@ -393,6 +395,23 @@ static void console_init()
}
message(LOG, "console=%s\n", console);
}
static void fixup_argv(int argc, char **argv, char *new_argv0)
{
int len;
/* Fix up argv[0] to be certain we claim to be init */
len = strlen(argv[0]);
memset(argv[0], 0, len);
strncpy(argv[0], new_argv0, len);
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
len = 1;
while (argc > len) {
memset(argv[len], 0, strlen(argv[len]));
len++;
}
}
static pid_t run(char *command, char *terminal, int get_enter)
{
@@ -402,6 +421,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
char *tmpCmd, *s;
char *cmd[255], *cmdpath;
char buf[255];
struct stat sb;
static const char press_enter[] =
#ifdef CUSTOMIZED_BANNER
@@ -447,8 +467,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
signal(SIGHUP, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
struct stat statBuf;
if (stat(terminal, &statBuf) != 0) {
if (stat(terminal, &sb) != 0) {
message(LOG | CONSOLE, "device '%s' does not exist.\n",
terminal);
exit(1);
@@ -463,29 +482,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
tcsetpgrp(0, getpgrp());
set_term(0);
if (get_enter == TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
#ifdef DEBUG_INIT
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
command, getpid(), terminal);
#endif
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
#ifdef DEBUG_INIT
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
getpid(), terminal, command);
#endif
/* See if any special /bin/sh requiring characters are present */
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
cmd[0] = SHELL;
@@ -497,7 +493,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
} else {
/* Convert command (char*) into cmd (char**, one word per string) */
for (tmpCmd = command, i = 0;
(tmpCmd = strsep(&command, " \t")) != NULL;) {
(tmpCmd = strsep(&command, " \t")) != NULL;) {
if (*tmpCmd != '\0') {
cmd[i] = tmpCmd;
tmpCmd++;
@@ -507,53 +503,72 @@ static pid_t run(char *command, char *terminal, int get_enter)
cmd[i] = NULL;
}
cmdpath = cmd[0];
cmdpath = cmd[0];
/*
Interactive shells want to see a dash in argv[0]. This
typically is handled by login, argv will be setup this
way if a dash appears at the front of the command path
/*
Interactive shells want to see a dash in argv[0]. This
typically is handled by login, argv will be setup this
way if a dash appears at the front of the command path
(like "-/bin/sh").
*/
*/
if (*cmdpath == '-') {
char *s;
if (*cmdpath == '-') {
/* skip over the dash */
++cmdpath;
/* skip over the dash */
++cmdpath;
/* find the last component in the command pathname */
s = get_last_path_component(cmdpath);
/* find the last component in the command pathname */
s = get_last_path_component(cmdpath);
/* make a new argv[0] */
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
message(LOG | CONSOLE, "malloc failed");
cmd[0] = cmdpath;
} else {
cmd[0][0] = '-';
strcpy(cmd[0]+1, s);
}
}
/* make a new argv[0] */
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
message(LOG | CONSOLE, "malloc failed");
cmd[0] = cmdpath;
} else {
cmd[0][0] = '-';
strcpy(cmd[0]+1, s);
}
}
if (get_enter == TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
#ifdef DEBUG_INIT
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
cmd[0], getpid(), terminal);
#endif
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
#ifdef DEBUG_INIT
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
getpid(), terminal, command);
#endif
#if defined BB_FEATURE_INIT_COREDUMPS
{
struct stat sb;
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
#endif
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execve(cmdpath, cmd, environment);
execve(cmdpath, cmd, environment);
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
strerror(errno));
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
strerror(errno));
exit(-1);
}
return pid;
@@ -603,12 +618,12 @@ static void check_memory()
}
/* Run all commands to be run right before halt/reboot */
static void run_lastAction(void)
static void run_actions(initActionEnum action)
{
initAction *a, *tmp;
for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr;
if (a->action == CTRLALTDEL) {
if (a->action == action) {
waitfor(a->process, a->console, FALSE);
delete_initAction(a);
}
@@ -640,7 +655,7 @@ static void shutdown_system(void)
sleep(1);
/* run everything to be run at "ctrlaltdel" */
run_lastAction();
run_actions(SHUTDOWN);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -682,6 +697,11 @@ static void reboot_signal(int sig)
exit(0);
}
static void ctrlaltdel_signal(int sig)
{
run_actions(CTRLALTDEL);
}
#endif /* ! DEBUG_INIT */
static void new_initAction(initActionEnum action, char *process, char *cons)
@@ -753,10 +773,12 @@ static void parse_inittab(void)
if (file == NULL) {
/* No inittab file -- set up some default behavior */
#endif
/* Reboot on Ctrl-Alt-Del */
new_initAction(CTRLALTDEL, "/sbin/reboot", console);
/* Swapoff on halt/reboot */
new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console);
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */
new_initAction(CTRLALTDEL, "/bin/umount -a -r", console);
new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Askfirst shell on tty1 */
new_initAction(ASKFIRST, SHELL, console);
/* Askfirst shell on tty2 */
@@ -869,7 +891,7 @@ extern int init_main(int argc, char **argv)
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, halt_signal);
signal(SIGINT, reboot_signal);
signal(SIGINT, ctrlaltdel_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
@@ -937,11 +959,8 @@ extern int init_main(int argc, char **argv)
parse_inittab();
}
/* Fix up argv[0] to be certain we claim to be init */
argv[0]="init";
if (argc > 1)
argv[1][0]=0;
/* Make the command line just say "init" -- thats all, nothing else */
fixup_argv(argc, argv, "init");
/* Now run everything that needs to be run */
+99 -80
View File
@@ -85,13 +85,14 @@ static const int RB_ENABLE_CAD = 0x89abcdef;
static const int RB_DISABLE_CAD = 0;
#define RB_POWER_OFF 0x4321fedc
static const int RB_AUTOBOOT = 0x01234567;
#if defined(__GLIBC__) || defined (__UCLIBC__)
#include <sys/reboot.h>
#endif
#if __GNU_LIBRARY__ > 5
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#endif
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
@@ -112,13 +113,11 @@ static const int RB_AUTOBOOT = 0x01234567;
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
#if __GNU_LIBRARY__ > 5
#include <sys/kdaemon.h>
#else
#include <sys/syscall.h>
#include <linux/unistd.h>
static _syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
extern int bdflush (int func, long int data);
#endif
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
@@ -146,7 +145,8 @@ typedef enum {
ASKFIRST,
WAIT,
ONCE,
CTRLALTDEL
CTRLALTDEL,
SHUTDOWN
} initActionEnum;
/* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +162,7 @@ static const struct initActionType actions[] = {
{"wait", WAIT},
{"once", ONCE},
{"ctrlaltdel", CTRLALTDEL},
{"shutdown", SHUTDOWN},
{0, 0}
};
@@ -188,6 +189,7 @@ static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
static void message(int device, char *fmt, ...)
@@ -393,6 +395,23 @@ static void console_init()
}
message(LOG, "console=%s\n", console);
}
static void fixup_argv(int argc, char **argv, char *new_argv0)
{
int len;
/* Fix up argv[0] to be certain we claim to be init */
len = strlen(argv[0]);
memset(argv[0], 0, len);
strncpy(argv[0], new_argv0, len);
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
len = 1;
while (argc > len) {
memset(argv[len], 0, strlen(argv[len]));
len++;
}
}
static pid_t run(char *command, char *terminal, int get_enter)
{
@@ -402,6 +421,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
char *tmpCmd, *s;
char *cmd[255], *cmdpath;
char buf[255];
struct stat sb;
static const char press_enter[] =
#ifdef CUSTOMIZED_BANNER
@@ -447,8 +467,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
signal(SIGHUP, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
struct stat statBuf;
if (stat(terminal, &statBuf) != 0) {
if (stat(terminal, &sb) != 0) {
message(LOG | CONSOLE, "device '%s' does not exist.\n",
terminal);
exit(1);
@@ -463,29 +482,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
tcsetpgrp(0, getpgrp());
set_term(0);
if (get_enter == TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
#ifdef DEBUG_INIT
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
command, getpid(), terminal);
#endif
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
#ifdef DEBUG_INIT
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
getpid(), terminal, command);
#endif
/* See if any special /bin/sh requiring characters are present */
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
cmd[0] = SHELL;
@@ -497,7 +493,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
} else {
/* Convert command (char*) into cmd (char**, one word per string) */
for (tmpCmd = command, i = 0;
(tmpCmd = strsep(&command, " \t")) != NULL;) {
(tmpCmd = strsep(&command, " \t")) != NULL;) {
if (*tmpCmd != '\0') {
cmd[i] = tmpCmd;
tmpCmd++;
@@ -507,53 +503,72 @@ static pid_t run(char *command, char *terminal, int get_enter)
cmd[i] = NULL;
}
cmdpath = cmd[0];
cmdpath = cmd[0];
/*
Interactive shells want to see a dash in argv[0]. This
typically is handled by login, argv will be setup this
way if a dash appears at the front of the command path
/*
Interactive shells want to see a dash in argv[0]. This
typically is handled by login, argv will be setup this
way if a dash appears at the front of the command path
(like "-/bin/sh").
*/
*/
if (*cmdpath == '-') {
char *s;
if (*cmdpath == '-') {
/* skip over the dash */
++cmdpath;
/* skip over the dash */
++cmdpath;
/* find the last component in the command pathname */
s = get_last_path_component(cmdpath);
/* find the last component in the command pathname */
s = get_last_path_component(cmdpath);
/* make a new argv[0] */
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
message(LOG | CONSOLE, "malloc failed");
cmd[0] = cmdpath;
} else {
cmd[0][0] = '-';
strcpy(cmd[0]+1, s);
}
}
/* make a new argv[0] */
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
message(LOG | CONSOLE, "malloc failed");
cmd[0] = cmdpath;
} else {
cmd[0][0] = '-';
strcpy(cmd[0]+1, s);
}
}
if (get_enter == TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
#ifdef DEBUG_INIT
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
cmd[0], getpid(), terminal);
#endif
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
#ifdef DEBUG_INIT
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
getpid(), terminal, command);
#endif
#if defined BB_FEATURE_INIT_COREDUMPS
{
struct stat sb;
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
#endif
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execve(cmdpath, cmd, environment);
execve(cmdpath, cmd, environment);
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
strerror(errno));
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
strerror(errno));
exit(-1);
}
return pid;
@@ -603,12 +618,12 @@ static void check_memory()
}
/* Run all commands to be run right before halt/reboot */
static void run_lastAction(void)
static void run_actions(initActionEnum action)
{
initAction *a, *tmp;
for (a = initActionList; a; a = tmp) {
tmp = a->nextPtr;
if (a->action == CTRLALTDEL) {
if (a->action == action) {
waitfor(a->process, a->console, FALSE);
delete_initAction(a);
}
@@ -640,7 +655,7 @@ static void shutdown_system(void)
sleep(1);
/* run everything to be run at "ctrlaltdel" */
run_lastAction();
run_actions(SHUTDOWN);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -682,6 +697,11 @@ static void reboot_signal(int sig)
exit(0);
}
static void ctrlaltdel_signal(int sig)
{
run_actions(CTRLALTDEL);
}
#endif /* ! DEBUG_INIT */
static void new_initAction(initActionEnum action, char *process, char *cons)
@@ -753,10 +773,12 @@ static void parse_inittab(void)
if (file == NULL) {
/* No inittab file -- set up some default behavior */
#endif
/* Reboot on Ctrl-Alt-Del */
new_initAction(CTRLALTDEL, "/sbin/reboot", console);
/* Swapoff on halt/reboot */
new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console);
new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
/* Umount all filesystems on halt/reboot */
new_initAction(CTRLALTDEL, "/bin/umount -a -r", console);
new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
/* Askfirst shell on tty1 */
new_initAction(ASKFIRST, SHELL, console);
/* Askfirst shell on tty2 */
@@ -869,7 +891,7 @@ extern int init_main(int argc, char **argv)
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, halt_signal);
signal(SIGINT, reboot_signal);
signal(SIGINT, ctrlaltdel_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
@@ -937,11 +959,8 @@ extern int init_main(int argc, char **argv)
parse_inittab();
}
/* Fix up argv[0] to be certain we claim to be init */
argv[0]="init";
if (argc > 1)
argv[1][0]=0;
/* Make the command line just say "init" -- thats all, nothing else */
fixup_argv(argc, argv, "init");
/* Now run everything that needs to be run */
+2 -2
View File
@@ -28,9 +28,9 @@ extern int reboot_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
return(kill(*(find_pid_by_name("init")), SIGINT));
return(kill(*(find_pid_by_name("init")), SIGTERM));
#else
return(kill(1, SIGINT));
return(kill(1, SIGTERM));
#endif
}
+32 -52
View File
@@ -60,10 +60,14 @@
#include <string.h>
#include <getopt.h>
#include <sys/utsname.h>
#include <sys/syscall.h>
#include <linux/unistd.h>
#include "busybox.h"
#ifdef BB_FEATURE_NEW_MODULE_INTERFACE
# define new_sys_init_module init_module
#else
# define old_sys_init_module init_module
#endif
#if defined(__powerpc__)
#define BB_USE_PLT_ENTRIES
#define BB_PLT_ENTRY_SIZE 16
@@ -119,7 +123,7 @@
#ifndef MODUTILS_MODULE_H
static const int MODUTILS_MODULE_H = 1;
#ident "$Id: insmod.c,v 1.51 2001/03/12 23:08:34 markw Exp $"
#ident "$Id: insmod.c,v 1.57 2001/04/05 07:33:10 andersen Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish
@@ -325,7 +329,7 @@ int delete_module(const char *);
#ifndef MODUTILS_OBJ_H
static const int MODUTILS_OBJ_H = 1;
#ident "$Id: insmod.c,v 1.51 2001/03/12 23:08:34 markw Exp $"
#ident "$Id: insmod.c,v 1.57 2001/04/05 07:33:10 andersen Exp $"
/* The relocatable object is manipulated using elfin types. */
@@ -373,6 +377,15 @@ static const int MODUTILS_OBJ_H = 1;
#elif defined(__mips__)
/* Account for ELF spec changes. */
#ifndef EM_MIPS_RS3_LE
#ifdef EM_MIPS_RS4_BE
#define EM_MIPS_RS3_LE EM_MIPS_RS4_BE
#else
#define EM_MIPS_RS3_LE 10
#endif
#endif /* !EM_MIPS_RS3_LE */
#define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE)
#define SHT_RELM SHT_REL
#define Elf32_RelM Elf32_Rel
@@ -665,20 +678,8 @@ int n_ext_modules;
int n_ext_modules_used;
/* Some firendly syscalls to cheer everyone's day... */
#define __NR_new_sys_init_module __NR_init_module
_syscall2(int, new_sys_init_module, const char *, name,
const struct new_module *, info)
#define __NR_old_sys_init_module __NR_init_module
_syscall5(int, old_sys_init_module, const char *, name, char *, code,
unsigned, codesize, struct old_mod_routines *, routines,
struct old_symbol_table *, symtab)
#ifndef BB_RMMOD
_syscall1(int, delete_module, const char *, name)
#else
extern int delete_module(const char *);
#endif
/* This is kind of troublesome. See, we don't actually support
the m68k or the arm the same way we support i386 and (now)
@@ -691,31 +692,8 @@ extern int delete_module(const char *);
-- Bryan Rittmeyer <bryan@ixiacom.com> */
#ifdef BB_FEATURE_OLD_MODULE_INTERFACE
_syscall1(int, get_kernel_syms, struct old_kernel_sym *, ks)
#endif
#if defined(__i386__) || defined(__m68k__) || defined(__arm__) \
|| defined(__powerpc__)
/* Jump through hoops to fixup error return codes */
#define __NR__create_module __NR_create_module
static inline _syscall2(long, _create_module, const char *, name, size_t,
size)
unsigned long create_module(const char *name, size_t size)
{
long ret = _create_module(name, size);
if (ret == -1 && errno > 125) {
ret = -errno;
errno = 0;
}
return ret;
}
#else
_syscall2(unsigned long, create_module, const char *, name, size_t, size)
#endif
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
static char m_filename[BUFSIZ + 1];
static char m_fullName[BUFSIZ + 1];
/*======================================================================*/
@@ -793,7 +771,9 @@ arch_apply_relocation(struct obj_file *f,
ElfW(RelM) *rel, ElfW(Addr) v)
{
struct arch_file *ifile = (struct arch_file *) f;
#if !(defined(__mips__))
struct arch_symbol *isym = (struct arch_symbol *) sym;
#endif
ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset);
ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset;
@@ -1199,18 +1179,18 @@ int arch_create_got(struct obj_file *f)
#if defined(BB_USE_GOT_ENTRIES)
if (got_offset) {
struct obj_section* relsec = obj_find_section(f, ".got");
struct obj_section* myrelsec = obj_find_section(f, ".got");
if (relsec) {
obj_extend_section(relsec, got_offset);
if (myrelsec) {
obj_extend_section(myrelsec, got_offset);
} else {
relsec = obj_create_alloced_section(f, ".got",
myrelsec = obj_create_alloced_section(f, ".got",
BB_GOT_ENTRY_SIZE,
got_offset);
assert(relsec);
assert(myrelsec);
}
ifile->got = relsec;
ifile->got = myrelsec;
}
#endif
@@ -1737,19 +1717,19 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
while (*q++ == ',');
} else {
char *contents = f->sections[sym->secidx]->contents;
char *loc = contents + sym->value;
char *myloc = contents + sym->value;
char *r; /* To search for commas */
/* Break the string with comas */
while ((r = strchr(q, ',')) != (char *) NULL) {
*r++ = '\0';
obj_string_patch(f, sym->secidx, loc - contents, q);
loc += sizeof(char *);
obj_string_patch(f, sym->secidx, myloc - contents, q);
myloc += sizeof(char *);
q = r;
}
/* last part */
obj_string_patch(f, sym->secidx, loc - contents, q);
obj_string_patch(f, sym->secidx, myloc - contents, q);
}
argc--, argv++;
+2 -2
View File
@@ -3,7 +3,7 @@
* that either displays or sets the characteristics of
* one or more of the system's networking interfaces.
*
* Version: $Id: interface.c,v 1.5 2001/03/15 15:37:48 mjn3 Exp $
* Version: $Id: interface.c,v 1.6 2001/04/09 23:52:18 andersen Exp $
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation
@@ -115,7 +115,7 @@ struct in6_ifreq {
#endif /* HAVE_AFINET6 */
#if HAVE_AFIPX
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
#include <netipx/ipx.h>
#else
#include "ipx.h"
+9 -28
View File
@@ -40,20 +40,14 @@
#include <ctype.h>
#include <sys/syslog.h>
#if ! defined __GLIBC__ && ! defined __UCLIBC__
#include <sys/syscall.h>
#include <linux/unistd.h>
#ifndef __alpha__
# define __NR_klogctl __NR_syslog
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
#else /* __alpha__ */
#define klogctl syslog
#endif
#if __GNU_LIBRARY__ < 5
# ifdef __alpha__
# define klogctl syslog
# endif
#else
# include <sys/klog.h>
#endif
#include "busybox.h"
static void klogd_signal(int sig)
@@ -124,18 +118,10 @@ static void doKlogd (void)
}
}
static void daemon_init (char **argv, char *dz, void fn (void))
{
setsid(); /* start a new session? */
strncpy(argv[0], dz, strlen(argv[0]));
fn();
exit(0);
}
extern int klogd_main(int argc, char **argv)
{
/* no options, no getopt */
int opt, pid;
int opt;
int doFork = TRUE;
/* do normal option parsing */
@@ -150,15 +136,10 @@ extern int klogd_main(int argc, char **argv)
}
if (doFork == TRUE) {
pid = fork();
if (pid < 0)
exit(pid);
else if (pid == 0) {
daemon_init (argv, "klogd", doKlogd);
}
} else {
doKlogd();
if (daemon(0, 1) < 0)
perror_msg_and_die("daemon");
}
doKlogd();
return EXIT_SUCCESS;
}
+73 -90
View File
@@ -65,9 +65,13 @@
#include <unistd.h>
#include <getopt.h>
#undef BB_FEATURE_SH_WORDEXP
#ifdef BB_LOCALE_SUPPORT
#include <locale.h>
#endif
#if BB_FEATURE_SH_WORDEXP
//#define BB_FEATURE_SH_WORDEXP
#ifdef BB_FEATURE_SH_WORDEXP
#include <wordexp.h>
#define expand_t wordexp_t
#undef BB_FEATURE_SH_BACKTICKS
@@ -79,7 +83,6 @@
#include "cmdedit.h"
static const int MAX_LINE = 256; /* size of input buffer for cwd data */
static const int MAX_READ = 128; /* size of input buffer for `read' builtin */
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
@@ -142,7 +145,6 @@ struct close_me {
/* function prototypes for builtins */
static int builtin_cd(struct child_prog *cmd);
static int builtin_env(struct child_prog *dummy);
static int builtin_exec(struct child_prog *cmd);
static int builtin_exit(struct child_prog *cmd);
static int builtin_fg_bg(struct child_prog *cmd);
@@ -202,7 +204,6 @@ static struct built_in_command bltins[] = {
/* Table of forking built-in functions (things that fork cannot change global
* variables in the parent process, such as the current working directory) */
static struct built_in_command bltins_forking[] = {
{"env", "Print all environment variables", builtin_env},
{"pwd", "Print current directory", builtin_pwd},
{"help", "List shell built-in commands", builtin_help},
{NULL, NULL, NULL}
@@ -231,7 +232,7 @@ static char syntax_err[]="syntax error near unexpected token";
#endif
static char *PS1;
static char *PS2;
static char *PS2 = "> ";
#ifdef DEBUG_SHELL
@@ -255,14 +256,13 @@ static inline void debug_printf(const char *format, ...) { }
builtin previous use notes
------ ----------------- ---------
cd cmd->progs[0]
env 0
exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins
exit cmd->progs[0]
fg_bg cmd->progs[0], job_list->head, job_list->fg
help 0
jobs job_list->head
pwd 0
export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them
export cmd->progs[0]
source cmd->progs[0]
unset cmd->progs[0]
read cmd->progs[0]
@@ -296,22 +296,11 @@ static int builtin_cd(struct child_prog *child)
printf("cd: %s: %m\n", newdir);
return EXIT_FAILURE;
}
getcwd(cwd, sizeof(char)*MAX_LINE);
cwd = xgetcwd(cwd);
return EXIT_SUCCESS;
}
/* built-in 'env' handler */
static int builtin_env(struct child_prog *dummy)
{
char **e;
for (e = environ; *e; e++) {
printf( "%s\n", *e);
}
return (0);
}
/* built-in 'exec' handler */
static int builtin_exec(struct child_prog *child)
{
@@ -423,7 +412,6 @@ static int builtin_jobs(struct child_prog *child)
/* built-in 'pwd' handler */
static int builtin_pwd(struct child_prog *dummy)
{
getcwd(cwd, MAX_LINE);
printf( "%s\n", cwd);
return EXIT_SUCCESS;
}
@@ -435,7 +423,11 @@ static int builtin_export(struct child_prog *child)
char *v = child->argv[1];
if (v == NULL) {
return (builtin_env(child));
char **e;
for (e = environ; *e; e++) {
printf( "%s\n", *e);
}
return 0;
}
res = putenv(v);
if (res)
@@ -443,9 +435,15 @@ static int builtin_export(struct child_prog *child)
#ifndef BB_FEATURE_SH_SIMPLE_PROMPT
if (strncmp(v, "PS1=", 4)==0)
PS1 = getenv("PS1");
else if (strncmp(v, "PS2=", 4)==0)
PS2 = getenv("PS2");
#endif
#ifdef BB_LOCALE_SUPPORT
if(strncmp(v, "LC_ALL=", 7)==0)
setlocale(LC_ALL, getenv("LC_ALL"));
if(strncmp(v, "LC_CTYPE=", 9)==0)
setlocale(LC_CTYPE, getenv("LC_CTYPE"));
#endif
return (res);
}
@@ -627,10 +625,7 @@ static int builtin_unset(struct child_prog *child)
*/
static int run_command_predicate(char *cmd)
{
int n=strlen(cmd);
local_pending_command = xmalloc(n+1);
strncpy(local_pending_command, cmd, n);
local_pending_command[n]='\0';
local_pending_command = xstrdup(cmd);
return( busy_loop(NULL));
}
#endif
@@ -687,16 +682,16 @@ static void free_job(struct job *cmd)
cmd->job_list = keep;
}
/* remove a job from the job_list */
static void remove_job(struct jobset *job_list, struct job *job)
/* remove a job from a jobset */
static void remove_job(struct jobset *j_list, struct job *job)
{
struct job *prevjob;
free_job(job);
if (job == job_list->head) {
job_list->head = job->next;
if (job == j_list->head) {
j_list->head = job->next;
} else {
prevjob = job_list->head;
prevjob = j_list->head;
while (prevjob->next != job)
prevjob = prevjob->next;
prevjob->next = job->next;
@@ -707,7 +702,7 @@ static void remove_job(struct jobset *job_list, struct job *job)
/* Checks to see if any background processes have exited -- if they
have, figure out why and see if a job has completed */
static void checkjobs(struct jobset *job_list)
static void checkjobs(struct jobset *j_list)
{
struct job *job;
pid_t childpid;
@@ -715,7 +710,7 @@ static void checkjobs(struct jobset *job_list)
int prognum = 0;
while ((childpid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
for (job = job_list->head; job; job = job->next) {
for (job = j_list->head; job; job = job->next) {
prognum = 0;
while (prognum < job->num_progs &&
job->progs[prognum].pid != childpid) prognum++;
@@ -734,7 +729,7 @@ static void checkjobs(struct jobset *job_list)
if (!job->running_progs) {
printf(JOB_STATUS_FORMAT, job->jobid, "Done", job->text);
remove_job(job_list, job);
remove_job(j_list, job);
}
} else {
/* child stopped */
@@ -812,15 +807,10 @@ static inline void cmdedit_set_initial_prompt(void)
{
#ifdef BB_FEATURE_SH_SIMPLE_PROMPT
PS1 = NULL;
PS2 = "> ";
#else
PS1 = getenv("PS1");
if(PS1==0) {
if(PS1==0)
PS1 = "\\w \\$ ";
}
PS2 = getenv("PS2");
if(PS2==0)
PS2 = "> ";
#endif
}
@@ -881,9 +871,6 @@ static int get_command(FILE * source, char *command)
return 1;
}
/* remove trailing newline */
chomp(command);
return 0;
}
@@ -910,35 +897,35 @@ static char* itoa(register int i)
#endif
#if defined BB_FEATURE_SH_ENVIRONMENT && ! defined BB_FEATURE_SH_WORDEXP
char * strsep_space( char *string, int * index)
char * strsep_space( char *string, int * ix)
{
char *token, *begin;
begin = string;
/* Short circuit the trivial case */
if ( !string || ! string[*index])
if ( !string || ! string[*ix])
return NULL;
/* Find the end of the token. */
while( string && string[*index] && !isspace(string[*index]) ) {
(*index)++;
while( string && string[*ix] && !isspace(string[*ix]) ) {
(*ix)++;
}
/* Find the end of any whitespace trailing behind
* the token and let that be part of the token */
while( string && string[*index] && isspace(string[*index]) ) {
(*index)++;
while( string && string[*ix] && isspace(string[*ix]) ) {
(*ix)++;
}
if (! string && *index==0) {
if (! string && *ix==0) {
/* Nothing useful was found */
return NULL;
}
token = xmalloc(*index+1);
token[*index] = '\0';
strncpy(token, string, *index);
token = xmalloc(*ix+1);
token[*ix] = '\0';
strncpy(token, string, *ix);
return token;
}
@@ -950,7 +937,7 @@ static int expand_arguments(char *command)
#ifdef BB_FEATURE_SH_ENVIRONMENT
expand_t expand_result;
char *src, *dst, *var;
int index = 0;
int ix = 0;
int i=0, length, total_length=0, retval;
const char *out_of_space = "out of space during expansion";
#endif
@@ -959,19 +946,19 @@ static int expand_arguments(char *command)
chomp(command);
/* Fix up escape sequences to be the Real Thing(tm) */
while( command && command[index]) {
if (command[index] == '\\') {
char *tmp = command+index+1;
command[index+1] = process_escape_sequence( &tmp );
memmove(command+index, command+index+1, strlen(command+index));
while( command && command[ix]) {
if (command[ix] == '\\') {
const char *tmp = command+ix+1;
command[ix] = process_escape_sequence( &tmp );
memmove(command+ix + 1, tmp, strlen(tmp)+1);
}
index++;
ix++;
}
#ifdef BB_FEATURE_SH_ENVIRONMENT
#if BB_FEATURE_SH_WORDEXP
#ifdef BB_FEATURE_SH_WORDEXP
/* This first part uses wordexp() which is a wonderful C lib
* function which expands nearly everything. */
retval = wordexp (command, &expand_result, WRDE_SHOWERR);
@@ -1028,8 +1015,8 @@ static int expand_arguments(char *command)
* we write stuff into the original (in a minute) */
cmd = cmd_copy = strdup(command);
*command = '\0';
for (index = 0, tmpcmd = cmd;
(tmpcmd = strsep_space(cmd, &index)) != NULL; cmd += index, index=0) {
for (ix = 0, tmpcmd = cmd;
(tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) {
if (*tmpcmd == '\0')
break;
retval = glob(tmpcmd, flags, NULL, &expand_result);
@@ -1099,11 +1086,11 @@ static int expand_arguments(char *command)
case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
{
int index=*(dst + 1)-48;
if (index >= argc) {
int ixx=*(dst + 1)-48;
if (ixx >= argc) {
var='\0';
} else {
var = argv[index];
var = argv[ixx];
}
}
break;
@@ -1116,25 +1103,24 @@ static int expand_arguments(char *command)
} else {
/* Looks like an environment variable */
char delim_hold;
int num_skip_chars=1;
int num_skip_chars=0;
int dstlen = strlen(dst);
/* Is this a ${foo} type variable? */
if (dstlen >=2 && *(dst+1) == '{') {
src=strchr(dst+1, '}');
num_skip_chars=2;
num_skip_chars=1;
} else {
src=strpbrk(dst+1, " \t~`!$^&*()=|\\[];\"'<>?./");
src=dst+1;
while(isalnum(*src) || *src=='_') src++;
}
if (src == NULL) {
src = dst+dstlen;
}
delim_hold=*src;
*src='\0'; /* temporary */
var = getenv(dst + num_skip_chars);
var = getenv(dst + 1 + num_skip_chars);
*src=delim_hold;
if (num_skip_chars==2) {
src++;
}
src += num_skip_chars;
}
if (var == NULL) {
/* Seems we got an un-expandable variable. So delete it. */
@@ -1149,8 +1135,7 @@ static int expand_arguments(char *command)
}
/* Move stuff to the end of the string to accommodate
* filling the created gap with the new stuff */
memmove(dst+subst_len, src, trail_len);
*(dst+subst_len+trail_len)='\0';
memmove(dst+subst_len, src, trail_len+1);
/* Now copy in the new stuff */
memcpy(dst, var, subst_len);
src = dst+subst_len;
@@ -1475,7 +1460,6 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
break;
#else
error_msg("character expected after \\");
free(command);
free_job(job);
return 1;
#endif
@@ -1566,9 +1550,9 @@ static int pseudo_exec(struct child_prog *child)
#endif
{
char** argv=child->argv;
char** argv_l=child->argv;
int argc_l;
for(argc_l=0;*argv!=NULL; argv++, argc_l++);
for(argc_l=0;*argv_l!=NULL; argv_l++, argc_l++);
optind = 1;
run_applet_by_name(name, argc_l, child->argv);
}
@@ -1581,19 +1565,19 @@ static int pseudo_exec(struct child_prog *child)
static void insert_job(struct job *newjob, int inbg)
{
struct job *thejob;
struct jobset *job_list=newjob->job_list;
struct jobset *j_list=newjob->job_list;
/* find the ID for thejob to use */
newjob->jobid = 1;
for (thejob = job_list->head; thejob; thejob = thejob->next)
for (thejob = j_list->head; thejob; thejob = thejob->next)
if (thejob->jobid >= newjob->jobid)
newjob->jobid = thejob->jobid + 1;
/* add thejob to the list of running jobs */
if (!job_list->head) {
thejob = job_list->head = xmalloc(sizeof(*thejob));
if (!j_list->head) {
thejob = j_list->head = xmalloc(sizeof(*thejob));
} else {
for (thejob = job_list->head; thejob->next; thejob = thejob->next) /* nothing */;
for (thejob = j_list->head; thejob->next; thejob = thejob->next) /* nothing */;
thejob->next = xmalloc(sizeof(*thejob));
thejob = thejob->next;
}
@@ -1839,8 +1823,10 @@ static int busy_loop(FILE * input)
#ifdef BB_FEATURE_CLEAN_UP
void free_memory(void)
{
if (cwd)
if (cwd) {
free(cwd);
cwd = NULL;
}
if (local_pending_command)
free(local_pending_command);
@@ -1860,7 +1846,6 @@ int shell_main(int argc_l, char **argv_l)
/* These variables need re-initializing when recursing */
shell_context = 0;
cwd=NULL;
local_pending_command = NULL;
close_me_head = NULL;
job_list.head = NULL;
@@ -1931,8 +1916,7 @@ int shell_main(int argc_l, char **argv_l)
}
/* initialize the cwd -- this is never freed...*/
cwd=(char*)xmalloc(sizeof(char)*MAX_LINE+1);
getcwd(cwd, sizeof(char)*MAX_LINE);
cwd = xgetcwd(0);
#ifdef BB_FEATURE_CLEAN_UP
atexit(free_memory);
@@ -1942,7 +1926,6 @@ int shell_main(int argc_l, char **argv_l)
cmdedit_set_initial_prompt();
#else
PS1 = NULL;
PS2 = "> ";
#endif
return (busy_loop(input));
+1
View File
@@ -0,0 +1 @@
loop.h
+11
View File
@@ -0,0 +1,11 @@
# Silly wrapper makefile. This Makefile is _not_ used by the build system for
# busybox, it is just to make working on libbb more conveinient.
# -Erik Andersen
all:
make -C .. libbb.a
clean:
- rm -rf libbb.a
- find -name \*.o -exec rm -f {} \;
+15
View File
@@ -0,0 +1,15 @@
Please see the LICENSE file for copyright information.
libbb is BusyBox's utility library. This all used to be in a single file
(utility.c to be specific). When I split utility.c up to create libbb, I did
not carefully fix up the copyright and licensing information. I'll do that for
the next release.
For now, justtrust me that a bunch of people have worked on this stuff,
and it is all GPL'ed.
Erik Andersen
<andersen@lineo.com>
<andersee@debian.org>
<andersee@codepoet.org>
+53
View File
@@ -0,0 +1,53 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include "libbb.h"
int ask_confirmation()
{
int c = '\0';
int ret = 0;
while (c != '\n') {
c = getchar();
if ( c != '\n' ) {
ret = ((c=='y')||(c=='Y')) ? 1 : 0;
}
}
return ret;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+141
View File
@@ -0,0 +1,141 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <string.h>
#include "libbb.h"
/*
* Routine to see if a text string is matched by a wildcard pattern.
* Returns TRUE if the text is matched, or FALSE if it is not matched
* or if the pattern is invalid.
* * matches zero or more characters
* ? matches a single character
* [abc] matches 'a', 'b' or 'c'
* \c quotes character c
* Adapted from code written by Ingo Wilken, and
* then taken from sash, Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Permission to distribute this code under the GPL has been granted.
*/
extern int check_wildcard_match(const char *text, const char *pattern)
{
const char *retryPat;
const char *retryText;
int ch;
int found;
int len;
retryPat = NULL;
retryText = NULL;
while (*text || *pattern) {
ch = *pattern++;
switch (ch) {
case '*':
retryPat = pattern;
retryText = text;
break;
case '[':
found = FALSE;
while ((ch = *pattern++) != ']') {
if (ch == '\\')
ch = *pattern++;
if (ch == '\0')
return FALSE;
if (*text == ch)
found = TRUE;
}
len=strlen(text);
if (found == FALSE && len!=0) {
return FALSE;
}
if (found == TRUE) {
if (strlen(pattern)==0 && len==1) {
return TRUE;
}
if (len!=0) {
text++;
continue;
}
}
/* fall into next case */
case '?':
if (*text++ == '\0')
return FALSE;
break;
case '\\':
ch = *pattern++;
if (ch == '\0')
return FALSE;
/* fall into next case */
default:
if (*text == ch) {
if (*text)
text++;
break;
}
if (*text) {
pattern = retryPat;
text = ++retryText;
break;
}
return FALSE;
}
if (pattern == NULL)
return FALSE;
}
return TRUE;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+52
View File
@@ -0,0 +1,52 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <string.h>
#include "libbb.h"
void chomp(char *s)
{
size_t len = strlen(s);
if (len == 0)
return;
if (s[len-1] == '\n')
s[len-1] = '\0';
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+24
View File
@@ -0,0 +1,24 @@
/*
* busybox library eXtendet funcion
*
* concatenate path and file name to new allocation buffer,
* not addition '/' if path name already have '/'
*
*/
#include "libbb.h"
extern char *concat_path_file(const char *path, const char *filename)
{
char *outbuf;
int l;
int flg_slash = 1;
l = strlen(path);
if(l>0 && path[l-1] == '/')
flg_slash--;
l += strlen(filename);
outbuf = xmalloc(l+1+flg_slash);
sprintf(outbuf, (flg_slash ? "%s/%s" : "%s%s"), path, filename);
return outbuf;
}
+180
View File
@@ -0,0 +1,180 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <errno.h>
#include <utime.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "libbb.h"
/*
* Copy one file to another, while possibly preserving its modes, times, and
* modes. Returns TRUE if successful, or FALSE on a failure with an error
* message output. (Failure is not indicated if attributes cannot be set.)
* -Erik Andersen
*/
int
copy_file(const char *srcName, const char *destName,
int setModes, int followLinks, int forceFlag)
{
int rfd;
int wfd;
int status;
struct stat srcStatBuf;
struct stat dstStatBuf;
struct utimbuf times;
if (followLinks == TRUE)
status = stat(srcName, &srcStatBuf);
else
status = lstat(srcName, &srcStatBuf);
if (status < 0) {
perror_msg("%s", srcName);
return FALSE;
}
if (followLinks == TRUE)
status = stat(destName, &dstStatBuf);
else
status = lstat(destName, &dstStatBuf);
if (status < 0 || forceFlag==TRUE) {
unlink(destName);
dstStatBuf.st_ino = -1;
dstStatBuf.st_dev = -1;
}
if ((srcStatBuf.st_dev == dstStatBuf.st_dev) &&
(srcStatBuf.st_ino == dstStatBuf.st_ino)) {
error_msg("Copying file \"%s\" to itself", srcName);
return FALSE;
}
if (S_ISDIR(srcStatBuf.st_mode)) {
//fprintf(stderr, "copying directory %s to %s\n", srcName, destName);
/* Make sure the directory is writable */
status = mkdir(destName, 0777777 ^ umask(0));
if (status < 0 && errno != EEXIST) {
perror_msg("%s", destName);
return FALSE;
}
} else if (S_ISLNK(srcStatBuf.st_mode)) {
char link_val[BUFSIZ + 1];
int link_size;
//fprintf(stderr, "copying link %s to %s\n", srcName, destName);
/* Warning: This could possibly truncate silently, to BUFSIZ chars */
link_size = readlink(srcName, &link_val[0], BUFSIZ);
if (link_size < 0) {
perror_msg("%s", srcName);
return FALSE;
}
link_val[link_size] = '\0';
status = symlink(link_val, destName);
if (status < 0) {
perror_msg("%s", destName);
return FALSE;
}
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
if (setModes == TRUE) {
/* Try to set owner, but fail silently like GNU cp */
lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
}
#endif
return TRUE;
} else if (S_ISFIFO(srcStatBuf.st_mode)) {
//fprintf(stderr, "copying fifo %s to %s\n", srcName, destName);
if (mkfifo(destName, 0644) < 0) {
perror_msg("%s", destName);
return FALSE;
}
} else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode)
|| S_ISSOCK(srcStatBuf.st_mode)) {
//fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName);
if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) {
perror_msg("%s", destName);
return FALSE;
}
} else if (S_ISREG(srcStatBuf.st_mode)) {
//fprintf(stderr, "copying regular file %s to %s\n", srcName, destName);
rfd = open(srcName, O_RDONLY);
if (rfd < 0) {
perror_msg("%s", srcName);
return FALSE;
}
wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC,
srcStatBuf.st_mode);
if (wfd < 0) {
perror_msg("%s", destName);
close(rfd);
return FALSE;
}
if (copy_file_chunk(rfd, wfd, srcStatBuf.st_size)==FALSE)
goto error_exit;
close(rfd);
if (close(wfd) < 0) {
return FALSE;
}
}
if (setModes == TRUE) {
/* This is fine, since symlinks never get here */
if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0)
perror_msg_and_die("%s", destName);
if (chmod(destName, srcStatBuf.st_mode) < 0)
perror_msg_and_die("%s", destName);
times.actime = srcStatBuf.st_atime;
times.modtime = srcStatBuf.st_mtime;
if (utime(destName, &times) < 0)
perror_msg_and_die("%s", destName);
}
return TRUE;
error_exit:
perror_msg("%s", destName);
close(rfd);
close(wfd);
return FALSE;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+60
View File
@@ -0,0 +1,60 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <sys/stat.h>
#include "libbb.h"
/*
* Copy chunksize bytes between two file descriptors
*/
int copy_file_chunk(int srcfd, int dstfd, off_t chunksize)
{
off_t size;
char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */
while (chunksize > 0) {
if (chunksize > BUFSIZ)
size = BUFSIZ;
else
size = chunksize;
if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) < size)
return(FALSE);
chunksize -= size;
}
return (TRUE);
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+71
View File
@@ -0,0 +1,71 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "libbb.h"
/*
* Attempt to create the directories along the specified path, except for
* the final component. The mode is given for the final directory only,
* while all previous ones get default protections. Errors are not reported
* here, as failures to restore files can be reported later.
*/
extern int create_path(const char *name, int mode)
{
char *cp;
char *cpOld;
char buf[BUFSIZ + 1];
int retVal = 0;
strcpy(buf, name);
for (cp = buf; *cp == '/'; cp++);
cp = strchr(cp, '/');
while (cp) {
cpOld = cp;
cp = strchr(cp + 1, '/');
*cpOld = '\0';
retVal = mkdir(buf, cp ? 0777 : mode);
if (retVal != 0 && errno != EEXIST) {
perror_msg("%s", buf);
return FALSE;
}
*cpOld = '/';
}
return TRUE;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+101
View File
@@ -0,0 +1,101 @@
/* vi: set sw=4 ts=4: */
/*
* daemon implementation for uClibc
*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Modified for uClibc by Erik Andersen
* <andersee@debian.org>, <andersen@lineo.com>
*
* The uClibc Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The GNU C Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the GNU C Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Original copyright notice is retained at the end of this file.
*/
#include <features.h>
#include <fcntl.h>
#include <paths.h>
#include <unistd.h>
#if __GNU_LIBRARY__ < 5
int daemon( int nochdir, int noclose )
{
int fd;
switch (fork()) {
case -1:
return(-1);
case 0:
break;
default:
_exit(0);
}
if (setsid() == -1)
return(-1);
if (!nochdir)
chdir("/");
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > 2)
close(fd);
}
return(0);
}
#endif
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
*
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+59
View File
@@ -0,0 +1,59 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <fcntl.h>
#include "libbb.h"
/* try to open up the specified device */
extern int device_open(char *device, int mode)
{
int m, f, fd = -1;
m = mode | O_NONBLOCK;
/* Retry up to 5 times */
for (f = 0; f < 5; f++)
if ((fd = open(device, m, 0600)) >= 0)
break;
if (fd < 0)
return fd;
/* Reset original flags. */
if (m != mode)
fcntl(fd, F_SETFL, mode);
return fd;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+52
View File
@@ -0,0 +1,52 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "libbb.h"
extern void error_msg(const char *s, ...)
{
va_list p;
va_start(p, s);
verror_msg(s, p);
va_end(p);
putc('\n', stderr);
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+53
View File
@@ -0,0 +1,53 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "libbb.h"
extern void error_msg_and_die(const char *s, ...)
{
va_list p;
va_start(p, s);
verror_msg(s, p);
va_end(p);
putc('\n', stderr);
exit(EXIT_FAILURE);
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+81
View File
@@ -0,0 +1,81 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <string.h>
#include "libbb.h"
#include <mntent.h>
/*
* Given a block device, find the mount table entry if that block device
* is mounted.
*
* Given any other file (or directory), find the mount table entry for its
* filesystem.
*/
extern struct mntent *find_mount_point(const char *name, const char *table)
{
struct stat s;
dev_t mountDevice;
FILE *mountTable;
struct mntent *mountEntry;
if (stat(name, &s) != 0)
return 0;
if ((s.st_mode & S_IFMT) == S_IFBLK)
mountDevice = s.st_rdev;
else
mountDevice = s.st_dev;
if ((mountTable = setmntent(table, "r")) == 0)
return 0;
while ((mountEntry = getmntent(mountTable)) != 0) {
if (strcmp(name, mountEntry->mnt_dir) == 0
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
break;
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
break;
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
break;
}
endmntent(mountTable);
return mountEntry;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+175
View File
@@ -0,0 +1,175 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
#include "libbb.h"
#define READ_BUF_SIZE 50
/* For Erik's nifty devps device driver */
#ifdef BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devps.h>
/* find_pid_by_name()
*
* This finds the pid of the specified process,
* by using the /dev/ps device driver.
*
* Returns a list of all matching PIDs
*/
extern pid_t* find_pid_by_name( char* pidName)
{
int fd, i, j;
char device[] = "/dev/ps";
pid_t num_pids;
pid_t* pid_array = NULL;
pid_t* pidList=NULL;
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
perror_msg_and_die("open failed for `%s'", device);
/* Find out how many processes there are */
if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
perror_msg_and_die("\nDEVPS_GET_PID_LIST");
/* Allocate some memory -- grab a few extras just in case
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
perror_msg_and_die("\nDEVPS_GET_PID_LIST");
/* Now search for a match */
for (i=1, j=0; i<pid_array[0] ; i++) {
char* p;
struct pid_info info;
info.pid = pid_array[i];
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
perror_msg_and_die("\nDEVPS_GET_PID_INFO");
/* Make sure we only match on the process name */
p=info.command_line+1;
while ((*p != 0) && !isspace(*(p)) && (*(p-1) != '\\')) {
(p)++;
}
if (isspace(*(p)))
*p='\0';
if ((strstr(info.command_line, pidName) != NULL)
&& (strlen(pidName) == strlen(info.command_line))) {
pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
pidList[j++]=info.pid;
}
}
if (pidList)
pidList[j]=0;
/* Free memory */
free( pid_array);
/* close device */
if (close (fd) != 0)
perror_msg_and_die("close failed for `%s'", device);
return pidList;
}
#else /* BB_FEATURE_USE_DEVPS_PATCH */
/* find_pid_by_name()
*
* This finds the pid of the specified process.
* Currently, it's implemented by rummaging through
* the proc filesystem.
*
* Returns a list of all matching PIDs
*/
extern pid_t* find_pid_by_name( char* pidName)
{
DIR *dir;
struct dirent *next;
pid_t* pidList=NULL;
int i=0;
dir = opendir("/proc");
if (!dir)
perror_msg_and_die("Cannot open /proc");
while ((next = readdir(dir)) != NULL) {
FILE *status;
char filename[READ_BUF_SIZE];
char buffer[READ_BUF_SIZE];
char name[READ_BUF_SIZE];
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
sprintf(filename, "/proc/%s/status", next->d_name);
if (! (status = fopen(filename, "r")) ) {
continue;
}
if (fgets(buffer, READ_BUF_SIZE-1, status) == NULL) {
fclose(status);
continue;
}
fclose(status);
/* Buffer should contain a string like "Name: binary_name" */
sscanf(buffer, "%*s %s", name);
if (strcmp(name, pidName) == 0) {
pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
if (pidList)
pidList[i]=0;
return pidList;
}
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+85
View File
@@ -0,0 +1,85 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include "libbb.h"
extern int find_real_root_device_name(char* name)
{
DIR *dir;
struct dirent *entry;
struct stat statBuf, rootStat;
char fileName[BUFSIZ];
if (stat("/", &rootStat) != 0) {
error_msg("could not stat '/'");
return( FALSE);
}
dir = opendir("/dev");
if (!dir) {
error_msg("could not open '/dev'");
return( FALSE);
}
while((entry = readdir(dir)) != NULL) {
/* Must skip ".." since that is "/", and so we
* would get a false positive on ".." */
if (strcmp(entry->d_name, "..") == 0)
continue;
snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name);
if (stat(fileName, &statBuf) != 0)
continue;
/* Some char devices have the same dev_t as block
* devices, so make sure this is a block device */
if (! S_ISBLK(statBuf.st_mode))
continue;
if (statBuf.st_rdev == rootStat.st_rdev) {
strcpy(name, fileName);
return ( TRUE);
}
}
return( FALSE);
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
Loaded 100 of 202 files, more files were not shown because too many files have changed in this diff. Show more