Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1101d23604 | ||
|
|
eef658068b | ||
|
|
2e397341d9 | ||
|
|
262dd039eb | ||
|
|
3fe7f9f20b | ||
|
|
a3e57ca700 | ||
|
|
f13df3752c | ||
|
|
9a8195cc03 | ||
|
|
b9167cb67f | ||
|
|
632bb57135 | ||
|
|
c366050a23 | ||
|
|
f29f797f54 | ||
|
|
0a64de9b4f | ||
|
|
229dd2b905 | ||
|
|
5d68857b9c | ||
|
|
a6c752201e | ||
|
|
91e581fa04 | ||
|
|
5a50def0f4 | ||
|
|
6e703034f4 | ||
|
|
26702fe191 | ||
|
|
e5b6c7dd9c | ||
|
|
4fd10fc73b | ||
|
|
200be97e36 | ||
|
|
5a728cfdfe | ||
|
|
3becdfc316 | ||
|
|
53642b066c | ||
|
|
9057b6a918 | ||
|
|
ab01ed12bd | ||
|
|
5e1189e187 | ||
|
|
95c1c1e05f | ||
|
|
d5ba77d03e | ||
|
|
50ed0676ad | ||
|
|
cbd6628c8c | ||
|
|
9cf3bfa7c1 | ||
|
|
b4f8606c05 | ||
|
|
08e7f75ba2 | ||
|
|
f17792ca9b | ||
|
|
61677feff7 | ||
|
|
62dc17a3b1 | ||
|
|
f0657d3229 | ||
|
|
a2685735b1 | ||
|
|
f3b3d17060 | ||
|
|
0817d1372c | ||
|
|
84e09e4437 | ||
|
|
ecd512453c | ||
|
|
5dd853ad2a | ||
|
|
6a34b539db | ||
|
|
825aead68b | ||
|
|
93d6513d93 | ||
|
|
7a4b719486 | ||
|
|
6bd3602988 | ||
|
|
c0dac18d6d | ||
|
|
e9fee653dc | ||
|
|
d4bc1fcad8 | ||
|
|
5661fe078e | ||
|
|
cbb0a4b40d | ||
|
|
b99ca13261 | ||
|
|
68a9ea4208 | ||
|
|
183da4ade1 | ||
|
|
983b51b17b | ||
|
|
3364d78b18 | ||
|
|
6acaa40f27 | ||
|
|
deea048bec | ||
|
|
1ad302ac90 | ||
|
|
e454fb68a3 | ||
|
|
298854f029 | ||
|
|
ec5bd90916 | ||
|
|
016ffe9307 | ||
|
|
0d068a2067 | ||
|
|
c053e41fa0 | ||
|
|
42094cdad5 | ||
|
|
1dbe340eba | ||
|
|
c7c634bd88 | ||
|
|
6c41c44898 | ||
|
|
531bcb6826 | ||
|
|
6273f655c8 | ||
|
|
161220c498 | ||
|
|
13456d1fcd | ||
|
|
d75af99529 | ||
|
|
a967e3c8f0 | ||
|
|
ce91732416 | ||
|
|
3522eb1ab3 | ||
|
|
269bba2514 | ||
|
|
47d3bb3b6d | ||
|
|
54969a1f64 | ||
|
|
692a4502b0 | ||
|
|
2ac2fae728 | ||
|
|
cbd0d625c7 | ||
|
|
06249f24f3 | ||
|
|
ea6b67de65 | ||
|
|
246cc6dddd | ||
|
|
e916d24805 | ||
|
|
9c5c29d442 | ||
|
|
65fc1c70f7 | ||
|
|
fb002d0df0 | ||
|
|
66be5e7e29 | ||
|
|
6437170cb3 | ||
|
|
029011b9ee | ||
|
|
7c4b2f3fe5 | ||
|
|
a51ecdd9e4 | ||
|
|
5b911ddd57 | ||
|
|
dc75a739ac | ||
|
|
f7c49ef2d1 | ||
|
|
3b9522f2af | ||
|
|
6e769df47d | ||
|
|
d07ee46919 | ||
|
|
fa4718efcf | ||
|
|
42387e4964 | ||
|
|
27fdd081ef | ||
|
|
e272915e1f | ||
|
|
bf5f009862 | ||
|
|
08c965a0a1 |
No files matched your search
@@ -1,8 +1,8 @@
|
||||
List of the authors of code contained in busybox.
|
||||
List of the authors of code contained in BusyBox.
|
||||
|
||||
If you should be listed here, or the description of
|
||||
what you have done needs more detail, or is incorect,
|
||||
_please_ let me know.
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
@@ -16,7 +16,7 @@ Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, tee
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
@@ -28,6 +28,9 @@ Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
@@ -37,4 +40,5 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
@@ -1,3 +1,77 @@
|
||||
0.43
|
||||
* Major update to the provided documentation.
|
||||
* Busybox now includes a shell! It currently costs 7.5 k (plus an
|
||||
additional 2.5 k if you compile in command line editing). Handles
|
||||
job control, has the usual set of builtins, and does everything
|
||||
except for handling programming statements (if, while, etc...)
|
||||
* Busybox can now work perfectly when /proc is disabled, thereby
|
||||
saving a bunch of memory (kernel /proc support is not thin). This
|
||||
is done by making use of some nice kernel patches I wrote up to
|
||||
support the features that busybox requires and that /proc usually
|
||||
provides. To enable this, turn on BB_FEATURE_USE_DEVPS_PATCH and
|
||||
patch your kernel with the devps patch in the kernel-patches/
|
||||
directory.
|
||||
* Wrote basename, dirname, killall, and uptime.
|
||||
* tar has been completely rewritten by me. Both tar creation and
|
||||
extraction are now well behaved. Costs 7.6k with all optional
|
||||
tar features enabled, and 5k for just tar extraction support.
|
||||
* Added freeramdisk, which will free up all memory associated
|
||||
with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
|
||||
and then adjusted a bit by me.
|
||||
* Added tr from John Lombardo <john@deltanet.com>
|
||||
* Added echo and test (from me).
|
||||
* Added usleep contributed by Nicolas Pitre <nico@cam.org>
|
||||
* BusyBox's bss size has been majorly reduced (was 384668, is now 28740).
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
- When `tail' fails to open a file it now exits.
|
||||
- When `syslogd' is given the `-n' option it should still use
|
||||
fork() for running klogd.
|
||||
* nslookup types are now changed to u_int32_t (instead of uint32_t)
|
||||
changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
|
||||
* Fixed "du" so it gives the same answers as GNU "du" (busybox du used
|
||||
to count hard-linked files more then once). Many thanks to
|
||||
Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
|
||||
* Removed /proc dependancies for init and free (while maintaining
|
||||
exactly the same functionality). /proc takes up 90k of kernel
|
||||
space, so it is nice to avoid using it at all costs.
|
||||
* init no longer tries to mount /proc (unless there is less the 1 meg
|
||||
free). Use of /proc (or not) is policy that should be set up in
|
||||
/etc/fstab (or in hardcoded scripts), not in init.
|
||||
* Fixed rebooting when init runs as an initrd.
|
||||
* Fixes and updates from Karl M. Hegbloom <karlheg@debian.org>
|
||||
- update.c rewritten to look more like update-2.11
|
||||
- moveed the inode hash out of du.c and into utility.c to make
|
||||
it a common resource that can be used by other apps.
|
||||
- cp_mv.c now checks inodes to see if a source and dest are
|
||||
the same, and prints an error (instead of endlessly looping).
|
||||
- mv now attempts to do a rename, and will fall back to doing
|
||||
a copy only if the rename fails.
|
||||
- Syslogd now supports multiple concurrent connections
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
- Fixes to sort. Removed "-g", fixed and added "-r"
|
||||
- Fixes to the makefile for handling "strip"
|
||||
* An initial telnet implementation was added by
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
|
||||
* ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
|
||||
to match the terminal (defaults to width=79 when this is off).
|
||||
* ps now accepts (and ignores) all options except for "--help" (which
|
||||
as would be expected displays help).
|
||||
* Fixed mount'ing loop devices when the filesystem type was not
|
||||
specified. It used to revert to non-loop after the first try.
|
||||
* all mallocs now use xmalloc (and so are OOM error safe), and
|
||||
the common error handling saves a few bytes. Thanks to
|
||||
Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
|
||||
* Fix "+" parsing bug in date, from "Merle F. McClelland" <mfm@cts.com>.
|
||||
* Fix symlink following bug in chmod -R and friends.
|
||||
* Now allows SYSV style 'chown foo:bar' in addition to 'chown foo.bar'
|
||||
* Fixed a bug in the busybox globbing routine such that 'find /dir -name [i]'
|
||||
no longer segfaults.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.42
|
||||
|
||||
* Fairly massive restructuring of umount.c to deal with remounting
|
||||
@@ -61,8 +135,8 @@
|
||||
* Fixed a bug where init could have reference already freed memory.
|
||||
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
|
||||
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Added (and documented) "-n" option for head - Cleanup for a number of
|
||||
* usage messages -- also
|
||||
* Added (and documented) "-n" option for head
|
||||
* Cleanup for a number of usage messages -- also
|
||||
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Cosmetic fix to busybox.c (Don't print a comma at the
|
||||
end of line if there are no more application names).
|
||||
@@ -73,7 +147,7 @@
|
||||
* Created a tiny tail implementation, removing -c, -q, -v, and making
|
||||
tail -f work only with a single file. This reduced tail from 6k to
|
||||
2.4k. The bigger/more featured tail can still be had by disabling
|
||||
BB_FEATURE_SIMPLE_TAIL in dusybox.defs.h
|
||||
BB_FEATURE_SIMPLE_TAIL in busybox.defs.h
|
||||
* Ping now falls back to doing the right thing if /etc/protocols
|
||||
turns up missing.
|
||||
* Fixed mount and umount. Previously they could leak loop device
|
||||
@@ -90,9 +164,9 @@
|
||||
- added "skip" and "seek" to dd.
|
||||
- ls no longer messus up output when combining files and
|
||||
directories on the command line
|
||||
* swapoff -a was not working. Now it is. init did not cleanly unmount
|
||||
* filesystems on reboot. Now it does. "sed -ne s/foo/bar/" worked but
|
||||
* "sed -n -e s/foo/bar/" didn't.
|
||||
* swapoff -a was not working. Now it is.
|
||||
* init did not cleanly unmount filesystems on reboot. Now it does.
|
||||
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't.
|
||||
Now both work.
|
||||
* Some architectures (PowerPc) assume chars are unsigned, so they could
|
||||
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
|
||||
@@ -444,11 +518,11 @@
|
||||
* from Matthew Grant <grantma@anathoth.gen.nz>
|
||||
to accomodate glibc timezone support. I then ripped out GNU
|
||||
getopt.
|
||||
* mkswap -- new version merged from util-linux. Can now make
|
||||
* >128Meg swaps. Replaced the old and star, unstar, and tarcat
|
||||
* with the tar
|
||||
implementation from sash. Now tar behaves as god intended it
|
||||
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* mkswap -- new version merged from util-linux. Can now make
|
||||
>128Meg swaps.
|
||||
* Replaced the old and star, unstar, and tarcat with the tar
|
||||
implementation from sash. Now tar behaves as god intended it
|
||||
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* dd -- rewritten. Can with with files, stdin, stdout. Added the
|
||||
* following new apps: loadfont -- added from debian boot floppies
|
||||
* chroot -- added based on a patch from Paolo Molaro
|
||||
|
||||
@@ -18,18 +18,17 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# PROG := busybox
|
||||
VERSION := 0.42
|
||||
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
|
||||
PROG := busybox
|
||||
VERSION := 0.43
|
||||
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
# eg: `make DODEBUG=true tests'
|
||||
DODEBUG = false
|
||||
|
||||
# If you want a static binary, turn this on. I can't think
|
||||
# of many situations where anybody would ever want it static,
|
||||
# but...
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC = false
|
||||
|
||||
# This will choke on a non-debian system
|
||||
@@ -72,12 +71,12 @@ endif
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
LDFLAGS =
|
||||
LDFLAGS =
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS = -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
ifeq ($(DOSTATIC),true)
|
||||
LDFLAGS += --static
|
||||
@@ -89,7 +88,7 @@ ifndef $(PREFIX)
|
||||
endif
|
||||
|
||||
LIBRARIES =
|
||||
OBJECTS = $(shell ./busybox.sh) messages.o utility.o
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_SCRIPT
|
||||
@@ -97,39 +96,35 @@ ifdef BB_INIT_SCRIPT
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
.PHONY: all
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP) $@
|
||||
|
||||
$(STRIP)
|
||||
$(MAKE) -C docs
|
||||
|
||||
busybox.links: busybox.def.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
regexp.o nfsmount.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
|
||||
.PHONY: test tests
|
||||
test tests:
|
||||
cd tests && $(MAKE) all
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
- cd tests && $(MAKE) distclean
|
||||
|
||||
.PHONY: install
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
.PHONY: dist release
|
||||
dist release: distclean
|
||||
$(MAKE) -C docs
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
|
||||
@@ -7,17 +7,17 @@ an editor such as "elvis-tiny" or "ae", and you have a working system.
|
||||
Busybox was begun to support the Debian Rescue/Install disks, but it
|
||||
also makes an excellent environment for any small or embedded system.
|
||||
|
||||
As of version 0.20 there is a version number. : ) Also as of version
|
||||
0.20, BB is now modularized to easily allow you to build of only the
|
||||
BB parts you need, thereby reducing binary size. To turn off unwanted
|
||||
Busybox components, simply edit the file busybox.def.h and comment out
|
||||
the parts you do not need using C++ style (//) comments.
|
||||
As of version 0.20 there is a version number. : ) Also as of version 0.20, BB
|
||||
is now modularized to easily allow you to build only the BB parts you need,
|
||||
thereby reducing binary size. To turn off unwanted Busybox components, simply
|
||||
edit the file busybox.def.h and comment out the parts you do not need using C++
|
||||
style (//) comments.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable.
|
||||
PREFIX environment variable (i.e. make PREFIX="/tmp/foo" install)
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
|
||||
@@ -15,55 +15,400 @@ around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
* cut
|
||||
* expr
|
||||
* wget (or whatever I call it)
|
||||
* tftp
|
||||
* ftp
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
Add a compile option to turn off all the compiled in help
|
||||
and usage information. Some folks don't need or want it...
|
||||
|
||||
Some known bugs, todo items, etc...
|
||||
-----------------------
|
||||
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
busybox.defs.h is too big and hard to follow.
|
||||
|
||||
Perhaps I need to add a better build system (like the Linux kernel?)
|
||||
|
||||
-----------------------
|
||||
|
||||
Feature request:
|
||||
|
||||
/bin/busybox --install -s which makes all links to commands that it
|
||||
can support (an optionnal -s should be used for symbolic links instead
|
||||
of hard links).
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
[andersen@slag busybox]$ ./busybox du /bin
|
||||
6213 /bin
|
||||
[andersen@slag busybox]$ du /bin
|
||||
2971 /bin
|
||||
[andersen@slag busybox]$ du --block-size=512 /bin
|
||||
5943 /bin
|
||||
> Have you ever thought of doig network logging in busybox syslogd ? It
|
||||
> would quite make sense on embedded systems... :)
|
||||
|
||||
So far I had not considered it. Basically, you wish to have
|
||||
messages from the embedded box logged to a remote network
|
||||
syslog box, right? I can see that this would be useful.
|
||||
I'll add this to the TODO list,
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
-rw-r--r-- 1000/1000 4398 2000-01-06 21:55 uniq.c
|
||||
-rw-r--r-- 1000/1000 1568 1999-10-20 18:08 update.c
|
||||
-rw-r----- 0/1000 1168 2000-01-29 21:03 update.o
|
||||
-rw-r--r-- 1000/1000 22820 2000-01-05 11:36 utility.c
|
||||
-rw-r----- 0/1000 7372 2000-01-29 21:03 utility.o
|
||||
tar: Skipping to next file header
|
||||
tar: Skipping to next file header
|
||||
tar: Archive - EOF not on block boundary
|
||||
tar: Error is not recoverable: exiting now
|
||||
|
||||
I think that the add_inode &c in utility.c needs to also stow the
|
||||
st_dev field, and that du.c should NOT call `reset_inode_list'
|
||||
because there can be hard links from inside one argv/ to inside
|
||||
another argv/. du.c probably ought to have an -x switch like GNU du
|
||||
does also...
|
||||
|
||||
|
||||
#1 You are storing by id instead of name like normal tar. Did you realize this?
|
||||
(or am I missing some compile option? )ctar did not do this, and I don't think
|
||||
it's a good idea for LRP.
|
||||
------------------------------------------------------------------
|
||||
|
||||
#2
|
||||
ctar did not produce the EOF error like your tar does. I believe you need to
|
||||
pad the end of the archive with at least 2 tarsized (512byte) blocks. (I
|
||||
think???)
|
||||
|
||||
#3
|
||||
There is no exclude file(s) option to tar. LRP's packaging system can not
|
||||
function without this. Will you have the time to add this soon?
|
||||
Date: Fri, 25 Feb 2000 08:23:12 +0000 (GMT)
|
||||
From: Riley Williams <rhw@MemAlpha.CX>
|
||||
X-Sender: rhw@moo.cus.org.uk
|
||||
To: almesber@lrc.di.epfl.ch
|
||||
Cc: "Albert D. Cahalan" <acahalan@cs.uml.edu>,
|
||||
Linux Kernel <linux-kernel@vger.rutgers.edu>
|
||||
Subject: Re: What /proc should contain [was: /proc/driver/microcode]
|
||||
In-Reply-To: <20000224165245.A29790@lrc.di.epfl.ch>
|
||||
Message-ID: <Pine.LNX.4.21.0002250806220.8741-100000@moo.cus.org.uk>
|
||||
Sender: owner-linux-kernel@vger.rutgers.edu
|
||||
Precedence: bulk
|
||||
|
||||
Hi there.
|
||||
|
||||
>> Nope, most /proc access is does via programs written in C.
|
||||
|
||||
> That varies a lot from file to file. E.g. I haven't seen any
|
||||
> programs that are specificly designed to read /proc/atm/* yet,
|
||||
> and I know of only one (fuser) that reads /proc/mounts,
|
||||
> extracting only partial information (just to pick two examples
|
||||
> that I'm quite familiar with).
|
||||
|
||||
As a point of reference, here's a slightly tweaked analysis of the
|
||||
programs on the system I'm reading your mail on. Basically, I ran the
|
||||
following script...
|
||||
|
||||
Q> #!/bin/bash
|
||||
Q> function use() {
|
||||
Q> for Z in $* ; do
|
||||
Q> strings $Z | grep /proc | sed "s=^=$Z ="
|
||||
Q> done
|
||||
Q> }
|
||||
Q> use /{,s}bin/* /usr/{,s}bin/* | sort -u | tee proc-usage
|
||||
|
||||
...and then went through it removing comments and print format
|
||||
strings. Replace /proc with /dev and you'd soon have an equivalent
|
||||
list for that - although I can report that such is MUCH larger...
|
||||
|
||||
There are three programs therein that refer to /proc/mounts ...
|
||||
|
||||
/bin/mount
|
||||
/bin/umount
|
||||
/usr/bin/eject
|
||||
|
||||
...and, as you stated, none that refer to /proc/atm on this system.
|
||||
However, as this is a RedHat Linux 5.0 based system, that's not
|
||||
necessarily an up to date reference thereto...
|
||||
|
||||
Here's the list anyway...
|
||||
|
||||
/bin/kill /proc/%d/cmdline
|
||||
/bin/kill /proc/%d/stat
|
||||
|
||||
/bin/mount /proc/devices
|
||||
/bin/mount /proc/filesystems
|
||||
/bin/mount /proc/mounts
|
||||
|
||||
/bin/netstat /proc/net
|
||||
/bin/netstat /proc/net/appletalk
|
||||
/bin/netstat /proc/net/ax25
|
||||
/bin/netstat /proc/net/ax25_route
|
||||
/bin/netstat /proc/net/dev
|
||||
/bin/netstat /proc/net/ip_masquerade
|
||||
/bin/netstat /proc/net/ipx
|
||||
/bin/netstat /proc/net/ipx_route
|
||||
/bin/netstat /proc/net/netstat
|
||||
/bin/netstat /proc/net/nr
|
||||
/bin/netstat /proc/net/nr_neigh
|
||||
/bin/netstat /proc/net/nr_nodes
|
||||
/bin/netstat /proc/net/raw
|
||||
/bin/netstat /proc/net/route
|
||||
/bin/netstat /proc/net/rt_cache
|
||||
/bin/netstat /proc/net/snmp
|
||||
/bin/netstat /proc/net/tcp
|
||||
/bin/netstat /proc/net/udp
|
||||
/bin/netstat /proc/net/unix
|
||||
|
||||
/bin/umount /proc/devices
|
||||
/bin/umount /proc/mounts
|
||||
|
||||
/sbin/arp /proc/net/appletalk
|
||||
/sbin/arp /proc/net/arp
|
||||
/sbin/arp /proc/net/ax25
|
||||
/sbin/arp /proc/net/ipx
|
||||
/sbin/arp /proc/net/nr
|
||||
/sbin/arp /proc/net/unix
|
||||
|
||||
/sbin/cardctl /proc/devices
|
||||
|
||||
/sbin/cardmgr /proc/devices
|
||||
|
||||
/sbin/fdisk /proc/ide/%s/media
|
||||
/sbin/fdisk /proc/scsi/scsi
|
||||
|
||||
/sbin/getty /proc/version
|
||||
|
||||
/sbin/ifconfig /proc/net
|
||||
/sbin/ifconfig /proc/net/appletalk
|
||||
/sbin/ifconfig /proc/net/ax25
|
||||
/sbin/ifconfig /proc/net/dev
|
||||
/sbin/ifconfig /proc/net/ipx
|
||||
/sbin/ifconfig /proc/net/nr
|
||||
/sbin/ifconfig /proc/net/unix
|
||||
|
||||
/sbin/ifup /proc/sys/kernel/modprobe
|
||||
|
||||
/sbin/ipchains /proc/net/ip_fwchains
|
||||
/sbin/ipchains /proc/net/ip_fwnames
|
||||
/sbin/ipchains /proc/net/ip_masquerade
|
||||
/sbin/ipchains /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
/sbin/ipmaddr /proc/net/dev_mcast
|
||||
/sbin/ipmaddr /proc/net/igmp
|
||||
/sbin/ipmaddr /proc/net/igmp6
|
||||
|
||||
/sbin/iptunnel /proc/net/dev
|
||||
|
||||
/sbin/killall5 /proc/%s/cmdline
|
||||
/sbin/killall5 /proc/%s/exe
|
||||
/sbin/killall5 /proc/%s/stat
|
||||
/sbin/killall5 /proc/version
|
||||
|
||||
/sbin/klogd /proc/kmsg
|
||||
|
||||
/sbin/lsmod /proc/modules
|
||||
|
||||
/sbin/modprobe /proc/modules
|
||||
|
||||
/sbin/pidof /proc/%s/cmdline
|
||||
/sbin/pidof /proc/%s/exe
|
||||
/sbin/pidof /proc/%s/stat
|
||||
/sbin/pidof /proc/version
|
||||
|
||||
/sbin/probe /proc/pci
|
||||
|
||||
/sbin/rarp /proc/net/ax25
|
||||
/sbin/rarp /proc/net/nr
|
||||
/sbin/rarp /proc/net/rarp
|
||||
|
||||
/sbin/rmmod /proc/modules
|
||||
|
||||
/sbin/rmmod.static /proc/modules
|
||||
|
||||
/sbin/route /proc/net/appletalk
|
||||
/sbin/route /proc/net/ax25
|
||||
/sbin/route /proc/net/ax25_route
|
||||
/sbin/route /proc/net/ipx
|
||||
/sbin/route /proc/net/ipx_route
|
||||
/sbin/route /proc/net/nr
|
||||
/sbin/route /proc/net/nr_neigh
|
||||
/sbin/route /proc/net/nr_nodes
|
||||
/sbin/route /proc/net/route
|
||||
/sbin/route /proc/net/rt_cache
|
||||
/sbin/route /proc/net/unix
|
||||
|
||||
/sbin/scsi_info /proc/scsi
|
||||
/sbin/scsi_info /proc/scsi/%s
|
||||
/sbin/scsi_info /proc/scsi/scsi
|
||||
|
||||
/sbin/slattach /proc/net/ax25
|
||||
/sbin/slattach /proc/net/nr
|
||||
|
||||
/sbin/swapoff /proc/swaps
|
||||
|
||||
/sbin/swapon /proc/swaps
|
||||
|
||||
/sbin/uugetty /proc/version
|
||||
|
||||
/usr/bin/dig /proc/
|
||||
/usr/bin/dig /proc/interrupts
|
||||
/usr/bin/dig /proc/meminfo
|
||||
/usr/bin/dig /proc/rtc
|
||||
/usr/bin/dig /proc/self/status
|
||||
/usr/bin/dig /proc/stat
|
||||
|
||||
/usr/bin/dnsquery /proc/
|
||||
/usr/bin/dnsquery /proc/interrupts
|
||||
/usr/bin/dnsquery /proc/meminfo
|
||||
/usr/bin/dnsquery /proc/rtc
|
||||
/usr/bin/dnsquery /proc/self/status
|
||||
/usr/bin/dnsquery /proc/stat
|
||||
|
||||
/usr/bin/eject /proc/mounts
|
||||
|
||||
/usr/bin/emacs /proc/loadavg
|
||||
|
||||
/usr/bin/fetchmail /proc/net/dev
|
||||
|
||||
/usr/bin/free /proc/meminfo
|
||||
|
||||
/usr/bin/gmake /proc/loadavg
|
||||
|
||||
/usr/bin/gpm-root /proc/loadavg
|
||||
/usr/bin/gpm-root /proc/meminfo
|
||||
|
||||
/usr/bin/host /proc/
|
||||
/usr/bin/host /proc/interrupts
|
||||
/usr/bin/host /proc/meminfo
|
||||
/usr/bin/host /proc/rtc
|
||||
/usr/bin/host /proc/self/status
|
||||
/usr/bin/host /proc/stat
|
||||
|
||||
/usr/bin/hoststat /proc/loadavg
|
||||
|
||||
/usr/bin/hwdiag /proc/cpuinfo
|
||||
/usr/bin/hwdiag /proc/pci
|
||||
/usr/bin/hwdiag /proc/scsi/scsi
|
||||
/usr/bin/hwdiag /proc/version
|
||||
|
||||
/usr/bin/lsdev /proc/dma
|
||||
/usr/bin/lsdev /proc/interrupts
|
||||
/usr/bin/lsdev /proc/ioports
|
||||
|
||||
/usr/bin/mailq /proc/loadavg
|
||||
|
||||
/usr/bin/make /proc/loadavg
|
||||
|
||||
/usr/bin/mcookie /proc/loadavg
|
||||
/usr/bin/mcookie /proc/stat
|
||||
|
||||
/usr/bin/newaliases /proc/loadavg
|
||||
|
||||
/usr/bin/nslookup /proc/
|
||||
/usr/bin/nslookup /proc/interrupts
|
||||
/usr/bin/nslookup /proc/meminfo
|
||||
/usr/bin/nslookup /proc/rtc
|
||||
/usr/bin/nslookup /proc/self/status
|
||||
/usr/bin/nslookup /proc/stat
|
||||
|
||||
/usr/bin/nsupdate /proc/
|
||||
/usr/bin/nsupdate /proc/interrupts
|
||||
/usr/bin/nsupdate /proc/meminfo
|
||||
/usr/bin/nsupdate /proc/rtc
|
||||
/usr/bin/nsupdate /proc/self/status
|
||||
/usr/bin/nsupdate /proc/stat
|
||||
|
||||
/usr/bin/pgp /proc/version
|
||||
/usr/bin/pgpe /proc/version
|
||||
/usr/bin/pgpk /proc/version
|
||||
/usr/bin/pgps /proc/version
|
||||
/usr/bin/pgpv /proc/version
|
||||
|
||||
/usr/bin/procinfo /proc/cmdline
|
||||
/usr/bin/procinfo /proc/devices
|
||||
/usr/bin/procinfo /proc/dma
|
||||
/usr/bin/procinfo /proc/filesystems
|
||||
/usr/bin/procinfo /proc/interrupts
|
||||
/usr/bin/procinfo /proc/loadavg
|
||||
/usr/bin/procinfo /proc/meminfo
|
||||
/usr/bin/procinfo /proc/modules
|
||||
/usr/bin/procinfo /proc/stat
|
||||
/usr/bin/procinfo /proc/uptime
|
||||
/usr/bin/procinfo /proc/version
|
||||
|
||||
/usr/bin/purgestat /proc/loadavg
|
||||
|
||||
/usr/bin/screen /proc/loadavg
|
||||
|
||||
/usr/bin/strace /proc/%d/stat
|
||||
|
||||
/usr/bin/top /proc/cpuinfo
|
||||
/usr/bin/top /proc/meminfo
|
||||
/usr/bin/top /proc/stat
|
||||
|
||||
/usr/bin/vmstat /proc/%s/stat
|
||||
/usr/bin/vmstat /proc/meminfo
|
||||
/usr/bin/vmstat /proc/stat
|
||||
|
||||
/usr/sbin/atd /proc/loadavg
|
||||
|
||||
/usr/sbin/dnskeygen /proc/
|
||||
/usr/sbin/dnskeygen /proc/interrupts
|
||||
/usr/sbin/dnskeygen /proc/meminfo
|
||||
/usr/sbin/dnskeygen /proc/rtc
|
||||
/usr/sbin/dnskeygen /proc/self/status
|
||||
/usr/sbin/dnskeygen /proc/stat
|
||||
|
||||
/usr/sbin/fuser /proc/%d/stat
|
||||
/usr/sbin/fuser /proc/net/%s
|
||||
/usr/sbin/fuser /proc/net/unix
|
||||
|
||||
/usr/sbin/in.identd /proc/net/tcp
|
||||
|
||||
/usr/sbin/irpd /proc/
|
||||
/usr/sbin/irpd /proc/interrupts
|
||||
/usr/sbin/irpd /proc/meminfo
|
||||
/usr/sbin/irpd /proc/rtc
|
||||
/usr/sbin/irpd /proc/self/status
|
||||
/usr/sbin/irpd /proc/stat
|
||||
|
||||
/usr/sbin/named /proc/
|
||||
/usr/sbin/named /proc/interrupts
|
||||
/usr/sbin/named /proc/meminfo
|
||||
/usr/sbin/named /proc/rtc
|
||||
/usr/sbin/named /proc/self/status
|
||||
/usr/sbin/named /proc/stat
|
||||
|
||||
/usr/sbin/named-xfer /proc/
|
||||
/usr/sbin/named-xfer /proc/interrupts
|
||||
/usr/sbin/named-xfer /proc/meminfo
|
||||
/usr/sbin/named-xfer /proc/rtc
|
||||
/usr/sbin/named-xfer /proc/self/status
|
||||
/usr/sbin/named-xfer /proc/stat
|
||||
|
||||
/usr/sbin/readprofile /proc/profile
|
||||
|
||||
/usr/sbin/rwhod /proc/loadavg
|
||||
/usr/sbin/rwhod /proc/uptime
|
||||
|
||||
/usr/sbin/sendmail /proc/loadavg
|
||||
|
||||
/usr/sbin/setconsole /proc/openprom/options
|
||||
/usr/sbin/setconsole /proc/openprom/options/${console}-mode
|
||||
/usr/sbin/setconsole /proc/openprom/options/input-device
|
||||
/usr/sbin/setconsole /proc/openprom/options/output-device
|
||||
|
||||
Best wishes from Riley.
|
||||
|
||||
* Copyright (C) 1999, Memory Alpha Systems.
|
||||
* All rights and wrongs reserved.
|
||||
|
||||
+----------------------------------------------------------------------+
|
||||
| There is something frustrating about the quality and speed of Linux |
|
||||
| development, ie., the quality is too high and the speed is too high, |
|
||||
| in other words, I can implement this XXXX feature, but I bet someone |
|
||||
| else has already done so and is just about to release their patch. |
|
||||
+----------------------------------------------------------------------+
|
||||
* http://www.memalpha.cx/Linux/Kernel/
|
||||
|
||||
|
||||
-
|
||||
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
|
||||
the body of a message to majordomo@vger.rutgers.edu
|
||||
Please read the FAQ at http://www.tux.org/lkml/
|
||||
|
||||
+234
-180
@@ -4,10 +4,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -34,258 +30,304 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CP_MV //bin
|
||||
{"cp", cp_mv_main},
|
||||
{"mv", cp_mv_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP //usr/bin
|
||||
{"nslookup", nslookup_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
@@ -294,15 +336,17 @@ static const struct Applet applets[] = {
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
@@ -335,8 +379,10 @@ int busybox_main(int argc, char **argv)
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
while (a->name != 0) {
|
||||
@@ -356,3 +402,11 @@ int busybox_main(int argc, char **argv)
|
||||
return (main(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+10
-6
@@ -4,12 +4,16 @@
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
@@ -15,6 +15,7 @@ for i in $h ; do
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
mkdir -p $1/bin
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+90
-86
@@ -1,13 +1,33 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* zcat : stripped version based on gzip sources
|
||||
Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
*/
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
@@ -16,6 +36,18 @@ static const char gunzip_usage[] =
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
@@ -89,25 +121,6 @@ static char *license_msg[] = {
|
||||
#define get_char() get_byte()
|
||||
#define put_char(c) put_byte(c)
|
||||
|
||||
/* #include "gzip.h" */
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
@@ -118,7 +131,7 @@ typedef char *voidp;
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
# define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
@@ -329,49 +342,46 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
#define do_exit(c) exit(c)
|
||||
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int unzip (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((int pack_level, ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (int pack_level, ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern int copy (int in, int out);
|
||||
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);
|
||||
|
||||
#ifndef __linux__
|
||||
extern char *basename OF((char *fname));
|
||||
extern char *basename (char *fname);
|
||||
#endif /* not __linux__ */
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
extern int inflate (void);
|
||||
|
||||
/* #include "lzw.h" */
|
||||
|
||||
@@ -415,8 +425,8 @@ extern int inflate OF((void));
|
||||
extern int maxbits; /* max bits per code for LZW */
|
||||
extern int block_mode; /* block compress mode -C compatible with 2.0 */
|
||||
|
||||
extern int lzw OF((int in, int out));
|
||||
extern int unlzw OF((int in, int out));
|
||||
extern int lzw (int in, int out);
|
||||
extern int unlzw (int in, int out);
|
||||
|
||||
|
||||
/* #include "revision.h" */
|
||||
@@ -605,7 +615,7 @@ typedef struct direct dir_type;
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -644,7 +654,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -687,7 +697,7 @@ long header_bytes; /* number of bytes in gzip header */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local int get_method OF((int in));
|
||||
local int get_method (int in);
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
@@ -773,7 +783,7 @@ int gunzip_main(int argc, char **argv)
|
||||
usage(gunzip_usage);
|
||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ifname, *argv);
|
||||
|
||||
@@ -781,13 +791,13 @@ int gunzip_main(int argc, char **argv)
|
||||
inFileNum = open(ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
@@ -812,7 +822,7 @@ int gunzip_main(int argc, char **argv)
|
||||
/* And get to work */
|
||||
if (strlen(ifname) > MAX_PATH_LEN - 4) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ofname, ifname);
|
||||
pos = strstr(ofname, ".gz");
|
||||
@@ -836,7 +846,7 @@ int gunzip_main(int argc, char **argv)
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
@@ -860,7 +870,7 @@ int gunzip_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
do_exit(exit_code);
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -953,7 +963,7 @@ int in; /* input file descriptor */
|
||||
*/
|
||||
RETSIGTYPE abort_gzip()
|
||||
{
|
||||
do_exit(ERROR);
|
||||
exit(ERROR);
|
||||
}
|
||||
|
||||
/* unzip.c -- decompress files in gzip or pkzip format.
|
||||
@@ -1027,7 +1037,7 @@ int in, out; /* input and output file descriptors */
|
||||
ofd = out;
|
||||
method = get_method(ifd);
|
||||
if (method < 0) {
|
||||
do_exit(exit_code); /* error message already emitted */
|
||||
exit(exit_code); /* error message already emitted */
|
||||
}
|
||||
|
||||
updcrc(NULL, 0); /* initialize crc */
|
||||
@@ -1218,7 +1228,7 @@ void flush_window()
|
||||
*/
|
||||
void write_buf(fd, buf, cnt)
|
||||
int fd;
|
||||
voidp buf;
|
||||
void * buf;
|
||||
unsigned cnt;
|
||||
{
|
||||
unsigned n;
|
||||
@@ -1228,7 +1238,7 @@ unsigned cnt;
|
||||
write_error();
|
||||
}
|
||||
cnt -= n;
|
||||
buf = (voidp) ((char *) buf + n);
|
||||
buf = (void *) ((char *) buf + n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1240,8 +1250,8 @@ unsigned cnt;
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -1291,12 +1301,6 @@ const char *reject;
|
||||
/* ========================================================================
|
||||
* Error handlers.
|
||||
*/
|
||||
void warn(a, b)
|
||||
char *a, *b; /* message strings juxtaposed in output */
|
||||
{
|
||||
WARN((stderr, "warning: %s%s\n", a, b));
|
||||
}
|
||||
|
||||
void read_error()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
@@ -1499,15 +1503,15 @@ struct huft {
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *));
|
||||
int huft_free OF((struct huft *));
|
||||
int inflate_codes OF((struct huft *, struct huft *, int, int));
|
||||
int inflate_stored OF((void));
|
||||
int inflate_fixed OF((void));
|
||||
int inflate_dynamic OF((void));
|
||||
int inflate_block OF((int *));
|
||||
int inflate OF((void));
|
||||
int huft_build (unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *);
|
||||
int huft_free (struct huft *);
|
||||
int inflate_codes (struct huft *, struct huft *, int, int);
|
||||
int inflate_stored (void);
|
||||
int inflate_fixed (void);
|
||||
int inflate_dynamic (void);
|
||||
int inflate_block (int *);
|
||||
int inflate (void);
|
||||
|
||||
|
||||
/* The inflate algorithm uses a sliding 32K byte window on the uncompressed
|
||||
|
||||
+94
-103
@@ -1,62 +1,58 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* gzip.c -- this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires the
|
||||
* zcat module for some important functions.
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Charles P. Wright <cpw@unix.asb.com>
|
||||
* "this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires
|
||||
* the zcat module for some important functions."
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Charles P. Wright <cpw@unix.asb.com>
|
||||
*/
|
||||
#include "internal.h"
|
||||
#ifdef BB_GZIP
|
||||
|
||||
//#ifndef BB_ZCAT
|
||||
//#error you need zcat to have gzip support!
|
||||
//#endif
|
||||
#include "internal.h"
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"When FILE is -, reads standard input. Implies -c.\n\n"
|
||||
"When FILE is '-', reads standard input. Implies -c.\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
|
||||
# include <string.h>
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# define memcpy(d, s, n) bcopy((s), (d), (n))
|
||||
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
|
||||
# define memzero(s, n) bzero((s), (n))
|
||||
#endif
|
||||
#include <string.h>
|
||||
#define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
@@ -121,13 +117,13 @@ extern int method; /* compression method */
|
||||
#endif
|
||||
|
||||
#ifdef DYN_ALLOC
|
||||
# define EXTERN(type, array) extern type * near array
|
||||
# define DECLARE(type, array, size) type * near array
|
||||
# define EXTERN(type, array) extern type * array
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
# define EXTERN(type, array) extern type array[]
|
||||
# define DECLARE(type, array, size) type array[size]
|
||||
@@ -284,55 +280,55 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip OF((int in, int out));
|
||||
extern int file_read OF((char *buf, unsigned size));
|
||||
extern int zip (int in, int out);
|
||||
extern int file_read (char *buf, unsigned size);
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int check_zipfile OF((int in));
|
||||
extern int unzip (int in, int out);
|
||||
extern int check_zipfile (int in);
|
||||
|
||||
/* in unpack.c */
|
||||
extern int unpack OF((int in, int out));
|
||||
extern int unpack (int in, int out);
|
||||
|
||||
/* in unlzh.c */
|
||||
extern int unlzh OF((int in, int out));
|
||||
extern int unlzh (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern char *strlwr OF((char *s));
|
||||
extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
extern void display_ratio OF((long num, long den, FILE * file));
|
||||
extern int copy (int in, int out);
|
||||
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 char *strlwr (char *s);
|
||||
extern char *add_envopt (int *argcp, char ***argvp, char *env);
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
extern void display_ratio (long num, long den, FILE * file);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
extern int inflate (void);
|
||||
|
||||
/* lzw.h -- define the lzw functions.
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
@@ -795,7 +791,7 @@ local int bi_valid;
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
int (*read_buf) OF((char *buf, unsigned size));
|
||||
int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* Current input function. Set to mem_read for in-memory compression */
|
||||
|
||||
@@ -1148,16 +1144,16 @@ local config configuration_table =
|
||||
/* ===========================================================================
|
||||
* Prototypes for local functions.
|
||||
*/
|
||||
local void fill_window OF((void));
|
||||
local void fill_window (void);
|
||||
|
||||
int longest_match OF((IPos cur_match));
|
||||
int longest_match (IPos cur_match);
|
||||
|
||||
#ifdef ASMV
|
||||
void match_init OF((void)); /* asm code initialization */
|
||||
void match_init (void); /* asm code initialization */
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
local void check_match OF((IPos start, IPos match, int length));
|
||||
local void check_match (IPos start, IPos match, int length);
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1708,7 +1704,7 @@ struct utimbuf {
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -1743,7 +1739,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
/* Separator for file name parts (see shorten_name()) */
|
||||
@@ -2246,17 +2242,17 @@ extern unsigned near strstart; /* window offset of current string */
|
||||
* Local (static) routines in this file.
|
||||
*/
|
||||
|
||||
local void init_block OF((void));
|
||||
local void pqdownheap OF((ct_data near * tree, int k));
|
||||
local void gen_bitlen OF((tree_desc near * desc));
|
||||
local void gen_codes OF((ct_data near * tree, int max_code));
|
||||
local void build_tree OF((tree_desc near * desc));
|
||||
local void scan_tree OF((ct_data near * tree, int max_code));
|
||||
local void send_tree OF((ct_data near * tree, int max_code));
|
||||
local int build_bl_tree OF((void));
|
||||
local void send_all_trees OF((int lcodes, int dcodes, int blcodes));
|
||||
local void compress_block OF((ct_data near * ltree, ct_data near * dtree));
|
||||
local void set_file_type OF((void));
|
||||
local void init_block (void);
|
||||
local void pqdownheap (ct_data near * tree, int k);
|
||||
local void gen_bitlen (tree_desc near * desc);
|
||||
local void gen_codes (ct_data near * tree, int max_code);
|
||||
local void build_tree (tree_desc near * desc);
|
||||
local void scan_tree (ct_data near * tree, int max_code);
|
||||
local void send_tree (ct_data near * tree, int max_code);
|
||||
local int build_bl_tree (void);
|
||||
local void send_all_trees (int lcodes, int dcodes, int blcodes);
|
||||
local void compress_block (ct_data near * ltree, ct_data near * dtree);
|
||||
local void set_file_type (void);
|
||||
|
||||
|
||||
#ifndef DEBUG
|
||||
@@ -3097,7 +3093,7 @@ local void set_file_type()
|
||||
bin_freq += dyn_ltree[n++].Freq;
|
||||
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
||||
if (*file_type == BINARY && translate_eol) {
|
||||
errorMsg("-l used on binary file", "");
|
||||
errorMsg("-l used on binary file");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3161,12 +3157,8 @@ char *s;
|
||||
|
||||
/* Provide missing strspn and strcspn functions. */
|
||||
|
||||
# ifndef __STDC__
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -3398,4 +3390,3 @@ unsigned size;
|
||||
isize += (ulg) len;
|
||||
return (int) len;
|
||||
}
|
||||
#endif
|
||||
+862
-1149
File diff suppressed because it is too large.
Load diff
+45
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -34,258 +30,304 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CP_MV //bin
|
||||
{"cp", cp_mv_main},
|
||||
{"mv", cp_mv_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP //usr/bin
|
||||
{"nslookup", nslookup_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
@@ -294,15 +336,17 @@ static const struct Applet applets[] = {
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
@@ -335,8 +379,10 @@ int busybox_main(int argc, char **argv)
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
while (a->name != 0) {
|
||||
@@ -356,3 +402,11 @@ int busybox_main(int argc, char **argv)
|
||||
return (main(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+122
-34
@@ -7,7 +7,7 @@
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_BUSYBOX
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
#define BB_CHROOT
|
||||
@@ -18,60 +18,64 @@
|
||||
#define BB_DD
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_ECHO
|
||||
#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
//#define BB_HALT
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_INIT
|
||||
// Don't turn BB_INSMOD on. It doesn't work.
|
||||
// Don't bother turning BB_INSMOD on. It doesn't work yet.
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
#define BB_LOADACM
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MKFS_MINIX
|
||||
//#define BB_MATH
|
||||
#define BB_MATH
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
#define BB_MNC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
//#define BB_MT
|
||||
#define BB_MT
|
||||
#define BB_NSLOOKUP
|
||||
#define BB_PING
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_REBOOT
|
||||
#define BB_REGEXP
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_RMMOD
|
||||
#define BB_SED
|
||||
//#define BB_SFDISK
|
||||
#define BB_SFDISK
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
#define BB_SWAPONOFF
|
||||
@@ -80,9 +84,15 @@
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TEST
|
||||
// Don't bother turning BB_TELNET on. It doesn't work properly yet.
|
||||
//#define BB_TELNET
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WHOAMI
|
||||
#define BB_UMOUNT
|
||||
@@ -94,16 +104,35 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, devmtab,
|
||||
// etc kernel drivers, thereby eliminating the need for
|
||||
// the /proc filesystem and thereby saving lots and lots
|
||||
// memory for more important things.
|
||||
// You can't use this and USE_PROCFS at the same time...
|
||||
// (BTW, I emailed Linus and this patch will not be going into the stock kernel)
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// enable features that use the /proc filesystem (apps that
|
||||
// break without this will tell you on compile)...
|
||||
// You can't use this and BB_FEATURE_USE_DEVPS_PATCH
|
||||
// at the same time...
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//
|
||||
// Enable full regular expressions. This adds about
|
||||
// 4k. When this is off, things that would normally
|
||||
// use regualr expressions (like grep) will just use
|
||||
// normal strings.
|
||||
#define BB_FEATURE_FULL_REGULAR_EXPRESSIONS
|
||||
//
|
||||
// Use only simple command help
|
||||
#define BB_FEATURE_TRIVIAL_HELP
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
@@ -111,23 +140,33 @@
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
////
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
//#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
// Allow init to permenently chroot, and umount the old root fs
|
||||
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
|
||||
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
|
||||
//#define BB_FEATURE_INIT_CHROOT
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
//Simple tail implementation (2k vs 6k for the full one). Still
|
||||
//provides 'tail -f' support -- but for only one file at a time.
|
||||
@@ -137,21 +176,70 @@
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
#ifdef BB_MOUNT
|
||||
//#define BB_MTAB
|
||||
#endif
|
||||
//
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for remounting filesystems
|
||||
#define BB_FEATURE_REMOUNT
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
//#define BB_FEATURE_TAR_CREATE
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Allow init to permenently chroot, and umount the old root fs
|
||||
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
|
||||
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
|
||||
#ifdef BB_MOUNT
|
||||
#define BB_FEATURE_INIT_CHROOT
|
||||
// Enable support for "--exclude" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
//// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable command line editing in the shell
|
||||
#define BB_FEATURE_SH_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell (not yet
|
||||
// working very well -- so don't turn this on)
|
||||
//#define BB_FEATURE_SH_TAB_COMPLETION
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
#define BB_MTAB
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_FULL_REGULAR_EXPRESSIONS && (defined BB_SED || defined BB_GREP )
|
||||
#define BB_REGEXP
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH
|
||||
#define BB_CMDEDIT
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
#ifndef BB_INIT
|
||||
#define BB_INIT
|
||||
#define BB_LINUXRC
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_GZIP
|
||||
#ifndef BB_GUNZIP
|
||||
#define BB_GUNZIP
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
+10
-6
@@ -4,12 +4,16 @@
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.42
|
||||
Version: 0.43
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+17
-10
@@ -3,7 +3,7 @@
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -48,7 +48,7 @@ static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] =
|
||||
"chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
|
||||
"chown [OPTION]... OWNER[<.|:>[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
@@ -60,7 +60,7 @@ static const char chmod_usage[] =
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
switch (whichApp) {
|
||||
case CHGRP_APP:
|
||||
@@ -98,13 +98,11 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
char *p;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp =
|
||||
(strcmp(*argv, "chown") == 0)?
|
||||
whichApp = (strcmp(*argv, "chown") == 0)?
|
||||
CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
|
||||
CHMOD_APP : CHGRP_APP;
|
||||
|
||||
appUsage =
|
||||
(whichApp == CHOWN_APP)?
|
||||
appUsage = (whichApp == CHOWN_APP)?
|
||||
chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
|
||||
|
||||
if (argc < 2)
|
||||
@@ -142,6 +140,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
goto bad_group;
|
||||
} else {
|
||||
groupName = strchr(*argv, '.');
|
||||
if (groupName == NULL)
|
||||
groupName = strchr(*argv, ':');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = strtoul(groupName, &p, 10);
|
||||
@@ -171,9 +171,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
fatalError( "%s: too few arguments\n", invocationName);
|
||||
}
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction
|
||||
(*(++argv), recursiveFlag, TRUE, FALSE, fileAction,
|
||||
fileAction) == FALSE)
|
||||
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE)
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
@@ -181,3 +180,11 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
bad_group:
|
||||
fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -34,3 +34,12 @@ int chvt_main(int argc, char **argv)
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -0,0 +1,651 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Termios command line History and Editting, originally
|
||||
* intended for NetBSD sh (ash)
|
||||
* Copyright (c) 1999
|
||||
* Main code: Adam Rogoyski <rogoyski@cs.utexas.edu>
|
||||
* Etc: Dave Cinege <dcinege@psychosis.com>
|
||||
* Majorly adjusted/re-written for busybox:
|
||||
* Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* You may use this code as you wish, so long as the original author(s)
|
||||
* are attributed in any redistributions of the source code.
|
||||
* This code is 'as is' with no warranty.
|
||||
* This code may safely be consumed by a BSD or GPL license.
|
||||
*
|
||||
* v 0.5 19990328 Initial release
|
||||
*
|
||||
* Future plans: Simple file and path name completion. (like BASH)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Usage and Known bugs:
|
||||
Terminal key codes are not extensive, and more will probably
|
||||
need to be added. This version was created on Debian GNU/Linux 2.x.
|
||||
Delete, Backspace, Home, End, and the arrow keys were tested
|
||||
to work in an Xterm and console. Ctrl-A also works as Home.
|
||||
Ctrl-E also works as End. The binary size increase is <3K.
|
||||
|
||||
Editting will not display correctly for lines greater then the
|
||||
terminal width. (more then one line.) However, history will.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termio.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#define MAX_HISTORY 15 /* Maximum length of the linked list for the command line history */
|
||||
|
||||
#define ESC 27
|
||||
#define DEL 127
|
||||
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||
|
||||
static struct history *his_front = NULL; /* First element in command line list */
|
||||
static struct history *his_end = NULL; /* Last element in command line list */
|
||||
static struct termio old_term, new_term; /* Current termio and the previous termio before starting ash */
|
||||
|
||||
static int cmdedit_termw = 80; /* actual terminal width */
|
||||
static int cmdedit_scroll = 27; /* width of EOL scrolling region */
|
||||
static int history_counter = 0; /* Number of commands in history list */
|
||||
static int reset_term = 0; /* Set to true if the terminal needs to be reset upon exit */
|
||||
|
||||
struct history {
|
||||
char *s;
|
||||
struct history *p;
|
||||
struct history *n;
|
||||
};
|
||||
|
||||
#define xwrite write
|
||||
|
||||
void
|
||||
cmdedit_setwidth(int w)
|
||||
{
|
||||
if (w > 20) {
|
||||
cmdedit_termw = w;
|
||||
cmdedit_scroll = w / 3;
|
||||
} else {
|
||||
errorMsg("\n*** Error: minimum screen width is 21\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cmdedit_reset_term(void)
|
||||
{
|
||||
if (reset_term)
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
||||
}
|
||||
|
||||
void clean_up_and_die(int sig)
|
||||
{
|
||||
cmdedit_reset_term();
|
||||
fprintf(stdout, "\n");
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Go to HOME position */
|
||||
void input_home(int outputFd, int *cursor)
|
||||
{
|
||||
while (*cursor > 0) {
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go to END position */
|
||||
void input_end(int outputFd, int *cursor, int len)
|
||||
{
|
||||
while (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in back of the cursor */
|
||||
void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\b \b", 3);
|
||||
--*cursor;
|
||||
memmove(command + *cursor, command + *cursor + 1,
|
||||
BUFSIZ - *cursor + 1);
|
||||
|
||||
for (j = *cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > *cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
|
||||
--*len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in front of the cursor */
|
||||
void input_delete(char* command, int outputFd, int cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (cursor == *len)
|
||||
return;
|
||||
|
||||
memmove(command + cursor, command + cursor + 1,
|
||||
BUFSIZ - cursor - 1);
|
||||
for (j = cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*len;
|
||||
}
|
||||
|
||||
/* Move forward one charactor */
|
||||
void input_forward(int outputFd, int *cursor, int len)
|
||||
{
|
||||
if (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move back one charactor */
|
||||
void input_backward(int outputFd, int *cursor)
|
||||
{
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
char** username_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char **matches = (char **) NULL;
|
||||
*num_matches=0;
|
||||
fprintf(stderr, "\nin username_tab_completion\n");
|
||||
return (matches);
|
||||
}
|
||||
|
||||
#include <dirent.h>
|
||||
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char *dirName;
|
||||
char **matches = (char **) NULL;
|
||||
DIR *dir;
|
||||
struct dirent *next;
|
||||
|
||||
matches = malloc( sizeof(char*)*50);
|
||||
|
||||
/* Stick a wildcard onto the command, for later use */
|
||||
strcat( command, "*");
|
||||
|
||||
/* Now wall the current directory */
|
||||
dirName = get_current_dir_name();
|
||||
dir = opendir(dirName);
|
||||
if (!dir) {
|
||||
/* Don't print an error, just shut up and return */
|
||||
*num_matches=0;
|
||||
return (matches);
|
||||
}
|
||||
while ((next = readdir(dir)) != NULL) {
|
||||
|
||||
/* Some quick sanity checks */
|
||||
if ((strcmp(next->d_name, "..") == 0)
|
||||
|| (strcmp(next->d_name, ".") == 0)) {
|
||||
continue;
|
||||
}
|
||||
/* See if this matches */
|
||||
if (check_wildcard_match(next->d_name, command) == TRUE) {
|
||||
/* Cool, found a match. Add it to the list */
|
||||
matches[*num_matches] = malloc(strlen(next->d_name)+1);
|
||||
strcpy( matches[*num_matches], next->d_name);
|
||||
++*num_matches;
|
||||
//matches = realloc( matches, sizeof(char*)*(*num_matches));
|
||||
}
|
||||
}
|
||||
|
||||
return (matches);
|
||||
}
|
||||
|
||||
void input_tab(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
/* Do TAB completion */
|
||||
static int num_matches=0;
|
||||
static char **matches = (char **) NULL;
|
||||
int pos = cursor;
|
||||
|
||||
|
||||
if (lastWasTab == FALSE) {
|
||||
char *tmp, *tmp1, *matchBuf;
|
||||
|
||||
/* For now, we will not bother with trying to distinguish
|
||||
* whether the cursor is in/at a command extression -- we
|
||||
* will always try all possable matches. If you don't like
|
||||
* that then feel free to fix it.
|
||||
*/
|
||||
|
||||
/* Make a local copy of the string -- up
|
||||
* to the position of the cursor */
|
||||
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
strncpy(matchBuf, command, cursor);
|
||||
tmp=matchBuf;
|
||||
|
||||
/* skip past any command seperator tokens */
|
||||
while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) {
|
||||
tmp=++tmp1;
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
}
|
||||
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
|
||||
/* Free up any memory already allocated */
|
||||
if (matches) {
|
||||
free(matches);
|
||||
matches = (char **) NULL;
|
||||
}
|
||||
|
||||
/* If the word starts with `~' and there is no slash in the word,
|
||||
* then try completing this word as a username. */
|
||||
|
||||
/* FIXME -- this check is broken! */
|
||||
if (*tmp == '~' && !strchr(tmp, '/'))
|
||||
matches = username_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Try to match any executable in our path and everything
|
||||
* in the current working directory that matches. */
|
||||
if (!matches)
|
||||
matches = exe_n_cwd_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Don't leak memory */
|
||||
free( matchBuf);
|
||||
|
||||
/* Did we find exactly one match? */
|
||||
if (matches && num_matches==1) {
|
||||
/* write out the matched command */
|
||||
strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos);
|
||||
len=strlen(command);
|
||||
cursor=len;
|
||||
xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Ok -- the last char was a TAB. Since they
|
||||
* just hit TAB again, print a list of all the
|
||||
* available choices... */
|
||||
if ( matches && num_matches>0 ) {
|
||||
int i, col;
|
||||
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Print the list of matches */
|
||||
for (i=0,col=0; i<num_matches; i++) {
|
||||
char foo[17];
|
||||
sprintf(foo, "%-14s ", matches[i]);
|
||||
col += xwrite(outputFd, foo, strlen(foo));
|
||||
if (col > 60 && matches[i+1] != NULL) {
|
||||
xwrite(outputFd, "\n", 1);
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Rewrite the prompt */
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
/* Rewrite the command */
|
||||
xwrite(outputFd, command, len);
|
||||
/* Put the cursor back to where it used to be */
|
||||
for (cursor=len; cursor > pos; cursor--)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void get_previous_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->p;
|
||||
}
|
||||
|
||||
void get_next_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->n;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is used to grab a character buffer
|
||||
* from the input file descriptor and allows you to
|
||||
* a string with full command editing (sortof like
|
||||
* a mini readline).
|
||||
*
|
||||
* The following standard commands are not implemented:
|
||||
* ESC-b -- Move back one word
|
||||
* ESC-f -- Move forward one word
|
||||
* ESC-d -- Delete back one word
|
||||
* ESC-h -- Delete forward one word
|
||||
* CTL-t -- Transpose two characters
|
||||
*
|
||||
* Furthermore, the "vi" command editing keys are not implemented.
|
||||
*
|
||||
* TODO: implement TAB command completion. :)
|
||||
*/
|
||||
extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
{
|
||||
|
||||
int inputFd=fileno(stdin);
|
||||
int outputFd=fileno(stdout);
|
||||
int nr = 0;
|
||||
int len = 0;
|
||||
int j = 0;
|
||||
int cursor = 0;
|
||||
int break_out = 0;
|
||||
int ret = 0;
|
||||
int lastWasTab = FALSE;
|
||||
char c = 0;
|
||||
struct history *hp = his_end;
|
||||
|
||||
memset(command, 0, sizeof(command));
|
||||
if (!reset_term) {
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCGETA, (void *) &old_term);
|
||||
memcpy(&new_term, &old_term, sizeof(struct termio));
|
||||
|
||||
new_term.c_cc[VMIN] = 1;
|
||||
new_term.c_cc[VTIME] = 0;
|
||||
new_term.c_lflag &= ~ICANON; /* unbuffered input */
|
||||
new_term.c_lflag &= ~ECHO;
|
||||
reset_term = 1;
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
} else {
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
}
|
||||
|
||||
memset(command, 0, BUFSIZ);
|
||||
|
||||
while (1) {
|
||||
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
/* Enter */
|
||||
*(command + len++ + 1) = c;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break_out = 1;
|
||||
break;
|
||||
case 1:
|
||||
/* Control-a -- Beginning of line */
|
||||
input_home(outputFd, &cursor);
|
||||
case 2:
|
||||
/* Control-b -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case 4:
|
||||
/* Control-d -- Delete one character, or exit
|
||||
* if the len=0 and no chars to delete */
|
||||
if (len == 0) {
|
||||
xwrite(outputFd, "exit", 4);
|
||||
clean_up_and_die(0);
|
||||
} else {
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
/* Control-e -- End of line */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
case 6:
|
||||
/* Control-f -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case '\b':
|
||||
case DEL:
|
||||
/* control-h and DEL */
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
break;
|
||||
case '\t':
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
input_tab(command, outputFd, &cursor, &len);
|
||||
#endif
|
||||
break;
|
||||
case 14:
|
||||
/* Control-n -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
/* Control-p -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case ESC:{
|
||||
/* escape sequence follows */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
if (c == '[') { /* 91 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
case 'A':
|
||||
/* Up Arrow -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
/* Down Arrow -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Rewrite the line with the selected history item */
|
||||
rewrite_line:
|
||||
/* erase old command from command line */
|
||||
len = strlen(command)-strlen(hp->s);
|
||||
while (len>0)
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
input_home(outputFd, &cursor);
|
||||
|
||||
/* write new command */
|
||||
strcpy(command, hp->s);
|
||||
len = strlen(hp->s);
|
||||
xwrite(outputFd, command, len);
|
||||
cursor = len;
|
||||
break;
|
||||
case 'C':
|
||||
/* Right Arrow -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case 'D':
|
||||
/* Left Arrow -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case '3':
|
||||
/* Delete */
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
break;
|
||||
case '1':
|
||||
/* Home (Ctrl-A) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case '4':
|
||||
/* End (Ctrl-E) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
if (c == '1' || c == '3' || c == '4')
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return; /* read 126 (~) */
|
||||
}
|
||||
if (c == 'O') {
|
||||
/* 79 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
switch (c) {
|
||||
case 'H':
|
||||
/* Home (xterm) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case 'F':
|
||||
/* End (xterm) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
}
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default: /* If it's regular input, do the normal thing */
|
||||
|
||||
if (!isprint(c)) { /* Skip non-printable characters */
|
||||
break;
|
||||
}
|
||||
|
||||
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
|
||||
break;
|
||||
|
||||
len++;
|
||||
|
||||
if (cursor == (len - 1)) { /* Append if at the end of the line */
|
||||
*(command + cursor) = c;
|
||||
} else { /* Insert otherwise */
|
||||
memmove(command + cursor + 1, command + cursor,
|
||||
len - cursor - 1);
|
||||
|
||||
*(command + cursor) = c;
|
||||
|
||||
for (j = cursor; j < len; j++)
|
||||
xwrite(outputFd, command + j, 1);
|
||||
for (; j > cursor; j--)
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
}
|
||||
|
||||
cursor++;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break;
|
||||
}
|
||||
if (c == '\t')
|
||||
lastWasTab = TRUE;
|
||||
else
|
||||
lastWasTab = FALSE;
|
||||
|
||||
if (break_out) /* Enter is the command terminator, no more input. */
|
||||
break;
|
||||
}
|
||||
|
||||
nr = len + 1;
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCSETA, (void *) &old_term);
|
||||
reset_term = 0;
|
||||
|
||||
|
||||
/* Handle command history log */
|
||||
if (*(command)) {
|
||||
|
||||
struct history *h = his_end;
|
||||
|
||||
if (!h) {
|
||||
/* No previous history */
|
||||
h = his_front = malloc(sizeof(struct history));
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->p = NULL;
|
||||
h->s = strdup(command);
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
his_end = h->n;
|
||||
history_counter++;
|
||||
} else {
|
||||
/* Add a new history command */
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
h->s = strdup(command);
|
||||
his_end = h->n;
|
||||
|
||||
/* After max history, remove the oldest command */
|
||||
if (history_counter >= MAX_HISTORY) {
|
||||
|
||||
struct history *p = his_front->n;
|
||||
|
||||
p->p = NULL;
|
||||
free(his_front->s);
|
||||
free(his_front);
|
||||
his_front = p;
|
||||
} else {
|
||||
history_counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
extern void cmdedit_init(void)
|
||||
{
|
||||
atexit(cmdedit_reset_term);
|
||||
signal(SIGINT, clean_up_and_die);
|
||||
signal(SIGQUIT, clean_up_and_die);
|
||||
signal(SIGTERM, clean_up_and_die);
|
||||
}
|
||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef GETLINE_H
|
||||
#define GETLINE_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stddef.h>
|
||||
|
||||
typedef size_t (*cmdedit_strwidth_proc)(char *);
|
||||
|
||||
void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */
|
||||
void cmdedit_setwidth(int); /* specify width of screen */
|
||||
void cmdedit_histadd(char *); /* adds entries to hist */
|
||||
void cmdedit_strwidth(cmdedit_strwidth_proc); /* to bind cmdedit_strlen */
|
||||
|
||||
extern int (*cmdedit_in_hook)(char *);
|
||||
extern int (*cmdedit_out_hook)(char *);
|
||||
extern int (*cmdedit_tab_hook)(char *, int, int *);
|
||||
|
||||
#else /* not __STDC__ */
|
||||
|
||||
void cmdedit_read_input(char* promptStr, char* command);
|
||||
void cmdedit_setwidth();
|
||||
void cmdedit_histadd();
|
||||
void cmdedit_strwidth();
|
||||
|
||||
extern int (*cmdedit_in_hook)();
|
||||
extern int (*cmdedit_out_hook)();
|
||||
extern int (*cmdedit_tab_hook)();
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* GETLINE_H */
|
||||
@@ -34,3 +34,12 @@ int chvt_main(int argc, char **argv)
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
+13
-5
@@ -7,6 +7,7 @@
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
@@ -21,6 +22,9 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
static const char loadacm_usage[] = "loadacm\n\n"
|
||||
"Loads an acm from standard input.\n";
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
@@ -33,20 +37,24 @@ int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadacm_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin)) {
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE * fp)
|
||||
@@ -353,8 +361,8 @@ void saveoldmap(int fd, char *omfil)
|
||||
unicode utf8_to_ucs2(char *buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
long utf_char = 0;
|
||||
unicode tc = 0;
|
||||
unsigned char c;
|
||||
|
||||
do {
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
#define PSF_MAXMODE 0x03
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
"\n" "\tLoad a console font from standard input.\n" "\n";
|
||||
static const char loadfont_usage[] = "loadfont\n\n"
|
||||
"Loads a console font from standard input.\n";
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
@@ -47,14 +47,18 @@ extern int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadfont_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
loadnewfont(fd);
|
||||
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
|
||||
+15
-12
@@ -29,11 +29,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
"\n"
|
||||
|
||||
"\tLoad a binary keyboard translation table from standard input.\n"
|
||||
"\n";
|
||||
static const char loadkmap_usage[] = "loadkmap\n\n"
|
||||
"Loads a binary keyboard translation table from standard input.\n";
|
||||
|
||||
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
@@ -43,28 +40,32 @@ int loadkmap_main(int argc, char **argv)
|
||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadkmap_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
read(0, buff, 7);
|
||||
if (0 != strncmp(buff, magic, 7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
ibuff = (u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
@@ -75,7 +76,7 @@ int loadkmap_main(int argc, char **argv)
|
||||
< 0) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
pos += readsz;
|
||||
}
|
||||
@@ -87,6 +88,8 @@ int loadkmap_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
+9
-1
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+10
-1
@@ -3,7 +3,7 @@
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+10
-19
@@ -64,8 +64,7 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
exit(FALSE);
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -149,10 +148,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
|
||||
exit(FALSE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,10 +183,8 @@ int date_main(int argc, char **argv)
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0) {
|
||||
fprintf(stderr, memory_exhausted, "date");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
@@ -202,8 +196,8 @@ int date_main(int argc, char **argv)
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
|
||||
date_fmt = *argv;
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
@@ -239,16 +233,13 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0) {
|
||||
fprintf(stderr, invalid_date, "date", date_str);
|
||||
exit(FALSE);
|
||||
}
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit(FALSE);
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,7 +267,7 @@ int date_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
|
||||
+25
-19
@@ -2,13 +2,13 @@
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code 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.
|
||||
* Based in part on code 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.
|
||||
*
|
||||
@@ -57,8 +57,8 @@ static const char dd_usage[] =
|
||||
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
@@ -114,11 +114,7 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc(blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Cannot allocate buffer\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
@@ -129,9 +125,12 @@ extern int dd_main(int argc, char **argv)
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror(inFile);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
@@ -140,10 +139,13 @@ extern int dd_main(int argc, char **argv)
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror(outFile);
|
||||
close(inFd);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
@@ -184,9 +186,13 @@ extern int dd_main(int argc, char **argv)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
|
||||
+17
-9
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -27,11 +27,9 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -40,7 +38,6 @@ static int df(char *device, const char *mountPoint)
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab *fstabItem;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
@@ -53,9 +50,9 @@ static int df(char *device, const char *mountPoint)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
@@ -78,6 +75,9 @@ extern int df_main(int argc, char **argv)
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
|
||||
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
}
|
||||
+47
-11
@@ -3,7 +3,7 @@
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -37,17 +37,21 @@
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7ld %s\n", size, filename);
|
||||
fprintf(stdout, "%ld\t%s\n", size, filename);
|
||||
}
|
||||
|
||||
static void print_summary(long size, char *filename)
|
||||
@@ -57,24 +61,26 @@ static void print_summary(long size, char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
int len;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
printf("du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
|
||||
/* Don't add in stuff pointed to by links */
|
||||
/* Don't add in stuff pointed to by symbolic links */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
return 0;
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
@@ -82,8 +88,14 @@ static long du(char *filename)
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) {
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(filename);
|
||||
if (filename[len - 1] == '/')
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char *name = entry->d_name;
|
||||
@@ -93,8 +105,9 @@ static long du(char *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
@@ -104,6 +117,17 @@ static long du(char *filename)
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
@@ -124,7 +148,11 @@ int du_main(int argc, char **argv)
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
@@ -144,13 +172,21 @@ int du_main(int argc, char **argv)
|
||||
|
||||
for (; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,137 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* echo implementation for busybox
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n\n"
|
||||
"Prints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n";
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
eflag = 0;
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
switch (c = *p++) {
|
||||
case 'a': c = '\007'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit( 0); /* exit */
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case '\\': break; /* c = '\\' */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
break;
|
||||
default:
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (*ap)
|
||||
putchar(' ');
|
||||
}
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kenneth Almquist.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -109,4 +109,4 @@ int head_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.8 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
+9
-2
@@ -2,8 +2,7 @@
|
||||
/*
|
||||
* Mini ln implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -128,3 +127,11 @@ extern int ln_main(int argc, char **argv)
|
||||
}
|
||||
exit TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+31
-14
@@ -70,11 +70,6 @@
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -93,7 +88,11 @@
|
||||
#define DISP_FULLTIME 32 /* show extended time display */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
#define DIR_RECURSE 256 /* -R (not yet implemented) */
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
@@ -450,10 +449,33 @@ static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
"R"
|
||||
"] [filenames...]\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tdo not hide entries starting with .\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-c\twith -l: show ctime (the time of last\n"
|
||||
"\t\tmodification of file status information)\n"
|
||||
#endif
|
||||
"] [filenames...]\n";
|
||||
"\t-d\tlist directory entries instead of contents\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-e\tlist both full date and full time\n"
|
||||
#endif
|
||||
"\t-l\tuse a long listing format\n"
|
||||
"\t-n\tlist numeric UIDs and GIDs instead of names\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-p\tappend indicator (one of /=@|) to entries\n"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-u\twith -l: show access time (the time of last\n"
|
||||
"\t\taccess of the file)\n"
|
||||
#endif
|
||||
"\t-x\tlist entries by lines instead of by columns\n"
|
||||
"\t-A\tdo not list implied . and ..\n"
|
||||
"\t-C\tlist entries by columns\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-F\tappend indicator (one of */=@|) to entries\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int ls_main(int argc, char **argv)
|
||||
{
|
||||
@@ -508,11 +530,6 @@ extern int ls_main(int argc, char **argv)
|
||||
case 'd':
|
||||
opts |= DIR_NOLIST;
|
||||
break;
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R':
|
||||
opts |= DIR_RECURSE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u':
|
||||
time_fmt = TIME_ACCESS;
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
/*
|
||||
* Mini mkdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
+2
-2
@@ -27,10 +27,10 @@
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
"Creates a named pipe (identical to 'mknod name p')\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n";
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
+39
-16
@@ -28,23 +28,47 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n\n"
|
||||
"Create a special file (block, character, or pipe).\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
|
||||
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n";
|
||||
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0;
|
||||
mode_t perm = 0666;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (argc != 5 || **(argv + 1) == '-') {
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
break;
|
||||
thisarg = *argv;
|
||||
thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--;
|
||||
argv++;
|
||||
parse_mode(*argv, &perm);
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc != 4 && argc != 2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
switch (argv[2][0]) {
|
||||
switch (argv[1][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
mode = S_IFCHR;
|
||||
@@ -54,23 +78,22 @@ int mknod_main(int argc, char **argv)
|
||||
break;
|
||||
case 'p':
|
||||
mode = S_IFIFO;
|
||||
if (argc!=2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
}
|
||||
|
||||
if (mode == S_IFCHR || mode == S_IFBLK) {
|
||||
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
|
||||
if (argc != 5) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[1]);
|
||||
}
|
||||
|
||||
mode |= 0666;
|
||||
mode |= perm;
|
||||
|
||||
if (mknod(argv[1], mode, dev) != 0) {
|
||||
perror(argv[1]);
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
if (mknod(argv[0], mode, dev) != 0)
|
||||
fatalError("%s: %s\n", argv[0], strerror(errno));
|
||||
exit (TRUE);
|
||||
}
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ static void verify __P((char *s, char *end));
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
|
||||
static const char printf_usage[] = "printf format [argument...]\n";
|
||||
static const char printf_usage[] = "printf format [argument...]\n\nFormats and prints the given data.\n";
|
||||
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@
|
||||
* Mini rm implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -42,7 +42,7 @@ static int forceFlag = FALSE;
|
||||
static const char *srcName;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (unlink(fileName) < 0) {
|
||||
perror(fileName);
|
||||
@@ -51,7 +51,7 @@ static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int dirAction(const char *fileName, struct stat *statbuf)
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
@@ -95,7 +95,7 @@ extern int rm_main(int argc, char **argv)
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
} else {
|
||||
if (recursiveAction(srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
TRUE, fileAction, dirAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Mini rmdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
+25
-35
@@ -3,7 +3,7 @@
|
||||
* Mini sort implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,7 +29,18 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
|
||||
static const char sort_usage[] = "sort [-n]"
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
" [-r]"
|
||||
#endif
|
||||
" [FILE]...\n\nSorts lines of text in the specified files\n";
|
||||
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
|
||||
static int reverse = 0;
|
||||
#else
|
||||
#define APPLY_REVERSE(x) (x)
|
||||
#endif
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
@@ -43,7 +54,6 @@ typedef struct Line {
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
@@ -60,36 +70,23 @@ static const int max = 1024;
|
||||
static Line *line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Initialize Line with string */
|
||||
static Line *line_init(Line * self, const char *string)
|
||||
{
|
||||
self->data = malloc((strlen(string) + 1) * sizeof(char));
|
||||
|
||||
if (self->data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(self->data, string);
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *line_newFromFile(FILE * src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
char *cstring = NULL;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
if ((cstring = cstring_lineFromFile(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
line_init(self, buffer);
|
||||
self->data = cstring;
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
@@ -120,7 +117,7 @@ static int compare_ascii(const void *a, const void *b)
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
return APPLY_REVERSE(strcmp(x->data, y->data));
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
@@ -138,7 +135,7 @@ static int compare_numeric(const void *a, const void *b)
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
return APPLY_REVERSE(xint - yint);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +163,7 @@ static List *list_insert(List * self, Line * line)
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
@@ -230,12 +227,6 @@ static void list_release(List * self)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* I need a list
|
||||
* to insert lines into
|
||||
* then I need to sort this list
|
||||
* and finally print it
|
||||
*/
|
||||
|
||||
int sort_main(int argc, char **argv)
|
||||
{
|
||||
@@ -254,20 +245,19 @@ int sort_main(int argc, char **argv)
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
/* numeric comparison */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
case 'r':
|
||||
/* reverse */
|
||||
reverse = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
@@ -310,4 +300,4 @@ int sort_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: sort.c,v 1.15 2000/04/17 04:22:09 beppu Exp $ */
|
||||
+3
-1
@@ -330,7 +330,7 @@ static int tail_file(const char *filename, off_t n_units)
|
||||
/* Not standard input. */
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
errorMsg("open error");
|
||||
fatalError("open error");
|
||||
|
||||
errors = tail_lines(filename, fd, (long) n_units);
|
||||
close(fd);
|
||||
@@ -444,6 +444,8 @@ extern int tail_main(int argc, char **argv)
|
||||
#define NDEBUG 1
|
||||
|
||||
|
||||
static void detailed_error(int i, int errnum, char *fmt, ...)
|
||||
__attribute__ ((format (printf, 3, 4)));
|
||||
static void detailed_error(int i, int errnum, char *fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
|
||||
+12
-3
@@ -3,7 +3,7 @@
|
||||
* Mini tee implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
@@ -38,7 +39,7 @@ static const char tee_usage[] =
|
||||
/* FileList _______________________________________________________________ */
|
||||
|
||||
#define FL_MAX 1024
|
||||
static FILE *FileList[FL_MAX];
|
||||
static FILE **FileList;
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function) (FILE * file, char c);
|
||||
@@ -99,6 +100,11 @@ int tee_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* init FILE pointers */
|
||||
FileList = calloc(FL_MAX, sizeof(FILE*));
|
||||
if (!FileList) {
|
||||
fprintf(stderr, "tee: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for (; i < argc; i++) {
|
||||
@@ -119,7 +125,10 @@ int tee_main(int argc, char **argv)
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
/* Don't bother to close files Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* free(FileList); */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.6 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: tee.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
@@ -0,0 +1,589 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* test implementation for busybox
|
||||
*
|
||||
* Copyright (c) by a whole pile of folks:
|
||||
*
|
||||
* test(1); version 7-like -- author Erik Baalbergen
|
||||
* modified by Eric Gisin to be used as built-in.
|
||||
* modified by Arnold Robbins to add SVR3 compatibility
|
||||
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
|
||||
* modified by J.T. Conklin for NetBSD.
|
||||
* modified by Herbert Xu to be used as built-in in ash.
|
||||
* modified by Erik Andersen <andersee@debian.org> to be used
|
||||
* in busybox.
|
||||
*
|
||||
* 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 states:
|
||||
* "This program is in the Public Domain."
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* test(1) accepts the following grammar:
|
||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
||||
nexpr ::= primary | "!" primary
|
||||
primary ::= unary-operator operand
|
||||
| operand binary-operator operand
|
||||
| operand
|
||||
| "(" oexpr ")"
|
||||
;
|
||||
unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
|
||||
"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
|
||||
|
||||
binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
|
||||
"-nt"|"-ot"|"-ef";
|
||||
operand ::= <any legal UNIX file name>
|
||||
*/
|
||||
|
||||
enum token {
|
||||
EOI,
|
||||
FILRD,
|
||||
FILWR,
|
||||
FILEX,
|
||||
FILEXIST,
|
||||
FILREG,
|
||||
FILDIR,
|
||||
FILCDEV,
|
||||
FILBDEV,
|
||||
FILFIFO,
|
||||
FILSOCK,
|
||||
FILSYM,
|
||||
FILGZ,
|
||||
FILTT,
|
||||
FILSUID,
|
||||
FILSGID,
|
||||
FILSTCK,
|
||||
FILNT,
|
||||
FILOT,
|
||||
FILEQ,
|
||||
FILUID,
|
||||
FILGID,
|
||||
STREZ,
|
||||
STRNZ,
|
||||
STREQ,
|
||||
STRNE,
|
||||
STRLT,
|
||||
STRGT,
|
||||
INTEQ,
|
||||
INTNE,
|
||||
INTGE,
|
||||
INTGT,
|
||||
INTLE,
|
||||
INTLT,
|
||||
UNOT,
|
||||
BAND,
|
||||
BOR,
|
||||
LPAREN,
|
||||
RPAREN,
|
||||
OPERAND
|
||||
};
|
||||
|
||||
enum token_types {
|
||||
UNOP,
|
||||
BINOP,
|
||||
BUNOP,
|
||||
BBINOP,
|
||||
PAREN
|
||||
};
|
||||
|
||||
struct t_op {
|
||||
const char *op_text;
|
||||
short op_num, op_type;
|
||||
} const ops [] = {
|
||||
{"-r", FILRD, UNOP},
|
||||
{"-w", FILWR, UNOP},
|
||||
{"-x", FILEX, UNOP},
|
||||
{"-e", FILEXIST,UNOP},
|
||||
{"-f", FILREG, UNOP},
|
||||
{"-d", FILDIR, UNOP},
|
||||
{"-c", FILCDEV,UNOP},
|
||||
{"-b", FILBDEV,UNOP},
|
||||
{"-p", FILFIFO,UNOP},
|
||||
{"-u", FILSUID,UNOP},
|
||||
{"-g", FILSGID,UNOP},
|
||||
{"-k", FILSTCK,UNOP},
|
||||
{"-s", FILGZ, UNOP},
|
||||
{"-t", FILTT, UNOP},
|
||||
{"-z", STREZ, UNOP},
|
||||
{"-n", STRNZ, UNOP},
|
||||
{"-h", FILSYM, UNOP}, /* for backwards compat */
|
||||
{"-O", FILUID, UNOP},
|
||||
{"-G", FILGID, UNOP},
|
||||
{"-L", FILSYM, UNOP},
|
||||
{"-S", FILSOCK,UNOP},
|
||||
{"=", STREQ, BINOP},
|
||||
{"!=", STRNE, BINOP},
|
||||
{"<", STRLT, BINOP},
|
||||
{">", STRGT, BINOP},
|
||||
{"-eq", INTEQ, BINOP},
|
||||
{"-ne", INTNE, BINOP},
|
||||
{"-ge", INTGE, BINOP},
|
||||
{"-gt", INTGT, BINOP},
|
||||
{"-le", INTLE, BINOP},
|
||||
{"-lt", INTLT, BINOP},
|
||||
{"-nt", FILNT, BINOP},
|
||||
{"-ot", FILOT, BINOP},
|
||||
{"-ef", FILEQ, BINOP},
|
||||
{"!", UNOT, BUNOP},
|
||||
{"-a", BAND, BBINOP},
|
||||
{"-o", BOR, BBINOP},
|
||||
{"(", LPAREN, PAREN},
|
||||
{")", RPAREN, PAREN},
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
char **t_wp;
|
||||
struct t_op const *t_wp_op;
|
||||
static gid_t *group_array = NULL;
|
||||
static int ngroups;
|
||||
|
||||
static enum token t_lex();
|
||||
static int oexpr();
|
||||
static int aexpr();
|
||||
static int nexpr();
|
||||
static int binop();
|
||||
static int primary();
|
||||
static int filstat();
|
||||
static int getn();
|
||||
static int newerf();
|
||||
static int olderf();
|
||||
static int equalf();
|
||||
static void syntax();
|
||||
static int test_eaccess();
|
||||
static int is_a_group_member();
|
||||
static void initialize_group_array();
|
||||
|
||||
extern int
|
||||
test_main(int argc, char** argv)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (strcmp(argv[0], "[") == 0) {
|
||||
if (strcmp(argv[--argc], "]"))
|
||||
fatalError("missing ]");
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
usage("test EXPRESSION\n"
|
||||
"or [ EXPRESSION ]\n\n"
|
||||
"Checks file types and compares values returning an exit\n"
|
||||
"code determined by the value of EXPRESSION.\n");
|
||||
}
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
switch (argc) {
|
||||
case 1:
|
||||
exit( 1);
|
||||
case 2:
|
||||
exit (*argv[1] == '\0');
|
||||
case 3:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
exit (!(*argv[2] == '\0'));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (argv[1][0] != '!' || argv[1][1] != '\0') {
|
||||
if (t_lex(argv[2]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[1];
|
||||
exit (binop() == 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
if (t_lex(argv[3]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[2];
|
||||
exit (!(binop() == 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
t_wp = &argv[1];
|
||||
res = !oexpr(t_lex(*t_wp));
|
||||
|
||||
if (*t_wp != NULL && *++t_wp != NULL)
|
||||
syntax(*t_wp, "unknown operand");
|
||||
|
||||
exit( res);
|
||||
}
|
||||
|
||||
static void
|
||||
syntax(op, msg)
|
||||
char *op;
|
||||
char *msg;
|
||||
{
|
||||
if (op && *op)
|
||||
fatalError("%s: %s", op, msg);
|
||||
else
|
||||
fatalError("%s", msg);
|
||||
}
|
||||
|
||||
static int
|
||||
oexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR)
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
aexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = nexpr(n);
|
||||
if (t_lex(*++t_wp) == BAND)
|
||||
return aexpr(t_lex(*++t_wp)) && res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
nexpr(n)
|
||||
enum token n; /* token */
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
}
|
||||
|
||||
static int
|
||||
primary(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
if (n == EOI)
|
||||
syntax(NULL, "argument expected");
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
syntax(NULL, "closing paren expected");
|
||||
return res;
|
||||
}
|
||||
if (t_wp_op && t_wp_op->op_type == UNOP) {
|
||||
/* unary expression */
|
||||
if (*++t_wp == NULL)
|
||||
syntax(t_wp_op->op_text, "argument expected");
|
||||
switch (n) {
|
||||
case STREZ:
|
||||
return strlen(*t_wp) == 0;
|
||||
case STRNZ:
|
||||
return strlen(*t_wp) != 0;
|
||||
case FILTT:
|
||||
return isatty(getn(*t_wp));
|
||||
default:
|
||||
return filstat(*t_wp, n);
|
||||
}
|
||||
}
|
||||
|
||||
if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
|
||||
return strlen(*t_wp) > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
binop()
|
||||
{
|
||||
const char *opnd1, *opnd2;
|
||||
struct t_op const *op;
|
||||
|
||||
opnd1 = *t_wp;
|
||||
(void) t_lex(*++t_wp);
|
||||
op = t_wp_op;
|
||||
|
||||
if ((opnd2 = *++t_wp) == (char *)0)
|
||||
syntax(op->op_text, "argument expected");
|
||||
|
||||
switch (op->op_num) {
|
||||
case STREQ:
|
||||
return strcmp(opnd1, opnd2) == 0;
|
||||
case STRNE:
|
||||
return strcmp(opnd1, opnd2) != 0;
|
||||
case STRLT:
|
||||
return strcmp(opnd1, opnd2) < 0;
|
||||
case STRGT:
|
||||
return strcmp(opnd1, opnd2) > 0;
|
||||
case INTEQ:
|
||||
return getn(opnd1) == getn(opnd2);
|
||||
case INTNE:
|
||||
return getn(opnd1) != getn(opnd2);
|
||||
case INTGE:
|
||||
return getn(opnd1) >= getn(opnd2);
|
||||
case INTGT:
|
||||
return getn(opnd1) > getn(opnd2);
|
||||
case INTLE:
|
||||
return getn(opnd1) <= getn(opnd2);
|
||||
case INTLT:
|
||||
return getn(opnd1) < getn(opnd2);
|
||||
case FILNT:
|
||||
return newerf (opnd1, opnd2);
|
||||
case FILOT:
|
||||
return olderf (opnd1, opnd2);
|
||||
case FILEQ:
|
||||
return equalf (opnd1, opnd2);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
filstat(nm, mode)
|
||||
char *nm;
|
||||
enum token mode;
|
||||
{
|
||||
struct stat s;
|
||||
int i;
|
||||
|
||||
if (mode == FILSYM) {
|
||||
#ifdef S_IFLNK
|
||||
if (lstat(nm, &s) == 0) {
|
||||
i = S_IFLNK;
|
||||
goto filetype;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stat(nm, &s) != 0)
|
||||
return 0;
|
||||
|
||||
switch (mode) {
|
||||
case FILRD:
|
||||
return test_eaccess(nm, R_OK) == 0;
|
||||
case FILWR:
|
||||
return test_eaccess(nm, W_OK) == 0;
|
||||
case FILEX:
|
||||
return test_eaccess(nm, X_OK) == 0;
|
||||
case FILEXIST:
|
||||
return 1;
|
||||
case FILREG:
|
||||
i = S_IFREG;
|
||||
goto filetype;
|
||||
case FILDIR:
|
||||
i = S_IFDIR;
|
||||
goto filetype;
|
||||
case FILCDEV:
|
||||
i = S_IFCHR;
|
||||
goto filetype;
|
||||
case FILBDEV:
|
||||
i = S_IFBLK;
|
||||
goto filetype;
|
||||
case FILFIFO:
|
||||
#ifdef S_IFIFO
|
||||
i = S_IFIFO;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSOCK:
|
||||
#ifdef S_IFSOCK
|
||||
i = S_IFSOCK;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSUID:
|
||||
i = S_ISUID;
|
||||
goto filebit;
|
||||
case FILSGID:
|
||||
i = S_ISGID;
|
||||
goto filebit;
|
||||
case FILSTCK:
|
||||
i = S_ISVTX;
|
||||
goto filebit;
|
||||
case FILGZ:
|
||||
return s.st_size > 0L;
|
||||
case FILUID:
|
||||
return s.st_uid == geteuid();
|
||||
case FILGID:
|
||||
return s.st_gid == getegid();
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
filetype:
|
||||
return ((s.st_mode & S_IFMT) == i);
|
||||
|
||||
filebit:
|
||||
return ((s.st_mode & i) != 0);
|
||||
}
|
||||
|
||||
static enum token
|
||||
t_lex(s)
|
||||
char *s;
|
||||
{
|
||||
struct t_op const *op = ops;
|
||||
|
||||
if (s == 0) {
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return EOI;
|
||||
}
|
||||
while (op->op_text) {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
t_wp_op = op;
|
||||
return op->op_num;
|
||||
}
|
||||
op++;
|
||||
}
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
/* atoi with error detection */
|
||||
static int
|
||||
getn(s)
|
||||
char *s;
|
||||
{
|
||||
char *p;
|
||||
long r;
|
||||
|
||||
errno = 0;
|
||||
r = strtol(s, &p, 10);
|
||||
|
||||
if (errno != 0)
|
||||
fatalError("%s: out of range", s);
|
||||
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
|
||||
if (*p)
|
||||
fatalError("%s: bad number", s);
|
||||
|
||||
return (int) r;
|
||||
}
|
||||
|
||||
static int
|
||||
newerf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
olderf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
equalf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev &&
|
||||
b1.st_ino == b2.st_ino);
|
||||
}
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int
|
||||
test_eaccess (path, mode)
|
||||
char *path;
|
||||
int mode;
|
||||
{
|
||||
struct stat st;
|
||||
int euid = geteuid();
|
||||
|
||||
if (stat (path, &st) < 0)
|
||||
return (-1);
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return (0);
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member (st.st_gid))
|
||||
mode <<= 3;
|
||||
|
||||
if (st.st_mode & mode)
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_group_array ()
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
|
||||
fatalError("Out of space");
|
||||
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
static int
|
||||
is_a_group_member (gid)
|
||||
gid_t gid;
|
||||
{
|
||||
register int i;
|
||||
|
||||
/* Short-circuit if possible, maybe saving a call to getgroups(). */
|
||||
if (gid == getgid() || gid == getegid())
|
||||
return (1);
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array ();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == group_array[i])
|
||||
return (1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Mini touch implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
+574
@@ -0,0 +1,574 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (c) 1988, 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
|
||||
"$Id: tr.c,v 1.4 2000/04/17 16:44:46 erik Exp $";
|
||||
#endif /* not lint */
|
||||
#endif /* #if 0 */
|
||||
|
||||
#include "internal.h"
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
enum { STRING1, STRING2 } which;
|
||||
enum { EOS, INFINITE, NORMAL, RANGE, SEQUENCE, SET } state;
|
||||
int cnt; /* character count */
|
||||
int lastch; /* last character */
|
||||
int equiv[2]; /* equivalence set */
|
||||
int *set; /* set of characters */
|
||||
char *str; /* user's string */
|
||||
} STR;
|
||||
|
||||
#include <limits.h>
|
||||
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
|
||||
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
|
||||
|
||||
static int next __P((STR *));
|
||||
|
||||
static int string1[NCHARS] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
}, string2[NCHARS];
|
||||
|
||||
STR s1 = { STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
STR s2 = { STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
|
||||
static void setup(string, arg, str, cflag)
|
||||
int *string;
|
||||
char *arg;
|
||||
STR *str;
|
||||
int cflag;
|
||||
{
|
||||
register int cnt, *p;
|
||||
|
||||
str->str = arg;
|
||||
bzero(string, NCHARS * sizeof(int));
|
||||
|
||||
while (next(str))
|
||||
string[str->lastch] = 1;
|
||||
if (cflag)
|
||||
for (p = string, cnt = NCHARS; cnt--; ++p)
|
||||
*p = !*p;
|
||||
}
|
||||
|
||||
static void tr_usage()
|
||||
{
|
||||
usage( "\ttr [-cdsu] string1 [string2]\n\n"
|
||||
"Translate, squeeze, and/or delete characters from standard\n"
|
||||
"input, writing to standard output.\n");
|
||||
}
|
||||
|
||||
|
||||
extern int tr_main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int ch, cnt, lastch, *p;
|
||||
int cflag, dflag, sflag, isstring2;
|
||||
|
||||
(void) setlocale(LC_CTYPE, "");
|
||||
|
||||
cflag = dflag = sflag = 0;
|
||||
while ((ch = getopt(argc, argv, "cdsu")) != -1)
|
||||
switch ((char) ch) {
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case 'u':
|
||||
setbuf(stdout, (char *) NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
tr_usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
default:
|
||||
tr_usage();
|
||||
/* NOTREACHED */
|
||||
case 1:
|
||||
isstring2 = 0;
|
||||
break;
|
||||
case 2:
|
||||
isstring2 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -ds [-c] string1 string2
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
* Squeeze all characters in string2.
|
||||
*/
|
||||
if (dflag && sflag) {
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
setup(string2, argv[1], &s2, 0);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] && (!string2[ch] || lastch != ch)) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -d [-c] string1
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (dflag) {
|
||||
if (isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
while ((ch = getchar()) != EOF)
|
||||
if (!string1[ch])
|
||||
(void) putchar(ch);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -s [-c] string1
|
||||
* Squeeze all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (sflag && !isstring2) {
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr [-cs] string1 string2
|
||||
* Replace all characters (or complemented characters) in string1 with
|
||||
* the character in the same position in string2. If the -s option is
|
||||
* specified, squeeze all the characters in string2.
|
||||
*/
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
s1.str = argv[0];
|
||||
s2.str = argv[1];
|
||||
|
||||
if (cflag)
|
||||
for (cnt = NCHARS, p = string1; cnt--;)
|
||||
*p++ = OOBCH;
|
||||
|
||||
if (!next(&s2))
|
||||
errx(1, "empty string2");
|
||||
|
||||
/* If string2 runs out of characters, use the last one specified. */
|
||||
if (sflag)
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
string2[ch] = 1;
|
||||
(void) next(&s2);
|
||||
} else
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
(void) next(&s2);
|
||||
}
|
||||
|
||||
if (cflag)
|
||||
for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
|
||||
*p = *p == OOBCH ? ch : cnt;
|
||||
|
||||
if (sflag)
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
|
||||
ch = string1[ch];
|
||||
if (!string2[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
} else
|
||||
while ((ch = getchar()) != EOF)
|
||||
(void) putchar(string1[ch]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int backslash __P((STR *));
|
||||
static int bracket __P((STR *));
|
||||
static int c_class __P((const void *, const void *));
|
||||
static void genclass __P((STR *));
|
||||
static void genequiv __P((STR *));
|
||||
static int genrange __P((STR *));
|
||||
static void genseq __P((STR *));
|
||||
|
||||
static int next(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch;
|
||||
|
||||
switch (s->state) {
|
||||
case EOS:
|
||||
return (0);
|
||||
case INFINITE:
|
||||
return (1);
|
||||
case NORMAL:
|
||||
switch (ch = (u_char) * s->str) {
|
||||
case '\0':
|
||||
s->state = EOS;
|
||||
return (0);
|
||||
case '\\':
|
||||
s->lastch = backslash(s);
|
||||
break;
|
||||
case '[':
|
||||
if (bracket(s))
|
||||
return (next(s));
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
++s->str;
|
||||
s->lastch = ch;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We can start a range at any time. */
|
||||
if (s->str[0] == '-' && genrange(s))
|
||||
return (next(s));
|
||||
return (1);
|
||||
case RANGE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
++s->lastch;
|
||||
return (1);
|
||||
case SEQUENCE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
case SET:
|
||||
if ((s->lastch = s->set[s->cnt++]) == OOBCH) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int bracket(s)
|
||||
register STR *s;
|
||||
{
|
||||
register char *p;
|
||||
|
||||
switch (s->str[1]) {
|
||||
case ':': /* "[:class:]" */
|
||||
if ((p = strstr(s->str + 2, ":]")) == NULL)
|
||||
return (0);
|
||||
*p = '\0';
|
||||
s->str += 2;
|
||||
genclass(s);
|
||||
s->str = p + 2;
|
||||
return (1);
|
||||
case '=': /* "[=equiv=]" */
|
||||
if ((p = strstr(s->str + 2, "=]")) == NULL)
|
||||
return (0);
|
||||
s->str += 2;
|
||||
genequiv(s);
|
||||
return (1);
|
||||
default: /* "[\###*n]" or "[#*n]" */
|
||||
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
|
||||
return (0);
|
||||
if (p[0] != '*' || index(p, ']') == NULL)
|
||||
return (0);
|
||||
s->str += 1;
|
||||
genseq(s);
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int (*func) __P((int));
|
||||
int *set;
|
||||
} CLASS;
|
||||
|
||||
static CLASS classes[] = {
|
||||
#undef isalnum
|
||||
{"alnum", isalnum,},
|
||||
#undef isalpha
|
||||
{"alpha", isalpha,},
|
||||
/*#undef isblank
|
||||
{ "blank", isblank, },*/
|
||||
#undef iscntrl
|
||||
{"cntrl", iscntrl,},
|
||||
#undef isdigit
|
||||
{"digit", isdigit,},
|
||||
#undef isgraph
|
||||
{"graph", isgraph,},
|
||||
#undef islower
|
||||
{"lower", islower,},
|
||||
#undef isprint
|
||||
{"print", isprint,},
|
||||
#undef ispunct
|
||||
{"punct", ispunct,},
|
||||
#undef isspace
|
||||
{"space", isspace,},
|
||||
#undef isupper
|
||||
{"upper", isupper,},
|
||||
#undef isxdigit
|
||||
{"xdigit", isxdigit,},
|
||||
};
|
||||
|
||||
static void genclass(s)
|
||||
STR *s;
|
||||
{
|
||||
register int cnt, (*func) __P((int));
|
||||
CLASS *cp, tmp;
|
||||
int *p;
|
||||
|
||||
tmp.name = s->str;
|
||||
if ((cp = (CLASS *) bsearch(&tmp, classes, sizeof(classes) /
|
||||
sizeof(CLASS), sizeof(CLASS),
|
||||
c_class)) == NULL) errx(1,
|
||||
"unknown class %s",
|
||||
s->str);
|
||||
|
||||
cp->set = p = xmalloc((NCHARS + 1) * sizeof(int));
|
||||
bzero(p, (NCHARS + 1) * sizeof(int));
|
||||
|
||||
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
|
||||
if ((func) (cnt))
|
||||
*p++ = cnt;
|
||||
*p = OOBCH;
|
||||
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = cp->set;
|
||||
}
|
||||
|
||||
static int c_class(a, b)
|
||||
const void *a, *b;
|
||||
{
|
||||
return (strcmp(((CLASS *) a)->name, ((CLASS *) b)->name));
|
||||
}
|
||||
|
||||
/*
|
||||
* English doesn't have any equivalence classes, so for now
|
||||
* we just syntax check and grab the character.
|
||||
*/
|
||||
static void genequiv(s)
|
||||
STR *s;
|
||||
{
|
||||
if (*s->str == '\\') {
|
||||
s->equiv[0] = backslash(s);
|
||||
if (*s->str != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
} else {
|
||||
s->equiv[0] = s->str[0];
|
||||
if (s->str[1] != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
}
|
||||
s->str += 2;
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = s->equiv;
|
||||
}
|
||||
|
||||
static int genrange(s)
|
||||
STR *s;
|
||||
{
|
||||
int stopval;
|
||||
char *savestart;
|
||||
|
||||
savestart = s->str;
|
||||
stopval = *++s->str == '\\' ? backslash(s) : (u_char) * s->str++;
|
||||
if (stopval < (u_char) s->lastch) {
|
||||
s->str = savestart;
|
||||
return (0);
|
||||
}
|
||||
s->cnt = stopval - s->lastch + 1;
|
||||
s->state = RANGE;
|
||||
--s->lastch;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void genseq(s)
|
||||
STR *s;
|
||||
{
|
||||
char *ep;
|
||||
|
||||
if (s->which == STRING1)
|
||||
errx(1, "sequences only valid in string2");
|
||||
|
||||
if (*s->str == '\\')
|
||||
s->lastch = backslash(s);
|
||||
else
|
||||
s->lastch = *s->str++;
|
||||
if (*s->str != '*')
|
||||
errx(1, "misplaced sequence asterisk");
|
||||
|
||||
switch (*++s->str) {
|
||||
case '\\':
|
||||
s->cnt = backslash(s);
|
||||
break;
|
||||
case ']':
|
||||
s->cnt = 0;
|
||||
++s->str;
|
||||
break;
|
||||
default:
|
||||
if (isdigit((u_char) * s->str)) {
|
||||
s->cnt = strtol(s->str, &ep, 0);
|
||||
if (*ep == ']') {
|
||||
s->str = ep + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
errx(1, "illegal sequence count");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
s->state = s->cnt ? SEQUENCE : INFINITE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate \??? into a character. Up to 3 octal digits, if no digits either
|
||||
* an escape code or a literal character.
|
||||
*/
|
||||
static int backslash(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch, cnt, val;
|
||||
|
||||
for (cnt = val = 0;;) {
|
||||
ch = (u_char) * ++s->str;
|
||||
if (!isascii(ch) || !isdigit(ch))
|
||||
break;
|
||||
val = val * 8 + ch - '0';
|
||||
if (++cnt == 3) {
|
||||
++s->str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cnt)
|
||||
return (val);
|
||||
if (ch != '\0')
|
||||
++s->str;
|
||||
switch (ch) {
|
||||
case 'a': /* escape characters */
|
||||
return ('\7');
|
||||
case 'b':
|
||||
return ('\b');
|
||||
case 'f':
|
||||
return ('\f');
|
||||
case 'n':
|
||||
return ('\n');
|
||||
case 'r':
|
||||
return ('\r');
|
||||
case 't':
|
||||
return ('\t');
|
||||
case 'v':
|
||||
return ('\13');
|
||||
case '\0': /* \" -> \ */
|
||||
s->state = EOS;
|
||||
return ('\\');
|
||||
default: /* \x" -> x */
|
||||
return (ch);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -25,8 +25,8 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
static const char tty_usage[] = "tty\n\n"
|
||||
"Print the file name of the terminal connected to standard input.\n"
|
||||
|
||||
"Print the file name of the terminal connected to standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tprint nothing, only return an exit status\n";
|
||||
|
||||
extern int tty_main(int argc, char **argv)
|
||||
|
||||
+4
-1
@@ -43,6 +43,7 @@
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
@@ -52,7 +53,9 @@ static const char uname_usage[] =
|
||||
"\t-s\tprint the operating system name\n"
|
||||
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n";
|
||||
"\t-v\tprint the operating system version\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
|
||||
+5
-11
@@ -3,7 +3,7 @@
|
||||
* Mini uniq implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,15 +28,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n";
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n\n"
|
||||
"Discard all but one of successive identical lines from INPUT\n"
|
||||
"(or standard input), writing to OUTPUT (or standard output).\n";
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
@@ -190,4 +184,4 @@ int uniq_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.7 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: uniq.c,v 1.9 2000/04/17 16:16:10 erik Exp $ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini usleep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char usleep_usage[] = "usleep N\n\n" "Pause for N microseconds.\n";
|
||||
|
||||
extern int usleep_main(int argc, char **argv)
|
||||
{
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(usleep_usage);
|
||||
}
|
||||
|
||||
usleep(atoi(*(++argv))); /* return void */
|
||||
exit(TRUE);
|
||||
}
|
||||
+2
-1
@@ -25,7 +25,8 @@
|
||||
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
||||
"Print line, word, and byte counts for each FILE, and a total line if\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tprint the byte counts\n"
|
||||
"\t-l\tprint the newline counts\n"
|
||||
|
||||
|
||||
+1
-3
@@ -25,9 +25,7 @@
|
||||
#include <pwd.h>
|
||||
|
||||
static const char whoami_usage[] = "whoami\n\n"
|
||||
"Print the user name associated with the current effective user id.\n"
|
||||
|
||||
"Same as id -un.\n";
|
||||
"Prints the user name associated with the current effective user id.\n";
|
||||
|
||||
extern int whoami_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
+7
-1
@@ -27,12 +27,18 @@ extern int yes_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc == 1)
|
||||
if (argc >=1 && *argv[1]=='-') {
|
||||
usage("yes [OPTION]... [STRING]...\n\n"
|
||||
"Repeatedly outputs a line with all specified STRING(s), or `y'.\n");
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
while (1)
|
||||
if (puts("y") == EOF) {
|
||||
perror("yes");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
for (i = 1; i < argc; i++)
|
||||
|
||||
@@ -37,11 +37,15 @@
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define is_cp 0
|
||||
#define is_mv 1
|
||||
static int dz_i; /* index into cp_mv_usage */
|
||||
static const char *dz; /* dollar zero, .bss */
|
||||
static int dz_i; /* index, .bss */
|
||||
static const char *cp_mv_usage[] = /* .rodata */
|
||||
{
|
||||
"cp [OPTION]... SOURCE DEST\n"
|
||||
@@ -55,92 +59,131 @@ static const char *cp_mv_usage[] = /* .rodata */
|
||||
"mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
"Warning!! This is not GNU `mv'. It does not preserve hard links.\n"
|
||||
};
|
||||
|
||||
static int recursiveFlag;
|
||||
static int followLinks;
|
||||
static int preserveFlag;
|
||||
|
||||
static const char *baseSrcName;
|
||||
static int srcDirFlag;
|
||||
static struct stat srcStatBuf;
|
||||
|
||||
static char baseDestName[PATH_MAX + 1];
|
||||
static size_t baseDestLen;
|
||||
static int destDirFlag;
|
||||
static struct stat destStatBuf;
|
||||
|
||||
static jmp_buf catch;
|
||||
static volatile int mv_Action_first_time;
|
||||
|
||||
static void name_too_long__exit (void) __attribute__((noreturn));
|
||||
|
||||
static
|
||||
void name_too_long__exit (void)
|
||||
{
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
const char *srcBasename;
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > PATH_MAX)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > PATH_MAX)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
char destName[PATH_MAX + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
char *name;
|
||||
|
||||
strcpy(destName, baseDestName);
|
||||
destLen = strlen(destName);
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, dz, baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
}
|
||||
else if (destDirFlag == TRUE) {
|
||||
fill_baseDest_buf(&destName[0], &destLen);
|
||||
}
|
||||
else {
|
||||
srcBasename = baseSrcName;
|
||||
}
|
||||
if (mv_Action_first_time && (dz_i == is_mv)) {
|
||||
mv_Action_first_time = errno = 0;
|
||||
if (rename(fileName, destName) < 0 && errno != EXDEV) {
|
||||
fprintf(stderr, "%s: rename(%s, %s): %s\n",
|
||||
dz, fileName, destName, strerror(errno));
|
||||
goto do_copyFile; /* Try anyway... */
|
||||
}
|
||||
else if (errno == EXDEV)
|
||||
goto do_copyFile;
|
||||
else
|
||||
longjmp(catch, 1); /* succeeded with rename() */
|
||||
}
|
||||
do_copyFile:
|
||||
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
|
||||
if (is_in_ino_dev_hashtable(statbuf, &name)) {
|
||||
if (link(name, destName) < 0) {
|
||||
fprintf(stderr, "%s: link(%s, %s): %s\n",
|
||||
dz, name, destName, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(statbuf, destName);
|
||||
}
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks);
|
||||
}
|
||||
|
||||
static int
|
||||
rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
int status = TRUE;
|
||||
|
||||
if (S_ISDIR(statbuf->st_mode)) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
} else if (unlink(fileName) < 0) {
|
||||
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
extern int cp_mv_main(int argc, char **argv)
|
||||
{
|
||||
__label__ name_too_long__exit;
|
||||
__label__ exit_false;
|
||||
|
||||
int recursiveFlag;
|
||||
int followLinks;
|
||||
int preserveFlag;
|
||||
|
||||
const char *baseSrcName;
|
||||
int srcDirFlag;
|
||||
struct stat srcStatBuf;
|
||||
|
||||
char baseDestName[PATH_MAX + 1];
|
||||
size_t baseDestLen;
|
||||
int destDirFlag;
|
||||
struct stat destStatBuf;
|
||||
|
||||
void fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
const char *srcBasename;
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
}
|
||||
|
||||
int fileAction(const char *fileName, struct stat *statbuf) {
|
||||
char destName[PATH_MAX + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
|
||||
strcpy(destName, baseDestName);
|
||||
destLen = strlen(destName);
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, "cp", baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
} else if (destDirFlag == TRUE) {
|
||||
fill_baseDest_buf(&destName[0], &destLen);
|
||||
} else {
|
||||
srcBasename = baseSrcName;
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks);
|
||||
}
|
||||
|
||||
int rmfileAction(const char *fileName, struct stat *statbuf) {
|
||||
if (unlink(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int rmdirAction(const char *fileName, struct stat *statbuf) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((dz = strrchr(*argv, '/')) == NULL)
|
||||
dz = *argv;
|
||||
else
|
||||
dz++;
|
||||
dz = *argv; /* already basename'd by busybox.c:main */
|
||||
if (*dz == 'c' && *(dz + 1) == 'p')
|
||||
dz_i = is_cp;
|
||||
else
|
||||
@@ -199,53 +242,93 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 1) {
|
||||
size_t srcLen;
|
||||
int flags_memo;
|
||||
volatile int flags_memo;
|
||||
int status;
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
name_too_long__exit();
|
||||
|
||||
if (srcLen == 0)
|
||||
continue;
|
||||
if (srcLen == 0) continue; /* "" */
|
||||
|
||||
srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
|
||||
|
||||
if ((flags_memo = (recursiveFlag == TRUE &&
|
||||
srcDirFlag == TRUE && destDirFlag == TRUE))) {
|
||||
if ((destStatBuf.st_ino == srcStatBuf.st_ino) &&
|
||||
(destStatBuf.st_rdev == srcStatBuf.st_rdev)) {
|
||||
fprintf(stderr,
|
||||
"%s: Cannot %s `%s' into a subdirectory of itself, `%s/%s'\n",
|
||||
dz, dz, baseSrcName, baseDestName, baseSrcName);
|
||||
continue;
|
||||
|
||||
struct stat sb;
|
||||
int state = 0;
|
||||
char *pushd, *d, *p;
|
||||
|
||||
if ((pushd = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (chdir(baseDestName) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if ((d = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
while (!state && *d != '\0') {
|
||||
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
|
||||
fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno));
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((sb.st_ino == srcStatBuf.st_ino) &&
|
||||
(sb.st_dev == srcStatBuf.st_dev)) {
|
||||
fprintf(stderr,
|
||||
"%s: Cannot %s `%s' "
|
||||
"into a subdirectory of itself, `%s/%s'\n",
|
||||
dz, dz, baseSrcName, baseDestName, baseSrcName);
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((p = strrchr(d, '/')) != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
if (chdir(pushd) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno));
|
||||
free(pushd);
|
||||
free(d);
|
||||
continue;
|
||||
}
|
||||
free(pushd);
|
||||
free(d);
|
||||
if (state < 0)
|
||||
continue;
|
||||
else
|
||||
fill_baseDest_buf(baseDestName, &baseDestLen);
|
||||
}
|
||||
if (recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE)
|
||||
goto exit_false;
|
||||
|
||||
if (dz_i == is_mv &&
|
||||
recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE)
|
||||
goto exit_false;
|
||||
|
||||
status = setjmp(catch);
|
||||
if (status == 0) {
|
||||
mv_Action_first_time = 1;
|
||||
if (recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, FALSE,
|
||||
cp_mv_Action, cp_mv_Action, NULL) == FALSE) goto exit_false;
|
||||
if (dz_i == is_mv &&
|
||||
recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, TRUE,
|
||||
rm_Action, rm_Action, NULL) == FALSE) goto exit_false;
|
||||
}
|
||||
if (flags_memo)
|
||||
*(baseDestName + baseDestLen) = '\0';
|
||||
}
|
||||
|
||||
// exit_true:
|
||||
exit TRUE;
|
||||
|
||||
name_too_long__exit:
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
exit_false:
|
||||
exit_false:
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// c-file-style: "linux"
|
||||
// tab-width: 4
|
||||
// End:
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -64,8 +64,7 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
exit(FALSE);
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -149,10 +148,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
|
||||
exit(FALSE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,10 +183,8 @@ int date_main(int argc, char **argv)
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0) {
|
||||
fprintf(stderr, memory_exhausted, "date");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
@@ -202,8 +196,8 @@ int date_main(int argc, char **argv)
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
|
||||
date_fmt = *argv;
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
@@ -239,16 +233,13 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0) {
|
||||
fprintf(stderr, invalid_date, "date", date_str);
|
||||
exit(FALSE);
|
||||
}
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit(FALSE);
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,7 +267,7 @@ int date_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code 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.
|
||||
* Based in part on code 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.
|
||||
*
|
||||
@@ -57,8 +57,8 @@ static const char dd_usage[] =
|
||||
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
@@ -114,11 +114,7 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc(blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Cannot allocate buffer\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
@@ -129,9 +125,12 @@ extern int dd_main(int argc, char **argv)
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror(inFile);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
@@ -140,10 +139,13 @@ extern int dd_main(int argc, char **argv)
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror(outFile);
|
||||
close(inFd);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
@@ -184,9 +186,13 @@ extern int dd_main(int argc, char **argv)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# define.sh - creates an include file full of #defines
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# define.sh POSIX_ME_HARDER ...
|
||||
#
|
||||
# <GPL>
|
||||
|
||||
for i ; do
|
||||
case $1 in
|
||||
!!*!!)
|
||||
echo "// #define" `echo $1 | sed 's/^!!\(.*\)!!$/\1/'`
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "#define $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# </GPL>
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -27,11 +27,9 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -40,7 +38,6 @@ static int df(char *device, const char *mountPoint)
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab *fstabItem;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
@@ -53,9 +50,9 @@ static int df(char *device, const char *mountPoint)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
@@ -78,6 +75,9 @@ extern int df_main(int argc, char **argv)
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
|
||||
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ int dmesg_main(int argc, char **argv)
|
||||
|
||||
if (bufsize < 4096)
|
||||
bufsize = 4096;
|
||||
buf = (char *) malloc(bufsize);
|
||||
buf = (char *) xmalloc(bufsize);
|
||||
n = klogctl(cmd, buf, bufsize);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
|
||||
-1025
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
# busybox/docs/Makefile - Create the documentation
|
||||
# ------------------------
|
||||
# Copyright (C) 2000 Erik Andersen <andersee@debian.org> GPL
|
||||
|
||||
all: clean doc
|
||||
|
||||
doc:
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
pod2html busybox.pod > ../BusyBox.html
|
||||
@rm pod2html-*
|
||||
pod2man --center=BusyBox --release="version $(VERSION)" busybox.pod > ../BusyBox.1
|
||||
pod2text busybox.pod > ../BusyBox.txt
|
||||
@rm -f pod2html*
|
||||
|
||||
clean:
|
||||
@rm -f ../BusyBox.html ../BusyBox.1 ../BusyBox.txt pod2html*
|
||||
|
||||
distclean: clean
|
||||
|
||||
+1445
-272
File diff suppressed because it is too large.
Load diff
@@ -3,7 +3,7 @@
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -37,17 +37,21 @@
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7ld %s\n", size, filename);
|
||||
fprintf(stdout, "%ld\t%s\n", size, filename);
|
||||
}
|
||||
|
||||
static void print_summary(long size, char *filename)
|
||||
@@ -57,24 +61,26 @@ static void print_summary(long size, char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
int len;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
printf("du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
|
||||
/* Don't add in stuff pointed to by links */
|
||||
/* Don't add in stuff pointed to by symbolic links */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
return 0;
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
@@ -82,8 +88,14 @@ static long du(char *filename)
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) {
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(filename);
|
||||
if (filename[len - 1] == '/')
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char *name = entry->d_name;
|
||||
@@ -93,8 +105,9 @@ static long du(char *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
@@ -104,6 +117,17 @@ static long du(char *filename)
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
@@ -124,7 +148,11 @@ int du_main(int argc, char **argv)
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
@@ -144,13 +172,21 @@ int du_main(int argc, char **argv)
|
||||
|
||||
for (; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -13,34 +13,34 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <utmp.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
static const char dutmp_usage[] = "dutmp\n"
|
||||
"\n"
|
||||
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
static const char dutmp_usage[] = "dutmp [FILE]\n\n"
|
||||
"Dump utmp file format (pipe delimited) from FILE\n"
|
||||
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n";
|
||||
|
||||
extern int dutmp_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
FILE *f;
|
||||
struct utmp ut;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
if (argc<2) {
|
||||
f = stdin;
|
||||
} else if (*argv[1] == '-' ) {
|
||||
usage(dutmp_usage);
|
||||
}
|
||||
|
||||
if (**(++argv) == 0) {
|
||||
f = fopen(*(++argv), "r");
|
||||
if (f < 0) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
} else {
|
||||
f = fopen(argv[1], "r");
|
||||
if (f == NULL) {
|
||||
fatalError(io_error, argv[1], strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
while (fread(&ut, 1, sizeof(struct utmp), f)) {
|
||||
// printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
|
||||
while (fread(&ut, sizeof(struct utmp), 1, f)) {
|
||||
printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
|
||||
ut.ut_type, ut.ut_pid, ut.ut_line,
|
||||
ut.ut_id, ut.ut_user, ut.ut_host,
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* echo implementation for busybox
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n\n"
|
||||
"Prints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n";
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
eflag = 0;
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
switch (c = *p++) {
|
||||
case 'a': c = '\007'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit( 0); /* exit */
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case '\\': break; /* c = '\\' */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
break;
|
||||
default:
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (*ap)
|
||||
putchar(' ');
|
||||
}
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kenneth Almquist.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
|
||||
+123
-123
@@ -3,7 +3,7 @@
|
||||
* Mini sed implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* Modifications for addresses and append command have been
|
||||
@@ -184,129 +184,129 @@ extern int sed_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while (argc > 1) {
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
if (**argv != '-')
|
||||
usage(sed_usage);
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.42
|
||||
Version: 0.43
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
From alan@lxorguk.ukuu.org.uk Thu Apr 13 08:07:22 2000
|
||||
Return-Path: <alan@lxorguk.ukuu.org.uk>
|
||||
Delivered-To: andersen@dillweed.dsl.xmission.com
|
||||
Received: from localhost (dillweed.dsl.xmission.com [10.0.0.1])
|
||||
by dillweed.dsl.xmission.com (Postfix) with ESMTP id 1D57A11A4F5
|
||||
for <andersen@dillweed.dsl.xmission.com>; Thu, 13 Apr 2000 08:07:22 -0600 (MDT)
|
||||
Envelope-to: andersen@xmission.com
|
||||
Received: from mail.xmission.com
|
||||
by localhost with IMAP (fetchmail-5.3.3)
|
||||
for andersen@dillweed.dsl.xmission.com (single-drop); Thu, 13 Apr 2000 08:07:22 -0600 (MDT)
|
||||
Received: from [194.168.151.1] (helo=the-village.bc.nu)
|
||||
by mail.xmission.com with esmtp (Exim 3.03 #3)
|
||||
id 12fhQk-0002OZ-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 05:05:03 -0600
|
||||
Received: from alan by the-village.bc.nu with local (Exim 2.12 #1)
|
||||
id 12fhQ9-0002nD-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 12:04:25 +0100
|
||||
Subject: Re: kernel ps drivers [Was: vm locking question]
|
||||
To: andersen@xmission.com
|
||||
Date: Thu, 13 Apr 2000 12:04:23 +0100 (BST)
|
||||
In-Reply-To: <20000412224130.A2748@xmission.com> from "Erik Andersen" at Apr 12, 2000 10:41:30 PM
|
||||
X-Mailer: ELM [version 2.5 PL1]
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=us-ascii
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Message-Id: <E12fhQ9-0002nD-00@the-village.bc.nu>
|
||||
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
|
||||
Status: RO
|
||||
X-Status: A
|
||||
Content-Length: 242
|
||||
Lines: 6
|
||||
|
||||
> On the subject of ps, would you be willing to accept my /dev/ps
|
||||
> patch into the kernel? If no, any suggestions on what should
|
||||
> be done differently (if anything) to make it worthy of inclusion?
|
||||
|
||||
For 2.2.x no, for 2.3.x ask Linus not me
|
||||
|
||||
|
||||
From torvalds@transmeta.com Thu Apr 13 09:18:16 2000
|
||||
Return-Path: <torvalds@transmeta.com>
|
||||
Delivered-To: andersen@dillweed.dsl.xmission.com
|
||||
Received: from localhost (dillweed.dsl.xmission.com [10.0.0.1])
|
||||
by dillweed.dsl.xmission.com (Postfix) with ESMTP id 3776411A3DF
|
||||
for <andersen@dillweed.dsl.xmission.com>; Thu, 13 Apr 2000 09:18:16 -0600 (MDT)
|
||||
Envelope-to: andersen@xmission.com
|
||||
Received: from mail.xmission.com
|
||||
by localhost with IMAP (fetchmail-5.3.3)
|
||||
for andersen@dillweed.dsl.xmission.com (single-drop); Thu, 13 Apr 2000 09:18:16 -0600 (MDT)
|
||||
Received: from [209.10.217.66] (helo=neon-gw.transmeta.com)
|
||||
by mail.xmission.com with esmtp (Exim 3.03 #3)
|
||||
id 12flK2-0004dd-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 09:14:22 -0600
|
||||
Received: (from root@localhost)
|
||||
by neon-gw.transmeta.com (8.9.3/8.9.3) id IAA18635;
|
||||
Thu, 13 Apr 2000 08:10:51 -0700
|
||||
Received: from mailhost.transmeta.com(10.1.1.15) by neon-gw.transmeta.com via smap (V2.1)
|
||||
id xma018629; Thu, 13 Apr 00 08:10:25 -0700
|
||||
Received: from penguin.transmeta.com (root@penguin.transmeta.com [10.1.2.202])
|
||||
by deepthought.transmeta.com (8.9.3/8.9.3) with ESMTP id IAA12264;
|
||||
Thu, 13 Apr 2000 08:13:53 -0700 (PDT)
|
||||
Received: from localhost (torvalds@localhost) by penguin.transmeta.com (8.9.3/8.7.3) with ESMTP id IAA02051; Thu, 13 Apr 2000 08:13:53 -0700
|
||||
X-Authentication-Warning: penguin.transmeta.com: torvalds owned process doing -bs
|
||||
Date: Thu, 13 Apr 2000 08:13:53 -0700 (PDT)
|
||||
From: Linus Torvalds <torvalds@transmeta.com>
|
||||
To: Erik Andersen <andersen@xmission.com>
|
||||
Cc: Alan Cox <alan@redhat.com>
|
||||
Subject: Re: kernel ps drivers [Was: vm locking question]
|
||||
In-Reply-To: <20000413083127.A976@xmission.com>
|
||||
Message-ID: <Pine.LNX.4.10.10004130812170.2000-100000@penguin.transmeta.com>
|
||||
MIME-Version: 1.0
|
||||
Content-Type: TEXT/PLAIN; charset=US-ASCII
|
||||
Status: RO
|
||||
Content-Length: 659
|
||||
Lines: 16
|
||||
|
||||
|
||||
|
||||
On Thu, 13 Apr 2000, Erik Andersen wrote:
|
||||
>
|
||||
> For 2.3.x would you be willing to accept my /dev/ps driver into the kernel?
|
||||
> (Assuming I remove the /dev/modules driver (since it was pointed out that there
|
||||
> is a perfectly good syscall providing that interface). If no, is there anything
|
||||
> that could be done differently (if anything) to make it worthy of inclusion?
|
||||
|
||||
I do dislike /dev/ps mightily. If the problem is that /proc is too large,
|
||||
then the right solution is to just clean up /proc. Which is getting done.
|
||||
And yes, /proc will be larger than /dev/ps, but I still find that
|
||||
preferable to having two incompatible ways to do the same thing.
|
||||
|
||||
Linus
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -62,7 +62,7 @@
|
||||
#define CMD_ALL 11
|
||||
#define CMD_INFO 12
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
#define CMD_XRES 13
|
||||
#define CMD_YRES 14
|
||||
#define CMD_VXRES 15
|
||||
@@ -104,9 +104,9 @@ struct cmdoptions_t {
|
||||
"-hsync", 1, CMD_HSYNC}, {
|
||||
"-vsync", 1, CMD_VSYNC}, {
|
||||
"-laced", 1, CMD_LACED}, {
|
||||
"-double", 1, CMD_DOUBLE},
|
||||
#ifdef BB_FBSET_FANCY
|
||||
{
|
||||
"-double", 1, CMD_DOUBLE}, {
|
||||
"--help", 0, CMD_HELP}, {
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
"--help", 0, CMD_HELP}, {
|
||||
"-all", 0, CMD_ALL}, {
|
||||
"-xres", 1, CMD_XRES}, {
|
||||
@@ -130,9 +130,8 @@ struct cmdoptions_t {
|
||||
"-bcast", 1, CMD_BCAST}, {
|
||||
"-rgba", 1, CMD_RGBA}, {
|
||||
"-step", 1, CMD_STEP}, {
|
||||
"-move", 1, CMD_MOVE},
|
||||
"-move", 1, CMD_MOVE}, {
|
||||
#endif
|
||||
{
|
||||
0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -164,8 +163,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
}
|
||||
}
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"W: mode reading was disabled on this copy of fbset; ignoring request\n");
|
||||
errorMsg( "mode reading not compiled in\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -199,7 +197,7 @@ static void showmode(struct fb_var_screeninfo *v)
|
||||
v->vsync_len);
|
||||
}
|
||||
printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
|
||||
hrate / 1e3, vrate);
|
||||
#endif
|
||||
@@ -218,7 +216,7 @@ static void showmode(struct fb_var_screeninfo *v)
|
||||
printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
|
||||
v->red.offset, v->green.length, v->green.offset, v->blue.length,
|
||||
v->blue.offset, v->transp.length, v->transp.offset);
|
||||
printf("endmode\n");
|
||||
printf("endmode\n\n");
|
||||
}
|
||||
|
||||
static void fbset_usage(void)
|
||||
@@ -229,10 +227,11 @@ static void fbset_usage(void)
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
#endif
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n");
|
||||
fprintf(stderr, "\tThe following options are recognized:\n");
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n\n");
|
||||
fprintf(stderr, "Show and modify frame buffer device settings\n\n");
|
||||
fprintf(stderr, "The following options are recognized:\n");
|
||||
for (i = 0; g_cmdoptions[i].name; i++)
|
||||
fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name);
|
||||
fprintf(stderr, "\t%s\n", g_cmdoptions[i].name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -283,7 +282,7 @@ extern int fbset_main(int argc, char **argv)
|
||||
varset.hsync_len = strtoul(argv[6], 0, 0);
|
||||
varset.vsync_len = strtoul(argv[7], 0, 0);
|
||||
break;
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
case CMD_XRES:
|
||||
varset.xres = strtoul(argv[1], 0, 0);
|
||||
break;
|
||||
@@ -323,7 +322,8 @@ extern int fbset_main(int argc, char **argv)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
|
||||
PERROR("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
close(fh);
|
||||
/* Don't close the file, as exiting will take care of that */
|
||||
/* close(fh); */
|
||||
|
||||
return (TRUE);
|
||||
exit (TRUE);
|
||||
}
|
||||
@@ -33,8 +33,8 @@ extern int fdflush_main(int argc, char **argv)
|
||||
int value;
|
||||
int fd;
|
||||
|
||||
if (argc <= 1 || **(argv++) == '-') {
|
||||
usage("fdflush device\n");
|
||||
if (argc <= 1 || **(++argv) == '-') {
|
||||
usage("fdflush device\n\nForce floppy disk drive to detect disk change\n");
|
||||
}
|
||||
|
||||
fd = open(*argv, 0);
|
||||
@@ -44,7 +44,9 @@ extern int fdflush_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
value = ioctl(fd, FDFLUSH, 0);
|
||||
close(fd);
|
||||
/* Don't bother closing. Exit does
|
||||
* that, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
|
||||
if (value) {
|
||||
perror(*argv);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini find implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -37,12 +37,12 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
"\t-follow\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (pattern == NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
@@ -109,7 +109,7 @@ int find_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@
|
||||
* Mini find implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -37,12 +37,12 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
"\t-follow\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (pattern == NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
@@ -109,7 +109,7 @@ int find_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini free implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -23,15 +23,33 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
#define DIVISOR 1024
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
char *cmd[] = { "cat", "/proc/meminfo", "\0" };
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
info.totalram/=DIVISOR;
|
||||
info.freeram/=DIVISOR;
|
||||
info.totalswap/=DIVISOR;
|
||||
info.freeswap/=DIVISOR;
|
||||
info.sharedram/=DIVISOR;
|
||||
info.bufferram/=DIVISOR;
|
||||
|
||||
exit(cat_main(3, cmd));
|
||||
|
||||
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
|
||||
"shared", "buffers");
|
||||
|
||||
printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
|
||||
info.totalram-info.freeram, info.freeram,
|
||||
info.sharedram, info.bufferram);
|
||||
|
||||
printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
|
||||
info.totalswap-info.freeswap, info.freeswap);
|
||||
|
||||
printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
|
||||
(info.totalram-info.freeram)+(info.totalswap-info.freeswap),
|
||||
info.freeram+info.freeswap);
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* freeramdisk implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
|
||||
* Adjusted a bit by Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static const char freeramdisk_usage[] =
|
||||
"freeramdisk DEVICE\n\n"
|
||||
"Free all memory used by the specified ramdisk.\n";
|
||||
|
||||
extern int
|
||||
freeramdisk_main(int argc, char **argv)
|
||||
{
|
||||
char rname[256] = "/dev/ram";
|
||||
int f;
|
||||
|
||||
if (argc < 2 || ( argv[1] && *argv[1] == '-')) {
|
||||
usage(freeramdisk_usage);
|
||||
}
|
||||
|
||||
if (argc >1)
|
||||
strcpy(rname, argv[1]);
|
||||
|
||||
if ((f = open(rname, O_RDWR)) == -1) {
|
||||
fatalError( "freeramdisk: cannot open %s: %s\n", rname, strerror(errno));
|
||||
}
|
||||
if (ioctl(f, BLKFLSBUF) < 0) {
|
||||
fatalError( "freeramdisk: failed ioctl on %s: %s\n", rname, strerror(errno));
|
||||
}
|
||||
/* Don't bother closing. Exit does
|
||||
* that, so we can save a few bytes */
|
||||
/* close(f); */
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
|
||||
+13
-28
@@ -603,23 +603,13 @@ static void read_superblock(void)
|
||||
|
||||
static void read_tables(void)
|
||||
{
|
||||
inode_map = malloc(IMAPS * BLOCK_SIZE);
|
||||
if (!inode_map)
|
||||
die("Unable to allocate buffer for inode map");
|
||||
zone_map = malloc(ZMAPS * BLOCK_SIZE);
|
||||
if (!inode_map)
|
||||
die("Unable to allocate buffer for zone map");
|
||||
inode_map = xmalloc(IMAPS * BLOCK_SIZE);
|
||||
zone_map = xmalloc(ZMAPS * BLOCK_SIZE);
|
||||
memset(inode_map, 0, sizeof(inode_map));
|
||||
memset(zone_map, 0, sizeof(zone_map));
|
||||
inode_buffer = malloc(INODE_BUFFER_SIZE);
|
||||
if (!inode_buffer)
|
||||
die("Unable to allocate buffer for inodes");
|
||||
inode_count = malloc(INODES + 1);
|
||||
if (!inode_count)
|
||||
die("Unable to allocate buffer for inode count");
|
||||
zone_count = malloc(ZONES);
|
||||
if (!zone_count)
|
||||
die("Unable to allocate buffer for zone count");
|
||||
inode_buffer = xmalloc(INODE_BUFFER_SIZE);
|
||||
inode_count = xmalloc(INODES + 1);
|
||||
zone_count = xmalloc(ZONES);
|
||||
if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
|
||||
die("Unable to read inode map");
|
||||
if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
|
||||
@@ -1247,20 +1237,12 @@ static void alloc_name_list(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
name_list = malloc(sizeof(char *) * MAX_DEPTH);
|
||||
if (!name_list) {
|
||||
fprintf(stderr,"fsck_minix: name_list: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
for (i = 0; i < MAX_DEPTH; i++) {
|
||||
name_list[i] = malloc(sizeof(char) * PATH_MAX + 1);
|
||||
if (!name_list[i]) {
|
||||
fprintf(stderr,"fsck_minix: name_list: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
|
||||
for (i = 0; i < MAX_DEPTH; i++)
|
||||
name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* execute this atexit() to deallocate name_list[] */
|
||||
/* piptigger was here */
|
||||
static void free_name_list(void)
|
||||
@@ -1276,6 +1258,7 @@ static void free_name_list(void)
|
||||
free(name_list);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int fsck_minix_main(int argc, char **argv)
|
||||
{
|
||||
@@ -1284,7 +1267,9 @@ extern int fsck_minix_main(int argc, char **argv)
|
||||
int retcode = 0;
|
||||
|
||||
alloc_name_list();
|
||||
atexit(free_name_list);
|
||||
/* Don't bother to free memory. Exit does
|
||||
* that automagically, so we can save a few bytes */
|
||||
//atexit(free_name_list);
|
||||
|
||||
if (argc && *argv)
|
||||
program_name = *argv;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -1,13 +1,33 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* zcat : stripped version based on gzip sources
|
||||
Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
*/
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
@@ -16,6 +36,18 @@ static const char gunzip_usage[] =
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
@@ -89,25 +121,6 @@ static char *license_msg[] = {
|
||||
#define get_char() get_byte()
|
||||
#define put_char(c) put_byte(c)
|
||||
|
||||
/* #include "gzip.h" */
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
@@ -118,7 +131,7 @@ typedef char *voidp;
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
# define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
@@ -329,49 +342,46 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
#define do_exit(c) exit(c)
|
||||
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int unzip (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((int pack_level, ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (int pack_level, ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern int copy (int in, int out);
|
||||
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);
|
||||
|
||||
#ifndef __linux__
|
||||
extern char *basename OF((char *fname));
|
||||
extern char *basename (char *fname);
|
||||
#endif /* not __linux__ */
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
extern int inflate (void);
|
||||
|
||||
/* #include "lzw.h" */
|
||||
|
||||
@@ -415,8 +425,8 @@ extern int inflate OF((void));
|
||||
extern int maxbits; /* max bits per code for LZW */
|
||||
extern int block_mode; /* block compress mode -C compatible with 2.0 */
|
||||
|
||||
extern int lzw OF((int in, int out));
|
||||
extern int unlzw OF((int in, int out));
|
||||
extern int lzw (int in, int out);
|
||||
extern int unlzw (int in, int out);
|
||||
|
||||
|
||||
/* #include "revision.h" */
|
||||
@@ -605,7 +615,7 @@ typedef struct direct dir_type;
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -644,7 +654,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -687,7 +697,7 @@ long header_bytes; /* number of bytes in gzip header */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local int get_method OF((int in));
|
||||
local int get_method (int in);
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
@@ -773,7 +783,7 @@ int gunzip_main(int argc, char **argv)
|
||||
usage(gunzip_usage);
|
||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ifname, *argv);
|
||||
|
||||
@@ -781,13 +791,13 @@ int gunzip_main(int argc, char **argv)
|
||||
inFileNum = open(ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
@@ -812,7 +822,7 @@ int gunzip_main(int argc, char **argv)
|
||||
/* And get to work */
|
||||
if (strlen(ifname) > MAX_PATH_LEN - 4) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ofname, ifname);
|
||||
pos = strstr(ofname, ".gz");
|
||||
@@ -836,7 +846,7 @@ int gunzip_main(int argc, char **argv)
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
@@ -860,7 +870,7 @@ int gunzip_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
do_exit(exit_code);
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -953,7 +963,7 @@ int in; /* input file descriptor */
|
||||
*/
|
||||
RETSIGTYPE abort_gzip()
|
||||
{
|
||||
do_exit(ERROR);
|
||||
exit(ERROR);
|
||||
}
|
||||
|
||||
/* unzip.c -- decompress files in gzip or pkzip format.
|
||||
@@ -1027,7 +1037,7 @@ int in, out; /* input and output file descriptors */
|
||||
ofd = out;
|
||||
method = get_method(ifd);
|
||||
if (method < 0) {
|
||||
do_exit(exit_code); /* error message already emitted */
|
||||
exit(exit_code); /* error message already emitted */
|
||||
}
|
||||
|
||||
updcrc(NULL, 0); /* initialize crc */
|
||||
@@ -1218,7 +1228,7 @@ void flush_window()
|
||||
*/
|
||||
void write_buf(fd, buf, cnt)
|
||||
int fd;
|
||||
voidp buf;
|
||||
void * buf;
|
||||
unsigned cnt;
|
||||
{
|
||||
unsigned n;
|
||||
@@ -1228,7 +1238,7 @@ unsigned cnt;
|
||||
write_error();
|
||||
}
|
||||
cnt -= n;
|
||||
buf = (voidp) ((char *) buf + n);
|
||||
buf = (void *) ((char *) buf + n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1240,8 +1250,8 @@ unsigned cnt;
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -1291,12 +1301,6 @@ const char *reject;
|
||||
/* ========================================================================
|
||||
* Error handlers.
|
||||
*/
|
||||
void warn(a, b)
|
||||
char *a, *b; /* message strings juxtaposed in output */
|
||||
{
|
||||
WARN((stderr, "warning: %s%s\n", a, b));
|
||||
}
|
||||
|
||||
void read_error()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
@@ -1499,15 +1503,15 @@ struct huft {
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *));
|
||||
int huft_free OF((struct huft *));
|
||||
int inflate_codes OF((struct huft *, struct huft *, int, int));
|
||||
int inflate_stored OF((void));
|
||||
int inflate_fixed OF((void));
|
||||
int inflate_dynamic OF((void));
|
||||
int inflate_block OF((int *));
|
||||
int inflate OF((void));
|
||||
int huft_build (unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *);
|
||||
int huft_free (struct huft *);
|
||||
int inflate_codes (struct huft *, struct huft *, int, int);
|
||||
int inflate_stored (void);
|
||||
int inflate_fixed (void);
|
||||
int inflate_dynamic (void);
|
||||
int inflate_block (int *);
|
||||
int inflate (void);
|
||||
|
||||
|
||||
/* The inflate algorithm uses a sliding 32K byte window on the uncompressed
|
||||
|
||||
@@ -1,62 +1,58 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* gzip.c -- this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires the
|
||||
* zcat module for some important functions.
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Charles P. Wright <cpw@unix.asb.com>
|
||||
* "this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires
|
||||
* the zcat module for some important functions."
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Charles P. Wright <cpw@unix.asb.com>
|
||||
*/
|
||||
#include "internal.h"
|
||||
#ifdef BB_GZIP
|
||||
|
||||
//#ifndef BB_ZCAT
|
||||
//#error you need zcat to have gzip support!
|
||||
//#endif
|
||||
#include "internal.h"
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"When FILE is -, reads standard input. Implies -c.\n\n"
|
||||
"When FILE is '-', reads standard input. Implies -c.\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
|
||||
# include <string.h>
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# define memcpy(d, s, n) bcopy((s), (d), (n))
|
||||
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
|
||||
# define memzero(s, n) bzero((s), (n))
|
||||
#endif
|
||||
#include <string.h>
|
||||
#define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
@@ -121,13 +117,13 @@ extern int method; /* compression method */
|
||||
#endif
|
||||
|
||||
#ifdef DYN_ALLOC
|
||||
# define EXTERN(type, array) extern type * near array
|
||||
# define DECLARE(type, array, size) type * near array
|
||||
# define EXTERN(type, array) extern type * array
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
# define EXTERN(type, array) extern type array[]
|
||||
# define DECLARE(type, array, size) type array[size]
|
||||
@@ -284,55 +280,55 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip OF((int in, int out));
|
||||
extern int file_read OF((char *buf, unsigned size));
|
||||
extern int zip (int in, int out);
|
||||
extern int file_read (char *buf, unsigned size);
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int check_zipfile OF((int in));
|
||||
extern int unzip (int in, int out);
|
||||
extern int check_zipfile (int in);
|
||||
|
||||
/* in unpack.c */
|
||||
extern int unpack OF((int in, int out));
|
||||
extern int unpack (int in, int out);
|
||||
|
||||
/* in unlzh.c */
|
||||
extern int unlzh OF((int in, int out));
|
||||
extern int unlzh (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern char *strlwr OF((char *s));
|
||||
extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
extern void display_ratio OF((long num, long den, FILE * file));
|
||||
extern int copy (int in, int out);
|
||||
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 char *strlwr (char *s);
|
||||
extern char *add_envopt (int *argcp, char ***argvp, char *env);
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
extern void display_ratio (long num, long den, FILE * file);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
extern int inflate (void);
|
||||
|
||||
/* lzw.h -- define the lzw functions.
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
@@ -795,7 +791,7 @@ local int bi_valid;
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
int (*read_buf) OF((char *buf, unsigned size));
|
||||
int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* Current input function. Set to mem_read for in-memory compression */
|
||||
|
||||
@@ -1148,16 +1144,16 @@ local config configuration_table =
|
||||
/* ===========================================================================
|
||||
* Prototypes for local functions.
|
||||
*/
|
||||
local void fill_window OF((void));
|
||||
local void fill_window (void);
|
||||
|
||||
int longest_match OF((IPos cur_match));
|
||||
int longest_match (IPos cur_match);
|
||||
|
||||
#ifdef ASMV
|
||||
void match_init OF((void)); /* asm code initialization */
|
||||
void match_init (void); /* asm code initialization */
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
local void check_match OF((IPos start, IPos match, int length));
|
||||
local void check_match (IPos start, IPos match, int length);
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1708,7 +1704,7 @@ struct utimbuf {
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -1743,7 +1739,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
/* Separator for file name parts (see shorten_name()) */
|
||||
@@ -2246,17 +2242,17 @@ extern unsigned near strstart; /* window offset of current string */
|
||||
* Local (static) routines in this file.
|
||||
*/
|
||||
|
||||
local void init_block OF((void));
|
||||
local void pqdownheap OF((ct_data near * tree, int k));
|
||||
local void gen_bitlen OF((tree_desc near * desc));
|
||||
local void gen_codes OF((ct_data near * tree, int max_code));
|
||||
local void build_tree OF((tree_desc near * desc));
|
||||
local void scan_tree OF((ct_data near * tree, int max_code));
|
||||
local void send_tree OF((ct_data near * tree, int max_code));
|
||||
local int build_bl_tree OF((void));
|
||||
local void send_all_trees OF((int lcodes, int dcodes, int blcodes));
|
||||
local void compress_block OF((ct_data near * ltree, ct_data near * dtree));
|
||||
local void set_file_type OF((void));
|
||||
local void init_block (void);
|
||||
local void pqdownheap (ct_data near * tree, int k);
|
||||
local void gen_bitlen (tree_desc near * desc);
|
||||
local void gen_codes (ct_data near * tree, int max_code);
|
||||
local void build_tree (tree_desc near * desc);
|
||||
local void scan_tree (ct_data near * tree, int max_code);
|
||||
local void send_tree (ct_data near * tree, int max_code);
|
||||
local int build_bl_tree (void);
|
||||
local void send_all_trees (int lcodes, int dcodes, int blcodes);
|
||||
local void compress_block (ct_data near * ltree, ct_data near * dtree);
|
||||
local void set_file_type (void);
|
||||
|
||||
|
||||
#ifndef DEBUG
|
||||
@@ -3097,7 +3093,7 @@ local void set_file_type()
|
||||
bin_freq += dyn_ltree[n++].Freq;
|
||||
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
||||
if (*file_type == BINARY && translate_eol) {
|
||||
errorMsg("-l used on binary file", "");
|
||||
errorMsg("-l used on binary file");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3161,12 +3157,8 @@ char *s;
|
||||
|
||||
/* Provide missing strspn and strcspn functions. */
|
||||
|
||||
# ifndef __STDC__
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -3398,4 +3390,3 @@ unsigned size;
|
||||
isize += (ulg) len;
|
||||
return (int) len;
|
||||
}
|
||||
#endif
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
extern int halt_main(int argc, char **argv)
|
||||
{
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
/* don't assume init's pid == 1 */
|
||||
exit(kill(findInitPid(), SIGUSR1));
|
||||
exit(kill(*(findPidByName("init")), SIGUSR1));
|
||||
#else
|
||||
exit(kill(1, SIGUSR1));
|
||||
#endif
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -109,4 +109,4 @@ int head_main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.8 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
@@ -28,34 +28,43 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/types.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <linux/version.h>
|
||||
#include <paths.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kdaemon.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/kdaemon.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/version.h>
|
||||
#include <sys/sysinfo.h> /* For check_free_memory() */
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
# include <sys/syslog.h>
|
||||
#endif
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
|
||||
#if defined BB_FEATURE_INIT_COREDUMPS
|
||||
/*
|
||||
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
|
||||
* before processes are spawned to set core file size as unlimited.
|
||||
* This is for debugging only. Don't use this is production, unless
|
||||
* you want core dumps lying about....
|
||||
*/
|
||||
#define CORE_ENABLE_FLAG_FILE "/.init_enable_core"
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
@@ -63,19 +72,19 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#ifndef INIT_SCRIPT
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#endif
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
|
||||
/* Allowed init action types */
|
||||
typedef enum {
|
||||
@@ -87,7 +96,7 @@ typedef enum {
|
||||
CTRLALTDEL
|
||||
} initActionEnum;
|
||||
|
||||
/* And now a list of the actions we support in the version of init */
|
||||
/* A mapping between "inittab" action name strings and action type codes. */
|
||||
typedef struct initActionType {
|
||||
const char *name;
|
||||
initActionEnum action;
|
||||
@@ -103,7 +112,7 @@ static const struct initActionType actions[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
/* Set up a linked list of initactions, to be read from inittab */
|
||||
/* Set up a linked list of initActions, to be read from inittab */
|
||||
typedef struct initActionTag initAction;
|
||||
struct initActionTag {
|
||||
pid_t pid;
|
||||
@@ -116,16 +125,19 @@ initAction *initActionList = NULL;
|
||||
|
||||
|
||||
static char *secondConsole = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
static int kernelVersion = 0;
|
||||
static char termType[32] = "TERM=ansi";
|
||||
static char console[32] = _PATH_CONSOLE;
|
||||
static char *log = VT_LOG;
|
||||
static int kernelVersion = 0;
|
||||
static char termType[32] = "TERM=linux";
|
||||
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 */
|
||||
void message(int device, char *fmt, ...)
|
||||
/* Print a message to the specified device.
|
||||
* Device may be bitwise-or'd from LOG | CONSOLE */
|
||||
static void message(int device, char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
static void message(int device, char *fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
int fd;
|
||||
@@ -194,23 +206,25 @@ void message(int device, char *fmt, ...)
|
||||
void set_term(int fd)
|
||||
{
|
||||
struct termios tty;
|
||||
static const char control_characters[] = {
|
||||
'\003', '\034', '\177', '\025', '\004', '\0',
|
||||
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
|
||||
'\017', '\027', '\026', '\0'
|
||||
};
|
||||
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* set control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
tty.c_cc[VINTR] = 3; /* C-c */
|
||||
tty.c_cc[VQUIT] = 28; /* C-\ */
|
||||
tty.c_cc[VERASE] = 127; /* C-? */
|
||||
tty.c_cc[VKILL] = 21; /* C-u */
|
||||
tty.c_cc[VEOF] = 4; /* C-d */
|
||||
tty.c_cc[VSTART] = 17; /* C-q */
|
||||
tty.c_cc[VSTOP] = 19; /* C-s */
|
||||
tty.c_cc[VSUSP] = 26; /* C-z */
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
//tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
//tty.c_cflag |= HUPCL|CLOCAL;
|
||||
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL | IXON | IXOFF;
|
||||
@@ -226,25 +240,17 @@ void set_term(int fd)
|
||||
}
|
||||
|
||||
/* How much memory does this machine have? */
|
||||
static int mem_total()
|
||||
static int check_free_memory()
|
||||
{
|
||||
char s[80];
|
||||
char *p = "/proc/meminfo";
|
||||
FILE *f;
|
||||
const char pattern[] = "MemTotal:";
|
||||
struct sysinfo info;
|
||||
|
||||
if ((f = fopen(p, "r")) < 0) {
|
||||
message(LOG, "Error opening %s: %s\n", p, strerror(errno));
|
||||
sysinfo(&info);
|
||||
if (sysinfo(&info) != 0) {
|
||||
message(LOG, "Error checking free memory: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
while (NULL != fgets(s, 79, f)) {
|
||||
p = strstr(s, pattern);
|
||||
if (NULL != p) {
|
||||
fclose(f);
|
||||
return (atoi(p + strlen(pattern)));
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
return((info.totalram+info.totalswap)/1024);
|
||||
}
|
||||
|
||||
static void console_init()
|
||||
@@ -252,6 +258,7 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct vt_stat vt;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
@@ -274,8 +281,6 @@ static void console_init()
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
/* this is a serial console */
|
||||
@@ -314,6 +319,10 @@ static void console_init()
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
log = NULL;
|
||||
secondConsole = NULL;
|
||||
/* Force the TERM setting to vt102 for serial console --
|
||||
* iff TERM is set to linux (the default) */
|
||||
if (strcmp( termType, "TERM=linux" ) == 0)
|
||||
snprintf(termType, sizeof(termType) - 1, "TERM=vt102");
|
||||
message(LOG | CONSOLE,
|
||||
"serial console detected. Disabling virtual terminals.\r\n");
|
||||
}
|
||||
@@ -343,10 +352,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
#ifdef DEBUG_INIT
|
||||
pid_t shell_pgid = getpid();
|
||||
#endif
|
||||
|
||||
/* Clean up */
|
||||
close(0);
|
||||
close(1);
|
||||
@@ -380,8 +385,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
* specifies.
|
||||
*/
|
||||
char c;
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
pid_t shell_pgid = getpid();
|
||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||
command, shell_pgid, terminal);
|
||||
#endif
|
||||
@@ -416,6 +421,18 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
cmd[i] = NULL;
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
execve(cmd[0], cmd, environment);
|
||||
@@ -450,13 +467,15 @@ static void check_memory()
|
||||
{
|
||||
struct stat statBuf;
|
||||
|
||||
if (mem_total() > 3500)
|
||||
if (check_free_memory() > 1000)
|
||||
return;
|
||||
|
||||
if (stat("/etc/fstab", &statBuf) == 0) {
|
||||
/* swapon -a requires /proc typically */
|
||||
waitfor("mount proc /proc -t proc", console, FALSE);
|
||||
/* Try to turn on swap */
|
||||
system("/sbin/swapon -a");
|
||||
if (mem_total() < 3500)
|
||||
waitfor("swapon -a", console, FALSE);
|
||||
if (check_free_memory() < 1000)
|
||||
goto goodnight;
|
||||
} else
|
||||
goto goodnight;
|
||||
@@ -551,6 +570,11 @@ static void reboot_signal(int sig)
|
||||
}
|
||||
|
||||
#if defined BB_FEATURE_INIT_CHROOT
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
static void check_chroot(int sig)
|
||||
{
|
||||
char *argv_init[2] = { "init", NULL, };
|
||||
@@ -742,7 +766,7 @@ void parse_inittab(void)
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Now peal off the process field from the end
|
||||
/* Now peel off the process field from the end
|
||||
* of the string */
|
||||
q = strrchr(p, ':');
|
||||
if (q == NULL || *(q + 1) == '\0') {
|
||||
@@ -753,7 +777,7 @@ void parse_inittab(void)
|
||||
++q;
|
||||
}
|
||||
|
||||
/* Now peal off the action field */
|
||||
/* Now peel off the action field */
|
||||
r = strrchr(p, ':');
|
||||
if (r == NULL || *(r + 1) == '\0') {
|
||||
message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
|
||||
@@ -792,7 +816,7 @@ void parse_inittab(void)
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
#endif /* BB_FEATURE_USE_INITTAB */
|
||||
}
|
||||
|
||||
|
||||
@@ -804,10 +828,16 @@ extern int init_main(int argc, char **argv)
|
||||
int status;
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 if we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init") != NULL) {
|
||||
usage("init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only by the kernel\n");
|
||||
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
|
||||
if (getpid() != 1
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
&& strstr(argv[0], "linuxrc") == NULL
|
||||
#endif
|
||||
)
|
||||
{
|
||||
usage("init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only "
|
||||
"by the kernel.\n");
|
||||
}
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
@@ -824,6 +854,9 @@ extern int init_main(int argc, char **argv)
|
||||
reboot(RB_DISABLE_CAD);
|
||||
#endif
|
||||
|
||||
/* Figure out what kernel this is running */
|
||||
kernelVersion = get_kernel_revision();
|
||||
|
||||
/* Figure out where the default console should be */
|
||||
console_init();
|
||||
|
||||
@@ -832,6 +865,7 @@ extern int init_main(int argc, char **argv)
|
||||
close(1);
|
||||
close(2);
|
||||
set_term(0);
|
||||
chdir("/");
|
||||
setsid();
|
||||
|
||||
/* Make sure PATH is set to something sane */
|
||||
@@ -839,23 +873,24 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Hello world */
|
||||
#ifndef DEBUG_INIT
|
||||
message(LOG | CONSOLE,
|
||||
message(
|
||||
#if ! defined BB_FEATURE_EXTRA_QUIET
|
||||
CONSOLE|
|
||||
#endif
|
||||
LOG,
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
BB_VER, BB_BT);
|
||||
#else
|
||||
message(LOG | CONSOLE,
|
||||
message(
|
||||
#if ! defined BB_FEATURE_EXTRA_QUIET
|
||||
CONSOLE|
|
||||
#endif
|
||||
LOG,
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
getpid(), BB_VER, BB_BT);
|
||||
#endif
|
||||
|
||||
|
||||
/* Mount /proc */
|
||||
if (mount("proc", "/proc", "proc", 0, 0) == 0) {
|
||||
message(LOG | CONSOLE, "Mounting /proc: done.\n");
|
||||
kernelVersion = get_kernel_revision();
|
||||
} else
|
||||
message(LOG | CONSOLE, "Mounting /proc: failed!\n");
|
||||
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
@@ -876,7 +911,7 @@ extern int init_main(int argc, char **argv)
|
||||
* of "askfirst" shells */
|
||||
parse_inittab();
|
||||
}
|
||||
|
||||
|
||||
/* Fix up argv[0] to be certain we claim to be init */
|
||||
strncpy(argv[0], "init", strlen(argv[0])+1);
|
||||
if (argc > 1)
|
||||
@@ -953,3 +988,11 @@ extern int init_main(int argc, char **argv)
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+5
-1
@@ -26,6 +26,10 @@
|
||||
|
||||
extern int halt_main(int argc, char **argv)
|
||||
{
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
/* don't assume init's pid == 1 */
|
||||
exit(kill(findInitPid(), SIGUSR1));
|
||||
exit(kill(*(findPidByName("init")), SIGUSR1));
|
||||
#else
|
||||
exit(kill(1, SIGUSR1));
|
||||
#endif
|
||||
}
|
||||
+132
-89
@@ -28,34 +28,43 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/types.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <linux/version.h>
|
||||
#include <paths.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kdaemon.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/kdaemon.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/version.h>
|
||||
#include <sys/sysinfo.h> /* For check_free_memory() */
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
# include <sys/syslog.h>
|
||||
#endif
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
|
||||
#if defined BB_FEATURE_INIT_COREDUMPS
|
||||
/*
|
||||
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
|
||||
* before processes are spawned to set core file size as unlimited.
|
||||
* This is for debugging only. Don't use this is production, unless
|
||||
* you want core dumps lying about....
|
||||
*/
|
||||
#define CORE_ENABLE_FLAG_FILE "/.init_enable_core"
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
@@ -63,19 +72,19 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITTAB "/etc/inittab" /* inittab file location */
|
||||
#ifndef INIT_SCRIPT
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
|
||||
#endif
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
|
||||
/* Allowed init action types */
|
||||
typedef enum {
|
||||
@@ -87,7 +96,7 @@ typedef enum {
|
||||
CTRLALTDEL
|
||||
} initActionEnum;
|
||||
|
||||
/* And now a list of the actions we support in the version of init */
|
||||
/* A mapping between "inittab" action name strings and action type codes. */
|
||||
typedef struct initActionType {
|
||||
const char *name;
|
||||
initActionEnum action;
|
||||
@@ -103,7 +112,7 @@ static const struct initActionType actions[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
/* Set up a linked list of initactions, to be read from inittab */
|
||||
/* Set up a linked list of initActions, to be read from inittab */
|
||||
typedef struct initActionTag initAction;
|
||||
struct initActionTag {
|
||||
pid_t pid;
|
||||
@@ -116,16 +125,19 @@ initAction *initActionList = NULL;
|
||||
|
||||
|
||||
static char *secondConsole = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
static int kernelVersion = 0;
|
||||
static char termType[32] = "TERM=ansi";
|
||||
static char console[32] = _PATH_CONSOLE;
|
||||
static char *log = VT_LOG;
|
||||
static int kernelVersion = 0;
|
||||
static char termType[32] = "TERM=linux";
|
||||
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 */
|
||||
void message(int device, char *fmt, ...)
|
||||
/* Print a message to the specified device.
|
||||
* Device may be bitwise-or'd from LOG | CONSOLE */
|
||||
static void message(int device, char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
static void message(int device, char *fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
int fd;
|
||||
@@ -194,23 +206,25 @@ void message(int device, char *fmt, ...)
|
||||
void set_term(int fd)
|
||||
{
|
||||
struct termios tty;
|
||||
static const char control_characters[] = {
|
||||
'\003', '\034', '\177', '\025', '\004', '\0',
|
||||
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
|
||||
'\017', '\027', '\026', '\0'
|
||||
};
|
||||
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* set control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
tty.c_cc[VINTR] = 3; /* C-c */
|
||||
tty.c_cc[VQUIT] = 28; /* C-\ */
|
||||
tty.c_cc[VERASE] = 127; /* C-? */
|
||||
tty.c_cc[VKILL] = 21; /* C-u */
|
||||
tty.c_cc[VEOF] = 4; /* C-d */
|
||||
tty.c_cc[VSTART] = 17; /* C-q */
|
||||
tty.c_cc[VSTOP] = 19; /* C-s */
|
||||
tty.c_cc[VSUSP] = 26; /* C-z */
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
//tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
//tty.c_cflag |= HUPCL|CLOCAL;
|
||||
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL | IXON | IXOFF;
|
||||
@@ -226,25 +240,17 @@ void set_term(int fd)
|
||||
}
|
||||
|
||||
/* How much memory does this machine have? */
|
||||
static int mem_total()
|
||||
static int check_free_memory()
|
||||
{
|
||||
char s[80];
|
||||
char *p = "/proc/meminfo";
|
||||
FILE *f;
|
||||
const char pattern[] = "MemTotal:";
|
||||
struct sysinfo info;
|
||||
|
||||
if ((f = fopen(p, "r")) < 0) {
|
||||
message(LOG, "Error opening %s: %s\n", p, strerror(errno));
|
||||
sysinfo(&info);
|
||||
if (sysinfo(&info) != 0) {
|
||||
message(LOG, "Error checking free memory: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
while (NULL != fgets(s, 79, f)) {
|
||||
p = strstr(s, pattern);
|
||||
if (NULL != p) {
|
||||
fclose(f);
|
||||
return (atoi(p + strlen(pattern)));
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
return((info.totalram+info.totalswap)/1024);
|
||||
}
|
||||
|
||||
static void console_init()
|
||||
@@ -252,6 +258,7 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct vt_stat vt;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
@@ -274,8 +281,6 @@ static void console_init()
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
/* this is a serial console */
|
||||
@@ -314,6 +319,10 @@ static void console_init()
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
log = NULL;
|
||||
secondConsole = NULL;
|
||||
/* Force the TERM setting to vt102 for serial console --
|
||||
* iff TERM is set to linux (the default) */
|
||||
if (strcmp( termType, "TERM=linux" ) == 0)
|
||||
snprintf(termType, sizeof(termType) - 1, "TERM=vt102");
|
||||
message(LOG | CONSOLE,
|
||||
"serial console detected. Disabling virtual terminals.\r\n");
|
||||
}
|
||||
@@ -343,10 +352,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
#ifdef DEBUG_INIT
|
||||
pid_t shell_pgid = getpid();
|
||||
#endif
|
||||
|
||||
/* Clean up */
|
||||
close(0);
|
||||
close(1);
|
||||
@@ -380,8 +385,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
* specifies.
|
||||
*/
|
||||
char c;
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
pid_t shell_pgid = getpid();
|
||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||
command, shell_pgid, terminal);
|
||||
#endif
|
||||
@@ -416,6 +421,18 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
cmd[i] = NULL;
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
execve(cmd[0], cmd, environment);
|
||||
@@ -450,13 +467,15 @@ static void check_memory()
|
||||
{
|
||||
struct stat statBuf;
|
||||
|
||||
if (mem_total() > 3500)
|
||||
if (check_free_memory() > 1000)
|
||||
return;
|
||||
|
||||
if (stat("/etc/fstab", &statBuf) == 0) {
|
||||
/* swapon -a requires /proc typically */
|
||||
waitfor("mount proc /proc -t proc", console, FALSE);
|
||||
/* Try to turn on swap */
|
||||
system("/sbin/swapon -a");
|
||||
if (mem_total() < 3500)
|
||||
waitfor("swapon -a", console, FALSE);
|
||||
if (check_free_memory() < 1000)
|
||||
goto goodnight;
|
||||
} else
|
||||
goto goodnight;
|
||||
@@ -551,6 +570,11 @@ static void reboot_signal(int sig)
|
||||
}
|
||||
|
||||
#if defined BB_FEATURE_INIT_CHROOT
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
static void check_chroot(int sig)
|
||||
{
|
||||
char *argv_init[2] = { "init", NULL, };
|
||||
@@ -742,7 +766,7 @@ void parse_inittab(void)
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Now peal off the process field from the end
|
||||
/* Now peel off the process field from the end
|
||||
* of the string */
|
||||
q = strrchr(p, ':');
|
||||
if (q == NULL || *(q + 1) == '\0') {
|
||||
@@ -753,7 +777,7 @@ void parse_inittab(void)
|
||||
++q;
|
||||
}
|
||||
|
||||
/* Now peal off the action field */
|
||||
/* Now peel off the action field */
|
||||
r = strrchr(p, ':');
|
||||
if (r == NULL || *(r + 1) == '\0') {
|
||||
message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
|
||||
@@ -792,7 +816,7 @@ void parse_inittab(void)
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
#endif /* BB_FEATURE_USE_INITTAB */
|
||||
}
|
||||
|
||||
|
||||
@@ -804,10 +828,16 @@ extern int init_main(int argc, char **argv)
|
||||
int status;
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 if we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init") != NULL) {
|
||||
usage("init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only by the kernel\n");
|
||||
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
|
||||
if (getpid() != 1
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
&& strstr(argv[0], "linuxrc") == NULL
|
||||
#endif
|
||||
)
|
||||
{
|
||||
usage("init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only "
|
||||
"by the kernel.\n");
|
||||
}
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
@@ -824,6 +854,9 @@ extern int init_main(int argc, char **argv)
|
||||
reboot(RB_DISABLE_CAD);
|
||||
#endif
|
||||
|
||||
/* Figure out what kernel this is running */
|
||||
kernelVersion = get_kernel_revision();
|
||||
|
||||
/* Figure out where the default console should be */
|
||||
console_init();
|
||||
|
||||
@@ -832,6 +865,7 @@ extern int init_main(int argc, char **argv)
|
||||
close(1);
|
||||
close(2);
|
||||
set_term(0);
|
||||
chdir("/");
|
||||
setsid();
|
||||
|
||||
/* Make sure PATH is set to something sane */
|
||||
@@ -839,23 +873,24 @@ extern int init_main(int argc, char **argv)
|
||||
|
||||
/* Hello world */
|
||||
#ifndef DEBUG_INIT
|
||||
message(LOG | CONSOLE,
|
||||
message(
|
||||
#if ! defined BB_FEATURE_EXTRA_QUIET
|
||||
CONSOLE|
|
||||
#endif
|
||||
LOG,
|
||||
"init started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
BB_VER, BB_BT);
|
||||
#else
|
||||
message(LOG | CONSOLE,
|
||||
message(
|
||||
#if ! defined BB_FEATURE_EXTRA_QUIET
|
||||
CONSOLE|
|
||||
#endif
|
||||
LOG,
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
|
||||
getpid(), BB_VER, BB_BT);
|
||||
#endif
|
||||
|
||||
|
||||
/* Mount /proc */
|
||||
if (mount("proc", "/proc", "proc", 0, 0) == 0) {
|
||||
message(LOG | CONSOLE, "Mounting /proc: done.\n");
|
||||
kernelVersion = get_kernel_revision();
|
||||
} else
|
||||
message(LOG | CONSOLE, "Mounting /proc: failed!\n");
|
||||
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
@@ -876,7 +911,7 @@ extern int init_main(int argc, char **argv)
|
||||
* of "askfirst" shells */
|
||||
parse_inittab();
|
||||
}
|
||||
|
||||
|
||||
/* Fix up argv[0] to be certain we claim to be init */
|
||||
strncpy(argv[0], "init", strlen(argv[0])+1);
|
||||
if (argc > 1)
|
||||
@@ -953,3 +988,11 @@ extern int init_main(int argc, char **argv)
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+5
-1
@@ -26,6 +26,10 @@
|
||||
|
||||
extern int poweroff_main(int argc, char **argv)
|
||||
{
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
/* don't assume init's pid == 1 */
|
||||
exit(kill(findInitPid(), SIGUSR2));
|
||||
exit(kill(*(findPidByName("init")), SIGUSR2));
|
||||
#else
|
||||
exit(kill(1, SIGUSR2));
|
||||
#endif
|
||||
}
|
||||
+13
-1
@@ -26,6 +26,18 @@
|
||||
|
||||
extern int reboot_main(int argc, char **argv)
|
||||
{
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
/* don't assume init's pid == 1 */
|
||||
exit(kill(findInitPid(), SIGINT));
|
||||
exit(kill(*(findPidByName("init")), SIGINT));
|
||||
#else
|
||||
exit(kill(1, SIGINT));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini insmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -15,6 +15,7 @@ for i in $h ; do
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
mkdir -p $1/bin
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+41
-9
@@ -46,17 +46,27 @@
|
||||
#define BUF_SIZE 8192
|
||||
#define EXPAND_ALLOC 1024
|
||||
|
||||
|
||||
#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
|
||||
#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
|
||||
#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
|
||||
#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
|
||||
|
||||
enum Location {
|
||||
_BB_DIR_ROOT = 0,
|
||||
_BB_DIR_BIN,
|
||||
_BB_DIR_SBIN,
|
||||
_BB_DIR_USR_BIN,
|
||||
_BB_DIR_USR_SBIN
|
||||
};
|
||||
|
||||
struct Applet {
|
||||
const char* name;
|
||||
int (*main)(int argc, char** argv);
|
||||
enum Location location;
|
||||
};
|
||||
|
||||
extern int basename_main(int argc, char **argv);
|
||||
extern int busybox_main(int argc, char** argv);
|
||||
extern int block_device_main(int argc, char** argv);
|
||||
extern int cat_main(int argc, char** argv);
|
||||
@@ -67,11 +77,13 @@ extern int chvt_main(int argc, char** argv);
|
||||
extern int clear_main(int argc, char** argv);
|
||||
extern int date_main(int argc, char** argv);
|
||||
extern int dd_main(int argc, char** argv);
|
||||
extern int dirname_main(int argc, char** argv);
|
||||
extern int deallocvt_main(int argc, char** argv);
|
||||
extern int df_main(int argc, char** argv);
|
||||
extern int dmesg_main(int argc, char** argv);
|
||||
extern int du_main(int argc, char** argv);
|
||||
extern int dutmp_main(int argc, char** argv);
|
||||
extern int echo_main(int argc, char** argv);
|
||||
extern int false_main(int argc, char** argv);
|
||||
extern int fbset_main(int argc, char** argv);
|
||||
extern int fdisk_main(int argc, char** argv);
|
||||
@@ -79,6 +91,7 @@ extern int fdflush_main(int argc, char **argv);
|
||||
extern int fsck_minix_main(int argc, char **argv);
|
||||
extern int find_main(int argc, char** argv);
|
||||
extern int free_main(int argc, char** argv);
|
||||
extern int freeramdisk_main(int argc, char** argv);
|
||||
extern int grep_main(int argc, char** argv);
|
||||
extern int gunzip_main (int argc, char** argv);
|
||||
extern int gzip_main(int argc, char** argv);
|
||||
@@ -122,6 +135,7 @@ extern int rmdir_main(int argc, char **argv);
|
||||
extern int rmmod_main(int argc, char** argv);
|
||||
extern int sed_main(int argc, char** argv);
|
||||
extern int sfdisk_main(int argc, char** argv);
|
||||
extern int shell_main(int argc, char** argv);
|
||||
extern int sleep_main(int argc, char** argv);
|
||||
extern int sort_main(int argc, char** argv);
|
||||
extern int swap_on_off_main(int argc, char** argv);
|
||||
@@ -130,28 +144,44 @@ extern int syslogd_main(int argc, char **argv);
|
||||
extern int tail_main(int argc, char** argv);
|
||||
extern int tar_main(int argc, char** argv);
|
||||
extern int tee_main(int argc, char** argv);
|
||||
extern int test_main(int argc, char** argv);
|
||||
extern int telnet_main(int argc, char** argv);
|
||||
extern int touch_main(int argc, char** argv);
|
||||
extern int tr_main(int argc, char** argv);
|
||||
extern int true_main(int argc, char** argv);
|
||||
extern int tput_main(int argc, char** argv);
|
||||
extern int tryopen_main(int argc, char** argv);
|
||||
extern int tty_main(int argc, char** argv);
|
||||
extern int umount_main(int argc, char** argv);
|
||||
extern int uname_main(int argc, char** argv);
|
||||
extern int uptime_main(int argc, char** argv);
|
||||
extern int uniq_main(int argc, char** argv);
|
||||
extern int update_main(int argc, char** argv);
|
||||
extern int usleep_main(int argc, char** argv);
|
||||
extern int wc_main(int argc, char** argv);
|
||||
extern int whoami_main(int argc, char** argv);
|
||||
extern int yes_main(int argc, char** argv);
|
||||
|
||||
|
||||
extern void usage(const char *usage) __attribute__ ((noreturn));
|
||||
extern void errorMsg(char *s, ...);
|
||||
extern void fatalError(char *s, ...) __attribute__ ((noreturn));
|
||||
extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
|
||||
|
||||
const char *modeString(int mode);
|
||||
const char *timeString(time_t timeVal);
|
||||
int isDirectory(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 copyFile(const char *srcName, const char *destName, int setModes,
|
||||
int followLinks);
|
||||
char *buildName(const char *dirName, const char *fileName);
|
||||
@@ -162,37 +192,39 @@ void freeChunks(void);
|
||||
int fullWrite(int fd, const char *buf, int len);
|
||||
int fullRead(int fd, char *buf, int len);
|
||||
int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
|
||||
int (*fileAction) (const char *fileName, struct stat* statbuf),
|
||||
int (*dirAction) (const char *fileName, struct stat* statbuf));
|
||||
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
|
||||
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
|
||||
void* userData);
|
||||
const char* timeString(time_t timeVal);
|
||||
|
||||
extern int createPath (const char *name, int mode);
|
||||
extern int parse_mode( const char* s, mode_t* theMode);
|
||||
|
||||
extern int get_kernel_revision(void);
|
||||
extern uid_t my_getpwnam(char *name);
|
||||
extern gid_t my_getgrnam(char *name);
|
||||
extern void my_getpwuid(char* name, uid_t uid);
|
||||
extern void my_getgrgid(char* group, gid_t gid);
|
||||
extern int get_kernel_revision();
|
||||
extern int get_console_fd(char* tty_name);
|
||||
extern struct mntent *findMountPoint(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 void mtab_free(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 getNum (const char *cp);
|
||||
extern pid_t findInitPid();
|
||||
extern pid_t* findPidByName( char* pidName);
|
||||
extern void *xmalloc (size_t size);
|
||||
extern int find_real_root_device_name(char* name);
|
||||
extern char *cstring_lineFromFile(FILE *f);
|
||||
|
||||
|
||||
#if defined BB_INIT || defined BB_SYSLOGD
|
||||
extern int device_open(char *device, int mode);
|
||||
#endif
|
||||
extern void whine_if_fstab_is_missing();
|
||||
|
||||
#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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini kill implementation for busybox
|
||||
* Mini kill/killall implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
@@ -35,6 +36,15 @@ static const char *kill_usage =
|
||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||
|
||||
#ifdef BB_KILLALL
|
||||
static const char *killall_usage =
|
||||
"killall [-signal] process-name [process-name ...]\n\n"
|
||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||
#endif
|
||||
|
||||
#define KILL 0
|
||||
#define KILLALL 1
|
||||
|
||||
struct signal_name {
|
||||
const char *name;
|
||||
@@ -120,13 +130,24 @@ const struct signal_name signames[] = {
|
||||
|
||||
extern int kill_main(int argc, char **argv)
|
||||
{
|
||||
int sig = SIGTERM;
|
||||
int whichApp, sig = SIGTERM;
|
||||
const char *appUsage;
|
||||
|
||||
#ifdef BB_KILLALL
|
||||
/* Figure out what we are trying to do here */
|
||||
whichApp = (strcmp(*argv, "killall") == 0)?
|
||||
KILLALL : KILL;
|
||||
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
|
||||
#else
|
||||
whichApp = KILL;
|
||||
appUsage = kill_usage;
|
||||
#endif
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
/* Parse any options */
|
||||
if (argc < 1)
|
||||
usage(kill_usage);
|
||||
usage(appUsage);
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
@@ -150,7 +171,7 @@ extern int kill_main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
usage(kill_usage);
|
||||
usage(appUsage);
|
||||
default:
|
||||
{
|
||||
if (isdigit(**argv)) {
|
||||
@@ -186,32 +207,44 @@ extern int kill_main(int argc, char **argv)
|
||||
|
||||
do_it_now:
|
||||
|
||||
while (--argc >= 0) {
|
||||
int pid;
|
||||
struct stat statbuf;
|
||||
char pidpath[20] = "/proc/";
|
||||
if (whichApp == KILL) {
|
||||
/* Looks like they want to do a kill. Do that */
|
||||
while (--argc >= 0) {
|
||||
int pid;
|
||||
|
||||
if (!isdigit(**argv)) {
|
||||
fprintf(stderr, "bad PID: %s\n", *argv);
|
||||
exit(FALSE);
|
||||
if (!isdigit(**argv))
|
||||
fatalError( "Bad PID: %s\n", strerror(errno));
|
||||
pid = strtol(*argv, NULL, 0);
|
||||
if (kill(pid, sig) != 0)
|
||||
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
||||
argv++;
|
||||
}
|
||||
pid = atoi(*argv);
|
||||
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
|
||||
if (stat(pidpath, &statbuf) != 0) {
|
||||
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
|
||||
exit(FALSE);
|
||||
}
|
||||
#ifdef BB_KILLALL
|
||||
else {
|
||||
pid_t myPid=getpid();
|
||||
/* Looks like they want to do a killall. Do that */
|
||||
while (--argc >= 0) {
|
||||
pid_t* pidList;
|
||||
|
||||
pidList = findPidByName( *argv);
|
||||
for(; pidList && *pidList!=0; pidList++) {
|
||||
if (*pidList==myPid)
|
||||
continue;
|
||||
if (kill(*pidList, sig) != 0)
|
||||
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
||||
}
|
||||
/* Note that we don't bother to free the memory
|
||||
* allocated in findPidByName(). It will be freed
|
||||
* upon exit, so we can save a byte or two */
|
||||
argv++;
|
||||
}
|
||||
fprintf(stderr, "sig = %d\n", sig);
|
||||
if (kill(pid, sig) != 0) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
#endif
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
|
||||
end:
|
||||
fprintf(stderr, "bad signal name: %s\n", *argv);
|
||||
exit(TRUE);
|
||||
fatalError( "bad signal name: %s\n", *argv);
|
||||
}
|
||||
Loaded 100 of 188 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user