Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aec27bca98 | ||
|
|
960be79964 | ||
|
|
be909b1cd5 | ||
|
|
d006c9e630 | ||
|
|
9ebccb2891 | ||
|
|
f1f6d58598 | ||
|
|
0c838af50b | ||
|
|
195fa15caf | ||
|
|
61dc057183 | ||
|
|
df5f6ba115 | ||
|
|
da9841efc1 | ||
|
|
da1d1e763d | ||
|
|
cc54d12ef7 | ||
|
|
dd23b8bb43 | ||
|
|
c674d70699 | ||
|
|
6315ce603b | ||
|
|
85c552035e | ||
|
|
9b2297a34e | ||
|
|
a0053735dc | ||
|
|
3849f9bfcc | ||
|
|
9a8243aa1e | ||
|
|
928faac503 | ||
|
|
34e1941c32 | ||
|
|
0b4551faf5 | ||
|
|
a03d86cf54 | ||
|
|
44735f8744 | ||
|
|
999bf72f49 | ||
|
|
e9b527ae48 | ||
|
|
161cf93404 | ||
|
|
f12724c21a | ||
|
|
a57ba4db64 | ||
|
|
2cd439f7f0 | ||
|
|
bd22ed8067 | ||
|
|
877a71bbf0 | ||
|
|
9cf44e79aa | ||
|
|
8f282f1b02 | ||
|
|
acecc47261 | ||
|
|
e6b9dfa967 | ||
|
|
53a955786d | ||
|
|
a2c83d885e | ||
|
|
03f9c81cec | ||
|
|
bb374a6935 | ||
|
|
4c95a28461 | ||
|
|
3312b0b626 | ||
|
|
2158092344 | ||
|
|
b9eb0233a9 | ||
|
|
b0b732bfe4 | ||
|
|
03f4c27bd6 | ||
|
|
67536ffa43 | ||
|
|
8845adc545 | ||
|
|
02bc25be56 | ||
|
|
e5cec4e3ac | ||
|
|
62bb2d02b6 | ||
|
|
a5dbb39dac | ||
|
|
c8c10c5715 | ||
|
|
f86aee74ce | ||
|
|
b1e379f7f3 | ||
|
|
78eab2f6c6 | ||
|
|
3cfa9ec09c | ||
|
|
6f5e281479 | ||
|
|
b2731b11ef | ||
|
|
1e03add675 | ||
|
|
5d893b6beb | ||
|
|
89bc256c94 | ||
|
|
f7cf2f7ef9 | ||
|
|
57ebebfb01 | ||
|
|
2086e3d679 | ||
|
|
028fb625f5 | ||
|
|
5331025f79 | ||
|
|
b02c54ebee | ||
|
|
72965e3454 | ||
|
|
b54833cde0 | ||
|
|
7c31ea4e29 | ||
|
|
5d41d60f1e | ||
|
|
2e1148b239 | ||
|
|
8bd891cbec | ||
|
|
1ca41775bb | ||
|
|
d37218941c | ||
|
|
268b8c4f38 | ||
|
|
0c96eba3de | ||
|
|
a44790f539 | ||
|
|
a2db097d66 | ||
|
|
1c314ad655 | ||
|
|
47cac6779a | ||
|
|
eb0283333b | ||
|
|
7cdc76dfbf | ||
|
|
d0edef3cbe | ||
|
|
495869f59a | ||
|
|
cb1d841f09 | ||
|
|
27b5924b96 | ||
|
|
8f425dbf9a | ||
|
|
83a949cb22 | ||
|
|
1386e70210 | ||
|
|
ef40aa81c5 | ||
|
|
3adffb7fc8 | ||
|
|
10dc9d4d17 | ||
|
|
8a24a6783a |
No files matched your search
@@ -31,6 +31,9 @@ Karl M. Hegbloom <karlheg@debian.org>
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
mktemp.c
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
documentation, bugfixes
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
|
||||
@@ -52,4 +55,3 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
|
||||
@@ -1,3 +1,66 @@
|
||||
0.46
|
||||
|
||||
* Better portability. Now should compile cleanly with libc5,
|
||||
GNU libc 2.0 and 2.1, and various Linux kernels including
|
||||
2.0.x, 2.2.x, and to 2.4.0-test*. (patch for 2.4.x kernels
|
||||
to make /proc/mounts behave included in the kernel-patches dir).
|
||||
* Fixed a _horrible_ bug where 'tar -tvf' could unlink
|
||||
local files that matched tarball contents!!! Fix thanks
|
||||
to Marius Groeger <mgroeger@sysgo.de>
|
||||
* Fixed a nasty bug in tar when could mess up saved symlinks.
|
||||
* Fixed tar creation support when reading from stdin ('tar -cf - . ')
|
||||
thanks to Daniel Quinlan <quinlan@transmeta.com>
|
||||
* Updates to handle Linux 2.4.0 kernels (kludged around the
|
||||
"none" entries in /proc/mounts, added a hack to make sysinfo
|
||||
work with both old and new kernels).
|
||||
* Fixed insmod module option parsing for options lacking an '='.
|
||||
Fix thanks to Marc Nijdam <marc_nijdam@hp.com>
|
||||
* Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
|
||||
Fix thanks to Arne Bernin <arne@matrix.loopback.org>
|
||||
* Several fixes from Marius Groeger <mag@sysgo.de>
|
||||
- Added support for "sh -c command args..."
|
||||
- Fixed globbing, i.e. 'echo * *' and 'echo "******"' now work.
|
||||
- Added shell environment variable substitution
|
||||
- Added the "read" shell builtin.
|
||||
* Fixed cursor editing in cmdedit.c. The following keyboard sequence
|
||||
used to create an infinite loop: ls, cursor up, left, down.
|
||||
* Added support for being a login shell, so things like
|
||||
'-su' or '-sh' (stuff where argv[0][0]=='-') will now always
|
||||
invoke the shell. Now you can use BusyBox as a login shell.
|
||||
* ls.c now ignores '-g', since some ftp clients like that sort
|
||||
of thing. Patch thanks to David Vrabel <dvrabel@arcom.co.uk>
|
||||
* Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that
|
||||
it always sets the controlling terminal before running any programs
|
||||
* Several fixes from Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
- Fixed tr so it recognizes standard escape sequences.
|
||||
Merged common escape seq. code from tr and echo into utility.c.
|
||||
- Major work in updating/cleaning up the docs, and getting the
|
||||
new SGML based docs into shape.
|
||||
- cleanup of ar.c
|
||||
- BusyBox should now poweroff when asked to do so.
|
||||
- Fixed 'ln -n' and 'ln -s' so they both work properly.
|
||||
* Reorganized signal names in kill.c for better architecture support
|
||||
-- patch thanks to simon wood <simon@mungewell.uklinux.net>
|
||||
* In 0.43, backspace and delete worked properly, but with 0.45,
|
||||
it just echoed a ^? for backspace, and ^H for control-h. This
|
||||
was due to a broken macro in init.c, that is now fixed.
|
||||
* Removed sfdisk from BusyBox. It was buggy, fat, and we really
|
||||
couldn't maintain it very well, so including it was not really
|
||||
very appropriate. Those wanting an fdisk are invited to
|
||||
grab a copy from util-linux.
|
||||
* Added 'dumpkmap' to allow people to dump a binary keymap, which can
|
||||
then be loaded in by 'loadkmap' -- submitted by
|
||||
Arne Bernin <arne@matrix.loopback.org>
|
||||
* Fixed NFS so it supports 2.4.x kernels and NFSv3.
|
||||
* Brand, new versions of grep and sed which use libc regex routines,
|
||||
thanks to Mark Whitley <markw@lineo.com>. The hand-tooled
|
||||
"regexp.[ch]" files have been removed. Much help on these from
|
||||
Matt Kraai as well.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.45
|
||||
* Now compiles vs libc5 (which can save lots of space for
|
||||
embedded systems).
|
||||
@@ -22,7 +85,7 @@
|
||||
* Replaced the telnet implementation with one written by
|
||||
Tomi Ollila <too@iki.fi> It works great and costs 3k.
|
||||
* BusyBox sh (lash) now supports being used as a standalone shell. When
|
||||
BB_FEATURE_STANDALONE_SHELL is defined, all the busybox commands may
|
||||
BB_FEATURE_SH_STANDALONE_SHELL is defined, all the busybox commands may
|
||||
be invoked as shell internals. Best used when compiling staticly
|
||||
(i.e. DOSTATIC=true)
|
||||
* BusyBox sh (lash) internals now behave as expected wrt pipes
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.45
|
||||
VERSION := 0.46
|
||||
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
@@ -33,7 +33,8 @@ DOSTATIC = false
|
||||
|
||||
# To compile vs an alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs. This is how I did it...
|
||||
#CFLAGS+=-nostdinc -I/home/andersen/CVS/uC-libc/include -I/usr/include/linux
|
||||
#GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
#CFLAGS+=-nostdinc -fno-builtin -I/home/andersen/CVS/uC-libc/include -I$(GCCINCDIR)
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = /home/andersen/CVS/uC-libc/libc.a
|
||||
|
||||
@@ -52,11 +53,11 @@ endif
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS += -Wall -g -fno-builtin -D_GNU_SOURCE
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
LDFLAGS +=
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
|
||||
LDFLAGS += -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
@@ -79,7 +80,6 @@ ifndef $(PREFIX)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
@@ -89,7 +89,10 @@ endif
|
||||
|
||||
all: busybox busybox.links doc
|
||||
|
||||
doc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
doc: olddoc
|
||||
|
||||
# Old Docs...
|
||||
olddoc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
@echo
|
||||
@@ -105,9 +108,33 @@ docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
|
||||
- ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
|
||||
- pod2html docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
|
||||
- pod2html --noindex docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f pod2html*
|
||||
|
||||
|
||||
# New docs based on DOCBOOK SGML
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busybox.html
|
||||
|
||||
docs/busybox.txt: docs/busybox.sgml
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
(cd docs; sgmltools -b txt busybox.sgml)
|
||||
|
||||
docs/busybox.dvi: docs/busybox.sgml
|
||||
(cd docs; sgmltools -b dvi busybox.sgml)
|
||||
|
||||
docs/busybox.ps: docs/busybox.sgml
|
||||
(cd docs; sgmltools -b ps busybox.sgml)
|
||||
|
||||
docs/busybox.pdf: docs/busybox.ps
|
||||
(cd docs; ps2pdf busybox.ps)
|
||||
|
||||
docs/busybox/busybox.html: docs/busybox.sgml
|
||||
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP)
|
||||
@@ -115,7 +142,7 @@ busybox: $(OBJECTS)
|
||||
busybox.links: busybox.def.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
regexp.o nfsmount.o cmdedit.o: %.o: %.h
|
||||
nfsmount.o cmdedit.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
|
||||
test tests:
|
||||
@@ -125,8 +152,11 @@ clean:
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
- rm -f docs/BusyBox.html docs/busybox.lineo.com/BusyBox.html \
|
||||
docs/BusyBox.1 docs/BusyBox.txt pod2html*
|
||||
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pdf docs/busybox.lineo.com/busybox.html
|
||||
- rm -rf docs/busybox
|
||||
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
@@ -150,4 +180,13 @@ dist release: distclean doc
|
||||
-print \
|
||||
| xargs rm -f; \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
| xargs rm -f; \
|
||||
\
|
||||
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
|
||||
|
||||
.PHONY: tags
|
||||
tags:
|
||||
ctags -R .
|
||||
@@ -16,58 +16,6 @@ around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
-----------
|
||||
|
||||
Bugs that need fixing:
|
||||
|
||||
- 'ln -n' has been disabled for this release, till we can fix a memory
|
||||
corruption bug.
|
||||
- fix 'cp' (or test suite script) so that it passes the last item in
|
||||
the test suite.
|
||||
- ps dirent race bug (need to stat the file before attempting chdir)
|
||||
- Make 'ln -s /tmp/file .' work the way GNU ln does (i.e. makes a link to
|
||||
/tmp/file in the current directory, rather then trying and failing to create
|
||||
a symlink named "." in the current working directory).
|
||||
- Prune sfdisk, graft in std fdisk instead
|
||||
|
||||
|
||||
We will rework these to use libc regex functions instead (as per the mailing
|
||||
list discussion):
|
||||
- 'grep foo$ file' doesn't work
|
||||
- 'grep *foo file' segfaults
|
||||
|
||||
|
||||
-----------
|
||||
|
||||
Linux 2.4.x kernels
|
||||
|
||||
BusyBox 0.45 currently will not work with the Linux 2.4.x kernels.
|
||||
I know of the following problems:
|
||||
|
||||
1) The sysinfo syscall has changed what it does (binary incompatable), breaking
|
||||
init and free.
|
||||
2) BusyBox NFS support is broken with 2.4.x (needs to be adjusted for NFSv3 and
|
||||
kernel header changes).
|
||||
3) mount,umount,and df are all broken by the "none" entries for fake filesystems
|
||||
such as the shared mem one. Al Viro claims these will be disappearing soon...
|
||||
|
||||
I made a kernel patch that reverts the sysinfo changes
|
||||
http://kernelnotes.org/lnxlists/linux-kernel/lk_0006_01/msg00619.html
|
||||
|
||||
and I have been fighting with Alan Cox to get these changes fixed in a binary
|
||||
compatable way, but Alan has so far not been very receptive. I am planning on
|
||||
appealing to Linus (when he gets back from vacation) and then going with
|
||||
whatever he decides...
|
||||
|
||||
So my thought is, 2.4.x just isn't ready for BusyBox to target it, and even if
|
||||
it was, BusyBox isn't ready yet either. Seems to me like this will not be
|
||||
ready for a while, and we should just not worry about it yet.
|
||||
|
||||
As long as I have BB_FEATURE_NFSMOUNT turned off, everything compiles cleanly
|
||||
for me with linux2.4.0test1-ac22-riel (i.e. I don't see the freeramdisk.c
|
||||
problem you reported). I use Debian potato (gcc 2.95.2, GNU libc 2.1.3).
|
||||
Of course, as noted above, compiling != working.
|
||||
|
||||
-----------
|
||||
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/netstat
|
||||
@@ -109,32 +57,6 @@ to be present in an embedded system.
|
||||
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).
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
> 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,
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
|
||||
+117
-6
@@ -39,9 +39,6 @@ const struct BB_applet applets[] = {
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -90,6 +87,9 @@ const struct BB_applet applets[] = {
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
@@ -261,9 +261,6 @@ const struct BB_applet applets[] = {
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -358,6 +355,83 @@ const struct BB_applet applets[] = {
|
||||
};
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
"/",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/usr/bin",
|
||||
"/usr/sbin",
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static char *busybox_fullpath()
|
||||
{
|
||||
pid_t pid;
|
||||
char path[256];
|
||||
char proc[256];
|
||||
int len;
|
||||
|
||||
pid = getpid();
|
||||
sprintf(proc, "/proc/%d/exe", pid);
|
||||
len = readlink(proc, path, 256);
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static int install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
if (use_symbolic_links) Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
sprintf (
|
||||
command,
|
||||
"%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name
|
||||
);
|
||||
#if 1
|
||||
rc |= Link(busybox, command);
|
||||
#else
|
||||
puts(command);
|
||||
#endif
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int uninstall_links() ?
|
||||
#endif
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -365,6 +439,36 @@ int main(int argc, char **argv)
|
||||
char *name;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
@@ -372,6 +476,13 @@ int main(int argc, char **argv)
|
||||
|
||||
*argv = name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1
|
||||
#define AR_VERBOSE 2
|
||||
#define AR_DISPLAY 4
|
||||
#define AR_EXT_TO_FILE 8
|
||||
#define AR_EXT_TO_STDOUT 16
|
||||
#define AR_PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define AR_VERBOSE 2 /* be verbose */
|
||||
#define AR_DISPLAY 4 /* display contents */
|
||||
#define AR_EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define AR_EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
@@ -302,20 +302,20 @@ extern int ar_main(int argc, char **argv)
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o': /* preserver original dates */
|
||||
funct = funct | 1;
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
break;
|
||||
case 'p': /* extract to stdout */
|
||||
funct = funct | 16;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
break;
|
||||
case 't': /* display contents */
|
||||
funct = funct | 4;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
break;
|
||||
case 'x': /* extract contents of archive */
|
||||
funct = funct | 8;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
break;
|
||||
case 'v': /* be verbose */
|
||||
funct = funct | 2;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
|
||||
+15
-15
@@ -35,11 +35,11 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1
|
||||
#define AR_VERBOSE 2
|
||||
#define AR_DISPLAY 4
|
||||
#define AR_EXT_TO_FILE 8
|
||||
#define AR_EXT_TO_STDOUT 16
|
||||
#define AR_PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define AR_VERBOSE 2 /* be verbose */
|
||||
#define AR_DISPLAY 4 /* display contents */
|
||||
#define AR_EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define AR_EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
@@ -302,20 +302,20 @@ extern int ar_main(int argc, char **argv)
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o': /* preserver original dates */
|
||||
funct = funct | 1;
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
break;
|
||||
case 'p': /* extract to stdout */
|
||||
funct = funct | 16;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
break;
|
||||
case 't': /* display contents */
|
||||
funct = funct | 4;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
break;
|
||||
case 'x': /* extract contents of archive */
|
||||
funct = funct | 8;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
break;
|
||||
case 'v': /* be verbose */
|
||||
funct = funct | 2;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <getopt.h>
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n"
|
||||
|
||||
+8
-2
@@ -198,6 +198,8 @@ extern int tar_main(int argc, char **argv)
|
||||
tarName = *(++argv);
|
||||
if (tarName == NULL)
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
if (!strcmp(tarName, "-"))
|
||||
tostdoutFlag = TRUE;
|
||||
stopIt=TRUE;
|
||||
break;
|
||||
|
||||
@@ -648,7 +650,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
}
|
||||
|
||||
/* Remove any clutter lying in our way */
|
||||
unlink( header.name);
|
||||
if (extractFlag == TRUE) /* .. but only if we are extracting (as */
|
||||
unlink( header.name); /* opposed to listing) (rob@sysgo.de) */
|
||||
|
||||
/* If we got here, we can be certain we have a legitimate
|
||||
* header to work with. So work with it. */
|
||||
@@ -824,12 +827,15 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
||||
|
||||
/* WARNING/NOTICE: I break Hard Links */
|
||||
if (S_ISLNK(statbuf->st_mode)) {
|
||||
int link_size=0;
|
||||
char buffer[BUFSIZ];
|
||||
header.typeflag = SYMTYPE;
|
||||
if ( readlink(fileName, buffer, sizeof(buffer) - 1) < 0) {
|
||||
link_size = readlink(fileName, buffer, sizeof(buffer) - 1);
|
||||
if ( link_size < 0) {
|
||||
errorMsg("Error reading symlink '%s': %s\n", header.name, strerror(errno));
|
||||
return ( FALSE);
|
||||
}
|
||||
buffer[link_size] = '\0';
|
||||
strncpy(header.linkname, buffer, sizeof(header.linkname));
|
||||
} else if (S_ISDIR(statbuf->st_mode)) {
|
||||
header.typeflag = DIRTYPE;
|
||||
|
||||
+2
-10
@@ -35,7 +35,7 @@ const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
char *s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(basename_usage);
|
||||
@@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
|
||||
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
s = get_last_path_component(*argv);
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
@@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
|
||||
printf("%s\n", s);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@ const struct BB_applet applets[] = {
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -90,6 +87,9 @@ const struct BB_applet applets[] = {
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
@@ -261,9 +261,6 @@ const struct BB_applet applets[] = {
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -358,6 +355,83 @@ const struct BB_applet applets[] = {
|
||||
};
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
"/",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/usr/bin",
|
||||
"/usr/sbin",
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static char *busybox_fullpath()
|
||||
{
|
||||
pid_t pid;
|
||||
char path[256];
|
||||
char proc[256];
|
||||
int len;
|
||||
|
||||
pid = getpid();
|
||||
sprintf(proc, "/proc/%d/exe", pid);
|
||||
len = readlink(proc, path, 256);
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static int install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
if (use_symbolic_links) Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
sprintf (
|
||||
command,
|
||||
"%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name
|
||||
);
|
||||
#if 1
|
||||
rc |= Link(busybox, command);
|
||||
#else
|
||||
puts(command);
|
||||
#endif
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int uninstall_links() ?
|
||||
#endif
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -365,6 +439,36 @@ int main(int argc, char **argv)
|
||||
char *name;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
@@ -372,6 +476,13 @@ int main(int argc, char **argv)
|
||||
|
||||
*argv = name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
|
||||
+31
-15
@@ -25,6 +25,7 @@
|
||||
#define BB_DMESG
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_FBSET
|
||||
#define BB_FDFLUSH
|
||||
@@ -44,7 +45,6 @@
|
||||
#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
#define BB_LOADACM
|
||||
@@ -55,7 +55,7 @@
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
#define BB_MAKEDEVS
|
||||
//#define BB_MD5SUM
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKFS_MINIX
|
||||
@@ -78,7 +78,6 @@
|
||||
#define BB_RMMOD
|
||||
#define BB_SED
|
||||
#define BB_SETKEYCODES
|
||||
#define BB_SFDISK
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
@@ -116,12 +115,18 @@
|
||||
// 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)
|
||||
//
|
||||
// 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 not use this and
|
||||
// USE_PROCFS at the same time... NOTE: If you enable this feature, you
|
||||
// _must_ have patched the kernel to include the devps patch that is included
|
||||
// in the busybox/kernel-patches directory. You will also need to create some
|
||||
// device special files /dev on your embedded system:
|
||||
// mknod /dev/modules c 10 23
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// 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
|
||||
@@ -159,7 +164,7 @@
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
//#define BB_FEATURE_SIMPLE_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
@@ -178,6 +183,9 @@
|
||||
//Make sure nothing is printed to the console on boot
|
||||
#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
//Should syslogd also provide klogd support?
|
||||
#define BB_FEATURE_KLOGD
|
||||
//
|
||||
//Simple tail implementation (2k vs 6k for the full one). Still
|
||||
//provides 'tail -f' support -- but for only one file at a time.
|
||||
#define BB_FEATURE_SIMPLE_TAIL
|
||||
@@ -188,14 +196,14 @@
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes
|
||||
// (This does not yet work with Linux 2.[34].x kernels)
|
||||
#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e. in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes
|
||||
// (This does not yet work with Linux 2.[34].x kernels)
|
||||
//#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
@@ -211,7 +219,7 @@
|
||||
//Allow the shell to invoke all the compiled in BusyBox commands as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell
|
||||
//amoung other thing.
|
||||
#define BB_FEATURE_STANDALONE_SHELL
|
||||
#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
// Enable tab completion in the shell (not yet
|
||||
// working very well -- so don't turn this on)
|
||||
@@ -220,6 +228,9 @@
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
//#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// You must enable one or both of these features
|
||||
// Support installing modules from pre 2.1 kernels
|
||||
//#define BB_FEATURE_INSMOD_OLD_KERNEL
|
||||
@@ -230,6 +241,11 @@
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
// #define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.45
|
||||
Version: 0.46
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -143,6 +143,12 @@ void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
/* Debug crap */
|
||||
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
|
||||
//xwrite(outputFd, command, *len);
|
||||
//*cursor = *len;
|
||||
|
||||
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\b \b", 3);
|
||||
--*cursor;
|
||||
@@ -534,7 +540,10 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
rewrite_line:
|
||||
/* erase old command from command line */
|
||||
len = strlen(command)-strlen(hp->s);
|
||||
while (len>0)
|
||||
|
||||
while (len>cursor)
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
while (cursor>0)
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
input_home(outputFd, &cursor);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef GETLINE_H
|
||||
#define GETLINE_H
|
||||
#ifndef CMDEDIT_H
|
||||
#define CMDEDIT_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
@@ -34,4 +34,4 @@ extern int (*cmdedit_tab_hook)();
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* GETLINE_H */
|
||||
#endif /* CMDEDIT_H */
|
||||
@@ -5,12 +5,16 @@
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,14 @@
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dumpkmap implementation for busybox
|
||||
*
|
||||
* Copyright (C) Arne Bernin <arne@matrix.loopback.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 <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char dumpkmap_usage[] = "dumpkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out a binary keyboard translation table to standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(dumpkmap_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(1, magic, 7);
|
||||
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
|
||||
flags[0]=1;
|
||||
flags[1]=1;
|
||||
flags[2]=1;
|
||||
flags[4]=1;
|
||||
flags[5]=1;
|
||||
flags[6]=1;
|
||||
flags[8]=1;
|
||||
flags[9]=1;
|
||||
flags[10]=1;
|
||||
flags[12]=1;
|
||||
|
||||
/* dump flags */
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
fprintf(stderr, "ioctl returned: %s, %s, %s, %xqq\n",strerror(errno),(char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,&ke.kb_value,2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
if (fstat(fileno(fp), &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
|
||||
@@ -24,14 +24,24 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/keyboard.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDSKBENT 0x4B47 /* sets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a binary keyboard translation table from standard input.\n"
|
||||
"\nLoads a binary keyboard translation table from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
@@ -27,7 +27,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/kd.h>
|
||||
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbkeycode {
|
||||
unsigned int scancode, keycode;
|
||||
};
|
||||
#define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */
|
||||
|
||||
|
||||
static const char setkeycodes_usage[] =
|
||||
"setkeycodes SCANCODE KEYCODE ...\n"
|
||||
|
||||
+2
-10
@@ -35,7 +35,7 @@ const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
char *s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(basename_usage);
|
||||
@@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
|
||||
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
s = get_last_path_component(*argv);
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
@@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
|
||||
printf("%s\n", s);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
+23
-7
@@ -51,15 +51,14 @@ int num_args;
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
|
||||
#define SET 1 /* option selected */
|
||||
#define OPTIONS 1 /*define option -s */
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
@@ -75,6 +74,7 @@ FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
int option = 0; /* for -s option */
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
@@ -85,7 +85,7 @@ void cut(void);
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -d allowed only with -f\n",
|
||||
"%s: Option -%s allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
@@ -161,7 +161,8 @@ void cut()
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
length = strlen(line) - 1;
|
||||
maxcol=0;
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
@@ -182,11 +183,15 @@ void cut()
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
|
||||
printf("%s", columns[j - 1]);
|
||||
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
} else if (option != OPTIONS) {
|
||||
printf("%s",line);
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
@@ -217,7 +222,8 @@ int cut_main(int argc, char **argv)
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
|
||||
"\t-d CHAR\tUse CHAR instead of tab as the field delimiter\n"
|
||||
"\t-s\tOnly output Lines if the include DELIM\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
@@ -229,7 +235,10 @@ int cut_main(int argc, char **argv)
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
delim = argv[i++][0];
|
||||
if (argc > i)
|
||||
delim = argv[i++][0];
|
||||
else
|
||||
cuterror(SYNTAX_ERROR);
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
@@ -248,6 +257,10 @@ int cut_main(int argc, char **argv)
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case 's':
|
||||
option = OPTIONS;
|
||||
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
@@ -268,6 +281,9 @@ int cut_main(int argc, char **argv)
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
|
||||
if (mode != OPTIONF && option == OPTIONS)
|
||||
warn(DELIMITER_NOT_APPLICABLE,"s");
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
|
||||
+5
-23
@@ -40,7 +40,7 @@ extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
@@ -65,28 +65,10 @@ echo_main(int argc, char** argv)
|
||||
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;
|
||||
}
|
||||
if (*p == 'c')
|
||||
exit(0);
|
||||
else
|
||||
c = process_escape_sequence(&p);
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
+17
-28
@@ -40,9 +40,7 @@ static const char ln_usage[] =
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
|
||||
"\t-f\tremove existing destination files\n"
|
||||
#if 0
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
@@ -52,7 +50,7 @@ static int followLinks = TRUE;
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
char *linkName;
|
||||
char *linkName, *dirName=NULL;
|
||||
int linkIntoDirFlag;
|
||||
int stopIt = FALSE;
|
||||
|
||||
@@ -92,41 +90,27 @@ extern int ln_main(int argc, char **argv)
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if (strlen(linkName) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
dirName = linkName;
|
||||
|
||||
while (argc-- >= 2) {
|
||||
#if 0
|
||||
char srcName[BUFSIZ + 1];
|
||||
int nChars;
|
||||
#endif
|
||||
int status;
|
||||
|
||||
if (strlen(*argv) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
if (linkIntoDirFlag == TRUE) {
|
||||
char *baseName = get_last_path_component(*argv);
|
||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||
strcpy(linkName, dirName);
|
||||
if(dirName[strlen(dirName)-1] != '/')
|
||||
strcat(linkName, "/");
|
||||
strcat(linkName,baseName);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (followLinks == FALSE) {
|
||||
strcpy(srcName, *argv);
|
||||
} else {
|
||||
/* Warning! This can silently truncate if > BUFSIZ, but
|
||||
I don't think that there can be one > BUFSIZ anyway. */
|
||||
nChars = readlink(*argv, srcName, BUFSIZ);
|
||||
srcName[nChars] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
if (removeoldFlag == TRUE) {
|
||||
status = (unlink(linkName) && errno != ENOENT);
|
||||
if (status != 0) {
|
||||
@@ -143,6 +127,11 @@ extern int ln_main(int argc, char **argv)
|
||||
perror(linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
free(linkName);
|
||||
|
||||
argv++;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
+3
-5
@@ -49,11 +49,7 @@
|
||||
/************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -345,7 +341,7 @@ static int list_item(const char *name)
|
||||
struct stat info;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char fullname[MAXNAMLEN + 1], *fnend;
|
||||
char fullname[BUFSIZ + 1], *fnend;
|
||||
|
||||
if (lstat(name, &info))
|
||||
goto listerr;
|
||||
@@ -568,6 +564,8 @@ extern int ls_main(int argc, char **argv)
|
||||
opts |= DISP_RECURSIVE;
|
||||
break;
|
||||
#endif
|
||||
case 'g': /* ignore -- for ftp servers */
|
||||
break;
|
||||
default:
|
||||
goto print_usage_message;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,14 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
|
||||
/* It turns out that libc5 doesn't have this in its headers
|
||||
* even though it is actually in the lib. Force it to work */
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
#define getline __getline
|
||||
extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--------md5.c
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ static Line *line_newFromFile(FILE * src)
|
||||
Line *self;
|
||||
char *cstring = NULL;
|
||||
|
||||
if ((cstring = cstring_lineFromFile(src))) {
|
||||
if ((cstring = get_line_from_file(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
@@ -304,4 +304,4 @@ int sort_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.17 2000/06/19 17:25:40 andersen Exp $ */
|
||||
/* $Id: sort.c,v 1.18 2000/06/28 22:15:26 markw Exp $ */
|
||||
+6
-12
@@ -111,22 +111,14 @@ static void map(register unsigned char *string1, register unsigned char *string2
|
||||
}
|
||||
}
|
||||
|
||||
static void expand(register char *arg, register unsigned char *buffer)
|
||||
static void expand(char *arg, register unsigned char *buffer)
|
||||
{
|
||||
int i, ac;
|
||||
|
||||
while (*arg) {
|
||||
if (*arg == '\\') {
|
||||
arg++;
|
||||
i = ac = 0;
|
||||
if (*arg >= '0' && *arg <= '7') {
|
||||
do {
|
||||
ac = (ac << 3) + *arg++ - '0';
|
||||
i++;
|
||||
} while (i < 4 && *arg >= '0' && *arg <= '7');
|
||||
*buffer++ = ac;
|
||||
} else if (*arg != '\0')
|
||||
*buffer++ = *arg++;
|
||||
*buffer++ = process_escape_sequence(&arg);
|
||||
} else if (*arg == '[') {
|
||||
arg++;
|
||||
i = *arg++;
|
||||
@@ -195,10 +187,12 @@ extern int tr_main(int argc, char **argv)
|
||||
expand(argv[index++], input);
|
||||
if (com_fl)
|
||||
complement(input);
|
||||
if (argv[index] != NULL)
|
||||
if (argv[index] != NULL) {
|
||||
if (*argv[index] == '\0')
|
||||
fatalError("tr: STRING2 cannot be empty\n");
|
||||
expand(argv[index], output);
|
||||
if (argv[index] != NULL)
|
||||
map(input, output);
|
||||
}
|
||||
for (ptr = input; *ptr; ptr++)
|
||||
invec[*ptr] = TRUE;
|
||||
for (ptr = output; *ptr; ptr++)
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
|
||||
/*struct passwd *getpwnam();*/
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#define RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
|
||||
@@ -51,15 +51,14 @@ int num_args;
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
|
||||
#define SET 1 /* option selected */
|
||||
#define OPTIONS 1 /*define option -s */
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
@@ -75,6 +74,7 @@ FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
int option = 0; /* for -s option */
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
@@ -85,7 +85,7 @@ void cut(void);
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -d allowed only with -f\n",
|
||||
"%s: Option -%s allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
@@ -161,7 +161,8 @@ void cut()
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
length = strlen(line) - 1;
|
||||
maxcol=0;
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
@@ -182,11 +183,15 @@ void cut()
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
|
||||
printf("%s", columns[j - 1]);
|
||||
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
} else if (option != OPTIONS) {
|
||||
printf("%s",line);
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
@@ -217,7 +222,8 @@ int cut_main(int argc, char **argv)
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
|
||||
"\t-d CHAR\tUse CHAR instead of tab as the field delimiter\n"
|
||||
"\t-s\tOnly output Lines if the include DELIM\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
@@ -229,7 +235,10 @@ int cut_main(int argc, char **argv)
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
delim = argv[i++][0];
|
||||
if (argc > i)
|
||||
delim = argv[i++][0];
|
||||
else
|
||||
cuterror(SYNTAX_ERROR);
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
@@ -248,6 +257,10 @@ int cut_main(int argc, char **argv)
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case 's':
|
||||
option = OPTIONS;
|
||||
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
@@ -268,6 +281,9 @@ int cut_main(int argc, char **argv)
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
|
||||
if (mode != OPTIONF && option == OPTIONS)
|
||||
warn(DELIMITER_NOT_APPLICABLE,"s");
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
|
||||
@@ -170,7 +170,7 @@ int dc_main(int argc, char **argv)
|
||||
char *line = NULL;
|
||||
char *cursor = NULL;
|
||||
char *token = NULL;
|
||||
while ((line = cstring_lineFromFile(stdin))) {
|
||||
while ((line = get_line_from_file(stdin))) {
|
||||
cursor = line;
|
||||
len = number_of_tokens(line);
|
||||
for (i = 0; i < len; i++) {
|
||||
|
||||
+5
-2
@@ -5,11 +5,14 @@
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
|
||||
Vendored
+8
-2
@@ -1,4 +1,10 @@
|
||||
busybox (0.45-1) frozen; urgency=low
|
||||
busybox (0.46-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 11 Jul 2000 12:15:44 -0600
|
||||
|
||||
busybox (0.45-1) unstable; urgency=low
|
||||
|
||||
* First attempt at packaging BusyBox as a .deb. This has been in
|
||||
in the Debian boot-floppies CVS tree forever. Hopefully, having it as a
|
||||
@@ -10,7 +16,7 @@ busybox (0.45-1) frozen; urgency=low
|
||||
times in the past that I would have loved to have this sitting on my system
|
||||
(i.e. when libc gets screwed up.)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sun, 18 Jun 2000 21:45:47 -0600
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 27 Jun 2000 12:26:41 -0600
|
||||
|
||||
Local variables:
|
||||
mode: debian-changelog
|
||||
|
||||
Vendored
+5
-5
@@ -1,14 +1,14 @@
|
||||
Source: busybox
|
||||
Priority: optional
|
||||
Maintainer: Erik Andersen <andersee@debian.org>
|
||||
Build-Depends: debhelper (>= 2.0.80)
|
||||
Build-Depends: debhelper
|
||||
Standards-Version: 3.1.1
|
||||
|
||||
Package: busybox
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Conflicts: binutils, bsdutils, console-tools, cpio, debianutils, dnsutils, dpkg, fbset, fdflush, fileutils, grep, gzip, hostname, modutils, mount, netbase, procps, psmisc, sed, sharutils, shellutils, sysklogd, sysvinit, tar, textutils, update, util-linux
|
||||
Replaces: dpkg, netbase
|
||||
Replaces: netbase
|
||||
Section: utils
|
||||
Description: Tiny utilities for the debian-installer and for embedded systems.
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
@@ -20,9 +20,9 @@ Description: Tiny utilities for the debian-installer and for embedded systems.
|
||||
counterparts.
|
||||
.
|
||||
BusyBox is used by the debian-installer. Installing BusyBox onto your Debian
|
||||
system is not recommended, unless you are intended to make a very small embedded
|
||||
system. Chances are good that for embedded systems, you will want to recompile
|
||||
to only include the tools and utilities you wish to include.
|
||||
system is not recommended, unless you are intended to make a very small
|
||||
embedded system. Chances are good that for embedded systems, you will want to
|
||||
recompile to only include the tools and utilities you wish to include.
|
||||
|
||||
Package: busybox-static
|
||||
Architecture: any
|
||||
|
||||
Vendored
+17
-6
@@ -74,12 +74,18 @@ busybox: install
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
rm -rf $(bb)/usr/share/doc/busybox/busybox.lineo.com/CVS \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/.cvsignore \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/images/CVS \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/images/.cvsignore
|
||||
#
|
||||
#Note that for busybox, we do not install any docs,
|
||||
# or man apges or anything else. This is in blatent violation of every
|
||||
# Debian policy out there, since this package is intended to be used
|
||||
# _only_ by the debian-installer.
|
||||
#
|
||||
#dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
# docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
#rm -rf $(bb)/usr/share/doc/busybox/busybox.lineo.com/CVS \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/.cvsignore \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/images/CVS \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/images/.cvsignore
|
||||
#dh_undocumented -p$@
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_strip -p$@
|
||||
@@ -87,6 +93,11 @@ busybox: install
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
#
|
||||
#Make _very_ sure there are no docs lurking about.
|
||||
#
|
||||
rm -rf $(bb)/usr/share/doc
|
||||
rm -rf $(bb)/usr/share/man
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <linux/unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -76,6 +76,17 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
|
||||
|
||||
<ul>
|
||||
|
||||
<p> <li> <b>11 July 2000 -- BusyBox 0.46 released</b>
|
||||
<br>
|
||||
|
||||
This release fixes several bugs (including a ugly bug in tar,
|
||||
and fixes for NFSv3 mount support). Added a dumpkmap to allow
|
||||
people to dump a binary keymaps for use with 'loadkmap', and a
|
||||
completely reworked 'grep' and 'sed' with should behave better.
|
||||
BusyBox shell can now also be used as a login shell.
|
||||
See the <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a> for complete details.
|
||||
|
||||
|
||||
<p> <li> <b>21 June 2000 -- BusyBox 0.45 released</b>
|
||||
<br>
|
||||
|
||||
@@ -148,28 +159,32 @@ Current documentation for BusyBox includes:
|
||||
a <em>lot</em> of time updating these docs and trying to make them
|
||||
fairly comprehensive for the BusyBox 0.43 release. If you find any
|
||||
errors (factual, grammatical, whatever) please let me know.
|
||||
|
||||
<li> More documentation will follow.
|
||||
<li> <a href="http://bugs.lineo.com/db/pa/lbusybox.html">BusyBoxBugs</a>.
|
||||
<li> If you need more help, the BusyBox
|
||||
<a href="http://opensource.lineo.com/lists/busybox/">mailing list</a> is
|
||||
a good place to start.
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Begin Projects section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="docs"><BIG><B>
|
||||
<A NAME="projects"><BIG><B>
|
||||
Projects using BusyBox
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
I know of the following projects that use BusyBox
|
||||
<ul>
|
||||
<li> <a href="http://www.lineo.com/products/embedix.html">Lineo Embedix Linux</a>
|
||||
<li> <a href="http://www.lineo.com/products/embedix_linux/">Lineo Embedix Linux</a>
|
||||
<li> <a href="http://cvs.debian.org/boot-floppies/">Debian boot floppies project</a>
|
||||
<li> <a href="http://www.linuxrouter.org/">Linux Router Project </a>
|
||||
<li> <a href="http://linux-embedded.org/">LEM</a>
|
||||
<li> <a href="http://www.toms.net/rb/">tomsrtbt</a>
|
||||
<li> <a href="http://www.stormix.com/">Stormix Installer</a>
|
||||
<li> <a href="http://www.emacinc.com/linux2_sbc.htm">EMAC Linux 2.0 SBC</a>
|
||||
<li> <a href="http://www.trinux.org/">Trinux</a>
|
||||
<li> <a href="http://www.suse.com/~peterb/x86/tinynet.html">tinynet</a>
|
||||
|
||||
</ul>
|
||||
Do you use BusyBox? I'd love to know about it and I'd be happy to link to you.
|
||||
|
||||
+143
-177
@@ -56,13 +56,13 @@ terse runtime description of their behavior.
|
||||
Currently defined functions include:
|
||||
|
||||
ar, basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date,
|
||||
dc, dd, deallocvt, df, dirname, dmesg, du, dutmp, echo, false, fbset,
|
||||
dc, dd, deallocvt, df, dirname, dmesg, du, dumpkmap, dutmp, echo, false, fbset,
|
||||
fdflush, find, free, freeramdisk, fsck.minix, grep, gunzip, gzip, halt,
|
||||
head, hostid, hostname, id, init, insmod, kill, killall, length, ln,
|
||||
loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, mkdir,
|
||||
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
|
||||
nslookup, ping, poweroff, printf, ps, pwd, reboot, rm, rmdir, rmmod, sed,
|
||||
setkeycodes, sfdisk, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail,
|
||||
setkeycodes, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail,
|
||||
tar, tee, telnet, test, touch, tr, true, tty, umount, uname, uniq, update,
|
||||
uptime, usleep, uudecode, uuencode, wc, which, whoami, yes, zcat, [
|
||||
|
||||
@@ -237,12 +237,6 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item clear
|
||||
|
||||
Clears the screen.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item chvt
|
||||
|
||||
Usage: chvt N
|
||||
@@ -251,6 +245,12 @@ Changes the foreground virtual terminal to /dev/ttyN
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item clear
|
||||
|
||||
Clears the screen.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item cp
|
||||
|
||||
Usage: cp [OPTION]... SOURCE DEST
|
||||
@@ -276,11 +276,12 @@ Prints selected fields from each input FILE to standard output.
|
||||
|
||||
Options:
|
||||
|
||||
-b LIST Output only bytes from LIST
|
||||
-c LIST Output only characters from LIST
|
||||
-d DELIM Use DELIM instead of tab as the field delimiter
|
||||
-f N Print only these fields
|
||||
-n Ignored
|
||||
-b LIST Output only bytes from LIST
|
||||
-c LIST Output only characters from LIST
|
||||
-d CHAR Use CHAR instead of tab as the field delimiter
|
||||
-s Only output Lines if the include DELIM
|
||||
-f N Print only these fields
|
||||
-n Ignored
|
||||
|
||||
Example:
|
||||
|
||||
@@ -362,6 +363,14 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item deallocvt
|
||||
|
||||
Usage: deallocvt N
|
||||
|
||||
Deallocates unused virtual terminal /dev/ttyN
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item df
|
||||
|
||||
Usage: df [filesystem ...]
|
||||
@@ -431,6 +440,14 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dumpkmap
|
||||
|
||||
Usage: dumpkmap
|
||||
|
||||
Prints out a binary keyboard translation table to standard input.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dutmp
|
||||
|
||||
Usage: dutmp [FILE]
|
||||
@@ -579,21 +596,13 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item deallocvt
|
||||
|
||||
Usage: deallocvt N
|
||||
|
||||
Deallocates unused virtual terminal /dev/ttyN
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item fsck.minix
|
||||
|
||||
Usage: fsck.minix [B<-larvsmf>] /dev/name
|
||||
|
||||
Performs a consistency check for MINIX filesystems.
|
||||
|
||||
OPTIONS:
|
||||
Options:
|
||||
|
||||
-l Lists all filenames
|
||||
-r Perform interactive repairs
|
||||
@@ -611,7 +620,7 @@ Usage: grep [OPTIONS]... PATTERN [FILE]...
|
||||
|
||||
Search for PATTERN in each FILE or standard input.
|
||||
|
||||
OPTIONS:
|
||||
Options:
|
||||
|
||||
-h suppress the prefixing filename on output
|
||||
-i ignore case distinctions
|
||||
@@ -1123,7 +1132,7 @@ Usage: mkfs.minix [B<-c> | B<-l> filename] [B<-nXX>] [B<-iXX>] /dev/name [blocks
|
||||
|
||||
Make a MINIX filesystem.
|
||||
|
||||
OPTIONS:
|
||||
Options:
|
||||
|
||||
-c Check the device for bad blocks
|
||||
-n [14|30] Specify the maximum length of filenames
|
||||
@@ -1186,25 +1195,6 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item nc
|
||||
|
||||
Usage: nc [IP] [port]
|
||||
|
||||
Netcat opens a pipe to IP:port
|
||||
|
||||
Example:
|
||||
|
||||
$ nc foobar.somedomain.com 25
|
||||
220 foobar ESMTP Exim 3.12 #1 Sat, 15 Apr 2000 00:03:02 -0600
|
||||
help
|
||||
214-Commands supported:
|
||||
214- HELO EHLO MAIL RCPT DATA AUTH
|
||||
214 NOOP QUIT RSET HELP
|
||||
quit
|
||||
221 foobar closing connection
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item more
|
||||
|
||||
Usage: more [file ...]
|
||||
@@ -1276,6 +1266,25 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item nc
|
||||
|
||||
Usage: nc [IP] [port]
|
||||
|
||||
Netcat opens a pipe to IP:port
|
||||
|
||||
Example:
|
||||
|
||||
$ nc foobar.somedomain.com 25
|
||||
220 foobar ESMTP Exim 3.12 #1 Sat, 15 Apr 2000 00:03:02 -0600
|
||||
help
|
||||
214-Commands supported:
|
||||
214- HELO EHLO MAIL RCPT DATA AUTH
|
||||
214 NOOP QUIT RSET HELP
|
||||
quit
|
||||
221 foobar closing connection
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item nslookup
|
||||
|
||||
Usage: nslookup [HOST]
|
||||
@@ -1492,49 +1501,6 @@ shell, this will do the job.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item sfdisk
|
||||
|
||||
Usage: sfdisk [options] device ...
|
||||
|
||||
device: something like /dev/hda or /dev/sda
|
||||
|
||||
useful options:
|
||||
|
||||
-s [or --show-size]: list size of a partition
|
||||
-c [or --id]: print or change partition Id
|
||||
-l [or --list]: list partitions of each device
|
||||
-d [or --dump]: idem, but in a format suitable for later input
|
||||
-i [or --increment]: number cylinders etc. from 1 instead of from 0
|
||||
-uS, -uB, -uC, -uM: accept/report in units of sectors/blocks/cylinders/MB
|
||||
-T [or --list-types]:list the known partition types
|
||||
-D [or --DOS]: for DOS-compatibility: waste a little space
|
||||
-R [or --re-read]: make kernel reread partition table
|
||||
-N# : change only the partition with number #
|
||||
-n : do not actually write to disk
|
||||
-O file : save the sectors that will be overwritten to file
|
||||
-I file : restore these sectors again
|
||||
-v [or --version]: print version
|
||||
-? [or --help]: print this message
|
||||
|
||||
dangerous options:
|
||||
|
||||
-g [or --show-geometry]: print the kernel's idea of the geometry
|
||||
-x [or --show-extended]: also list extended partitions on output
|
||||
|
||||
or expect descriptors for them on input
|
||||
-L [or --Linux]: do not complain about things irrelevant for Linux
|
||||
-q [or --quiet]: suppress warning messages
|
||||
You can override the detected geometry using:
|
||||
-C# [or --cylinders #]:set the number of cylinders to use
|
||||
-H# [or --heads #]: set the number of heads to use
|
||||
-S# [or --sectors #]: set the number of sectors to use
|
||||
|
||||
You can disable all consistency checking with:
|
||||
|
||||
-f [or --force]: do what I say, even if it is stupid
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item sleep
|
||||
|
||||
Usage: sleep N
|
||||
@@ -1566,6 +1532,30 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item swapoff
|
||||
|
||||
Usage: swapoff [OPTION] [device]
|
||||
|
||||
Stop swapping virtual memory pages on the given device.
|
||||
|
||||
Options:
|
||||
|
||||
-a Stop swapping on all swap devices
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item swapon
|
||||
|
||||
Usage: swapon [OPTION] [device]
|
||||
|
||||
Start swapping virtual memory pages on the given device.
|
||||
|
||||
Options:
|
||||
|
||||
-a Start swapping on all swap devices
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item sync
|
||||
|
||||
Usage: sync
|
||||
@@ -1590,30 +1580,6 @@ Options:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item swapon
|
||||
|
||||
Usage: swapon [OPTION] [device]
|
||||
|
||||
Start swapping virtual memory pages on the given device.
|
||||
|
||||
Options:
|
||||
|
||||
-a Start swapping on all swap devices
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item swapoff
|
||||
|
||||
Usage: swapoff [OPTION] [device]
|
||||
|
||||
Stop swapping virtual memory pages on the given device.
|
||||
|
||||
Options:
|
||||
|
||||
-a Stop swapping on all swap devices
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item tail
|
||||
|
||||
Usage: tail [OPTION] [FILE]...
|
||||
@@ -1665,6 +1631,33 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item tee
|
||||
|
||||
Usage: tee [OPTION]... [FILE]...
|
||||
|
||||
Copy standard input to each FILE, and also to standard output.
|
||||
|
||||
Options:
|
||||
|
||||
-a append to the given FILEs, do not overwrite
|
||||
|
||||
Example:
|
||||
|
||||
$ echo "Hello" | tee /tmp/foo
|
||||
$ cat /tmp/foo
|
||||
Hello
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item telnet
|
||||
|
||||
Usage: telnet host [port]
|
||||
|
||||
Telnet is used to establish interactive communication with another
|
||||
computer over a network using the TELNET protocol.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item test, [
|
||||
|
||||
Usage: test EXPRESSION
|
||||
@@ -1690,33 +1683,6 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item telnet
|
||||
|
||||
Usage: telnet host [port]
|
||||
|
||||
Telnet is used to establish interactive communication with another
|
||||
computer over a network using the TELNET protocol.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item tee
|
||||
|
||||
Usage: tee [OPTION]... [FILE]...
|
||||
|
||||
Copy standard input to each FILE, and also to standard output.
|
||||
|
||||
Options:
|
||||
|
||||
-a append to the given FILEs, do not overwrite
|
||||
|
||||
Example:
|
||||
|
||||
$ echo "Hello" | tee /tmp/foo
|
||||
$ cat /tmp/foo
|
||||
Hello
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item touch
|
||||
|
||||
Usage: touch [B<-c>] file [file ...]
|
||||
@@ -1782,45 +1748,6 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uuencode
|
||||
|
||||
Usage: uuencode [OPTION] [INFILE] REMOTEFILE
|
||||
|
||||
Uuencode a file.
|
||||
|
||||
Options:
|
||||
|
||||
-m use base64 encoding as of RFC1521
|
||||
|
||||
Example:
|
||||
|
||||
$ uuencode busybox busybox
|
||||
begin 755 busybox
|
||||
M?T5,1@$!`0````````````(``P`!````L+@$"#0```!0N@,``````#0`(``&
|
||||
.....
|
||||
$ uudecode busybox busybox > busybox.uu
|
||||
$
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uudecode
|
||||
|
||||
Usage: uudecode [OPTION] [FILE]
|
||||
|
||||
Uudecode a uuencoded file
|
||||
|
||||
Options:
|
||||
|
||||
-o FILE direct output to FILE
|
||||
|
||||
Example:
|
||||
|
||||
$ uudecode -o busybox busybox.uu
|
||||
$ ls -l busybox
|
||||
-rwxr-xr-x 1 ams ams 245264 Jun 7 21:35 busybox
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item umount
|
||||
|
||||
Usage: umount [flags] filesystem|directory
|
||||
@@ -1917,6 +1844,45 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uuencode
|
||||
|
||||
Usage: uuencode [OPTION] [INFILE] REMOTEFILE
|
||||
|
||||
Uuencode a file.
|
||||
|
||||
Options:
|
||||
|
||||
-m use base64 encoding as of RFC1521
|
||||
|
||||
Example:
|
||||
|
||||
$ uuencode busybox busybox
|
||||
begin 755 busybox
|
||||
M?T5,1@$!`0````````````(``P`!````L+@$"#0```!0N@,``````#0`(``&
|
||||
.....
|
||||
$ uudecode busybox busybox > busybox.uu
|
||||
$
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uudecode
|
||||
|
||||
Usage: uudecode [OPTION] [FILE]
|
||||
|
||||
Uudecode a uuencoded file
|
||||
|
||||
Options:
|
||||
|
||||
-o FILE direct output to FILE
|
||||
|
||||
Example:
|
||||
|
||||
$ uudecode -o busybox busybox.uu
|
||||
$ ls -l busybox
|
||||
-rwxr-xr-x 1 ams ams 245264 Jun 7 21:35 busybox
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item wc
|
||||
|
||||
Usage: wc [OPTION]... [FILE]...
|
||||
@@ -2062,4 +2028,4 @@ Enrique Zanardi <ezanardi@ull.es>
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: busybox.pod,v 1.51 2000/06/21 22:53:24 andersen Exp $
|
||||
# $Id: busybox.pod,v 1.56 2000/07/11 17:29:36 andersen Exp $
|
||||
+3594
File diff suppressed because it is too large.
Load diff
+100
@@ -0,0 +1,100 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dumpkmap implementation for busybox
|
||||
*
|
||||
* Copyright (C) Arne Bernin <arne@matrix.loopback.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 <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char dumpkmap_usage[] = "dumpkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out a binary keyboard translation table to standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(dumpkmap_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(1, magic, 7);
|
||||
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
|
||||
flags[0]=1;
|
||||
flags[1]=1;
|
||||
flags[2]=1;
|
||||
flags[4]=1;
|
||||
flags[5]=1;
|
||||
flags[6]=1;
|
||||
flags[8]=1;
|
||||
flags[9]=1;
|
||||
flags[10]=1;
|
||||
flags[12]=1;
|
||||
|
||||
/* dump flags */
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
fprintf(stderr, "ioctl returned: %s, %s, %s, %xqq\n",strerror(errno),(char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,&ke.kb_value,2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
@@ -65,28 +65,10 @@ echo_main(int argc, char** argv)
|
||||
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;
|
||||
}
|
||||
if (*p == 'c')
|
||||
exit(0);
|
||||
else
|
||||
c = process_escape_sequence(&p);
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
+465
-295
@@ -1,15 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini sed implementation for busybox
|
||||
*
|
||||
* sed.c - very minimalist version of sed
|
||||
*
|
||||
* 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
|
||||
* written by Marco Pantaleoni <panta@prosa.it>, <panta@elasticworld.org>
|
||||
* and are:
|
||||
* Copyright (C) 1999 Marco Pantaleoni.
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -27,333 +20,510 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
/*
|
||||
Supported features and commands in this version of sed:
|
||||
|
||||
- comments ('#')
|
||||
- Address matching: num|/matchstr/[,num|/matchstr/|$]command
|
||||
- Commands: p, d, s/match/replace/[g]
|
||||
|
||||
(Note: Specifying an address (range) to match is *optional*; commands
|
||||
default to the whole pattern space if no specific address match was
|
||||
requested.)
|
||||
|
||||
Unsupported features:
|
||||
|
||||
- transliteration (y/source-chars/dest-chars/) (use 'tr')
|
||||
- no support for characters other than the '/' character for regex matches
|
||||
- no pattern space hold space storing / swapping (x, etc.)
|
||||
- no labels / branching (: label, b, t, and friends)
|
||||
- and lots, lots more.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h> /* for realloc() */
|
||||
#include <unistd.h> /* for getopt() */
|
||||
#include <regex.h>
|
||||
#include <string.h> /* for strdup() */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <ctype.h> /* for isspace() */
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* externs */
|
||||
extern int optind; /* in unistd.h */
|
||||
extern char *optarg; /* ditto */
|
||||
|
||||
/* options */
|
||||
static int be_quiet = 0;
|
||||
|
||||
struct sed_cmd {
|
||||
|
||||
/* address storage */
|
||||
int beg_line; /* 'sed 1p' 0 == no begining line, apply commands to all lines */
|
||||
int end_line; /* 'sed 1,3p' 0 == no end line, use only beginning. -1 == $ */
|
||||
regex_t *beg_match; /* sed -e '/match/cmd' */
|
||||
regex_t *end_match; /* sed -e '/match/,/end_match/cmd' */
|
||||
|
||||
/* the command */
|
||||
char cmd; /* p,d,s (add more at your leisure :-) */
|
||||
|
||||
/* substitution command specific fields */
|
||||
regex_t *sub_match; /* sed -e 's/sub_match/replace/' */
|
||||
char *replace; /* sed -e 's/sub_match/replace/' XXX: who will hold the \1 \2 \3s? */
|
||||
unsigned int sub_g:1; /* sed -e 's/foo/bar/g' (global) */
|
||||
};
|
||||
|
||||
/* globals */
|
||||
static struct sed_cmd *sed_cmds = NULL; /* growable arrary holding a sequence of sed cmds */
|
||||
static int ncmds = 0; /* number of sed commands */
|
||||
|
||||
/*static char *cur_file = NULL;*/ /* file currently being processed XXX: do I need this? */
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] -e script [file...]\n"
|
||||
"sed [-Vhnef] pattern [files...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nAllowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regular expressions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regular expressions).\n"
|
||||
#endif
|
||||
"\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n"
|
||||
"-e script\tadd the script to the commands to be executed\n"
|
||||
"-f scriptfile\tadd the contents of script-file to the commands to be executed\n"
|
||||
"-h\tdisplay this help message\n"
|
||||
"-V\toutput version information and exit\n"
|
||||
"\n"
|
||||
"If no -e or -f is given, the first non-option argument is taken as the\n"
|
||||
"sed script to interpret. All remaining arguments are names of input\n"
|
||||
"files; if no input files are specified, then the standard input is read.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/* Flags & variables */
|
||||
|
||||
typedef enum { f_none, f_replace, f_append } sed_function;
|
||||
|
||||
#define NO_LINE -2
|
||||
#define LAST_LINE -1
|
||||
static int addr_line = NO_LINE;
|
||||
static char *addr_pattern = NULL;
|
||||
static int negated = 0;
|
||||
|
||||
#define SKIPSPACES(p) do { while (isspace(*(p))) (p)++; } while (0)
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
static inline int at_last(FILE * fp)
|
||||
static void destroy_cmd_strs()
|
||||
{
|
||||
int res = 0;
|
||||
if (sed_cmds == NULL)
|
||||
return;
|
||||
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
int ch;
|
||||
/* destroy all the elements in the array */
|
||||
while (--ncmds >= 0) {
|
||||
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
if (sed_cmds[ncmds].beg_match) {
|
||||
regfree(sed_cmds[ncmds].beg_match);
|
||||
free(sed_cmds[ncmds].beg_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].end_match) {
|
||||
regfree(sed_cmds[ncmds].end_match);
|
||||
free(sed_cmds[ncmds].end_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].sub_match) {
|
||||
regfree(sed_cmds[ncmds].sub_match);
|
||||
free(sed_cmds[ncmds].sub_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].replace)
|
||||
free(sed_cmds[ncmds].replace);
|
||||
}
|
||||
return res;
|
||||
|
||||
/* destroy the array */
|
||||
free(sed_cmds);
|
||||
sed_cmds = NULL;
|
||||
}
|
||||
|
||||
static void do_sed_repl(FILE * fp, char *needle, char *newNeedle,
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
static void exit_sed(int retcode, const char *message)
|
||||
{
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
destroy_cmd_strs();
|
||||
if (message)
|
||||
fputs(message, stderr);
|
||||
exit(retcode);
|
||||
}
|
||||
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
/*
|
||||
* trim_str - trims leading and trailing space from a string
|
||||
*
|
||||
* Note: This returns a malloc'ed string so you must store and free it
|
||||
* XXX: This should be in the utility.c file.
|
||||
*/
|
||||
static char *trim_str(const char *str)
|
||||
{
|
||||
int i;
|
||||
char *retstr = strdup(str);
|
||||
|
||||
/* trim leading whitespace */
|
||||
memmove(retstr, &retstr[strspn(retstr, " \n\t\v")], strlen(retstr));
|
||||
|
||||
/* trim trailing whitespace */
|
||||
i = strlen(retstr) - 1;
|
||||
while (isspace(retstr[i]))
|
||||
i--;
|
||||
retstr[++i] = 0;
|
||||
|
||||
/* Aside:
|
||||
*
|
||||
* you know, a strrspn() would really be nice cuz then we could say:
|
||||
*
|
||||
* retstr[strlen(retstr) - strrspn(retstr, " \n\t\v") + 1] = 0;
|
||||
*/
|
||||
|
||||
return retstr;
|
||||
}
|
||||
|
||||
/*
|
||||
* index_of_unescaped_slash - walks left to right through a string beginning
|
||||
* at a specified index and returns the index of the next unescaped slash.
|
||||
*/
|
||||
static int index_of_next_unescaped_slash(int idx, const char *str)
|
||||
{
|
||||
do {
|
||||
idx++;
|
||||
/* test if we've hit the end */
|
||||
if (str[idx] == 0)
|
||||
return -1;
|
||||
} while (str[idx] != '/' && str[idx - 1] != '\\');
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the index in the string just past where the address ends.
|
||||
*/
|
||||
static int get_address(const char *str, int *line, regex_t **regex)
|
||||
{
|
||||
char *my_str = strdup(str);
|
||||
int idx = 0;
|
||||
|
||||
if (isdigit(my_str[idx])) {
|
||||
do {
|
||||
idx++;
|
||||
} while (isdigit(my_str[idx]));
|
||||
my_str[idx] = 0;
|
||||
*line = atoi(my_str);
|
||||
*regex = NULL;
|
||||
}
|
||||
else if (my_str[idx] == '$') {
|
||||
*line = -1;
|
||||
*regex = NULL;
|
||||
idx++;
|
||||
}
|
||||
else if (my_str[idx] == '/') {
|
||||
idx = index_of_next_unescaped_slash(idx, my_str);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: unterminated match expression\n");
|
||||
my_str[idx] = '\0';
|
||||
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
||||
if (bb_regcomp(*regex, my_str+1, REG_NEWLINE) != 0) {
|
||||
free(my_str);
|
||||
exit_sed(1, NULL);
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
||||
fprintf(stderr, "\t(you probably didn't check the string you passed me)\n");
|
||||
idx = -1;
|
||||
}
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
free(my_str);
|
||||
return idx;
|
||||
}
|
||||
|
||||
static char *strdup_substr(const char *str, int start, int end)
|
||||
{
|
||||
int size = end - start + 1;
|
||||
char *newstr = xmalloc(size);
|
||||
memcpy(newstr, str+start, size-1);
|
||||
newstr[size-1] = '\0';
|
||||
return newstr;
|
||||
}
|
||||
|
||||
static void parse_cmd_str(struct sed_cmd *sed_cmd, const char *cmdstr)
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
/* parse the command
|
||||
* format is: [addr][,addr]cmd
|
||||
* |----||-----||-|
|
||||
* part1 part2 part3
|
||||
*/
|
||||
|
||||
/* first part (if present) is an address: either a number or a /regex/ */
|
||||
if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/')
|
||||
idx = get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
|
||||
|
||||
/* second part (if present) will begin with a comma */
|
||||
if (cmdstr[idx] == ',')
|
||||
idx += get_address(&cmdstr[++idx], &sed_cmd->end_line, &sed_cmd->end_match);
|
||||
|
||||
/* last part (mandatory) will be a command */
|
||||
if (cmdstr[idx] == '\0')
|
||||
exit_sed(1, "sed: missing command\n");
|
||||
if (!strchr("pds", cmdstr[idx])) /* <-- XXX add new commands here */
|
||||
exit_sed(1, "sed: invalid command\n");
|
||||
sed_cmd->cmd = cmdstr[idx];
|
||||
/* special-case handling for 's' */
|
||||
if (sed_cmd->cmd == 's') {
|
||||
int oldidx, cflags = REG_NEWLINE;
|
||||
char *match;
|
||||
/* format for substitution is:
|
||||
* s/match/replace/gI
|
||||
* | ||
|
||||
* mandatory optional
|
||||
*/
|
||||
|
||||
/* verify that we have an 's' followed by a 'slash' */
|
||||
if (cmdstr[++idx] != '/')
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
|
||||
/* save the match string */
|
||||
oldidx = idx+1;
|
||||
idx = index_of_next_unescaped_slash(idx, cmdstr);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
match = strdup_substr(cmdstr, oldidx, idx);
|
||||
|
||||
/* save the replacement string */
|
||||
oldidx = idx+1;
|
||||
idx = index_of_next_unescaped_slash(idx, cmdstr);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
sed_cmd->replace = strdup_substr(cmdstr, oldidx, idx);
|
||||
|
||||
/* process the flags */
|
||||
while (cmdstr[++idx]) {
|
||||
switch (cmdstr[idx]) {
|
||||
case 'g':
|
||||
sed_cmd->sub_g = 1;
|
||||
break;
|
||||
case 'I':
|
||||
cflags |= REG_ICASE;
|
||||
break;
|
||||
default:
|
||||
exit_sed(1, "sed: bad option in substitution expression\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
|
||||
/* compile the regex */
|
||||
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
||||
if (bb_regcomp(sed_cmd->sub_match, match, cflags) != 0) {
|
||||
free(match);
|
||||
exit_sed(1, NULL);
|
||||
}
|
||||
|
||||
line++;
|
||||
free(match);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_sed_append(FILE * fp, char *appendline, int quietFlag)
|
||||
static void add_cmd_str(const char *cmdstr)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
char *my_cmdstr = trim_str(cmdstr);
|
||||
|
||||
/* if this is a comment, don't even bother */
|
||||
if (my_cmdstr[0] == '#') {
|
||||
free(my_cmdstr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* grow the array */
|
||||
sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
|
||||
/* zero new element */
|
||||
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
|
||||
/* load command string into new array element */
|
||||
parse_cmd_str(&sed_cmds[ncmds-1], my_cmdstr);
|
||||
}
|
||||
|
||||
|
||||
static void load_cmd_file(char *filename)
|
||||
{
|
||||
FILE *cmdfile;
|
||||
char *line;
|
||||
|
||||
cmdfile = fopen(filename, "r");
|
||||
if (cmdfile == NULL)
|
||||
exit_sed(1, strerror(errno));
|
||||
|
||||
while ((line = get_line_from_file(cmdfile)) != NULL) {
|
||||
line[strlen(line)-1] = 0; /* eat newline */
|
||||
add_cmd_str(line);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
|
||||
{
|
||||
int altered = 0;
|
||||
|
||||
switch (sed_cmd->cmd) {
|
||||
|
||||
case 'p':
|
||||
fputs(line, stdout);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
altered++;
|
||||
break;
|
||||
|
||||
case 's': /* oo, a fun one :-) */
|
||||
|
||||
/* we only substitute if the substitution 'search' expression matches */
|
||||
if (regexec(sed_cmd->sub_match, line, 0, NULL, 0) == 0) {
|
||||
regmatch_t regmatch;
|
||||
int i;
|
||||
char *ptr = (char *)line;
|
||||
|
||||
while (*ptr) {
|
||||
/* if we can match the search string... */
|
||||
if (regexec(sed_cmd->sub_match, ptr, 1, ®match, 0) == 0) {
|
||||
/* print everything before the match, */
|
||||
for (i = 0; i < regmatch.rm_so; i++)
|
||||
fputc(ptr[i], stdout);
|
||||
/* then print the substitution in its place */
|
||||
fputs(sed_cmd->replace, stdout);
|
||||
/* then advance past the match */
|
||||
ptr += regmatch.rm_eo;
|
||||
/* and let the calling function know that something
|
||||
* has been changed */
|
||||
altered++;
|
||||
|
||||
/* if we're not doing this globally... */
|
||||
if (!sed_cmd->sub_g)
|
||||
break;
|
||||
}
|
||||
/* if we COULD NOT match the search string (meaning we've gone past
|
||||
* all previous instances), get out */
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* is there anything left to print? */
|
||||
if (*ptr)
|
||||
fputs(ptr, stdout);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return altered;
|
||||
}
|
||||
|
||||
static void process_file(FILE *file)
|
||||
{
|
||||
char *line = NULL;
|
||||
static int linenum = 0; /* GNU sed does not restart counting lines at EOF */
|
||||
unsigned int still_in_range = 0;
|
||||
int line_altered;
|
||||
int i;
|
||||
|
||||
/* go through every line in the file */
|
||||
while ((line = get_line_from_file(file)) != NULL) {
|
||||
|
||||
linenum++;
|
||||
line_altered = 0;
|
||||
|
||||
/* for every line, go through all the commands */
|
||||
for (i = 0; i < ncmds; i++) {
|
||||
|
||||
/* are we acting on a range of matched lines? */
|
||||
if (sed_cmds[i].beg_match && sed_cmds[i].end_match) {
|
||||
if (still_in_range || regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0) {
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
still_in_range = 1;
|
||||
if (regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
|
||||
still_in_range = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* are we trying to match a single line? */
|
||||
else if (sed_cmds[i].beg_match) {
|
||||
if (regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* are we acting on a range of line numbers? */
|
||||
else if (sed_cmds[i].beg_line > 0 && sed_cmds[i].end_line > 0) {
|
||||
if (linenum >= sed_cmds[i].beg_line && linenum <= sed_cmds[i].end_line)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* are we acting on a specified line number */
|
||||
else if (sed_cmds[i].beg_line > 0) {
|
||||
if (linenum == sed_cmds[i].beg_line)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* not acting on matches or line numbers. act on every line */
|
||||
else
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
line++;
|
||||
/* we will print the line unless we were told to be quiet or if the
|
||||
* line was altered (via a 'd'elete or 's'ubstitution) */
|
||||
if (!be_quiet && !line_altered)
|
||||
fputs(line, stdout);
|
||||
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
int opt;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
/* do special-case option parsing */
|
||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||
usage(sed_usage);
|
||||
}
|
||||
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
usage(sed_usage);
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
||||
switch (opt) {
|
||||
case 'V':
|
||||
printf("Print Busybox version here\n");
|
||||
exit(0);
|
||||
break;
|
||||
case 'h':
|
||||
usage(sed_usage);
|
||||
break;
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
be_quiet++;
|
||||
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;
|
||||
add_cmd_str(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
case 'f':
|
||||
load_cmd_file(optarg);
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
return(TRUE);
|
||||
|
||||
/* if we didn't get a pattern from a -e and no command file was specified,
|
||||
* argv[optind] should be the pattern. no pattern, no worky */
|
||||
if (ncmds == 0) {
|
||||
if (argv[optind] == NULL)
|
||||
usage(sed_usage);
|
||||
else {
|
||||
add_cmd_str(argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) {
|
||||
process_file(stdin);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind; i < argc; i++) {
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "sed: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
process_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit_sed(0, NULL);
|
||||
|
||||
/* not reached */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.45
|
||||
Version: 0.46
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
I have a version of free I wrote for BusyBox that uses sysinfo (rather then
|
||||
/proc) to get its information. Under 2.2.x it reports normal stuff, i.e.
|
||||
[andersen@dillweed busybox]$ ./free
|
||||
total used free shared buffers
|
||||
Mem: 127800 124268 3532 16956 7544
|
||||
Swap: 128516 13584 114932
|
||||
Total: 256316 137852 118464
|
||||
|
||||
while under 2.2.0-test1-ac7 it reports wierd numbers (~ #/4096)
|
||||
[andersen@dillweed busybox]$ ./free
|
||||
total used free shared buffers
|
||||
Mem: 30 11 19 0 1
|
||||
Swap: 31 0 31
|
||||
Total: 61 11 50
|
||||
|
||||
After investigating the problem, it turns out that somewhere during 2.3.x the
|
||||
values for memory stored in struct sysinfo changed from being stored as bytes
|
||||
to being units of PAGE_SIZE, but kernel/info.c was never updated to reflect
|
||||
this change in definition.
|
||||
|
||||
Breaking free isn't that big of a deal, but I also use sysinfo in init to check
|
||||
that the box has enough ram from within the init process (and no, mounting
|
||||
/proc from within init and reading /proc/meminfo is not a good solution.
|
||||
BusyBox is often used in embedded systems where /proc is not compiled in).
|
||||
|
||||
The following patch reinstates the traditional sysinfo(2) interface by
|
||||
returning bytes (not units of PAGE_SIZE) for memory values.
|
||||
|
||||
An additional patch suggestion (not included here) would be to eliminate the
|
||||
supurfluous "mem_unit" variable from struct_sysinfo in include/linux/kernel.h
|
||||
and arch/*/mm/init.c.
|
||||
|
||||
-Erik
|
||||
|
||||
--
|
||||
Erik B. Andersen Web: http://www.xmission.com/~andersen/
|
||||
email: andersee@debian.org
|
||||
--This message was written using 73% post-consumer electrons--
|
||||
|
||||
--- linux/kernel/info.c.orig Mon Aug 23 12:15:53 1999
|
||||
+++ linux/kernel/info.c Sun Jun 4 01:13:11 2000
|
||||
@@ -2,6 +2,8 @@
|
||||
* linux/kernel/info.c
|
||||
*
|
||||
* Copyright (C) 1992 Darren Senn
|
||||
+ * Fixed to once again return bytes instead of page counts,
|
||||
+ * June 2000, by Erik Andersen <andersee@debian.org>
|
||||
*/
|
||||
|
||||
/* This implements the sysinfo() system call */
|
||||
@@ -10,7 +12,6 @@
|
||||
#include <linux/unistd.h>
|
||||
#include <linux/swap.h>
|
||||
#include <linux/smp_lock.h>
|
||||
-
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
asmlinkage long sys_sysinfo(struct sysinfo *info)
|
||||
@@ -31,6 +32,17 @@
|
||||
|
||||
si_meminfo(&val);
|
||||
si_swapinfo(&val);
|
||||
+
|
||||
+ /* These are in units of PAGE_SIZE, but this interface
|
||||
+ * has always returned bytes. Make it return bytes */
|
||||
+ val.totalram*=PAGE_SIZE;
|
||||
+ val.freeram*=PAGE_SIZE;
|
||||
+ val.sharedram*=PAGE_SIZE;
|
||||
+ val.bufferram*=PAGE_SIZE;
|
||||
+ val.totalswap*=PAGE_SIZE;
|
||||
+ val.freeswap*=PAGE_SIZE;
|
||||
+ val.totalhigh*=PAGE_SIZE;
|
||||
+ val.freehigh*=PAGE_SIZE;
|
||||
|
||||
if (copy_to_user(info, &val, sizeof(struct sysinfo)))
|
||||
return -EFAULT;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
On Sat Jul 01, 2000 at 12:04:36PM -0400, Alexander Viro wrote:
|
||||
>
|
||||
> Try to trace the path from their roots to absolute root(s)... They simply
|
||||
> should not be in the output - that's a debugging stuff and I have no
|
||||
> problems with removing it from /proc/mounts. No heuristics needed - we
|
||||
> can pass NULL as dev_name in kern_mount() and check for NULL ->mnt_devname
|
||||
> in get_filesystem_info(). I'll do that as soon as threading patches will
|
||||
> be over (hopefully RSN - they went to Linus).
|
||||
>
|
||||
|
||||
Ok, cool. So something like then? I kept in the filter for FS_NOMOUNT
|
||||
filesystems, as I assume those should never show up in /proc/mounts, and added
|
||||
that filter to the /proc/filesystems listing as well.
|
||||
|
||||
-Erik
|
||||
|
||||
--
|
||||
Erik B. Andersen Web: http://www.xmission.com/~andersen/
|
||||
email: andersee@debian.org
|
||||
--This message was written using 73% post-consumer electrons--
|
||||
|
||||
|
||||
--- fs/super.c.virgin Wed Jun 28 22:42:35 2000
|
||||
+++ fs/super.c Mon Jul 3 12:07:07 2000
|
||||
@@ -251,6 +251,10 @@ int get_filesystem_list(char * buf)
|
||||
read_lock(&file_systems_lock);
|
||||
tmp = file_systems;
|
||||
while (tmp && len < PAGE_SIZE - 80) {
|
||||
+ /* Filter out any filesystems that are marked as FS_NOMOUNT.
|
||||
+ * User space doesn't need to know or care about them */
|
||||
+ if (tmp->fs_flags & FS_NOMOUNT)
|
||||
+ continue;
|
||||
len += sprintf(buf+len, "%s\t%s\n",
|
||||
(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
|
||||
tmp->name);
|
||||
@@ -443,6 +447,16 @@ int get_filesystem_info( char *buf )
|
||||
path = d_path(tmp->mnt_root, tmp, buffer, PAGE_SIZE);
|
||||
if (!path)
|
||||
continue;
|
||||
+ /* Filter out any filesystems that are marked as FS_NOMOUNT.
|
||||
+ * User space doesn't need to know or care about them */
|
||||
+ if (tmp->mnt_sb->s_type->fs_flags & FS_NOMOUNT)
|
||||
+ continue;
|
||||
+ /* kern_mount() allows the kernel to mount internal-use-only
|
||||
+ * filesystems, and marks then with ->mnt_devname==NULL, so
|
||||
+ * filter out those here */
|
||||
+ if (tmp->mnt_devname == NULL)
|
||||
+ continue;
|
||||
+
|
||||
len += sprintf( buf + len, "%s %s %s %s",
|
||||
tmp->mnt_devname, path,
|
||||
tmp->mnt_sb->s_type->name,
|
||||
@@ -895,7 +909,7 @@ struct vfsmount *kern_mount(struct file_
|
||||
put_unnamed_dev(dev);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
- mnt = add_vfsmnt(sb, sb->s_root, sb->s_root, NULL, "none", type->name);
|
||||
+ mnt = add_vfsmnt(sb, sb->s_root, sb->s_root, NULL, NULL, type->name);
|
||||
if (!mnt) {
|
||||
kill_super(sb, 0);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
-
|
||||
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/
|
||||
File renamed without changes.
@@ -61,28 +61,29 @@
|
||||
/* #define CMD_XCOMPAT 10 */
|
||||
#define CMD_ALL 11
|
||||
#define CMD_INFO 12
|
||||
#define CMD_CHANGE 13
|
||||
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
#define CMD_XRES 13
|
||||
#define CMD_YRES 14
|
||||
#define CMD_VXRES 15
|
||||
#define CMD_VYRES 16
|
||||
#define CMD_DEPTH 17
|
||||
#define CMD_MATCH 18
|
||||
#define CMD_PIXCLOCK 19
|
||||
#define CMD_LEFT 20
|
||||
#define CMD_RIGHT 21
|
||||
#define CMD_UPPER 22
|
||||
#define CMD_LOWER 23
|
||||
#define CMD_HSLEN 24
|
||||
#define CMD_VSLEN 25
|
||||
#define CMD_CSYNC 26
|
||||
#define CMD_GSYNC 27
|
||||
#define CMD_EXTSYNC 28
|
||||
#define CMD_BCAST 29
|
||||
#define CMD_RGBA 30
|
||||
#define CMD_STEP 31
|
||||
#define CMD_MOVE 32
|
||||
#define CMD_XRES 100
|
||||
#define CMD_YRES 101
|
||||
#define CMD_VXRES 102
|
||||
#define CMD_VYRES 103
|
||||
#define CMD_DEPTH 104
|
||||
#define CMD_MATCH 105
|
||||
#define CMD_PIXCLOCK 106
|
||||
#define CMD_LEFT 107
|
||||
#define CMD_RIGHT 108
|
||||
#define CMD_UPPER 109
|
||||
#define CMD_LOWER 110
|
||||
#define CMD_HSLEN 111
|
||||
#define CMD_VSLEN 112
|
||||
#define CMD_CSYNC 113
|
||||
#define CMD_GSYNC 114
|
||||
#define CMD_EXTSYNC 115
|
||||
#define CMD_BCAST 116
|
||||
#define CMD_RGBA 117
|
||||
#define CMD_STEP 118
|
||||
#define CMD_MOVE 119
|
||||
#endif
|
||||
|
||||
static unsigned int g_options = 0;
|
||||
@@ -106,6 +107,7 @@ struct cmdoptions_t {
|
||||
"-laced", 1, CMD_LACED}, {
|
||||
"-double", 1, CMD_DOUBLE}, {
|
||||
"-help", 0, CMD_HELP}, {
|
||||
"-n", 0, CMD_CHANGE}, {
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
"-help", 0, CMD_HELP}, {
|
||||
"-all", 0, CMD_ALL}, {
|
||||
@@ -138,7 +140,7 @@ struct cmdoptions_t {
|
||||
static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
const char *mode)
|
||||
{
|
||||
#ifdef BB_FBSET_READMODE
|
||||
#ifdef BB_FEATURE_FBSET_READMODE
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *p = buf;
|
||||
@@ -286,6 +288,9 @@ 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;
|
||||
case CMD_CHANGE:
|
||||
g_options |= OPT_CHANGE;
|
||||
break;
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
case CMD_XRES:
|
||||
varset.xres = strtoul(argv[1], 0, 0);
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/* From <linux/fd.h> */
|
||||
#define FDFLUSH _IO(2,0x4b)
|
||||
|
||||
extern int fdflush_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
+119
-106
@@ -1,10 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
* Mini grep implementation for busybox using libc regex.
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -22,149 +20,164 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||
|
||||
+ -q option (be quiet)
|
||||
+ exit code depending on grep result (TRUE or FALSE)
|
||||
(useful for scripts)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <regex.h>
|
||||
#include <string.h> /* for strerror() */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_too_few_args
|
||||
#include "messages.c"
|
||||
#include "internal.h"
|
||||
|
||||
extern int optind; /* in unistd.h */
|
||||
extern int errno; /* for use with strerror() */
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n"
|
||||
"grep [-ihHnqvs] pattern [files...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSearch for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"Options:\n"
|
||||
"\t-H\tprefix output lines with filename where match was found\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n"
|
||||
"\t-v\tselect non-matching lines\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expressions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expressions).\n"
|
||||
#endif
|
||||
"\t-v\tselect non-matching lines\n"
|
||||
"\t-s\tsuppress file open/read error messages\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
/* options */
|
||||
static int ignore_case = 0;
|
||||
static int print_filename = 0;
|
||||
static int print_line_num = 0;
|
||||
static int be_quiet = 0;
|
||||
static int invert_search = 0;
|
||||
static int suppress_err_msgs = 0;
|
||||
|
||||
static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
||||
int ignoreCase, int tellLine, int invertSearch)
|
||||
/* globals */
|
||||
static regex_t regex; /* storage space for compiled regular expression */
|
||||
static int nmatches = 0; /* keeps track of the number of matches */
|
||||
static char *cur_file = NULL; /* the current file we are reading */
|
||||
|
||||
|
||||
static void print_matched_line(char *line, int linenum)
|
||||
{
|
||||
long line = 0;
|
||||
char *haystack;
|
||||
int truth = !invertSearch;
|
||||
if (print_filename)
|
||||
printf("%s:", cur_file);
|
||||
if (print_line_num)
|
||||
printf("%i:", linenum);
|
||||
|
||||
while ((haystack = cstring_lineFromFile(fp))) {
|
||||
line++;
|
||||
if (find_match(haystack, needle, ignoreCase) == truth) {
|
||||
if (tellName == TRUE)
|
||||
printf("%s:", fileName);
|
||||
|
||||
if (tellLine == TRUE)
|
||||
printf("%ld:", line);
|
||||
|
||||
if (beQuiet == FALSE)
|
||||
fputs(haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
}
|
||||
free(haystack);
|
||||
}
|
||||
printf("%s", line);
|
||||
}
|
||||
|
||||
static void grep_file(FILE *file)
|
||||
{
|
||||
char *line = NULL;
|
||||
int ret;
|
||||
int linenum = 0;
|
||||
|
||||
while ((line = get_line_from_file(file)) != NULL) {
|
||||
linenum++;
|
||||
ret = regexec(®ex, line, 0, NULL, 0);
|
||||
if (ret == 0 && !invert_search) { /* match */
|
||||
|
||||
/* if we found a match but were told to be quiet, stop here and
|
||||
* return success */
|
||||
if (be_quiet) {
|
||||
regfree(®ex);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
nmatches++;
|
||||
|
||||
print_matched_line(line, linenum);
|
||||
|
||||
} else if (ret == REG_NOMATCH && invert_search) {
|
||||
print_matched_line(line, linenum);
|
||||
}
|
||||
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
extern int grep_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName = TRUE;
|
||||
int ignoreCase = FALSE;
|
||||
int tellLine = FALSE;
|
||||
int invertSearch = FALSE;
|
||||
int opt;
|
||||
int reflags;
|
||||
|
||||
if (argc < 1) {
|
||||
/* do special-case option parsing */
|
||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||
usage(grep_usage);
|
||||
}
|
||||
argv++;
|
||||
|
||||
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "iHhnqvs")) > 0) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
ignore_case++;
|
||||
break;
|
||||
case 'H':
|
||||
print_filename++;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
print_filename--;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
print_line_num++;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
be_quiet++;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
invertSearch = TRUE;
|
||||
invert_search++;
|
||||
break;
|
||||
case 's':
|
||||
suppress_err_msgs++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0 || *argv == NULL) {
|
||||
fatalError(too_few_args, "grep");
|
||||
}
|
||||
/* argv[optind] should be the regex pattern; no pattern, no worky */
|
||||
if (argv[optind] == NULL)
|
||||
usage(grep_usage);
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
/* compile the regular expression
|
||||
* we're not going to mess with sub-expressions, and we need to
|
||||
* treat newlines right. */
|
||||
reflags = REG_NOSUB | REG_NEWLINE;
|
||||
if (ignore_case)
|
||||
reflags |= REG_ICASE;
|
||||
if (bb_regcomp(®ex, argv[optind], reflags) != 0)
|
||||
exit(1);
|
||||
|
||||
if (argc == 0) {
|
||||
do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine, invertSearch);
|
||||
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
||||
* there is more than one file to grep, we will print the filenames */
|
||||
if ((argc-1) - (optind+1) > 0)
|
||||
print_filename++;
|
||||
|
||||
/* If no files were specified, or '-' was specified, take input from
|
||||
* stdin. Otherwise, we grep through all the files specified. */
|
||||
if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
|
||||
grep_file(stdin);
|
||||
} else {
|
||||
/* Never print the filename for just one file */
|
||||
if (argc == 1)
|
||||
tellName = FALSE;
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror(fileName);
|
||||
continue;
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind + 1; i < argc; i++) {
|
||||
cur_file = argv[i];
|
||||
file = fopen(cur_file, "r");
|
||||
if (file == NULL) {
|
||||
if (!suppress_err_msgs)
|
||||
fprintf(stderr, "grep: %s: %s\n", cur_file, strerror(errno));
|
||||
} else {
|
||||
grep_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine, invertSearch);
|
||||
|
||||
if (ferror(fp))
|
||||
perror(fileName);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
return(match);
|
||||
|
||||
regfree(®ex);
|
||||
|
||||
if (nmatches == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
@@ -23,20 +23,36 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#define DIVISOR 1024
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
info.totalram/=DIVISOR;
|
||||
info.freeram/=DIVISOR;
|
||||
info.totalswap/=DIVISOR;
|
||||
info.freeswap/=DIVISOR;
|
||||
info.sharedram/=DIVISOR;
|
||||
info.bufferram/=DIVISOR;
|
||||
|
||||
/* Kernels prior to 2.4.x will return info.mem_unit==0. Kernels after
|
||||
* 2.4.x actually fill this value in */
|
||||
if (info.mem_unit==0) {
|
||||
/* Looks like we have a kernel prior to Linux 2.4.x */
|
||||
info.mem_unit=1024;
|
||||
info.totalram/=info.mem_unit;
|
||||
info.freeram/=info.mem_unit;
|
||||
info.totalswap/=info.mem_unit;
|
||||
info.freeswap/=info.mem_unit;
|
||||
info.sharedram/=info.mem_unit;
|
||||
info.bufferram/=info.mem_unit;
|
||||
} else {
|
||||
/* Bah. Linux 2.4.x completely changed sysinfo. This can in theory
|
||||
overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap
|
||||
on an embedded system? */
|
||||
info.mem_unit/=1024;
|
||||
info.totalram*=info.mem_unit;
|
||||
info.freeram*=info.mem_unit;
|
||||
info.totalswap*=info.mem_unit;
|
||||
info.freeswap*=info.mem_unit;
|
||||
info.sharedram*=info.mem_unit;
|
||||
info.bufferram*=info.mem_unit;
|
||||
}
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("free\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
@@ -61,3 +77,5 @@ extern int free_main(int argc, char **argv)
|
||||
info.freeram+info.freeswap);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
@@ -32,6 +31,9 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* From linux/fs.h */
|
||||
#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
|
||||
|
||||
|
||||
static const char freeramdisk_usage[] =
|
||||
"freeramdisk DEVICE\n"
|
||||
|
||||
+97
-3
@@ -99,8 +99,102 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include <linux/minix_fs.h>
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
|
||||
|
||||
#define MINIX_ROOT_INO 1
|
||||
#define MINIX_LINK_MAX 250
|
||||
#define MINIX2_LINK_MAX 65530
|
||||
|
||||
#define MINIX_I_MAP_SLOTS 8
|
||||
#define MINIX_Z_MAP_SLOTS 64
|
||||
#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
|
||||
#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
|
||||
#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */
|
||||
#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
|
||||
#define MINIX_VALID_FS 0x0001 /* Clean fs. */
|
||||
#define MINIX_ERROR_FS 0x0002 /* fs has errors. */
|
||||
|
||||
#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
|
||||
#define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode)))
|
||||
|
||||
#define MINIX_V1 0x0001 /* original minix fs */
|
||||
#define MINIX_V2 0x0002 /* minix V2 fs */
|
||||
|
||||
#define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version
|
||||
|
||||
/*
|
||||
* This is the original minix inode layout on disk.
|
||||
* Note the 8-bit gid and atime and ctime.
|
||||
*/
|
||||
struct minix_inode {
|
||||
u16 i_mode;
|
||||
u16 i_uid;
|
||||
u32 i_size;
|
||||
u32 i_time;
|
||||
u8 i_gid;
|
||||
u8 i_nlinks;
|
||||
u16 i_zone[9];
|
||||
};
|
||||
|
||||
/*
|
||||
* The new minix inode has all the time entries, as well as
|
||||
* long block numbers and a third indirect block (7+1+1+1
|
||||
* instead of 7+1+1). Also, some previously 8-bit values are
|
||||
* now 16-bit. The inode is now 64 bytes instead of 32.
|
||||
*/
|
||||
struct minix2_inode {
|
||||
u16 i_mode;
|
||||
u16 i_nlinks;
|
||||
u16 i_uid;
|
||||
u16 i_gid;
|
||||
u32 i_size;
|
||||
u32 i_atime;
|
||||
u32 i_mtime;
|
||||
u32 i_ctime;
|
||||
u32 i_zone[10];
|
||||
};
|
||||
|
||||
/*
|
||||
* minix super-block data on disk
|
||||
*/
|
||||
struct minix_super_block {
|
||||
u16 s_ninodes;
|
||||
u16 s_nzones;
|
||||
u16 s_imap_blocks;
|
||||
u16 s_zmap_blocks;
|
||||
u16 s_firstdatazone;
|
||||
u16 s_log_zone_size;
|
||||
u32 s_max_size;
|
||||
u16 s_magic;
|
||||
u16 s_state;
|
||||
u32 s_zones;
|
||||
};
|
||||
|
||||
struct minix_dir_entry {
|
||||
u16 inode;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
#define BLOCK_SIZE_BITS 10
|
||||
#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
|
||||
|
||||
#define NAME_MAX 255 /* # chars in a file name */
|
||||
|
||||
#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
|
||||
|
||||
#define MINIX_VALID_FS 0x0001 /* Clean fs. */
|
||||
#define MINIX_ERROR_FS 0x0002 /* fs has errors. */
|
||||
|
||||
#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
|
||||
#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
|
||||
|
||||
#ifndef BLKGETSIZE
|
||||
#define BLKGETSIZE _IO(0x12,96) /* return device size */
|
||||
#endif
|
||||
|
||||
#ifdef MINIX2_SUPER_MAGIC2
|
||||
#define HAVE_MINIX2 1
|
||||
@@ -203,7 +297,7 @@ static void show_usage(void)
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
fprintf(stderr,
|
||||
"\nPerforms a consistency check for MINIX filesystems.\n\n");
|
||||
fprintf(stderr, "OPTIONS:\n");
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, "\t-l\tLists all filenames\n");
|
||||
fprintf(stderr, "\t-r\tPerform interactive repairs\n");
|
||||
fprintf(stderr, "\t-a\tPerform automatic repairs\n");
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
* Mini grep implementation for busybox using libc regex.
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -22,149 +20,164 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||
|
||||
+ -q option (be quiet)
|
||||
+ exit code depending on grep result (TRUE or FALSE)
|
||||
(useful for scripts)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <regex.h>
|
||||
#include <string.h> /* for strerror() */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_too_few_args
|
||||
#include "messages.c"
|
||||
#include "internal.h"
|
||||
|
||||
extern int optind; /* in unistd.h */
|
||||
extern int errno; /* for use with strerror() */
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n"
|
||||
"grep [-ihHnqvs] pattern [files...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSearch for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"Options:\n"
|
||||
"\t-H\tprefix output lines with filename where match was found\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n"
|
||||
"\t-v\tselect non-matching lines\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expressions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expressions).\n"
|
||||
#endif
|
||||
"\t-v\tselect non-matching lines\n"
|
||||
"\t-s\tsuppress file open/read error messages\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
/* options */
|
||||
static int ignore_case = 0;
|
||||
static int print_filename = 0;
|
||||
static int print_line_num = 0;
|
||||
static int be_quiet = 0;
|
||||
static int invert_search = 0;
|
||||
static int suppress_err_msgs = 0;
|
||||
|
||||
static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
||||
int ignoreCase, int tellLine, int invertSearch)
|
||||
/* globals */
|
||||
static regex_t regex; /* storage space for compiled regular expression */
|
||||
static int nmatches = 0; /* keeps track of the number of matches */
|
||||
static char *cur_file = NULL; /* the current file we are reading */
|
||||
|
||||
|
||||
static void print_matched_line(char *line, int linenum)
|
||||
{
|
||||
long line = 0;
|
||||
char *haystack;
|
||||
int truth = !invertSearch;
|
||||
if (print_filename)
|
||||
printf("%s:", cur_file);
|
||||
if (print_line_num)
|
||||
printf("%i:", linenum);
|
||||
|
||||
while ((haystack = cstring_lineFromFile(fp))) {
|
||||
line++;
|
||||
if (find_match(haystack, needle, ignoreCase) == truth) {
|
||||
if (tellName == TRUE)
|
||||
printf("%s:", fileName);
|
||||
|
||||
if (tellLine == TRUE)
|
||||
printf("%ld:", line);
|
||||
|
||||
if (beQuiet == FALSE)
|
||||
fputs(haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
}
|
||||
free(haystack);
|
||||
}
|
||||
printf("%s", line);
|
||||
}
|
||||
|
||||
static void grep_file(FILE *file)
|
||||
{
|
||||
char *line = NULL;
|
||||
int ret;
|
||||
int linenum = 0;
|
||||
|
||||
while ((line = get_line_from_file(file)) != NULL) {
|
||||
linenum++;
|
||||
ret = regexec(®ex, line, 0, NULL, 0);
|
||||
if (ret == 0 && !invert_search) { /* match */
|
||||
|
||||
/* if we found a match but were told to be quiet, stop here and
|
||||
* return success */
|
||||
if (be_quiet) {
|
||||
regfree(®ex);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
nmatches++;
|
||||
|
||||
print_matched_line(line, linenum);
|
||||
|
||||
} else if (ret == REG_NOMATCH && invert_search) {
|
||||
print_matched_line(line, linenum);
|
||||
}
|
||||
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
extern int grep_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName = TRUE;
|
||||
int ignoreCase = FALSE;
|
||||
int tellLine = FALSE;
|
||||
int invertSearch = FALSE;
|
||||
int opt;
|
||||
int reflags;
|
||||
|
||||
if (argc < 1) {
|
||||
/* do special-case option parsing */
|
||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||
usage(grep_usage);
|
||||
}
|
||||
argv++;
|
||||
|
||||
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "iHhnqvs")) > 0) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
ignore_case++;
|
||||
break;
|
||||
case 'H':
|
||||
print_filename++;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
print_filename--;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
print_line_num++;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
be_quiet++;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
invertSearch = TRUE;
|
||||
invert_search++;
|
||||
break;
|
||||
case 's':
|
||||
suppress_err_msgs++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0 || *argv == NULL) {
|
||||
fatalError(too_few_args, "grep");
|
||||
}
|
||||
/* argv[optind] should be the regex pattern; no pattern, no worky */
|
||||
if (argv[optind] == NULL)
|
||||
usage(grep_usage);
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
/* compile the regular expression
|
||||
* we're not going to mess with sub-expressions, and we need to
|
||||
* treat newlines right. */
|
||||
reflags = REG_NOSUB | REG_NEWLINE;
|
||||
if (ignore_case)
|
||||
reflags |= REG_ICASE;
|
||||
if (bb_regcomp(®ex, argv[optind], reflags) != 0)
|
||||
exit(1);
|
||||
|
||||
if (argc == 0) {
|
||||
do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine, invertSearch);
|
||||
/* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
|
||||
* there is more than one file to grep, we will print the filenames */
|
||||
if ((argc-1) - (optind+1) > 0)
|
||||
print_filename++;
|
||||
|
||||
/* If no files were specified, or '-' was specified, take input from
|
||||
* stdin. Otherwise, we grep through all the files specified. */
|
||||
if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
|
||||
grep_file(stdin);
|
||||
} else {
|
||||
/* Never print the filename for just one file */
|
||||
if (argc == 1)
|
||||
tellName = FALSE;
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror(fileName);
|
||||
continue;
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind + 1; i < argc; i++) {
|
||||
cur_file = argv[i];
|
||||
file = fopen(cur_file, "r");
|
||||
if (file == NULL) {
|
||||
if (!suppress_err_msgs)
|
||||
fprintf(stderr, "grep: %s: %s\n", cur_file, strerror(errno));
|
||||
} else {
|
||||
grep_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine, invertSearch);
|
||||
|
||||
if (ferror(fp))
|
||||
perror(fileName);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
return(match);
|
||||
|
||||
regfree(®ex);
|
||||
|
||||
if (nmatches == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <getopt.h>
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n"
|
||||
|
||||
@@ -37,23 +37,42 @@
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <linux/version.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/unistd.h>
|
||||
#include <sys/sysinfo.h> /* For check_free_memory() */
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
//#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/wait.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
# include <sys/syslog.h>
|
||||
#endif
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
struct vt_stat {
|
||||
unsigned short v_active; /* active vt */
|
||||
unsigned short v_signal; /* signal to send */
|
||||
unsigned short v_state; /* vt bitmask */
|
||||
};
|
||||
#define VT_GETSTATE 0x5603 /* get global vt state info */
|
||||
|
||||
/* From <linux/serial.h> */
|
||||
struct serial_struct {
|
||||
int type;
|
||||
int line;
|
||||
int port;
|
||||
int irq;
|
||||
int flags;
|
||||
int xmit_fifo_size;
|
||||
int custom_divisor;
|
||||
int baud_base;
|
||||
unsigned short close_delay;
|
||||
char reserved_char[2];
|
||||
int hub6;
|
||||
unsigned short closing_wait; /* time to wait before closing */
|
||||
unsigned short closing_wait2; /* no longer used... */
|
||||
int reserved[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef RB_HALT_SYSTEM
|
||||
#define RB_HALT_SYSTEM 0xcdef0123
|
||||
@@ -86,9 +105,7 @@
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
#include <sys/kdaemon.h>
|
||||
@@ -226,8 +243,6 @@ static void message(int device, char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
#define CTRLCHAR(ch) ((ch)&0x1f)
|
||||
|
||||
/* Set terminal settings to reasonable defaults */
|
||||
void set_term(int fd)
|
||||
{
|
||||
@@ -236,14 +251,14 @@ void set_term(int fd)
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* set control chars */
|
||||
tty.c_cc[VINTR] = CTRLCHAR('C'); /* Ctrl-C */
|
||||
tty.c_cc[VQUIT] = CTRLCHAR('\\'); /* Ctrl-\ */
|
||||
tty.c_cc[VERASE] = CTRLCHAR('?'); /* Ctrl-? */
|
||||
tty.c_cc[VKILL] = CTRLCHAR('U'); /* Ctrl-U */
|
||||
tty.c_cc[VEOF] = CTRLCHAR('D'); /* Ctrl-D */
|
||||
tty.c_cc[VSTOP] = CTRLCHAR('S'); /* Ctrl-S */
|
||||
tty.c_cc[VSTART] = CTRLCHAR('Q'); /* Ctrl-Q */
|
||||
tty.c_cc[VSUSP] = CTRLCHAR('Z'); /* Ctrl-Z */
|
||||
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;
|
||||
@@ -270,13 +285,28 @@ static int check_free_memory()
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
/* Pre initialize mem_unit in case this kernel is something prior to
|
||||
* the linux 2.4 kernel (which will actually fill in mem_unit... */
|
||||
sysinfo(&info);
|
||||
if (sysinfo(&info) != 0) {
|
||||
message(LOG, "Error checking free memory: %s\n", strerror(errno));
|
||||
printf("Error checking free memory: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (info.mem_unit==0) {
|
||||
/* Looks like we have a kernel prior to Linux 2.4.x */
|
||||
info.mem_unit=1024;
|
||||
info.totalram/=info.mem_unit;
|
||||
info.totalswap/=info.mem_unit;
|
||||
} else {
|
||||
/* Bah. Linux 2.4.x completely changed sysinfo. This can in theory
|
||||
overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap
|
||||
on an embedded system? */
|
||||
info.mem_unit/=1024;
|
||||
info.totalram*=info.mem_unit;
|
||||
info.totalswap*=info.mem_unit;
|
||||
}
|
||||
|
||||
return((info.totalram+info.totalswap)/1024);
|
||||
return(info.totalram+info.totalswap);
|
||||
}
|
||||
|
||||
static void console_init()
|
||||
@@ -398,6 +428,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
dup2(fd, 0);
|
||||
dup2(fd, 1);
|
||||
dup2(fd, 2);
|
||||
ioctl(0, TIOCSCTTY, 0);
|
||||
tcsetpgrp(0, getpgrp());
|
||||
set_term(0);
|
||||
|
||||
@@ -554,7 +585,7 @@ static void shutdown_system(void)
|
||||
run_lastAction();
|
||||
|
||||
sync();
|
||||
if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
|
||||
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
|
||||
/* bdflush, kupdate not needed for kernels >2.2.11 */
|
||||
bdflush(1, 0);
|
||||
sync();
|
||||
@@ -573,11 +604,9 @@ static void halt_signal(int sig)
|
||||
/* allow time for last message to reach serial console */
|
||||
sleep(2);
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
if (sig == SIGUSR2)
|
||||
if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
|
||||
init_reboot(RB_POWER_OFF);
|
||||
else
|
||||
#endif
|
||||
init_reboot(RB_HALT_SYSTEM);
|
||||
exit(0);
|
||||
}
|
||||
@@ -873,7 +902,7 @@ extern int init_main(int argc, char **argv)
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
signal(SIGUSR1, halt_signal);
|
||||
signal(SIGUSR2, reboot_signal);
|
||||
signal(SIGUSR2, halt_signal);
|
||||
signal(SIGINT, reboot_signal);
|
||||
signal(SIGTERM, reboot_signal);
|
||||
#if defined BB_FEATURE_INIT_CHROOT
|
||||
|
||||
+56
-27
@@ -37,23 +37,42 @@
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <linux/version.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/unistd.h>
|
||||
#include <sys/sysinfo.h> /* For check_free_memory() */
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
//#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/wait.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
# include <sys/syslog.h>
|
||||
#endif
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
struct vt_stat {
|
||||
unsigned short v_active; /* active vt */
|
||||
unsigned short v_signal; /* signal to send */
|
||||
unsigned short v_state; /* vt bitmask */
|
||||
};
|
||||
#define VT_GETSTATE 0x5603 /* get global vt state info */
|
||||
|
||||
/* From <linux/serial.h> */
|
||||
struct serial_struct {
|
||||
int type;
|
||||
int line;
|
||||
int port;
|
||||
int irq;
|
||||
int flags;
|
||||
int xmit_fifo_size;
|
||||
int custom_divisor;
|
||||
int baud_base;
|
||||
unsigned short close_delay;
|
||||
char reserved_char[2];
|
||||
int hub6;
|
||||
unsigned short closing_wait; /* time to wait before closing */
|
||||
unsigned short closing_wait2; /* no longer used... */
|
||||
int reserved[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef RB_HALT_SYSTEM
|
||||
#define RB_HALT_SYSTEM 0xcdef0123
|
||||
@@ -86,9 +105,7 @@
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
#include <sys/kdaemon.h>
|
||||
@@ -226,8 +243,6 @@ static void message(int device, char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
#define CTRLCHAR(ch) ((ch)&0x1f)
|
||||
|
||||
/* Set terminal settings to reasonable defaults */
|
||||
void set_term(int fd)
|
||||
{
|
||||
@@ -236,14 +251,14 @@ void set_term(int fd)
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* set control chars */
|
||||
tty.c_cc[VINTR] = CTRLCHAR('C'); /* Ctrl-C */
|
||||
tty.c_cc[VQUIT] = CTRLCHAR('\\'); /* Ctrl-\ */
|
||||
tty.c_cc[VERASE] = CTRLCHAR('?'); /* Ctrl-? */
|
||||
tty.c_cc[VKILL] = CTRLCHAR('U'); /* Ctrl-U */
|
||||
tty.c_cc[VEOF] = CTRLCHAR('D'); /* Ctrl-D */
|
||||
tty.c_cc[VSTOP] = CTRLCHAR('S'); /* Ctrl-S */
|
||||
tty.c_cc[VSTART] = CTRLCHAR('Q'); /* Ctrl-Q */
|
||||
tty.c_cc[VSUSP] = CTRLCHAR('Z'); /* Ctrl-Z */
|
||||
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;
|
||||
@@ -270,13 +285,28 @@ static int check_free_memory()
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
/* Pre initialize mem_unit in case this kernel is something prior to
|
||||
* the linux 2.4 kernel (which will actually fill in mem_unit... */
|
||||
sysinfo(&info);
|
||||
if (sysinfo(&info) != 0) {
|
||||
message(LOG, "Error checking free memory: %s\n", strerror(errno));
|
||||
printf("Error checking free memory: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (info.mem_unit==0) {
|
||||
/* Looks like we have a kernel prior to Linux 2.4.x */
|
||||
info.mem_unit=1024;
|
||||
info.totalram/=info.mem_unit;
|
||||
info.totalswap/=info.mem_unit;
|
||||
} else {
|
||||
/* Bah. Linux 2.4.x completely changed sysinfo. This can in theory
|
||||
overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap
|
||||
on an embedded system? */
|
||||
info.mem_unit/=1024;
|
||||
info.totalram*=info.mem_unit;
|
||||
info.totalswap*=info.mem_unit;
|
||||
}
|
||||
|
||||
return((info.totalram+info.totalswap)/1024);
|
||||
return(info.totalram+info.totalswap);
|
||||
}
|
||||
|
||||
static void console_init()
|
||||
@@ -398,6 +428,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
||||
dup2(fd, 0);
|
||||
dup2(fd, 1);
|
||||
dup2(fd, 2);
|
||||
ioctl(0, TIOCSCTTY, 0);
|
||||
tcsetpgrp(0, getpgrp());
|
||||
set_term(0);
|
||||
|
||||
@@ -554,7 +585,7 @@ static void shutdown_system(void)
|
||||
run_lastAction();
|
||||
|
||||
sync();
|
||||
if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
|
||||
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
|
||||
/* bdflush, kupdate not needed for kernels >2.2.11 */
|
||||
bdflush(1, 0);
|
||||
sync();
|
||||
@@ -573,11 +604,9 @@ static void halt_signal(int sig)
|
||||
/* allow time for last message to reach serial console */
|
||||
sleep(2);
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
if (sig == SIGUSR2)
|
||||
if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
|
||||
init_reboot(RB_POWER_OFF);
|
||||
else
|
||||
#endif
|
||||
init_reboot(RB_HALT_SYSTEM);
|
||||
exit(0);
|
||||
}
|
||||
@@ -873,7 +902,7 @@ extern int init_main(int argc, char **argv)
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
signal(SIGUSR1, halt_signal);
|
||||
signal(SIGUSR2, reboot_signal);
|
||||
signal(SIGUSR2, halt_signal);
|
||||
signal(SIGINT, reboot_signal);
|
||||
signal(SIGTERM, reboot_signal);
|
||||
#if defined BB_FEATURE_INIT_CHROOT
|
||||
|
||||
@@ -38,9 +38,8 @@
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--------modutils module.h, lines 45-242
|
||||
@@ -71,7 +70,7 @@
|
||||
#ifndef MODUTILS_MODULE_H
|
||||
#define MODUTILS_MODULE_H 1
|
||||
|
||||
#ident "$Id: insmod.c,v 1.9 2000/06/19 19:53:30 andersen Exp $"
|
||||
#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $"
|
||||
|
||||
/* This file contains the structures used by the 2.0 and 2.1 kernels.
|
||||
We do not use the kernel headers directly because we do not wish
|
||||
@@ -277,7 +276,7 @@ int delete_module(const char *);
|
||||
#ifndef MODUTILS_OBJ_H
|
||||
#define MODUTILS_OBJ_H 1
|
||||
|
||||
#ident "$Id: insmod.c,v 1.9 2000/06/19 19:53:30 andersen Exp $"
|
||||
#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $"
|
||||
|
||||
/* The relocatable object is manipulated using elfin types. */
|
||||
|
||||
@@ -530,6 +529,9 @@ _syscall2(int, new_sys_init_module, const char *, name,
|
||||
_syscall5(int, old_sys_init_module, const char *, name, char *, code,
|
||||
unsigned, codesize, struct old_mod_routines *, routines,
|
||||
struct old_symbol_table *, symtab)
|
||||
#ifndef __NR_query_module
|
||||
#define __NR_query_module 167
|
||||
#endif
|
||||
_syscall5(int, query_module, const char *, name, int, which,
|
||||
void *, buf, size_t, bufsize, size_t*, ret);
|
||||
#ifndef BB_RMMOD
|
||||
@@ -1189,8 +1191,10 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
int *loc;
|
||||
|
||||
p = *argv;
|
||||
if ((q = strchr(p, '=')) == NULL)
|
||||
if ((q = strchr(p, '=')) == NULL) {
|
||||
argc--;
|
||||
continue;
|
||||
}
|
||||
*q++ = '\0';
|
||||
|
||||
sym = obj_find_symbol(f, p);
|
||||
@@ -1210,9 +1214,7 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
str = alloca(strlen(q));
|
||||
for (r = str, q++; *q != '"'; ++q, ++r) {
|
||||
if (*q == '\0') {
|
||||
fprintf(stderr,
|
||||
"improperly terminated string argument for %s\n",
|
||||
p);
|
||||
fprintf(stderr, "improperly terminated string argument for %s\n", p);
|
||||
return 0;
|
||||
} else if (*q == '\\')
|
||||
switch (*++q) {
|
||||
@@ -1341,7 +1343,7 @@ static int old_get_kernel_symbols(void)
|
||||
|
||||
nks = get_kernel_syms(NULL);
|
||||
if (nks < 0) {
|
||||
perror("get_kernel_syms: %m");
|
||||
errorMsg("get_kernel_syms: %s: %s", m_name, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1522,7 +1524,7 @@ old_init_module(const char *m_name, struct obj_file *f,
|
||||
m_size | (flag_autoclean ? OLD_MOD_AUTOCLEAN
|
||||
: 0), &routines, symtab);
|
||||
if (ret)
|
||||
perror("init_module: %m");
|
||||
errorMsg("init_module: %s: %s", m_name, strerror(errno));
|
||||
|
||||
free(image);
|
||||
free(symtab);
|
||||
@@ -1552,8 +1554,10 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
int min, max, n;
|
||||
|
||||
p = *argv;
|
||||
if ((q = strchr(p, '=')) == NULL)
|
||||
if ((q = strchr(p, '=')) == NULL) {
|
||||
argc--;
|
||||
continue;
|
||||
}
|
||||
|
||||
key = alloca(q - p + 6);
|
||||
memcpy(key, "parm_", 5);
|
||||
@@ -1837,7 +1841,7 @@ static int new_get_kernel_symbols(void)
|
||||
module_names = xrealloc(module_names, bufsize = ret);
|
||||
goto retry_modules_load;
|
||||
}
|
||||
perror("QM_MODULES: %m\n");
|
||||
errorMsg("QM_MODULES: %s", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1856,7 +1860,7 @@ static int new_get_kernel_symbols(void)
|
||||
/* The module was removed out from underneath us. */
|
||||
continue;
|
||||
}
|
||||
perror("query_module: QM_INFO: %m");
|
||||
errorMsg("query_module: QM_INFO: %s: %s", mn, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1871,7 +1875,7 @@ static int new_get_kernel_symbols(void)
|
||||
/* The module was removed out from underneath us. */
|
||||
continue;
|
||||
default:
|
||||
perror("query_module: QM_SYMBOLS: %m");
|
||||
errorMsg("query_module: QM_SYMBOLS: %s: %s", mn, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1896,7 +1900,7 @@ static int new_get_kernel_symbols(void)
|
||||
syms = xrealloc(syms, bufsize = ret);
|
||||
goto retry_kern_sym_load;
|
||||
}
|
||||
perror("kernel: QM_SYMBOLS: %m");
|
||||
errorMsg("kernel: QM_SYMBOLS: %s", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
nksyms = nsyms = ret;
|
||||
@@ -2077,7 +2081,7 @@ new_init_module(const char *m_name, struct obj_file *f,
|
||||
|
||||
ret = new_sys_init_module(m_name, (struct new_module *) image);
|
||||
if (ret)
|
||||
perror("init_module: %m");
|
||||
errorMsg("init_module: %s: %s", m_name, strerror(errno));
|
||||
|
||||
free(image);
|
||||
|
||||
@@ -2457,7 +2461,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (fread(&f->header, sizeof(f->header), 1, fp) != 1) {
|
||||
perror("error reading ELF header: %m");
|
||||
errorMsg("error reading ELF header: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2496,7 +2500,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
|
||||
fseek(fp, f->header.e_shoff, SEEK_SET);
|
||||
if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) {
|
||||
perror("error reading ELF section headers: %m");
|
||||
errorMsg("error reading ELF section headers: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2526,8 +2530,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
sec->contents = xmalloc(sec->header.sh_size);
|
||||
fseek(fp, sec->header.sh_offset, SEEK_SET);
|
||||
if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
|
||||
fprintf(stderr,
|
||||
"error reading ELF section data: %m\n");
|
||||
errorMsg("error reading ELF section data: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -2724,8 +2727,7 @@ extern int insmod_main( int argc, char **argv)
|
||||
if (m_filename[0] == '\0'
|
||||
|| ((fp = fopen(m_filename, "r")) == NULL))
|
||||
{
|
||||
perror("No module by that name found in " _PATH_MODULES
|
||||
"\n");
|
||||
errorMsg("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
@@ -2857,7 +2859,7 @@ extern int insmod_main( int argc, char **argv)
|
||||
m_size);
|
||||
goto out;
|
||||
default:
|
||||
perror("create_module: %m");
|
||||
errorMsg("create_module: %s: %s", m_name, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
+34
-7
@@ -30,12 +30,14 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include <mntent.h>
|
||||
#if ! defined(__GLIBC__) && ! defined (__UCLIBC__)
|
||||
#include <asm/string.h>
|
||||
#endif
|
||||
#include <regex.h>
|
||||
/* for the _syscall() macros */
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
|
||||
/* Some useful definitions */
|
||||
@@ -104,7 +106,6 @@ extern const struct BB_applet applets[];
|
||||
extern int ar_main(int argc, char **argv);
|
||||
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);
|
||||
extern int chmod_chown_chgrp_main(int argc, char** argv);
|
||||
extern int chroot_main(int argc, char** argv);
|
||||
@@ -120,6 +121,7 @@ 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 dumpkmap_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);
|
||||
@@ -258,9 +260,16 @@ 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* findPidByName( char* pidName);
|
||||
extern void *xmalloc (size_t size);
|
||||
extern int find_real_root_device_name(char* name);
|
||||
extern char *cstring_lineFromFile(FILE *f);
|
||||
extern char *get_line_from_file(FILE *file);
|
||||
extern char process_escape_sequence(char **ptr);
|
||||
extern char *get_last_path_component(char *path);
|
||||
extern int bb_regcomp(regex_t *preg, const char *regex, int cflags);
|
||||
|
||||
extern void *xmalloc (size_t size);
|
||||
extern char *xstrdup (const char *s);
|
||||
extern char *xstrndup (const char *s, int n);
|
||||
|
||||
|
||||
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
||||
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
||||
@@ -296,9 +305,27 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
|
||||
#define RB_POWER_OFF 0x4321fedc
|
||||
#endif
|
||||
|
||||
/* Include our own copy of struct sysinfo to avoid binary compatability
|
||||
* problems with Linux 2.4, which changed things. Grumble, grumble. */
|
||||
struct sysinfo {
|
||||
long uptime; /* Seconds since boot */
|
||||
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
|
||||
unsigned long totalram; /* Total usable main memory size */
|
||||
unsigned long freeram; /* Available memory size */
|
||||
unsigned long sharedram; /* Amount of shared memory */
|
||||
unsigned long bufferram; /* Memory used by buffers */
|
||||
unsigned long totalswap; /* Total swap space size */
|
||||
unsigned long freeswap; /* swap space still available */
|
||||
unsigned short procs; /* Number of current processes */
|
||||
unsigned long totalhigh; /* Total high memory size */
|
||||
unsigned long freehigh; /* Available high memory size */
|
||||
unsigned int mem_unit; /* Memory unit size in bytes */
|
||||
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
|
||||
};
|
||||
extern int sysinfo (struct sysinfo* info);
|
||||
|
||||
#ifndef setbit
|
||||
/* Bit map related macros -- libc5 doens't provide these... sigh. */
|
||||
#ifndef setbit
|
||||
#define NBBY CHAR_BIT
|
||||
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
|
||||
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
|
||||
|
||||
@@ -58,76 +58,60 @@ struct signal_name {
|
||||
};
|
||||
|
||||
const struct signal_name signames[] = {
|
||||
/* Everything, order not important */
|
||||
{"HUP", SIGHUP},
|
||||
{"INT", SIGINT},
|
||||
{"QUIT", SIGQUIT},
|
||||
{"ILL", SIGILL},
|
||||
{"TRAP", SIGTRAP},
|
||||
{"ABRT", SIGABRT},
|
||||
#ifndef __alpha__
|
||||
{"IOT", SIGIOT},
|
||||
#endif
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"EMT", SIGEMT},
|
||||
#else
|
||||
{"BUS", SIGBUS},
|
||||
#endif
|
||||
{"FPE", SIGFPE},
|
||||
{"KILL", SIGKILL},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"BUS", SIGBUS},
|
||||
#else
|
||||
{"USR1", SIGUSR1},
|
||||
#endif
|
||||
{"SEGV", SIGSEGV},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"SYS", SIGSYS},
|
||||
#else
|
||||
{"USR2", SIGUSR2},
|
||||
#endif
|
||||
{"PIPE", SIGPIPE},
|
||||
{"ALRM", SIGALRM},
|
||||
{"TERM", SIGTERM},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"URG", SIGURG},
|
||||
{"STOP", SIGSTOP},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CONT", SIGCONT},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"TTIN", SIGTTIN},
|
||||
{"TTOU", SIGTTOU},
|
||||
{"IO", SIGIO},
|
||||
# ifndef __alpha__
|
||||
{"POLL", SIGIO},
|
||||
# endif
|
||||
{"XCPU", SIGXCPU},
|
||||
{"XFSZ", SIGXFSZ},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
{"PROF", SIGPROF},
|
||||
{"WINCH", SIGWINCH},
|
||||
# ifdef __alpha__
|
||||
{"INFO", SIGINFO},
|
||||
# else
|
||||
{"LOST", SIGLOST},
|
||||
# endif
|
||||
{"BUS", SIGBUS},
|
||||
{"USR1", SIGUSR1},
|
||||
{"USR2", SIGUSR2},
|
||||
#else
|
||||
{"STKFLT", SIGSTKFLT},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"CONT", SIGCONT},
|
||||
{"STOP", SIGSTOP},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CONT", SIGCONT},
|
||||
{"TTIN", SIGTTIN},
|
||||
{"TTOU", SIGTTOU},
|
||||
{"URG", SIGURG},
|
||||
{"IO", SIGIO},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"XCPU", SIGXCPU},
|
||||
{"XFSZ", SIGXFSZ},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
{"PROF", SIGPROF},
|
||||
{"WINCH", SIGWINCH},
|
||||
{"IO", SIGIO},
|
||||
{"URG", SIGURG},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
#ifndef __alpha__
|
||||
/* everything except alpha */
|
||||
{"IOT", SIGIOT},
|
||||
{"POLL", SIGPOLL},
|
||||
#endif
|
||||
#if defined(__sparc__) || defined(__alpha__) || defined(__mips__)
|
||||
/* everthing except intel */
|
||||
{"EMT", SIGEMT},
|
||||
{"SYS", SIGSYS},
|
||||
# ifdef __alpha__
|
||||
/* alpha only */
|
||||
{"LOST", SIGLOST},
|
||||
#endif
|
||||
#ifdef __sparc__
|
||||
/* space only */
|
||||
{"INFO", SIGINFO},
|
||||
#endif
|
||||
#ifdef __mips__
|
||||
/* mips only */
|
||||
{"CLD", SIGCLD},
|
||||
{"PWR", SIGPWR},
|
||||
#endif
|
||||
#else
|
||||
/* intel only */
|
||||
{"STKFLT", SIGSTKFLT},
|
||||
{"PWR", SIGPWR},
|
||||
{"UNUSED", SIGUNUSED},
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include "cmdedit.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_READ 128 /* size of input buffer for `read' builtin */
|
||||
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
|
||||
|
||||
|
||||
@@ -89,18 +89,21 @@ struct builtInCommand {
|
||||
int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
|
||||
};
|
||||
|
||||
/* Some function prototypes */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||
/* function prototypes for builtins */
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk);
|
||||
|
||||
|
||||
/* function prototypes for shell stuff */
|
||||
static void checkJobs(struct jobSet *jobList);
|
||||
static int getCommand(FILE * source, char *command);
|
||||
static int parseCommand(char **commandPtr, struct job *job, int *isBg);
|
||||
@@ -111,35 +114,37 @@ static int busy_loop(FILE * input);
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins[] = {
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", shell_cd},
|
||||
{"exit", "Exit from shell()", "exit", shell_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", builtin_cd},
|
||||
{"exit", "Exit from shell()", "exit", builtin_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", builtin_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", builtin_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", builtin_unset},
|
||||
{"read", "Input environment variable", "read [VAR]", builtin_read},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins_forking[] = {
|
||||
{"env", "Print all environment variables", "env", shell_env},
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
{"env", "Print all environment variables", "env", builtin_env},
|
||||
{"pwd", "Print current directory", "pwd", builtin_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", builtin_source},
|
||||
{"help", "List shell built-in commands", "help", builtin_help},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n"
|
||||
"sh [FILE]...\n"
|
||||
" or: sh -c command [args]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nlash: The BusyBox command interpreter (shell).\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static char cwd[1024];
|
||||
static char *prompt = "# ";
|
||||
static char *cwd = NULL;
|
||||
static char *local_pending_command = NULL;
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
void win_changed(int sig)
|
||||
@@ -154,7 +159,7 @@ void win_changed(int sig)
|
||||
|
||||
|
||||
/* built-in 'cd <path>' handler */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
@@ -172,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'env' handler */
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
char **e;
|
||||
|
||||
@@ -183,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'exit' handler */
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
@@ -192,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'fg' and 'bg' handler */
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
{
|
||||
int i, jobNum;
|
||||
struct job *job=NULL;
|
||||
@@ -225,8 +230,9 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
}
|
||||
|
||||
@@ -242,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
}
|
||||
|
||||
/* built-in 'help' handler */
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
struct builtInCommand *x;
|
||||
|
||||
@@ -259,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'jobs' handler */
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
@@ -277,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
|
||||
|
||||
/* built-in 'pwd' handler */
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
fprintf(stdout, "%s\n", cwd);
|
||||
@@ -285,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'export VAR=value' handler */
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
return (shell_env(cmd, junk));
|
||||
return (builtin_env(cmd, junk));
|
||||
}
|
||||
res = putenv(cmd->progs[0].argv[1]);
|
||||
if (res)
|
||||
@@ -298,8 +304,42 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* built-in 'read VAR' handler */
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res = 0, len, newlen;
|
||||
char *s;
|
||||
char string[MAX_READ];
|
||||
|
||||
if (cmd->progs[0].argv[1]) {
|
||||
/* argument (VAR) given: put "VAR=" into buffer */
|
||||
strcpy(string, cmd->progs[0].argv[1]);
|
||||
len = strlen(string);
|
||||
string[len++] = '=';
|
||||
string[len] = '\0';
|
||||
fgets(&string[len], sizeof(string) - len, stdin); /* read string */
|
||||
newlen = strlen(string);
|
||||
if(newlen > len)
|
||||
string[--newlen] = '\0'; /* chomp trailing newline */
|
||||
/*
|
||||
** string should now contain "VAR=<value>"
|
||||
** copy it (putenv() won't do that, so we must make sure
|
||||
** the string resides in a static buffer!)
|
||||
*/
|
||||
res = -1;
|
||||
if((s = strdup(string)))
|
||||
res = putenv(s);
|
||||
if (res)
|
||||
fprintf(stdout, "read: %s\n", strerror(errno));
|
||||
}
|
||||
else
|
||||
fgets(string, sizeof(string), stdin);
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* Built-in '.' handler (read-in and execute commands from file) */
|
||||
static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_source(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
FILE *input;
|
||||
int status;
|
||||
@@ -320,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'unset VAR' handler */
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
fprintf(stdout, "unset: parameter required.\n");
|
||||
@@ -411,6 +451,17 @@ static void checkJobs(struct jobSet *jobList)
|
||||
|
||||
static int getCommand(FILE * source, char *command)
|
||||
{
|
||||
if (source == NULL) {
|
||||
if (local_pending_command) {
|
||||
/* a command specified (-c option): return it & mark it done */
|
||||
strcpy(command, local_pending_command);
|
||||
free(local_pending_command);
|
||||
local_pending_command = NULL;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (source == stdin) {
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
int len;
|
||||
@@ -448,7 +499,7 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
int rc;
|
||||
int flags;
|
||||
int i;
|
||||
char *src, *dst;
|
||||
char *src, *dst, *var;
|
||||
|
||||
if (argc > 1) { /* cmd->globResult is already initialized */
|
||||
flags = GLOB_APPEND;
|
||||
@@ -458,6 +509,9 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
flags = 0;
|
||||
i = 0;
|
||||
}
|
||||
/* do shell variable substitution */
|
||||
if(*prog->argv[argc - 1] == '$' && (var = getenv(prog->argv[argc - 1] + 1)))
|
||||
prog->argv[argc - 1] = var;
|
||||
|
||||
rc = glob(prog->argv[argc - 1], flags, NULL, &prog->globResult);
|
||||
if (rc == GLOB_NOSPACE) {
|
||||
@@ -522,12 +576,13 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
job->progs = malloc(sizeof(*job->progs));
|
||||
|
||||
/* We set the argv elements to point inside of this string. The
|
||||
memory is freed by freeJob().
|
||||
memory is freed by freeJob(). Allocate twice the original
|
||||
length in case we need to quote every single character.
|
||||
|
||||
Getting clean memory relieves us of the task of NULL
|
||||
terminating things and makes the rest of this look a bit
|
||||
cleaner (though it is, admittedly, a tad less efficient) */
|
||||
job->cmdBuf = command = calloc(1, strlen(*commandPtr) + 1);
|
||||
job->cmdBuf = command = calloc(1, 2*strlen(*commandPtr) + 1);
|
||||
job->text = NULL;
|
||||
|
||||
prog = job->progs;
|
||||
@@ -570,9 +625,8 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
sizeof(*prog->argv) *
|
||||
argvAlloced);
|
||||
}
|
||||
prog->argv[argc] = buf;
|
||||
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
} else
|
||||
switch (*src) {
|
||||
@@ -602,6 +656,7 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
if (*chptr && *prog->argv[argc]) {
|
||||
buf++, argc++;
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +791,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
int nextin, nextout;
|
||||
int pipefds[2]; /* pipefd[0] is for reading */
|
||||
struct builtInCommand *x;
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
const struct BB_applet *a = applets;
|
||||
#endif
|
||||
|
||||
@@ -750,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
nextout = 1;
|
||||
}
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any non-forking builtins */
|
||||
for (x = bltins; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
return (x->function(&newJob, jobList));
|
||||
@@ -773,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
/* explicit redirections override pipes */
|
||||
setupRedirections(newJob.progs + i);
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any of the other builtins */
|
||||
for (x = bltins_forking; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
exit (x->function(&newJob, jobList));
|
||||
}
|
||||
}
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
/* Handle busybox internals here */
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
/* Check if the command matches any busybox internal commands here */
|
||||
/* TODO: Add matching when paths are appended (i.e. 'cat' currently
|
||||
* works, but '/bin/cat' doesn't ) */
|
||||
while (a->name != 0) {
|
||||
if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
|
||||
int argc;
|
||||
@@ -842,7 +899,8 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
jobList->fg = job;
|
||||
|
||||
/* move the new process group into the foreground */
|
||||
if (tcsetpgrp(0, newJob.pgrp))
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, newJob.pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
|
||||
@@ -894,10 +952,14 @@ static int busy_loop(FILE * input)
|
||||
char *nextCommand = NULL;
|
||||
struct jobSet jobList = { NULL, NULL };
|
||||
struct job newJob;
|
||||
pid_t parent_pgrp;
|
||||
int i;
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
/* save current owner of TTY so we can restore it on exit */
|
||||
parent_pgrp = tcgetpgrp(0);
|
||||
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
@@ -939,10 +1001,6 @@ static int busy_loop(FILE * input)
|
||||
|
||||
removeJob(&jobList, jobList.fg);
|
||||
jobList.fg = NULL;
|
||||
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
} else {
|
||||
/* the child was stopped */
|
||||
@@ -958,13 +1016,22 @@ static int busy_loop(FILE * input)
|
||||
|
||||
if (!jobList.fg) {
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, getpid()) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
}
|
||||
}
|
||||
free(command);
|
||||
|
||||
/* return controlling TTY back to parent process group before exiting */
|
||||
if (tcsetpgrp(0, parent_pgrp))
|
||||
perror("tcsetpgrp");
|
||||
|
||||
/* return exit status if called with "-c" */
|
||||
if (input == NULL && WIFEXITED(status))
|
||||
return WEXITSTATUS(status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -973,11 +1040,12 @@ int shell_main(int argc, char **argv)
|
||||
{
|
||||
FILE *input = stdin;
|
||||
|
||||
if (argc > 2) {
|
||||
usage(shell_usage);
|
||||
}
|
||||
/* initialize the cwd */
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
cwd = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (cwd == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
getcwd(cwd, sizeof(char)*BUFSIZ);
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
cmdedit_init();
|
||||
@@ -986,20 +1054,43 @@ int shell_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
//if (argv[0] && argv[0][0] == '-') {
|
||||
// shell_source("/etc/profile");
|
||||
// builtin_source("/etc/profile");
|
||||
//}
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
|
||||
fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
|
||||
} else {
|
||||
if (*argv[1]=='-') {
|
||||
usage("sh\n\nlash -- the BusyBox LAme SHell (command interpreter)\n");
|
||||
if (argv[1][0]=='-' && argv[1][1]=='c') {
|
||||
int i;
|
||||
local_pending_command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (local_pending_command == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
if (strlen(local_pending_command) + strlen(argv[i]) >= BUFSIZ) {
|
||||
local_pending_command = realloc(local_pending_command,
|
||||
strlen(local_pending_command) + strlen(argv[i]));
|
||||
if (local_pending_command==NULL)
|
||||
fatalError("sh: commands for -c option too long\n");
|
||||
}
|
||||
strcat(local_pending_command, argv[i]);
|
||||
if ( (i + 1) < argc)
|
||||
strcat(local_pending_command, " ");
|
||||
}
|
||||
input = NULL;
|
||||
|
||||
}
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
else if (argv[1][0]=='-') {
|
||||
usage(shell_usage);
|
||||
}
|
||||
else {
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ static const char ln_usage[] =
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
|
||||
"\t-f\tremove existing destination files\n"
|
||||
#if 0
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
@@ -52,7 +50,7 @@ static int followLinks = TRUE;
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
char *linkName;
|
||||
char *linkName, *dirName=NULL;
|
||||
int linkIntoDirFlag;
|
||||
int stopIt = FALSE;
|
||||
|
||||
@@ -92,41 +90,27 @@ extern int ln_main(int argc, char **argv)
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if (strlen(linkName) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
dirName = linkName;
|
||||
|
||||
while (argc-- >= 2) {
|
||||
#if 0
|
||||
char srcName[BUFSIZ + 1];
|
||||
int nChars;
|
||||
#endif
|
||||
int status;
|
||||
|
||||
if (strlen(*argv) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
if (linkIntoDirFlag == TRUE) {
|
||||
char *baseName = get_last_path_component(*argv);
|
||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||
strcpy(linkName, dirName);
|
||||
if(dirName[strlen(dirName)-1] != '/')
|
||||
strcat(linkName, "/");
|
||||
strcat(linkName,baseName);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (followLinks == FALSE) {
|
||||
strcpy(srcName, *argv);
|
||||
} else {
|
||||
/* Warning! This can silently truncate if > BUFSIZ, but
|
||||
I don't think that there can be one > BUFSIZ anyway. */
|
||||
nChars = readlink(*argv, srcName, BUFSIZ);
|
||||
srcName[nChars] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
if (removeoldFlag == TRUE) {
|
||||
status = (unlink(linkName) && errno != ENOENT);
|
||||
if (status != 0) {
|
||||
@@ -143,6 +127,11 @@ extern int ln_main(int argc, char **argv)
|
||||
perror(linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
free(linkName);
|
||||
|
||||
argv++;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
if (fstat(fileno(fp), &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
|
||||
+13
-3
@@ -24,14 +24,24 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/keyboard.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDSKBENT 0x4B47 /* sets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a binary keyboard translation table from standard input.\n"
|
||||
"\nLoads a binary keyboard translation table from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
@@ -49,11 +49,7 @@
|
||||
/************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -345,7 +341,7 @@ static int list_item(const char *name)
|
||||
struct stat info;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char fullname[MAXNAMLEN + 1], *fnend;
|
||||
char fullname[BUFSIZ + 1], *fnend;
|
||||
|
||||
if (lstat(name, &info))
|
||||
goto listerr;
|
||||
@@ -568,6 +564,8 @@ extern int ls_main(int argc, char **argv)
|
||||
opts |= DISP_RECURSIVE;
|
||||
break;
|
||||
#endif
|
||||
case 'g': /* ignore -- for ftp servers */
|
||||
break;
|
||||
default:
|
||||
goto print_usage_message;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,14 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
|
||||
/* It turns out that libc5 doesn't have this in its headers
|
||||
* even though it is actually in the lib. Force it to work */
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
#define getline __getline
|
||||
extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--------md5.c
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ int dc_main(int argc, char **argv)
|
||||
char *line = NULL;
|
||||
char *cursor = NULL;
|
||||
char *token = NULL;
|
||||
while ((line = cstring_lineFromFile(stdin))) {
|
||||
while ((line = get_line_from_file(stdin))) {
|
||||
cursor = line;
|
||||
len = number_of_tokens(line);
|
||||
for (i = 0; i < len; i++) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <linux/unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
|
||||
+98
-3
@@ -77,8 +77,103 @@
|
||||
#include <sys/param.h>
|
||||
#include <mntent.h>
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include <linux/minix_fs.h>
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
|
||||
|
||||
#define MINIX_ROOT_INO 1
|
||||
#define MINIX_LINK_MAX 250
|
||||
#define MINIX2_LINK_MAX 65530
|
||||
|
||||
#define MINIX_I_MAP_SLOTS 8
|
||||
#define MINIX_Z_MAP_SLOTS 64
|
||||
#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
|
||||
#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
|
||||
#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */
|
||||
#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
|
||||
#define MINIX_VALID_FS 0x0001 /* Clean fs. */
|
||||
#define MINIX_ERROR_FS 0x0002 /* fs has errors. */
|
||||
|
||||
#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
|
||||
#define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode)))
|
||||
|
||||
#define MINIX_V1 0x0001 /* original minix fs */
|
||||
#define MINIX_V2 0x0002 /* minix V2 fs */
|
||||
|
||||
#define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version
|
||||
|
||||
/*
|
||||
* This is the original minix inode layout on disk.
|
||||
* Note the 8-bit gid and atime and ctime.
|
||||
*/
|
||||
struct minix_inode {
|
||||
u16 i_mode;
|
||||
u16 i_uid;
|
||||
u32 i_size;
|
||||
u32 i_time;
|
||||
u8 i_gid;
|
||||
u8 i_nlinks;
|
||||
u16 i_zone[9];
|
||||
};
|
||||
|
||||
/*
|
||||
* The new minix inode has all the time entries, as well as
|
||||
* long block numbers and a third indirect block (7+1+1+1
|
||||
* instead of 7+1+1). Also, some previously 8-bit values are
|
||||
* now 16-bit. The inode is now 64 bytes instead of 32.
|
||||
*/
|
||||
struct minix2_inode {
|
||||
u16 i_mode;
|
||||
u16 i_nlinks;
|
||||
u16 i_uid;
|
||||
u16 i_gid;
|
||||
u32 i_size;
|
||||
u32 i_atime;
|
||||
u32 i_mtime;
|
||||
u32 i_ctime;
|
||||
u32 i_zone[10];
|
||||
};
|
||||
|
||||
/*
|
||||
* minix super-block data on disk
|
||||
*/
|
||||
struct minix_super_block {
|
||||
u16 s_ninodes;
|
||||
u16 s_nzones;
|
||||
u16 s_imap_blocks;
|
||||
u16 s_zmap_blocks;
|
||||
u16 s_firstdatazone;
|
||||
u16 s_log_zone_size;
|
||||
u32 s_max_size;
|
||||
u16 s_magic;
|
||||
u16 s_state;
|
||||
u32 s_zones;
|
||||
};
|
||||
|
||||
struct minix_dir_entry {
|
||||
u16 inode;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
#define BLOCK_SIZE_BITS 10
|
||||
#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
|
||||
|
||||
#define NAME_MAX 255 /* # chars in a file name */
|
||||
|
||||
#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
|
||||
|
||||
#define MINIX_VALID_FS 0x0001 /* Clean fs. */
|
||||
#define MINIX_ERROR_FS 0x0002 /* fs has errors. */
|
||||
|
||||
#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
|
||||
#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
|
||||
|
||||
#ifndef BLKGETSIZE
|
||||
#define BLKGETSIZE _IO(0x12,96) /* return device size */
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MINIX2_SUPER_MAGIC2
|
||||
#define HAVE_MINIX2 1
|
||||
@@ -183,7 +278,7 @@ static volatile void show_usage()
|
||||
program_name);
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
fprintf(stderr, "\nMake a MINIX filesystem.\n\n");
|
||||
fprintf(stderr, "OPTIONS:\n");
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
|
||||
fprintf(stderr,
|
||||
"\t-n [14|30]\tSpecify the maximum length of filenames\n");
|
||||
|
||||
+25
-23
@@ -38,9 +38,8 @@
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--------modutils module.h, lines 45-242
|
||||
@@ -71,7 +70,7 @@
|
||||
#ifndef MODUTILS_MODULE_H
|
||||
#define MODUTILS_MODULE_H 1
|
||||
|
||||
#ident "$Id: insmod.c,v 1.9 2000/06/19 19:53:30 andersen Exp $"
|
||||
#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $"
|
||||
|
||||
/* This file contains the structures used by the 2.0 and 2.1 kernels.
|
||||
We do not use the kernel headers directly because we do not wish
|
||||
@@ -277,7 +276,7 @@ int delete_module(const char *);
|
||||
#ifndef MODUTILS_OBJ_H
|
||||
#define MODUTILS_OBJ_H 1
|
||||
|
||||
#ident "$Id: insmod.c,v 1.9 2000/06/19 19:53:30 andersen Exp $"
|
||||
#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $"
|
||||
|
||||
/* The relocatable object is manipulated using elfin types. */
|
||||
|
||||
@@ -530,6 +529,9 @@ _syscall2(int, new_sys_init_module, const char *, name,
|
||||
_syscall5(int, old_sys_init_module, const char *, name, char *, code,
|
||||
unsigned, codesize, struct old_mod_routines *, routines,
|
||||
struct old_symbol_table *, symtab)
|
||||
#ifndef __NR_query_module
|
||||
#define __NR_query_module 167
|
||||
#endif
|
||||
_syscall5(int, query_module, const char *, name, int, which,
|
||||
void *, buf, size_t, bufsize, size_t*, ret);
|
||||
#ifndef BB_RMMOD
|
||||
@@ -1189,8 +1191,10 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
int *loc;
|
||||
|
||||
p = *argv;
|
||||
if ((q = strchr(p, '=')) == NULL)
|
||||
if ((q = strchr(p, '=')) == NULL) {
|
||||
argc--;
|
||||
continue;
|
||||
}
|
||||
*q++ = '\0';
|
||||
|
||||
sym = obj_find_symbol(f, p);
|
||||
@@ -1210,9 +1214,7 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
str = alloca(strlen(q));
|
||||
for (r = str, q++; *q != '"'; ++q, ++r) {
|
||||
if (*q == '\0') {
|
||||
fprintf(stderr,
|
||||
"improperly terminated string argument for %s\n",
|
||||
p);
|
||||
fprintf(stderr, "improperly terminated string argument for %s\n", p);
|
||||
return 0;
|
||||
} else if (*q == '\\')
|
||||
switch (*++q) {
|
||||
@@ -1341,7 +1343,7 @@ static int old_get_kernel_symbols(void)
|
||||
|
||||
nks = get_kernel_syms(NULL);
|
||||
if (nks < 0) {
|
||||
perror("get_kernel_syms: %m");
|
||||
errorMsg("get_kernel_syms: %s: %s", m_name, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1522,7 +1524,7 @@ old_init_module(const char *m_name, struct obj_file *f,
|
||||
m_size | (flag_autoclean ? OLD_MOD_AUTOCLEAN
|
||||
: 0), &routines, symtab);
|
||||
if (ret)
|
||||
perror("init_module: %m");
|
||||
errorMsg("init_module: %s: %s", m_name, strerror(errno));
|
||||
|
||||
free(image);
|
||||
free(symtab);
|
||||
@@ -1552,8 +1554,10 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
||||
int min, max, n;
|
||||
|
||||
p = *argv;
|
||||
if ((q = strchr(p, '=')) == NULL)
|
||||
if ((q = strchr(p, '=')) == NULL) {
|
||||
argc--;
|
||||
continue;
|
||||
}
|
||||
|
||||
key = alloca(q - p + 6);
|
||||
memcpy(key, "parm_", 5);
|
||||
@@ -1837,7 +1841,7 @@ static int new_get_kernel_symbols(void)
|
||||
module_names = xrealloc(module_names, bufsize = ret);
|
||||
goto retry_modules_load;
|
||||
}
|
||||
perror("QM_MODULES: %m\n");
|
||||
errorMsg("QM_MODULES: %s", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1856,7 +1860,7 @@ static int new_get_kernel_symbols(void)
|
||||
/* The module was removed out from underneath us. */
|
||||
continue;
|
||||
}
|
||||
perror("query_module: QM_INFO: %m");
|
||||
errorMsg("query_module: QM_INFO: %s: %s", mn, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1871,7 +1875,7 @@ static int new_get_kernel_symbols(void)
|
||||
/* The module was removed out from underneath us. */
|
||||
continue;
|
||||
default:
|
||||
perror("query_module: QM_SYMBOLS: %m");
|
||||
errorMsg("query_module: QM_SYMBOLS: %s: %s", mn, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1896,7 +1900,7 @@ static int new_get_kernel_symbols(void)
|
||||
syms = xrealloc(syms, bufsize = ret);
|
||||
goto retry_kern_sym_load;
|
||||
}
|
||||
perror("kernel: QM_SYMBOLS: %m");
|
||||
errorMsg("kernel: QM_SYMBOLS: %s", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
nksyms = nsyms = ret;
|
||||
@@ -2077,7 +2081,7 @@ new_init_module(const char *m_name, struct obj_file *f,
|
||||
|
||||
ret = new_sys_init_module(m_name, (struct new_module *) image);
|
||||
if (ret)
|
||||
perror("init_module: %m");
|
||||
errorMsg("init_module: %s: %s", m_name, strerror(errno));
|
||||
|
||||
free(image);
|
||||
|
||||
@@ -2457,7 +2461,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (fread(&f->header, sizeof(f->header), 1, fp) != 1) {
|
||||
perror("error reading ELF header: %m");
|
||||
errorMsg("error reading ELF header: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2496,7 +2500,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
|
||||
fseek(fp, f->header.e_shoff, SEEK_SET);
|
||||
if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) {
|
||||
perror("error reading ELF section headers: %m");
|
||||
errorMsg("error reading ELF section headers: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2526,8 +2530,7 @@ struct obj_file *obj_load(FILE * fp)
|
||||
sec->contents = xmalloc(sec->header.sh_size);
|
||||
fseek(fp, sec->header.sh_offset, SEEK_SET);
|
||||
if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
|
||||
fprintf(stderr,
|
||||
"error reading ELF section data: %m\n");
|
||||
errorMsg("error reading ELF section data: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -2724,8 +2727,7 @@ extern int insmod_main( int argc, char **argv)
|
||||
if (m_filename[0] == '\0'
|
||||
|| ((fp = fopen(m_filename, "r")) == NULL))
|
||||
{
|
||||
perror("No module by that name found in " _PATH_MODULES
|
||||
"\n");
|
||||
errorMsg("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
@@ -2857,7 +2859,7 @@ extern int insmod_main( int argc, char **argv)
|
||||
m_size);
|
||||
goto out;
|
||||
default:
|
||||
perror("create_module: %m");
|
||||
errorMsg("create_module: %s: %s", m_name, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#define __LIBRARY__
|
||||
#include <asm/unistd.h>
|
||||
/* #include <sys/syscall.h> */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,25 +43,41 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/mount.h>
|
||||
#include <ctype.h>
|
||||
#if defined BB_FEATURE_USE_DEVPS_PATCH
|
||||
#include <linux/devmtab.h>
|
||||
#endif
|
||||
#ifndef MS_RDONLY
|
||||
#include <linux/fs.h>
|
||||
#include <linux/devmtab.h> /* For Erik's nifty devmtab device driver */
|
||||
#endif
|
||||
|
||||
|
||||
#define MS_MGC_VAL 0xc0ed0000 /* Magic number indicatng "new" flags */
|
||||
#define MS_RDONLY 1 /* Mount read-only */
|
||||
#define MS_NOSUID 2 /* Ignore suid and sgid bits */
|
||||
#define MS_NODEV 4 /* Disallow access to device special files */
|
||||
#define MS_NOEXEC 8 /* Disallow program execution */
|
||||
#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
|
||||
#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
|
||||
#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
|
||||
#define S_QUOTA 128 /* Quota initialized for file/directory/symlink */
|
||||
#define S_APPEND 256 /* Append-only file */
|
||||
#define S_IMMUTABLE 512 /* Immutable file */
|
||||
#define MS_NOATIME 1024 /* Do not update access times. */
|
||||
#define MS_NODIRATIME 2048 /* Do not update directory access times */
|
||||
|
||||
|
||||
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/loop.h>
|
||||
|
||||
|
||||
static int use_loop = FALSE;
|
||||
#endif
|
||||
|
||||
extern int mount (__const char *__special_file, __const char *__dir,
|
||||
__const char *__fstype, unsigned long int __rwflag,
|
||||
__const void *__data);
|
||||
extern int umount (__const char *__special_file);
|
||||
extern int umount2 (__const char *__special_file, int __flags);
|
||||
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static const char mount_usage[] =
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* $Id: ping.c,v 1.17 2000/06/19 18:51:53 andersen Exp $
|
||||
* $Id: ping.c,v 1.19 2000/07/09 06:59:58 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
/* It turns out that libc5 doesn't have proper icmp support
|
||||
* built into it header files, so we have to supplement it */
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
typedef unsigned int socklen_t;
|
||||
|
||||
#define ICMP_MINLEN 8 /* abs minimum */
|
||||
@@ -173,7 +173,7 @@ static int in_cksum(unsigned short *buf, int sz)
|
||||
}
|
||||
|
||||
/* simple version */
|
||||
#ifdef BB_SIMPLE_PING
|
||||
#ifdef BB_FEATURE_SIMPLE_PING
|
||||
static const char *ping_usage = "ping host\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSend ICMP ECHO_REQUEST packets to network hosts\n"
|
||||
@@ -265,7 +265,7 @@ extern int ping_main(int argc, char **argv)
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
#else /* ! BB_SIMPLE_PING */
|
||||
#else /* ! BB_FEATURE_SIMPLE_PING */
|
||||
/* full(er) version */
|
||||
static const char *ping_usage = "ping [OPTION]... host\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
@@ -561,7 +561,7 @@ extern int ping_main(int argc, char **argv)
|
||||
ping(*argv);
|
||||
return(TRUE);
|
||||
}
|
||||
#endif /* ! BB_SIMPLE_PING */
|
||||
#endif /* ! BB_FEATURE_SIMPLE_PING */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
|
||||
+444
-745
File diff suppressed because it is too large.
Load diff
+157
-153
@@ -9,6 +9,11 @@
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
@@ -45,19 +50,33 @@
|
||||
/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
|
||||
#ifndef _rpcsvc_mount_h
|
||||
#define _rpcsvc_mount_h
|
||||
#include <asm/types.h>
|
||||
#define MOUNTPORT 635
|
||||
#define MNTPATHLEN 1024
|
||||
#define MNTNAMLEN 255
|
||||
#define FHSIZE 32
|
||||
#define FHSIZE3 64
|
||||
|
||||
typedef char fhandle[FHSIZE];
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_fhandle(XDR *, fhandle);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_fhandle(XDR *, fhandle);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_fhandle();
|
||||
#endif /* Old Style C */
|
||||
|
||||
typedef struct {
|
||||
u_int fhandle3_len;
|
||||
char *fhandle3_val;
|
||||
} fhandle3;
|
||||
|
||||
enum mountstat3 {
|
||||
MNT_OK = 0,
|
||||
MNT3ERR_PERM = 1,
|
||||
MNT3ERR_NOENT = 2,
|
||||
MNT3ERR_IO = 5,
|
||||
MNT3ERR_ACCES = 13,
|
||||
MNT3ERR_NOTDIR = 20,
|
||||
MNT3ERR_INVAL = 22,
|
||||
MNT3ERR_NAMETOOLONG = 63,
|
||||
MNT3ERR_NOTSUPP = 10004,
|
||||
MNT3ERR_SERVERFAULT = 10006,
|
||||
};
|
||||
typedef enum mountstat3 mountstat3;
|
||||
|
||||
struct fhstatus {
|
||||
u_int fhs_status;
|
||||
@@ -66,44 +85,29 @@ struct fhstatus {
|
||||
} fhstatus_u;
|
||||
};
|
||||
typedef struct fhstatus fhstatus;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_fhstatus(XDR *, fhstatus*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_fhstatus(XDR *, fhstatus*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_fhstatus();
|
||||
#endif /* Old Style C */
|
||||
|
||||
struct mountres3_ok {
|
||||
fhandle3 fhandle;
|
||||
struct {
|
||||
u_int auth_flavours_len;
|
||||
int *auth_flavours_val;
|
||||
} auth_flavours;
|
||||
};
|
||||
typedef struct mountres3_ok mountres3_ok;
|
||||
|
||||
struct mountres3 {
|
||||
mountstat3 fhs_status;
|
||||
union {
|
||||
mountres3_ok mountinfo;
|
||||
} mountres3_u;
|
||||
};
|
||||
typedef struct mountres3 mountres3;
|
||||
|
||||
typedef char *dirpath;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_dirpath(XDR *, dirpath*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_dirpath(XDR *, dirpath*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_dirpath();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef char *name;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_name(XDR *, name*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_name(XDR *, name*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_name();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct mountbody *mountlist;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_mountlist(XDR *, mountlist*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_mountlist(XDR *, mountlist*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_mountlist();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct mountbody {
|
||||
name ml_hostname;
|
||||
@@ -111,48 +115,16 @@ struct mountbody {
|
||||
mountlist ml_next;
|
||||
};
|
||||
typedef struct mountbody mountbody;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_mountbody(XDR *, mountbody*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_mountbody(XDR *, mountbody*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_mountbody();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct groupnode *groups;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_groups(XDR *, groups*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_groups(XDR *, groups*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_groups();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct groupnode {
|
||||
name gr_name;
|
||||
groups gr_next;
|
||||
};
|
||||
typedef struct groupnode groupnode;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_groupnode(XDR *, groupnode*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_groupnode(XDR *, groupnode*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_groupnode();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct exportnode *exports;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_exports(XDR *, exports*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_exports(XDR *, exports*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_exports();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct exportnode {
|
||||
dirpath ex_dir;
|
||||
@@ -160,14 +132,6 @@ struct exportnode {
|
||||
exports ex_next;
|
||||
};
|
||||
typedef struct exportnode exportnode;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_exportnode(XDR *, exportnode*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_exportnode(XDR *, exportnode*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_exportnode();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct ppathcnf {
|
||||
int pc_link_max;
|
||||
@@ -181,110 +145,62 @@ struct ppathcnf {
|
||||
short pc_mask[2];
|
||||
};
|
||||
typedef struct ppathcnf ppathcnf;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_ppathcnf(XDR *, ppathcnf*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_ppathcnf(XDR *, ppathcnf*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_ppathcnf();
|
||||
#endif /* Old Style C */
|
||||
|
||||
#endif /*!_rpcsvc_mount_h*/
|
||||
|
||||
#define MOUNTPROG ((u_long)100005)
|
||||
#define MOUNTVERS ((u_long)1)
|
||||
#define MOUNTPROG 100005
|
||||
#define MOUNTVERS 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
extern "C" void * mountproc_null_1(void *, CLIENT *);
|
||||
extern "C" void * mountproc_null_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
extern "C" fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
|
||||
extern "C" fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
extern "C" mountlist * mountproc_dump_1(void *, CLIENT *);
|
||||
extern "C" mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
extern "C" void * mountproc_umnt_1(dirpath *, CLIENT *);
|
||||
extern "C" void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
extern "C" void * mountproc_umntall_1(void *, CLIENT *);
|
||||
extern "C" void * mountproc_umntall_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
extern "C" exports * mountproc_export_1(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_export_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
extern "C" exports * mountproc_exportall_1(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_exportall_1_svc(void *, struct svc_req *);
|
||||
|
||||
#elif __STDC__
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define MOUNTPROC_NULL 0
|
||||
extern void * mountproc_null_1(void *, CLIENT *);
|
||||
extern void * mountproc_null_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
#define MOUNTPROC_MNT 1
|
||||
extern fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
|
||||
extern fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
#define MOUNTPROC_DUMP 2
|
||||
extern mountlist * mountproc_dump_1(void *, CLIENT *);
|
||||
extern mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
#define MOUNTPROC_UMNT 3
|
||||
extern void * mountproc_umnt_1(dirpath *, CLIENT *);
|
||||
extern void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
#define MOUNTPROC_UMNTALL 4
|
||||
extern void * mountproc_umntall_1(void *, CLIENT *);
|
||||
extern void * mountproc_umntall_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
#define MOUNTPROC_EXPORT 5
|
||||
extern exports * mountproc_export_1(void *, CLIENT *);
|
||||
extern exports * mountproc_export_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
#define MOUNTPROC_EXPORTALL 6
|
||||
extern exports * mountproc_exportall_1(void *, CLIENT *);
|
||||
extern exports * mountproc_exportall_1_svc(void *, struct svc_req *);
|
||||
extern int mountprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* Old Style C */
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
#else /* K&R C */
|
||||
#define MOUNTPROC_NULL 0
|
||||
extern void * mountproc_null_1();
|
||||
extern void * mountproc_null_1_svc();
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
#define MOUNTPROC_MNT 1
|
||||
extern fhstatus * mountproc_mnt_1();
|
||||
extern fhstatus * mountproc_mnt_1_svc();
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
#define MOUNTPROC_DUMP 2
|
||||
extern mountlist * mountproc_dump_1();
|
||||
extern mountlist * mountproc_dump_1_svc();
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
#define MOUNTPROC_UMNT 3
|
||||
extern void * mountproc_umnt_1();
|
||||
extern void * mountproc_umnt_1_svc();
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
#define MOUNTPROC_UMNTALL 4
|
||||
extern void * mountproc_umntall_1();
|
||||
extern void * mountproc_umntall_1_svc();
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
#define MOUNTPROC_EXPORT 5
|
||||
extern exports * mountproc_export_1();
|
||||
extern exports * mountproc_export_1_svc();
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
#define MOUNTPROC_EXPORTALL 6
|
||||
extern exports * mountproc_exportall_1();
|
||||
extern exports * mountproc_exportall_1_svc();
|
||||
#endif /* Old Style C */
|
||||
#define MOUNTVERS_POSIX ((u_long)2)
|
||||
extern int mountprog_1_freeresult ();
|
||||
#endif /* K&R C */
|
||||
#define MOUNTVERS_POSIX 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" void * mountproc_null_2(void *, CLIENT *);
|
||||
extern "C" void * mountproc_null_2_svc(void *, struct svc_req *);
|
||||
extern "C" fhstatus * mountproc_mnt_2(dirpath *, CLIENT *);
|
||||
extern "C" fhstatus * mountproc_mnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern "C" mountlist * mountproc_dump_2(void *, CLIENT *);
|
||||
extern "C" mountlist * mountproc_dump_2_svc(void *, struct svc_req *);
|
||||
extern "C" void * mountproc_umnt_2(dirpath *, CLIENT *);
|
||||
extern "C" void * mountproc_umnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern "C" void * mountproc_umntall_2(void *, CLIENT *);
|
||||
extern "C" void * mountproc_umntall_2_svc(void *, struct svc_req *);
|
||||
extern "C" exports * mountproc_export_2(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_export_2_svc(void *, struct svc_req *);
|
||||
extern "C" exports * mountproc_exportall_2(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_exportall_2_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
extern "C" ppathcnf * mountproc_pathconf_2(dirpath *, CLIENT *);
|
||||
extern "C" ppathcnf * mountproc_pathconf_2_svc(dirpath *, struct svc_req *);
|
||||
|
||||
#elif __STDC__
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern void * mountproc_null_2(void *, CLIENT *);
|
||||
extern void * mountproc_null_2_svc(void *, struct svc_req *);
|
||||
extern fhstatus * mountproc_mnt_2(dirpath *, CLIENT *);
|
||||
@@ -299,11 +215,12 @@ extern exports * mountproc_export_2(void *, CLIENT *);
|
||||
extern exports * mountproc_export_2_svc(void *, struct svc_req *);
|
||||
extern exports * mountproc_exportall_2(void *, CLIENT *);
|
||||
extern exports * mountproc_exportall_2_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
#define MOUNTPROC_PATHCONF 7
|
||||
extern ppathcnf * mountproc_pathconf_2(dirpath *, CLIENT *);
|
||||
extern ppathcnf * mountproc_pathconf_2_svc(dirpath *, struct svc_req *);
|
||||
extern int mountprog_2_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* Old Style C */
|
||||
#else /* K&R C */
|
||||
extern void * mountproc_null_2();
|
||||
extern void * mountproc_null_2_svc();
|
||||
extern fhstatus * mountproc_mnt_2();
|
||||
@@ -318,9 +235,96 @@ extern exports * mountproc_export_2();
|
||||
extern exports * mountproc_export_2_svc();
|
||||
extern exports * mountproc_exportall_2();
|
||||
extern exports * mountproc_exportall_2_svc();
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
#define MOUNTPROC_PATHCONF 7
|
||||
extern ppathcnf * mountproc_pathconf_2();
|
||||
extern ppathcnf * mountproc_pathconf_2_svc();
|
||||
#endif /* Old Style C */
|
||||
extern int mountprog_2_freeresult ();
|
||||
#endif /* K&R C */
|
||||
#define MOUNT_V3 3
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define MOUNTPROC3_NULL 0
|
||||
extern void * mountproc3_null_3(void *, CLIENT *);
|
||||
extern void * mountproc3_null_3_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC3_MNT 1
|
||||
extern mountres3 * mountproc3_mnt_3(dirpath *, CLIENT *);
|
||||
extern mountres3 * mountproc3_mnt_3_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC3_DUMP 2
|
||||
extern mountlist * mountproc3_dump_3(void *, CLIENT *);
|
||||
extern mountlist * mountproc3_dump_3_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC3_UMNT 3
|
||||
extern void * mountproc3_umnt_3(dirpath *, CLIENT *);
|
||||
extern void * mountproc3_umnt_3_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC3_UMNTALL 4
|
||||
extern void * mountproc3_umntall_3(void *, CLIENT *);
|
||||
extern void * mountproc3_umntall_3_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC3_EXPORT 5
|
||||
extern exports * mountproc3_export_3(void *, CLIENT *);
|
||||
extern exports * mountproc3_export_3_svc(void *, struct svc_req *);
|
||||
extern int mountprog_3_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
|
||||
|
||||
#else /* K&R C */
|
||||
#define MOUNTPROC3_NULL 0
|
||||
extern void * mountproc3_null_3();
|
||||
extern void * mountproc3_null_3_svc();
|
||||
#define MOUNTPROC3_MNT 1
|
||||
extern mountres3 * mountproc3_mnt_3();
|
||||
extern mountres3 * mountproc3_mnt_3_svc();
|
||||
#define MOUNTPROC3_DUMP 2
|
||||
extern mountlist * mountproc3_dump_3();
|
||||
extern mountlist * mountproc3_dump_3_svc();
|
||||
#define MOUNTPROC3_UMNT 3
|
||||
extern void * mountproc3_umnt_3();
|
||||
extern void * mountproc3_umnt_3_svc();
|
||||
#define MOUNTPROC3_UMNTALL 4
|
||||
extern void * mountproc3_umntall_3();
|
||||
extern void * mountproc3_umntall_3_svc();
|
||||
#define MOUNTPROC3_EXPORT 5
|
||||
extern exports * mountproc3_export_3();
|
||||
extern exports * mountproc3_export_3_svc();
|
||||
extern int mountprog_3_freeresult ();
|
||||
#endif /* K&R C */
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
extern bool_t xdr_fhandle (XDR *, fhandle);
|
||||
extern bool_t xdr_fhandle3 (XDR *, fhandle3*);
|
||||
extern bool_t xdr_mountstat3 (XDR *, mountstat3*);
|
||||
extern bool_t xdr_fhstatus (XDR *, fhstatus*);
|
||||
extern bool_t xdr_mountres3_ok (XDR *, mountres3_ok*);
|
||||
extern bool_t xdr_mountres3 (XDR *, mountres3*);
|
||||
extern bool_t xdr_dirpath (XDR *, dirpath*);
|
||||
extern bool_t xdr_name (XDR *, name*);
|
||||
extern bool_t xdr_mountlist (XDR *, mountlist*);
|
||||
extern bool_t xdr_mountbody (XDR *, mountbody*);
|
||||
extern bool_t xdr_groups (XDR *, groups*);
|
||||
extern bool_t xdr_groupnode (XDR *, groupnode*);
|
||||
extern bool_t xdr_exports (XDR *, exports*);
|
||||
extern bool_t xdr_exportnode (XDR *, exportnode*);
|
||||
extern bool_t xdr_ppathcnf (XDR *, ppathcnf*);
|
||||
|
||||
#else /* K&R C */
|
||||
extern bool_t xdr_fhandle ();
|
||||
extern bool_t xdr_fhandle3 ();
|
||||
extern bool_t xdr_mountstat3 ();
|
||||
extern bool_t xdr_fhstatus ();
|
||||
extern bool_t xdr_mountres3_ok ();
|
||||
extern bool_t xdr_mountres3 ();
|
||||
extern bool_t xdr_dirpath ();
|
||||
extern bool_t xdr_name ();
|
||||
extern bool_t xdr_mountlist ();
|
||||
extern bool_t xdr_mountbody ();
|
||||
extern bool_t xdr_groups ();
|
||||
extern bool_t xdr_groupnode ();
|
||||
extern bool_t xdr_exports ();
|
||||
extern bool_t xdr_exportnode ();
|
||||
extern bool_t xdr_ppathcnf ();
|
||||
|
||||
#endif /* K&R C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_NFSMOUNT_H_RPCGEN */
|
||||
@@ -1,6 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* $Id: ping.c,v 1.17 2000/06/19 18:51:53 andersen Exp $
|
||||
* $Id: ping.c,v 1.19 2000/07/09 06:59:58 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
/* It turns out that libc5 doesn't have proper icmp support
|
||||
* built into it header files, so we have to supplement it */
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
typedef unsigned int socklen_t;
|
||||
|
||||
#define ICMP_MINLEN 8 /* abs minimum */
|
||||
@@ -173,7 +173,7 @@ static int in_cksum(unsigned short *buf, int sz)
|
||||
}
|
||||
|
||||
/* simple version */
|
||||
#ifdef BB_SIMPLE_PING
|
||||
#ifdef BB_FEATURE_SIMPLE_PING
|
||||
static const char *ping_usage = "ping host\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSend ICMP ECHO_REQUEST packets to network hosts\n"
|
||||
@@ -265,7 +265,7 @@ extern int ping_main(int argc, char **argv)
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
#else /* ! BB_SIMPLE_PING */
|
||||
#else /* ! BB_FEATURE_SIMPLE_PING */
|
||||
/* full(er) version */
|
||||
static const char *ping_usage = "ping [OPTION]... host\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
@@ -561,7 +561,7 @@ extern int ping_main(int argc, char **argv)
|
||||
ping(*argv);
|
||||
return(TRUE);
|
||||
}
|
||||
#endif /* ! BB_SIMPLE_PING */
|
||||
#endif /* ! BB_FEATURE_SIMPLE_PING */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
|
||||
+27
-9
@@ -23,20 +23,36 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#define DIVISOR 1024
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
info.totalram/=DIVISOR;
|
||||
info.freeram/=DIVISOR;
|
||||
info.totalswap/=DIVISOR;
|
||||
info.freeswap/=DIVISOR;
|
||||
info.sharedram/=DIVISOR;
|
||||
info.bufferram/=DIVISOR;
|
||||
|
||||
/* Kernels prior to 2.4.x will return info.mem_unit==0. Kernels after
|
||||
* 2.4.x actually fill this value in */
|
||||
if (info.mem_unit==0) {
|
||||
/* Looks like we have a kernel prior to Linux 2.4.x */
|
||||
info.mem_unit=1024;
|
||||
info.totalram/=info.mem_unit;
|
||||
info.freeram/=info.mem_unit;
|
||||
info.totalswap/=info.mem_unit;
|
||||
info.freeswap/=info.mem_unit;
|
||||
info.sharedram/=info.mem_unit;
|
||||
info.bufferram/=info.mem_unit;
|
||||
} else {
|
||||
/* Bah. Linux 2.4.x completely changed sysinfo. This can in theory
|
||||
overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap
|
||||
on an embedded system? */
|
||||
info.mem_unit/=1024;
|
||||
info.totalram*=info.mem_unit;
|
||||
info.freeram*=info.mem_unit;
|
||||
info.totalswap*=info.mem_unit;
|
||||
info.freeswap*=info.mem_unit;
|
||||
info.sharedram*=info.mem_unit;
|
||||
info.bufferram*=info.mem_unit;
|
||||
}
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("free\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
@@ -61,3 +77,5 @@ extern int free_main(int argc, char **argv)
|
||||
info.freeram+info.freeswap);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
+32
-48
@@ -58,76 +58,60 @@ struct signal_name {
|
||||
};
|
||||
|
||||
const struct signal_name signames[] = {
|
||||
/* Everything, order not important */
|
||||
{"HUP", SIGHUP},
|
||||
{"INT", SIGINT},
|
||||
{"QUIT", SIGQUIT},
|
||||
{"ILL", SIGILL},
|
||||
{"TRAP", SIGTRAP},
|
||||
{"ABRT", SIGABRT},
|
||||
#ifndef __alpha__
|
||||
{"IOT", SIGIOT},
|
||||
#endif
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"EMT", SIGEMT},
|
||||
#else
|
||||
{"BUS", SIGBUS},
|
||||
#endif
|
||||
{"FPE", SIGFPE},
|
||||
{"KILL", SIGKILL},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"BUS", SIGBUS},
|
||||
#else
|
||||
{"USR1", SIGUSR1},
|
||||
#endif
|
||||
{"SEGV", SIGSEGV},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"SYS", SIGSYS},
|
||||
#else
|
||||
{"USR2", SIGUSR2},
|
||||
#endif
|
||||
{"PIPE", SIGPIPE},
|
||||
{"ALRM", SIGALRM},
|
||||
{"TERM", SIGTERM},
|
||||
#if defined(__sparc__) || defined(__alpha__)
|
||||
{"URG", SIGURG},
|
||||
{"STOP", SIGSTOP},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CONT", SIGCONT},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"TTIN", SIGTTIN},
|
||||
{"TTOU", SIGTTOU},
|
||||
{"IO", SIGIO},
|
||||
# ifndef __alpha__
|
||||
{"POLL", SIGIO},
|
||||
# endif
|
||||
{"XCPU", SIGXCPU},
|
||||
{"XFSZ", SIGXFSZ},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
{"PROF", SIGPROF},
|
||||
{"WINCH", SIGWINCH},
|
||||
# ifdef __alpha__
|
||||
{"INFO", SIGINFO},
|
||||
# else
|
||||
{"LOST", SIGLOST},
|
||||
# endif
|
||||
{"BUS", SIGBUS},
|
||||
{"USR1", SIGUSR1},
|
||||
{"USR2", SIGUSR2},
|
||||
#else
|
||||
{"STKFLT", SIGSTKFLT},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"CONT", SIGCONT},
|
||||
{"STOP", SIGSTOP},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CONT", SIGCONT},
|
||||
{"TTIN", SIGTTIN},
|
||||
{"TTOU", SIGTTOU},
|
||||
{"URG", SIGURG},
|
||||
{"IO", SIGIO},
|
||||
{"TSTP", SIGTSTP},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"XCPU", SIGXCPU},
|
||||
{"XFSZ", SIGXFSZ},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
{"PROF", SIGPROF},
|
||||
{"WINCH", SIGWINCH},
|
||||
{"IO", SIGIO},
|
||||
{"URG", SIGURG},
|
||||
{"VTALRM", SIGVTALRM},
|
||||
#ifndef __alpha__
|
||||
/* everything except alpha */
|
||||
{"IOT", SIGIOT},
|
||||
{"POLL", SIGPOLL},
|
||||
#endif
|
||||
#if defined(__sparc__) || defined(__alpha__) || defined(__mips__)
|
||||
/* everthing except intel */
|
||||
{"EMT", SIGEMT},
|
||||
{"SYS", SIGSYS},
|
||||
# ifdef __alpha__
|
||||
/* alpha only */
|
||||
{"LOST", SIGLOST},
|
||||
#endif
|
||||
#ifdef __sparc__
|
||||
/* space only */
|
||||
{"INFO", SIGINFO},
|
||||
#endif
|
||||
#ifdef __mips__
|
||||
/* mips only */
|
||||
{"CLD", SIGCLD},
|
||||
{"PWR", SIGPWR},
|
||||
#endif
|
||||
#else
|
||||
/* intel only */
|
||||
{"STKFLT", SIGSTKFLT},
|
||||
{"PWR", SIGPWR},
|
||||
{"UNUSED", SIGUNUSED},
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ extern int ps_main(int argc, char **argv)
|
||||
* this one uses the nifty new devps kernel device.
|
||||
*/
|
||||
|
||||
#include <linux/devps.h>
|
||||
#include <linux/devps.h> /* For Erik's nifty devps device driver */
|
||||
|
||||
|
||||
extern int ps_main(int argc, char **argv)
|
||||
|
||||
+2
-1
@@ -31,13 +31,14 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define FSHIFT 16 /* nr of bits of precision */
|
||||
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
|
||||
#define LOAD_INT(x) ((x) >> FSHIFT)
|
||||
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
|
||||
|
||||
|
||||
extern int uptime_main(int argc, char **argv)
|
||||
{
|
||||
int updays, uphours, upminutes;
|
||||
|
||||
@@ -203,7 +203,7 @@ extern int ps_main(int argc, char **argv)
|
||||
* this one uses the nifty new devps kernel device.
|
||||
*/
|
||||
|
||||
#include <linux/devps.h>
|
||||
#include <linux/devps.h> /* For Erik's nifty devps device driver */
|
||||
|
||||
|
||||
extern int ps_main(int argc, char **argv)
|
||||
|
||||
@@ -1,774 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* regexp.c */
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#if ( defined BB_GREP || defined BB_SED)
|
||||
|
||||
/* This also tries to find a needle in a haystack, but uses
|
||||
* real regular expressions.... The fake regular expression
|
||||
* version of find_match lives in utility.c. Using this version
|
||||
* will add 3.9k to busybox...
|
||||
* -Erik Andersen
|
||||
*/
|
||||
extern int find_match(char *haystack, char *needle, int ignoreCase)
|
||||
{
|
||||
int status;
|
||||
struct regexp *re;
|
||||
|
||||
re = regcomp(needle);
|
||||
status = regexec(re, haystack, FALSE, ignoreCase);
|
||||
free(re);
|
||||
return (status);
|
||||
}
|
||||
|
||||
#if defined BB_SED
|
||||
/* This performs substitutions after a regexp match has been found.
|
||||
* The new string is returned. It is malloc'ed, and do must be freed. */
|
||||
extern int replace_match(char *haystack, char *needle, char *newNeedle,
|
||||
int ignoreCase)
|
||||
{
|
||||
int status;
|
||||
struct regexp *re;
|
||||
char *s, buf[BUF_SIZE], *d = buf;
|
||||
|
||||
re = regcomp(needle);
|
||||
status = regexec(re, haystack, FALSE, ignoreCase);
|
||||
if (status == TRUE) {
|
||||
s = haystack;
|
||||
|
||||
do {
|
||||
/* copy stuff from before the match */
|
||||
while (s < re->startp[0])
|
||||
*d++ = *s++;
|
||||
/* substitute for the matched part */
|
||||
regsub(re, newNeedle, d);
|
||||
s = re->endp[0];
|
||||
d += strlen(d);
|
||||
} while (regexec(re, s, FALSE, ignoreCase) == TRUE);
|
||||
/* copy stuff from after the match */
|
||||
while ((*d++ = *s++)) {
|
||||
}
|
||||
d[0] = '\0';
|
||||
strcpy(haystack, buf);
|
||||
}
|
||||
free(re);
|
||||
return (status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* code swiped from elvis-tiny 1.4 (a clone of vi) and adjusted to
|
||||
* suit the needs of busybox by Erik Andersen.
|
||||
*
|
||||
* From the README:
|
||||
* "Elvis is freely redistributable, in either source form or executable form.
|
||||
* There are no restrictions on how you may use it".
|
||||
* Elvis was written by Steve Kirkendall <kirkenda@cs.pdx.edu>
|
||||
*
|
||||
*
|
||||
* This file contains the code that compiles regular expressions and executes
|
||||
* them. It supports the same syntax and features as vi's regular expression
|
||||
* code. Specifically, the meta characters are:
|
||||
* ^ matches the beginning of a line
|
||||
* $ matches the end of a line
|
||||
* \< matches the beginning of a word
|
||||
* \> matches the end of a word
|
||||
* . matches any single character
|
||||
* [] matches any character in a character class
|
||||
* \( delimits the start of a subexpression
|
||||
* \) delimits the end of a subexpression
|
||||
* * repeats the preceding 0 or more times
|
||||
* NOTE: You cannot follow a \) with a *.
|
||||
*
|
||||
* The physical structure of a compiled RE is as follows:
|
||||
* - First, there is a one-byte value that says how many character classes
|
||||
* are used in this regular expression
|
||||
* - Next, each character class is stored as a bitmap that is 256 bits
|
||||
* (32 bytes) long.
|
||||
* - A mixture of literal characters and compiled meta characters follows.
|
||||
* This begins with M_BEGIN(0) and ends with M_END(0). All meta chars
|
||||
* are stored as a \n followed by a one-byte code, so they take up two
|
||||
* bytes apiece. Literal characters take up one byte apiece. \n can't
|
||||
* be used as a literal character.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static char *previous; /* the previous regexp, used when null regexp is given */
|
||||
|
||||
#if defined BB_SED
|
||||
static char *previous1; /* a copy of the text from the previous substitution for regsub() */
|
||||
#endif
|
||||
|
||||
|
||||
/* These are used to classify or recognize meta-characters */
|
||||
#define META '\0'
|
||||
#define BASE_META(m) ((m) - 256)
|
||||
#define INT_META(c) ((c) + 256)
|
||||
#define IS_META(m) ((m) >= 256)
|
||||
#define IS_CLASS(m) ((m) >= M_CLASS(0) && (m) <= M_CLASS(9))
|
||||
#define IS_START(m) ((m) >= M_START(0) && (m) <= M_START(9))
|
||||
#define IS_END(m) ((m) >= M_END(0) && (m) <= M_END(9))
|
||||
#define IS_CLOSURE(m) ((m) >= M_SPLAT && (m) <= M_QMARK)
|
||||
#define ADD_META(s,m) (*(s)++ = META, *(s)++ = BASE_META(m))
|
||||
#define GET_META(s) (*(s) == META ? INT_META(*++(s)) : *s)
|
||||
|
||||
/* These are the internal codes used for each type of meta-character */
|
||||
#define M_BEGLINE 256 /* internal code for ^ */
|
||||
#define M_ENDLINE 257 /* internal code for $ */
|
||||
#define M_BEGWORD 258 /* internal code for \< */
|
||||
#define M_ENDWORD 259 /* internal code for \> */
|
||||
#define M_ANY 260 /* internal code for . */
|
||||
#define M_SPLAT 261 /* internal code for * */
|
||||
#define M_PLUS 262 /* internal code for \+ */
|
||||
#define M_QMARK 263 /* internal code for \? */
|
||||
#define M_CLASS(n) (264+(n)) /* internal code for [] */
|
||||
#define M_START(n) (274+(n)) /* internal code for \( */
|
||||
#define M_END(n) (284+(n)) /* internal code for \) */
|
||||
|
||||
/* These are used during compilation */
|
||||
static int class_cnt; /* used to assign class IDs */
|
||||
static int start_cnt; /* used to assign start IDs */
|
||||
static int end_stk[NSUBEXP]; /* used to assign end IDs */
|
||||
static int end_sp;
|
||||
static char *retext; /* points to the text being compiled */
|
||||
|
||||
/* error-handling stuff */
|
||||
jmp_buf errorhandler;
|
||||
|
||||
#define FAIL(why) do {fprintf(stderr, why); longjmp(errorhandler, 1);} while (0)
|
||||
|
||||
|
||||
|
||||
|
||||
/* This function builds a bitmap for a particular class */
|
||||
/* text -- start of the class */
|
||||
/* bmap -- the bitmap */
|
||||
static char *makeclass(char *text, char *bmap)
|
||||
{
|
||||
int i;
|
||||
int complement = 0;
|
||||
|
||||
|
||||
/* zero the bitmap */
|
||||
for (i = 0; bmap && i < 32; i++) {
|
||||
bmap[i] = 0;
|
||||
}
|
||||
|
||||
/* see if we're going to complement this class */
|
||||
if (*text == '^') {
|
||||
text++;
|
||||
complement = 1;
|
||||
}
|
||||
|
||||
/* add in the characters */
|
||||
while (*text && *text != ']') {
|
||||
/* is this a span of characters? */
|
||||
if (text[1] == '-' && text[2]) {
|
||||
/* spans can't be backwards */
|
||||
if (text[0] > text[2]) {
|
||||
FAIL("Backwards span in []");
|
||||
}
|
||||
|
||||
/* add each character in the span to the bitmap */
|
||||
for (i = text[0]; bmap && i <= text[2]; i++) {
|
||||
bmap[i >> 3] |= (1 << (i & 7));
|
||||
}
|
||||
|
||||
/* move past this span */
|
||||
text += 3;
|
||||
} else {
|
||||
/* add this single character to the span */
|
||||
i = *text++;
|
||||
if (bmap) {
|
||||
bmap[i >> 3] |= (1 << (i & 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* make sure the closing ] is missing */
|
||||
if (*text++ != ']') {
|
||||
FAIL("] missing");
|
||||
}
|
||||
|
||||
/* if we're supposed to complement this class, then do so */
|
||||
if (complement && bmap) {
|
||||
for (i = 0; i < 32; i++) {
|
||||
bmap[i] = ~bmap[i];
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* This function gets the next character or meta character from a string.
|
||||
* The pointer is incremented by 1, or by 2 for \-quoted characters. For [],
|
||||
* a bitmap is generated via makeclass() (if re is given), and the
|
||||
* character-class text is skipped.
|
||||
*/
|
||||
static int gettoken(sptr, re)
|
||||
char **sptr;
|
||||
regexp *re;
|
||||
{
|
||||
int c;
|
||||
|
||||
c = **sptr;
|
||||
++*sptr;
|
||||
if (c == '\\') {
|
||||
c = **sptr;
|
||||
++*sptr;
|
||||
switch (c) {
|
||||
case '<':
|
||||
return M_BEGWORD;
|
||||
|
||||
case '>':
|
||||
return M_ENDWORD;
|
||||
|
||||
case '(':
|
||||
if (start_cnt >= NSUBEXP) {
|
||||
FAIL("Too many \\(s");
|
||||
}
|
||||
end_stk[end_sp++] = start_cnt;
|
||||
return M_START(start_cnt++);
|
||||
|
||||
case ')':
|
||||
if (end_sp <= 0) {
|
||||
FAIL("Mismatched \\)");
|
||||
}
|
||||
return M_END(end_stk[--end_sp]);
|
||||
|
||||
case '*':
|
||||
return M_SPLAT;
|
||||
|
||||
case '.':
|
||||
return M_ANY;
|
||||
|
||||
case '+':
|
||||
return M_PLUS;
|
||||
|
||||
case '?':
|
||||
return M_QMARK;
|
||||
|
||||
default:
|
||||
return c;
|
||||
}
|
||||
} else {
|
||||
switch (c) {
|
||||
case '^':
|
||||
if (*sptr == retext + 1) {
|
||||
return M_BEGLINE;
|
||||
}
|
||||
return c;
|
||||
|
||||
case '$':
|
||||
if (!**sptr) {
|
||||
return M_ENDLINE;
|
||||
}
|
||||
return c;
|
||||
|
||||
case '.':
|
||||
return M_ANY;
|
||||
|
||||
case '*':
|
||||
return M_SPLAT;
|
||||
|
||||
case '[':
|
||||
/* make sure we don't have too many classes */
|
||||
if (class_cnt >= 10) {
|
||||
FAIL("Too many []s");
|
||||
}
|
||||
|
||||
/* process the character list for this class */
|
||||
if (re) {
|
||||
/* generate the bitmap for this class */
|
||||
*sptr = makeclass(*sptr, re->program + 1 + 32 * class_cnt);
|
||||
} else {
|
||||
/* skip to end of the class */
|
||||
*sptr = makeclass(*sptr, (char *) 0);
|
||||
}
|
||||
return M_CLASS(class_cnt++);
|
||||
|
||||
default:
|
||||
return c;
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/}
|
||||
|
||||
|
||||
|
||||
|
||||
/* This function calculates the number of bytes that will be needed for a
|
||||
* compiled RE. Its argument is the uncompiled version. It is not clever
|
||||
* about catching syntax errors; that is done in a later pass.
|
||||
*/
|
||||
static unsigned calcsize(text)
|
||||
char *text;
|
||||
{
|
||||
unsigned size;
|
||||
int token;
|
||||
|
||||
retext = text;
|
||||
class_cnt = 0;
|
||||
start_cnt = 1;
|
||||
end_sp = 0;
|
||||
size = 5;
|
||||
while ((token = gettoken(&text, (regexp *) 0)) != 0) {
|
||||
if (IS_CLASS(token)) {
|
||||
size += 34;
|
||||
} else if (IS_META(token)) {
|
||||
size += 2;
|
||||
} else {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* This function checks for a match between a character and a token which is
|
||||
* known to represent a single character. It returns 0 if they match, or
|
||||
* 1 if they don't.
|
||||
*/
|
||||
static int match1(regexp * re, char ch, int token, int ignoreCase)
|
||||
{
|
||||
if (!ch) {
|
||||
/* the end of a line can't match any RE of width 1 */
|
||||
return 1;
|
||||
}
|
||||
if (token == M_ANY) {
|
||||
return 0;
|
||||
} else if (IS_CLASS(token)) {
|
||||
if (re->program[1 + 32 * (token - M_CLASS(0)) + (ch >> 3)] & (1 << (ch & 7)))
|
||||
return 0;
|
||||
}
|
||||
//fprintf(stderr, "match1: ch='%c' token='%c': ", ch, token);
|
||||
if (ch == token || (ignoreCase == TRUE && tolower(ch) == tolower(token))) {
|
||||
//fprintf(stderr, "match\n");
|
||||
return 0;
|
||||
}
|
||||
//fprintf(stderr, "no match\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* This function checks characters up to and including the next closure, at
|
||||
* which point it does a recursive call to check the rest of it. This function
|
||||
* returns 0 if everything matches, or 1 if something doesn't match.
|
||||
*/
|
||||
/* re -- the regular expression */
|
||||
/* str -- the string */
|
||||
/* prog -- a portion of re->program, an compiled RE */
|
||||
/* here -- a portion of str, the string to compare it to */
|
||||
static int match(regexp * re, char *str, char *prog, char *here,
|
||||
int ignoreCase)
|
||||
{
|
||||
int token;
|
||||
int nmatched;
|
||||
int closure;
|
||||
|
||||
for (token = GET_META(prog); !IS_CLOSURE(token);
|
||||
prog++, token = GET_META(prog)) {
|
||||
switch (token) {
|
||||
/*case M_BEGLINE: can't happen; re->bol is used instead */
|
||||
case M_ENDLINE:
|
||||
if (*here)
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case M_BEGWORD:
|
||||
if (here != str &&
|
||||
(here[-1] == '_' ||
|
||||
(isascii(here[-1]) && isalnum(here[-1])))) return 1;
|
||||
break;
|
||||
|
||||
case M_ENDWORD:
|
||||
if ((here[0] == '_' || isascii(here[0])) && isalnum(here[0]))
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case M_START(0):
|
||||
case M_START(1):
|
||||
case M_START(2):
|
||||
case M_START(3):
|
||||
case M_START(4):
|
||||
case M_START(5):
|
||||
case M_START(6):
|
||||
case M_START(7):
|
||||
case M_START(8):
|
||||
case M_START(9):
|
||||
re->startp[token - M_START(0)] = (char *) here;
|
||||
break;
|
||||
|
||||
case M_END(0):
|
||||
case M_END(1):
|
||||
case M_END(2):
|
||||
case M_END(3):
|
||||
case M_END(4):
|
||||
case M_END(5):
|
||||
case M_END(6):
|
||||
case M_END(7):
|
||||
case M_END(8):
|
||||
case M_END(9):
|
||||
re->endp[token - M_END(0)] = (char *) here;
|
||||
if (token == M_END(0)) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* literal, M_CLASS(n), or M_ANY */
|
||||
if (match1(re, *here, token, ignoreCase) != 0)
|
||||
return 1;
|
||||
here++;
|
||||
}
|
||||
}
|
||||
|
||||
/* C L O S U R E */
|
||||
|
||||
/* step 1: see what we have to match against, and move "prog" to point
|
||||
* the the remainder of the compiled RE.
|
||||
*/
|
||||
closure = token;
|
||||
prog++, token = GET_META(prog);
|
||||
prog++;
|
||||
|
||||
/* step 2: see how many times we can match that token against the string */
|
||||
for (nmatched = 0;
|
||||
(closure != M_QMARK || nmatched < 1) && *here
|
||||
&& match1(re, *here, token, ignoreCase) == 0; nmatched++, here++) {
|
||||
}
|
||||
|
||||
/* step 3: try to match the remainder, and back off if it doesn't */
|
||||
while (nmatched >= 0 && match(re, str, prog, here, ignoreCase) != 0) {
|
||||
nmatched--;
|
||||
here--;
|
||||
}
|
||||
|
||||
/* so how did it work out? */
|
||||
if (nmatched >= ((closure == M_PLUS) ? 1 : 0))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* This function compiles a regexp. */
|
||||
extern regexp *regcomp(char *text)
|
||||
{
|
||||
int needfirst;
|
||||
unsigned size;
|
||||
int token;
|
||||
int peek;
|
||||
char *build;
|
||||
regexp *re;
|
||||
|
||||
|
||||
/* prepare for error handling */
|
||||
re = (regexp *) 0;
|
||||
if (setjmp(errorhandler)) {
|
||||
if (re) {
|
||||
free(re);
|
||||
}
|
||||
return (regexp *) 0;
|
||||
}
|
||||
|
||||
/* if an empty regexp string was given, use the previous one */
|
||||
if (*text == 0) {
|
||||
if (!previous) {
|
||||
FAIL("No previous RE");
|
||||
}
|
||||
text = previous;
|
||||
} else { /* non-empty regexp given, so remember it */
|
||||
|
||||
if (previous)
|
||||
free(previous);
|
||||
previous = (char *) malloc((unsigned) (strlen(text) + 1));
|
||||
if (previous)
|
||||
strcpy(previous, text);
|
||||
}
|
||||
|
||||
/* allocate memory */
|
||||
class_cnt = 0;
|
||||
start_cnt = 1;
|
||||
end_sp = 0;
|
||||
retext = text;
|
||||
size = calcsize(text) + sizeof(regexp);
|
||||
re = (regexp *) malloc((unsigned) size);
|
||||
|
||||
if (!re) {
|
||||
FAIL("Not enough memory for this RE");
|
||||
}
|
||||
|
||||
/* compile it */
|
||||
build = &re->program[1 + 32 * class_cnt];
|
||||
re->program[0] = class_cnt;
|
||||
for (token = 0; token < NSUBEXP; token++) {
|
||||
re->startp[token] = re->endp[token] = (char *) 0;
|
||||
}
|
||||
re->first = 0;
|
||||
re->bol = 0;
|
||||
re->minlen = 0;
|
||||
needfirst = 1;
|
||||
class_cnt = 0;
|
||||
start_cnt = 1;
|
||||
end_sp = 0;
|
||||
retext = text;
|
||||
for (token = M_START(0), peek = gettoken(&text, re);
|
||||
token; token = peek, peek = gettoken(&text, re)) {
|
||||
|
||||
/* special processing for the closure operator */
|
||||
if (IS_CLOSURE(peek)) {
|
||||
|
||||
/* detect misuse of closure operator */
|
||||
if (IS_START(token)) {
|
||||
FAIL("* or \\+ or \\? follows nothing");
|
||||
} else if (IS_META(token) && token != M_ANY && !IS_CLASS(token)) {
|
||||
FAIL("* or \\+ or \\? can only follow a normal character or . or []");
|
||||
}
|
||||
|
||||
/* it is okay -- make it prefix instead of postfix */
|
||||
ADD_META(build, peek);
|
||||
|
||||
/* take care of "needfirst" - is this the first char? */
|
||||
if (needfirst && peek == M_PLUS && !IS_META(token)) {
|
||||
re->first = token;
|
||||
}
|
||||
needfirst = 0;
|
||||
|
||||
/* we used "peek" -- need to refill it */
|
||||
peek = gettoken(&text, re);
|
||||
if (IS_CLOSURE(peek)) {
|
||||
FAIL("* or \\+ or \\? doubled up");
|
||||
}
|
||||
} else if (!IS_META(token)) {
|
||||
/* normal char is NOT argument of closure */
|
||||
if (needfirst) {
|
||||
re->first = token;
|
||||
needfirst = 0;
|
||||
}
|
||||
re->minlen++;
|
||||
} else if (token == M_ANY || IS_CLASS(token)) {
|
||||
/* . or [] is NOT argument of closure */
|
||||
needfirst = 0;
|
||||
re->minlen++;
|
||||
}
|
||||
|
||||
/* the "token" character is not closure -- process it normally */
|
||||
if (token == M_BEGLINE) {
|
||||
/* set the BOL flag instead of storing M_BEGLINE */
|
||||
re->bol = 1;
|
||||
} else if (IS_META(token)) {
|
||||
ADD_META(build, token);
|
||||
} else {
|
||||
*build++ = token;
|
||||
}
|
||||
}
|
||||
|
||||
/* end it with a \) which MUST MATCH the opening \( */
|
||||
ADD_META(build, M_END(0));
|
||||
if (end_sp > 0) {
|
||||
FAIL("Not enough \\)s");
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* This function searches through a string for text that matches an RE. */
|
||||
/* re -- the compiled regexp to search for */
|
||||
/* str -- the string to search through */
|
||||
/* bol -- does str start at the beginning of a line? (boolean) */
|
||||
/* ignoreCase -- ignoreCase or not */
|
||||
extern int regexec(struct regexp *re, char *str, int bol, int ignoreCase)
|
||||
{
|
||||
char *prog; /* the entry point of re->program */
|
||||
int len; /* length of the string */
|
||||
char *here;
|
||||
|
||||
/* if must start at the beginning of a line, and this isn't, then fail */
|
||||
if (re->bol && bol == TRUE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
len = strlen(str);
|
||||
prog = re->program + 1 + 32 * re->program[0];
|
||||
|
||||
/* search for the RE in the string */
|
||||
if (re->bol) {
|
||||
/* must occur at BOL */
|
||||
if ((re->first && match1(re, *(char *) str, re->first, ignoreCase)) /* wrong first letter? */
|
||||
||len < re->minlen /* not long enough? */
|
||||
|| match(re, (char *) str, prog, str, ignoreCase)) /* doesn't match? */
|
||||
return FALSE; /* THEN FAIL! */
|
||||
} else if (ignoreCase == FALSE) {
|
||||
/* can occur anywhere in the line, noignorecase */
|
||||
for (here = (char *) str; (re->first && re->first != *here)
|
||||
|| match(re, (char *) str, prog, here, ignoreCase);
|
||||
here++, len--) {
|
||||
if (len < re->minlen)
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
/* can occur anywhere in the line, ignorecase */
|
||||
for (here = (char *) str;
|
||||
(re->first && match1(re, *here, (int) re->first, ignoreCase))
|
||||
|| match(re, (char *) str, prog, here, ignoreCase);
|
||||
here++, len--) {
|
||||
if (len < re->minlen)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we didn't fail, then we must have succeeded */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined BB_SED
|
||||
/* This performs substitutions after a regexp match has been found. */
|
||||
extern void regsub(regexp * re, char *src, char *dst)
|
||||
{
|
||||
char *cpy;
|
||||
char *end;
|
||||
char c;
|
||||
char *start;
|
||||
int mod;
|
||||
|
||||
mod = 0;
|
||||
|
||||
start = src;
|
||||
while ((c = *src++) != '\0') {
|
||||
/* recognize any meta characters */
|
||||
if (c == '&') {
|
||||
cpy = re->startp[0];
|
||||
end = re->endp[0];
|
||||
} else if (c == '~') {
|
||||
cpy = previous1;
|
||||
if (cpy)
|
||||
end = cpy + strlen(cpy);
|
||||
} else if (c == '\\') {
|
||||
c = *src++;
|
||||
switch (c) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
/* \0 thru \9 mean "copy subexpression" */
|
||||
c -= '0';
|
||||
cpy = re->startp[(int) c];
|
||||
end = re->endp[(int) c];
|
||||
break;
|
||||
case 'U':
|
||||
case 'u':
|
||||
case 'L':
|
||||
case 'l':
|
||||
/* \U and \L mean "convert to upper/lowercase" */
|
||||
mod = c;
|
||||
continue;
|
||||
|
||||
case 'E':
|
||||
case 'e':
|
||||
/* \E ends the \U or \L */
|
||||
mod = 0;
|
||||
continue;
|
||||
case '&':
|
||||
/* "\&" means "original text" */
|
||||
*dst++ = c;
|
||||
continue;
|
||||
|
||||
case '~':
|
||||
/* "\~" means "previous text, if any" */
|
||||
*dst++ = c;
|
||||
continue;
|
||||
default:
|
||||
/* ordinary char preceded by backslash */
|
||||
*dst++ = c;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/* ordinary character, so just copy it */
|
||||
*dst++ = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Note: to reach this point in the code, we must have evaded
|
||||
* all "continue" statements. To do that, we must have hit
|
||||
* a metacharacter that involves copying.
|
||||
*/
|
||||
|
||||
/* if there is nothing to copy, loop */
|
||||
if (!cpy)
|
||||
continue;
|
||||
|
||||
/* copy over a portion of the original */
|
||||
while (cpy < end) {
|
||||
switch (mod) {
|
||||
case 'U':
|
||||
case 'u':
|
||||
/* convert to uppercase */
|
||||
if (isascii(*cpy) && islower(*cpy)) {
|
||||
*dst++ = toupper(*cpy);
|
||||
cpy++;
|
||||
} else {
|
||||
*dst++ = *cpy++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
case 'l':
|
||||
/* convert to lowercase */
|
||||
if (isascii(*cpy) && isupper(*cpy)) {
|
||||
*dst++ = tolower(*cpy);
|
||||
cpy++;
|
||||
} else {
|
||||
*dst++ = *cpy++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* copy without any conversion */
|
||||
*dst++ = *cpy++;
|
||||
}
|
||||
|
||||
/* \u and \l end automatically after the first char */
|
||||
if (mod && (mod == 'u' || mod == 'l')) {
|
||||
mod = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
/* remember what text we inserted this time */
|
||||
if (previous1)
|
||||
free(previous1);
|
||||
previous1 = (char *) malloc((unsigned) (strlen(start) + 1));
|
||||
if (previous1)
|
||||
strcpy(previous1, start);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BB_REGEXP */
|
||||
@@ -1,51 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Busybox regexp header file
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
||||
* Permission has been granted to redistribute this code under the GPL.
|
||||
*
|
||||
*/
|
||||
#ifndef _REGEXP_H_
|
||||
#define _REGEXP_H_
|
||||
|
||||
|
||||
|
||||
|
||||
#define NSUBEXP 10
|
||||
typedef struct regexp {
|
||||
char *startp[NSUBEXP];
|
||||
char *endp[NSUBEXP];
|
||||
int minlen; /* length of shortest possible match */
|
||||
char first; /* first character, if known; else \0 */
|
||||
char bol; /* boolean: must start at beginning of line? */
|
||||
char program[1]; /* Unwarranted chumminess with compiler. */
|
||||
} regexp;
|
||||
|
||||
|
||||
|
||||
extern regexp *regcomp(char* text);
|
||||
extern int regexec(struct regexp* re, char* str, int bol, int ignoreCase);
|
||||
extern void regsub(struct regexp* re, char* src, char* dst);
|
||||
|
||||
extern int find_match(char *haystack, char *needle, int ignoreCase);
|
||||
extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#define __LIBRARY__
|
||||
#include <asm/unistd.h>
|
||||
/* #include <sys/syscall.h> */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini sed implementation for busybox
|
||||
*
|
||||
* sed.c - very minimalist version of sed
|
||||
*
|
||||
* 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
|
||||
* written by Marco Pantaleoni <panta@prosa.it>, <panta@elasticworld.org>
|
||||
* and are:
|
||||
* Copyright (C) 1999 Marco Pantaleoni.
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -27,333 +20,510 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "regexp.h"
|
||||
/*
|
||||
Supported features and commands in this version of sed:
|
||||
|
||||
- comments ('#')
|
||||
- Address matching: num|/matchstr/[,num|/matchstr/|$]command
|
||||
- Commands: p, d, s/match/replace/[g]
|
||||
|
||||
(Note: Specifying an address (range) to match is *optional*; commands
|
||||
default to the whole pattern space if no specific address match was
|
||||
requested.)
|
||||
|
||||
Unsupported features:
|
||||
|
||||
- transliteration (y/source-chars/dest-chars/) (use 'tr')
|
||||
- no support for characters other than the '/' character for regex matches
|
||||
- no pattern space hold space storing / swapping (x, etc.)
|
||||
- no labels / branching (: label, b, t, and friends)
|
||||
- and lots, lots more.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h> /* for realloc() */
|
||||
#include <unistd.h> /* for getopt() */
|
||||
#include <regex.h>
|
||||
#include <string.h> /* for strdup() */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <ctype.h> /* for isspace() */
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* externs */
|
||||
extern int optind; /* in unistd.h */
|
||||
extern char *optarg; /* ditto */
|
||||
|
||||
/* options */
|
||||
static int be_quiet = 0;
|
||||
|
||||
struct sed_cmd {
|
||||
|
||||
/* address storage */
|
||||
int beg_line; /* 'sed 1p' 0 == no begining line, apply commands to all lines */
|
||||
int end_line; /* 'sed 1,3p' 0 == no end line, use only beginning. -1 == $ */
|
||||
regex_t *beg_match; /* sed -e '/match/cmd' */
|
||||
regex_t *end_match; /* sed -e '/match/,/end_match/cmd' */
|
||||
|
||||
/* the command */
|
||||
char cmd; /* p,d,s (add more at your leisure :-) */
|
||||
|
||||
/* substitution command specific fields */
|
||||
regex_t *sub_match; /* sed -e 's/sub_match/replace/' */
|
||||
char *replace; /* sed -e 's/sub_match/replace/' XXX: who will hold the \1 \2 \3s? */
|
||||
unsigned int sub_g:1; /* sed -e 's/foo/bar/g' (global) */
|
||||
};
|
||||
|
||||
/* globals */
|
||||
static struct sed_cmd *sed_cmds = NULL; /* growable arrary holding a sequence of sed cmds */
|
||||
static int ncmds = 0; /* number of sed commands */
|
||||
|
||||
/*static char *cur_file = NULL;*/ /* file currently being processed XXX: do I need this? */
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] -e script [file...]\n"
|
||||
"sed [-Vhnef] pattern [files...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nAllowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regular expressions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regular expressions).\n"
|
||||
#endif
|
||||
"\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n"
|
||||
"-e script\tadd the script to the commands to be executed\n"
|
||||
"-f scriptfile\tadd the contents of script-file to the commands to be executed\n"
|
||||
"-h\tdisplay this help message\n"
|
||||
"-V\toutput version information and exit\n"
|
||||
"\n"
|
||||
"If no -e or -f is given, the first non-option argument is taken as the\n"
|
||||
"sed script to interpret. All remaining arguments are names of input\n"
|
||||
"files; if no input files are specified, then the standard input is read.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/* Flags & variables */
|
||||
|
||||
typedef enum { f_none, f_replace, f_append } sed_function;
|
||||
|
||||
#define NO_LINE -2
|
||||
#define LAST_LINE -1
|
||||
static int addr_line = NO_LINE;
|
||||
static char *addr_pattern = NULL;
|
||||
static int negated = 0;
|
||||
|
||||
#define SKIPSPACES(p) do { while (isspace(*(p))) (p)++; } while (0)
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
static inline int at_last(FILE * fp)
|
||||
static void destroy_cmd_strs()
|
||||
{
|
||||
int res = 0;
|
||||
if (sed_cmds == NULL)
|
||||
return;
|
||||
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
int ch;
|
||||
/* destroy all the elements in the array */
|
||||
while (--ncmds >= 0) {
|
||||
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
if (sed_cmds[ncmds].beg_match) {
|
||||
regfree(sed_cmds[ncmds].beg_match);
|
||||
free(sed_cmds[ncmds].beg_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].end_match) {
|
||||
regfree(sed_cmds[ncmds].end_match);
|
||||
free(sed_cmds[ncmds].end_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].sub_match) {
|
||||
regfree(sed_cmds[ncmds].sub_match);
|
||||
free(sed_cmds[ncmds].sub_match);
|
||||
}
|
||||
if (sed_cmds[ncmds].replace)
|
||||
free(sed_cmds[ncmds].replace);
|
||||
}
|
||||
return res;
|
||||
|
||||
/* destroy the array */
|
||||
free(sed_cmds);
|
||||
sed_cmds = NULL;
|
||||
}
|
||||
|
||||
static void do_sed_repl(FILE * fp, char *needle, char *newNeedle,
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
static void exit_sed(int retcode, const char *message)
|
||||
{
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
destroy_cmd_strs();
|
||||
if (message)
|
||||
fputs(message, stderr);
|
||||
exit(retcode);
|
||||
}
|
||||
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
/*
|
||||
* trim_str - trims leading and trailing space from a string
|
||||
*
|
||||
* Note: This returns a malloc'ed string so you must store and free it
|
||||
* XXX: This should be in the utility.c file.
|
||||
*/
|
||||
static char *trim_str(const char *str)
|
||||
{
|
||||
int i;
|
||||
char *retstr = strdup(str);
|
||||
|
||||
/* trim leading whitespace */
|
||||
memmove(retstr, &retstr[strspn(retstr, " \n\t\v")], strlen(retstr));
|
||||
|
||||
/* trim trailing whitespace */
|
||||
i = strlen(retstr) - 1;
|
||||
while (isspace(retstr[i]))
|
||||
i--;
|
||||
retstr[++i] = 0;
|
||||
|
||||
/* Aside:
|
||||
*
|
||||
* you know, a strrspn() would really be nice cuz then we could say:
|
||||
*
|
||||
* retstr[strlen(retstr) - strrspn(retstr, " \n\t\v") + 1] = 0;
|
||||
*/
|
||||
|
||||
return retstr;
|
||||
}
|
||||
|
||||
/*
|
||||
* index_of_unescaped_slash - walks left to right through a string beginning
|
||||
* at a specified index and returns the index of the next unescaped slash.
|
||||
*/
|
||||
static int index_of_next_unescaped_slash(int idx, const char *str)
|
||||
{
|
||||
do {
|
||||
idx++;
|
||||
/* test if we've hit the end */
|
||||
if (str[idx] == 0)
|
||||
return -1;
|
||||
} while (str[idx] != '/' && str[idx - 1] != '\\');
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the index in the string just past where the address ends.
|
||||
*/
|
||||
static int get_address(const char *str, int *line, regex_t **regex)
|
||||
{
|
||||
char *my_str = strdup(str);
|
||||
int idx = 0;
|
||||
|
||||
if (isdigit(my_str[idx])) {
|
||||
do {
|
||||
idx++;
|
||||
} while (isdigit(my_str[idx]));
|
||||
my_str[idx] = 0;
|
||||
*line = atoi(my_str);
|
||||
*regex = NULL;
|
||||
}
|
||||
else if (my_str[idx] == '$') {
|
||||
*line = -1;
|
||||
*regex = NULL;
|
||||
idx++;
|
||||
}
|
||||
else if (my_str[idx] == '/') {
|
||||
idx = index_of_next_unescaped_slash(idx, my_str);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: unterminated match expression\n");
|
||||
my_str[idx] = '\0';
|
||||
*regex = (regex_t *)xmalloc(sizeof(regex_t));
|
||||
if (bb_regcomp(*regex, my_str+1, REG_NEWLINE) != 0) {
|
||||
free(my_str);
|
||||
exit_sed(1, NULL);
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "sed.c:get_address: no address found in string\n");
|
||||
fprintf(stderr, "\t(you probably didn't check the string you passed me)\n");
|
||||
idx = -1;
|
||||
}
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
free(my_str);
|
||||
return idx;
|
||||
}
|
||||
|
||||
static char *strdup_substr(const char *str, int start, int end)
|
||||
{
|
||||
int size = end - start + 1;
|
||||
char *newstr = xmalloc(size);
|
||||
memcpy(newstr, str+start, size-1);
|
||||
newstr[size-1] = '\0';
|
||||
return newstr;
|
||||
}
|
||||
|
||||
static void parse_cmd_str(struct sed_cmd *sed_cmd, const char *cmdstr)
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
/* parse the command
|
||||
* format is: [addr][,addr]cmd
|
||||
* |----||-----||-|
|
||||
* part1 part2 part3
|
||||
*/
|
||||
|
||||
/* first part (if present) is an address: either a number or a /regex/ */
|
||||
if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/')
|
||||
idx = get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
|
||||
|
||||
/* second part (if present) will begin with a comma */
|
||||
if (cmdstr[idx] == ',')
|
||||
idx += get_address(&cmdstr[++idx], &sed_cmd->end_line, &sed_cmd->end_match);
|
||||
|
||||
/* last part (mandatory) will be a command */
|
||||
if (cmdstr[idx] == '\0')
|
||||
exit_sed(1, "sed: missing command\n");
|
||||
if (!strchr("pds", cmdstr[idx])) /* <-- XXX add new commands here */
|
||||
exit_sed(1, "sed: invalid command\n");
|
||||
sed_cmd->cmd = cmdstr[idx];
|
||||
/* special-case handling for 's' */
|
||||
if (sed_cmd->cmd == 's') {
|
||||
int oldidx, cflags = REG_NEWLINE;
|
||||
char *match;
|
||||
/* format for substitution is:
|
||||
* s/match/replace/gI
|
||||
* | ||
|
||||
* mandatory optional
|
||||
*/
|
||||
|
||||
/* verify that we have an 's' followed by a 'slash' */
|
||||
if (cmdstr[++idx] != '/')
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
|
||||
/* save the match string */
|
||||
oldidx = idx+1;
|
||||
idx = index_of_next_unescaped_slash(idx, cmdstr);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
match = strdup_substr(cmdstr, oldidx, idx);
|
||||
|
||||
/* save the replacement string */
|
||||
oldidx = idx+1;
|
||||
idx = index_of_next_unescaped_slash(idx, cmdstr);
|
||||
if (idx == -1)
|
||||
exit_sed(1, "sed: bad format in substitution expression\n");
|
||||
sed_cmd->replace = strdup_substr(cmdstr, oldidx, idx);
|
||||
|
||||
/* process the flags */
|
||||
while (cmdstr[++idx]) {
|
||||
switch (cmdstr[idx]) {
|
||||
case 'g':
|
||||
sed_cmd->sub_g = 1;
|
||||
break;
|
||||
case 'I':
|
||||
cflags |= REG_ICASE;
|
||||
break;
|
||||
default:
|
||||
exit_sed(1, "sed: bad option in substitution expression\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
|
||||
/* compile the regex */
|
||||
sed_cmd->sub_match = (regex_t *)xmalloc(sizeof(regex_t));
|
||||
if (bb_regcomp(sed_cmd->sub_match, match, cflags) != 0) {
|
||||
free(match);
|
||||
exit_sed(1, NULL);
|
||||
}
|
||||
|
||||
line++;
|
||||
free(match);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_sed_append(FILE * fp, char *appendline, int quietFlag)
|
||||
static void add_cmd_str(const char *cmdstr)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
char *my_cmdstr = trim_str(cmdstr);
|
||||
|
||||
/* if this is a comment, don't even bother */
|
||||
if (my_cmdstr[0] == '#') {
|
||||
free(my_cmdstr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* grow the array */
|
||||
sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
|
||||
/* zero new element */
|
||||
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
|
||||
/* load command string into new array element */
|
||||
parse_cmd_str(&sed_cmds[ncmds-1], my_cmdstr);
|
||||
}
|
||||
|
||||
|
||||
static void load_cmd_file(char *filename)
|
||||
{
|
||||
FILE *cmdfile;
|
||||
char *line;
|
||||
|
||||
cmdfile = fopen(filename, "r");
|
||||
if (cmdfile == NULL)
|
||||
exit_sed(1, strerror(errno));
|
||||
|
||||
while ((line = get_line_from_file(cmdfile)) != NULL) {
|
||||
line[strlen(line)-1] = 0; /* eat newline */
|
||||
add_cmd_str(line);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
|
||||
{
|
||||
int altered = 0;
|
||||
|
||||
switch (sed_cmd->cmd) {
|
||||
|
||||
case 'p':
|
||||
fputs(line, stdout);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
altered++;
|
||||
break;
|
||||
|
||||
case 's': /* oo, a fun one :-) */
|
||||
|
||||
/* we only substitute if the substitution 'search' expression matches */
|
||||
if (regexec(sed_cmd->sub_match, line, 0, NULL, 0) == 0) {
|
||||
regmatch_t regmatch;
|
||||
int i;
|
||||
char *ptr = (char *)line;
|
||||
|
||||
while (*ptr) {
|
||||
/* if we can match the search string... */
|
||||
if (regexec(sed_cmd->sub_match, ptr, 1, ®match, 0) == 0) {
|
||||
/* print everything before the match, */
|
||||
for (i = 0; i < regmatch.rm_so; i++)
|
||||
fputc(ptr[i], stdout);
|
||||
/* then print the substitution in its place */
|
||||
fputs(sed_cmd->replace, stdout);
|
||||
/* then advance past the match */
|
||||
ptr += regmatch.rm_eo;
|
||||
/* and let the calling function know that something
|
||||
* has been changed */
|
||||
altered++;
|
||||
|
||||
/* if we're not doing this globally... */
|
||||
if (!sed_cmd->sub_g)
|
||||
break;
|
||||
}
|
||||
/* if we COULD NOT match the search string (meaning we've gone past
|
||||
* all previous instances), get out */
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* is there anything left to print? */
|
||||
if (*ptr)
|
||||
fputs(ptr, stdout);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return altered;
|
||||
}
|
||||
|
||||
static void process_file(FILE *file)
|
||||
{
|
||||
char *line = NULL;
|
||||
static int linenum = 0; /* GNU sed does not restart counting lines at EOF */
|
||||
unsigned int still_in_range = 0;
|
||||
int line_altered;
|
||||
int i;
|
||||
|
||||
/* go through every line in the file */
|
||||
while ((line = get_line_from_file(file)) != NULL) {
|
||||
|
||||
linenum++;
|
||||
line_altered = 0;
|
||||
|
||||
/* for every line, go through all the commands */
|
||||
for (i = 0; i < ncmds; i++) {
|
||||
|
||||
/* are we acting on a range of matched lines? */
|
||||
if (sed_cmds[i].beg_match && sed_cmds[i].end_match) {
|
||||
if (still_in_range || regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0) {
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
still_in_range = 1;
|
||||
if (regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
|
||||
still_in_range = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* are we trying to match a single line? */
|
||||
else if (sed_cmds[i].beg_match) {
|
||||
if (regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* are we acting on a range of line numbers? */
|
||||
else if (sed_cmds[i].beg_line > 0 && sed_cmds[i].end_line > 0) {
|
||||
if (linenum >= sed_cmds[i].beg_line && linenum <= sed_cmds[i].end_line)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* are we acting on a specified line number */
|
||||
else if (sed_cmds[i].beg_line > 0) {
|
||||
if (linenum == sed_cmds[i].beg_line)
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
}
|
||||
|
||||
/* not acting on matches or line numbers. act on every line */
|
||||
else
|
||||
line_altered += do_sed_command(&sed_cmds[i], line);
|
||||
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
line++;
|
||||
/* we will print the line unless we were told to be quiet or if the
|
||||
* line was altered (via a 'd'elete or 's'ubstitution) */
|
||||
if (!be_quiet && !line_altered)
|
||||
fputs(line, stdout);
|
||||
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
int opt;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
/* do special-case option parsing */
|
||||
if (argv[1] && (strcmp(argv[1], "--help") == 0))
|
||||
usage(sed_usage);
|
||||
}
|
||||
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
usage(sed_usage);
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "Vhne:f:")) > 0) {
|
||||
switch (opt) {
|
||||
case 'V':
|
||||
printf("Print Busybox version here\n");
|
||||
exit(0);
|
||||
break;
|
||||
case 'h':
|
||||
usage(sed_usage);
|
||||
break;
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
be_quiet++;
|
||||
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;
|
||||
add_cmd_str(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
case 'f':
|
||||
load_cmd_file(optarg);
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
return(TRUE);
|
||||
|
||||
/* if we didn't get a pattern from a -e and no command file was specified,
|
||||
* argv[optind] should be the pattern. no pattern, no worky */
|
||||
if (ncmds == 0) {
|
||||
if (argv[optind] == NULL)
|
||||
usage(sed_usage);
|
||||
else {
|
||||
add_cmd_str(argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) {
|
||||
process_file(stdin);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind; i < argc; i++) {
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "sed: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
process_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit_sed(0, NULL);
|
||||
|
||||
/* not reached */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
+8
-1
@@ -27,7 +27,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/kd.h>
|
||||
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbkeycode {
|
||||
unsigned int scancode, keycode;
|
||||
};
|
||||
#define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */
|
||||
|
||||
|
||||
static const char setkeycodes_usage[] =
|
||||
"setkeycodes SCANCODE KEYCODE ...\n"
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include "cmdedit.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_READ 128 /* size of input buffer for `read' builtin */
|
||||
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
|
||||
|
||||
|
||||
@@ -89,18 +89,21 @@ struct builtInCommand {
|
||||
int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
|
||||
};
|
||||
|
||||
/* Some function prototypes */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||
/* function prototypes for builtins */
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk);
|
||||
|
||||
|
||||
/* function prototypes for shell stuff */
|
||||
static void checkJobs(struct jobSet *jobList);
|
||||
static int getCommand(FILE * source, char *command);
|
||||
static int parseCommand(char **commandPtr, struct job *job, int *isBg);
|
||||
@@ -111,35 +114,37 @@ static int busy_loop(FILE * input);
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins[] = {
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", shell_cd},
|
||||
{"exit", "Exit from shell()", "exit", shell_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", builtin_cd},
|
||||
{"exit", "Exit from shell()", "exit", builtin_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", builtin_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", builtin_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", builtin_unset},
|
||||
{"read", "Input environment variable", "read [VAR]", builtin_read},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins_forking[] = {
|
||||
{"env", "Print all environment variables", "env", shell_env},
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
{"env", "Print all environment variables", "env", builtin_env},
|
||||
{"pwd", "Print current directory", "pwd", builtin_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", builtin_source},
|
||||
{"help", "List shell built-in commands", "help", builtin_help},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n"
|
||||
"sh [FILE]...\n"
|
||||
" or: sh -c command [args]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nlash: The BusyBox command interpreter (shell).\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static char cwd[1024];
|
||||
static char *prompt = "# ";
|
||||
static char *cwd = NULL;
|
||||
static char *local_pending_command = NULL;
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
void win_changed(int sig)
|
||||
@@ -154,7 +159,7 @@ void win_changed(int sig)
|
||||
|
||||
|
||||
/* built-in 'cd <path>' handler */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
@@ -172,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'env' handler */
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
char **e;
|
||||
|
||||
@@ -183,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'exit' handler */
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
@@ -192,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'fg' and 'bg' handler */
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
{
|
||||
int i, jobNum;
|
||||
struct job *job=NULL;
|
||||
@@ -225,8 +230,9 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
}
|
||||
|
||||
@@ -242,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
}
|
||||
|
||||
/* built-in 'help' handler */
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
struct builtInCommand *x;
|
||||
|
||||
@@ -259,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'jobs' handler */
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
@@ -277,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
|
||||
|
||||
/* built-in 'pwd' handler */
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
fprintf(stdout, "%s\n", cwd);
|
||||
@@ -285,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'export VAR=value' handler */
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
return (shell_env(cmd, junk));
|
||||
return (builtin_env(cmd, junk));
|
||||
}
|
||||
res = putenv(cmd->progs[0].argv[1]);
|
||||
if (res)
|
||||
@@ -298,8 +304,42 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* built-in 'read VAR' handler */
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res = 0, len, newlen;
|
||||
char *s;
|
||||
char string[MAX_READ];
|
||||
|
||||
if (cmd->progs[0].argv[1]) {
|
||||
/* argument (VAR) given: put "VAR=" into buffer */
|
||||
strcpy(string, cmd->progs[0].argv[1]);
|
||||
len = strlen(string);
|
||||
string[len++] = '=';
|
||||
string[len] = '\0';
|
||||
fgets(&string[len], sizeof(string) - len, stdin); /* read string */
|
||||
newlen = strlen(string);
|
||||
if(newlen > len)
|
||||
string[--newlen] = '\0'; /* chomp trailing newline */
|
||||
/*
|
||||
** string should now contain "VAR=<value>"
|
||||
** copy it (putenv() won't do that, so we must make sure
|
||||
** the string resides in a static buffer!)
|
||||
*/
|
||||
res = -1;
|
||||
if((s = strdup(string)))
|
||||
res = putenv(s);
|
||||
if (res)
|
||||
fprintf(stdout, "read: %s\n", strerror(errno));
|
||||
}
|
||||
else
|
||||
fgets(string, sizeof(string), stdin);
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* Built-in '.' handler (read-in and execute commands from file) */
|
||||
static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_source(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
FILE *input;
|
||||
int status;
|
||||
@@ -320,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'unset VAR' handler */
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
fprintf(stdout, "unset: parameter required.\n");
|
||||
@@ -411,6 +451,17 @@ static void checkJobs(struct jobSet *jobList)
|
||||
|
||||
static int getCommand(FILE * source, char *command)
|
||||
{
|
||||
if (source == NULL) {
|
||||
if (local_pending_command) {
|
||||
/* a command specified (-c option): return it & mark it done */
|
||||
strcpy(command, local_pending_command);
|
||||
free(local_pending_command);
|
||||
local_pending_command = NULL;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (source == stdin) {
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
int len;
|
||||
@@ -448,7 +499,7 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
int rc;
|
||||
int flags;
|
||||
int i;
|
||||
char *src, *dst;
|
||||
char *src, *dst, *var;
|
||||
|
||||
if (argc > 1) { /* cmd->globResult is already initialized */
|
||||
flags = GLOB_APPEND;
|
||||
@@ -458,6 +509,9 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
flags = 0;
|
||||
i = 0;
|
||||
}
|
||||
/* do shell variable substitution */
|
||||
if(*prog->argv[argc - 1] == '$' && (var = getenv(prog->argv[argc - 1] + 1)))
|
||||
prog->argv[argc - 1] = var;
|
||||
|
||||
rc = glob(prog->argv[argc - 1], flags, NULL, &prog->globResult);
|
||||
if (rc == GLOB_NOSPACE) {
|
||||
@@ -522,12 +576,13 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
job->progs = malloc(sizeof(*job->progs));
|
||||
|
||||
/* We set the argv elements to point inside of this string. The
|
||||
memory is freed by freeJob().
|
||||
memory is freed by freeJob(). Allocate twice the original
|
||||
length in case we need to quote every single character.
|
||||
|
||||
Getting clean memory relieves us of the task of NULL
|
||||
terminating things and makes the rest of this look a bit
|
||||
cleaner (though it is, admittedly, a tad less efficient) */
|
||||
job->cmdBuf = command = calloc(1, strlen(*commandPtr) + 1);
|
||||
job->cmdBuf = command = calloc(1, 2*strlen(*commandPtr) + 1);
|
||||
job->text = NULL;
|
||||
|
||||
prog = job->progs;
|
||||
@@ -570,9 +625,8 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
sizeof(*prog->argv) *
|
||||
argvAlloced);
|
||||
}
|
||||
prog->argv[argc] = buf;
|
||||
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
} else
|
||||
switch (*src) {
|
||||
@@ -602,6 +656,7 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
if (*chptr && *prog->argv[argc]) {
|
||||
buf++, argc++;
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +791,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
int nextin, nextout;
|
||||
int pipefds[2]; /* pipefd[0] is for reading */
|
||||
struct builtInCommand *x;
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
const struct BB_applet *a = applets;
|
||||
#endif
|
||||
|
||||
@@ -750,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
nextout = 1;
|
||||
}
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any non-forking builtins */
|
||||
for (x = bltins; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
return (x->function(&newJob, jobList));
|
||||
@@ -773,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
/* explicit redirections override pipes */
|
||||
setupRedirections(newJob.progs + i);
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any of the other builtins */
|
||||
for (x = bltins_forking; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
exit (x->function(&newJob, jobList));
|
||||
}
|
||||
}
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
/* Handle busybox internals here */
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
/* Check if the command matches any busybox internal commands here */
|
||||
/* TODO: Add matching when paths are appended (i.e. 'cat' currently
|
||||
* works, but '/bin/cat' doesn't ) */
|
||||
while (a->name != 0) {
|
||||
if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
|
||||
int argc;
|
||||
@@ -842,7 +899,8 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
jobList->fg = job;
|
||||
|
||||
/* move the new process group into the foreground */
|
||||
if (tcsetpgrp(0, newJob.pgrp))
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, newJob.pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
|
||||
@@ -894,10 +952,14 @@ static int busy_loop(FILE * input)
|
||||
char *nextCommand = NULL;
|
||||
struct jobSet jobList = { NULL, NULL };
|
||||
struct job newJob;
|
||||
pid_t parent_pgrp;
|
||||
int i;
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
/* save current owner of TTY so we can restore it on exit */
|
||||
parent_pgrp = tcgetpgrp(0);
|
||||
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
@@ -939,10 +1001,6 @@ static int busy_loop(FILE * input)
|
||||
|
||||
removeJob(&jobList, jobList.fg);
|
||||
jobList.fg = NULL;
|
||||
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
} else {
|
||||
/* the child was stopped */
|
||||
@@ -958,13 +1016,22 @@ static int busy_loop(FILE * input)
|
||||
|
||||
if (!jobList.fg) {
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, getpid()) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
}
|
||||
}
|
||||
free(command);
|
||||
|
||||
/* return controlling TTY back to parent process group before exiting */
|
||||
if (tcsetpgrp(0, parent_pgrp))
|
||||
perror("tcsetpgrp");
|
||||
|
||||
/* return exit status if called with "-c" */
|
||||
if (input == NULL && WIFEXITED(status))
|
||||
return WEXITSTATUS(status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -973,11 +1040,12 @@ int shell_main(int argc, char **argv)
|
||||
{
|
||||
FILE *input = stdin;
|
||||
|
||||
if (argc > 2) {
|
||||
usage(shell_usage);
|
||||
}
|
||||
/* initialize the cwd */
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
cwd = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (cwd == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
getcwd(cwd, sizeof(char)*BUFSIZ);
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
cmdedit_init();
|
||||
@@ -986,20 +1054,43 @@ int shell_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
//if (argv[0] && argv[0][0] == '-') {
|
||||
// shell_source("/etc/profile");
|
||||
// builtin_source("/etc/profile");
|
||||
//}
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
|
||||
fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
|
||||
} else {
|
||||
if (*argv[1]=='-') {
|
||||
usage("sh\n\nlash -- the BusyBox LAme SHell (command interpreter)\n");
|
||||
if (argv[1][0]=='-' && argv[1][1]=='c') {
|
||||
int i;
|
||||
local_pending_command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (local_pending_command == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
if (strlen(local_pending_command) + strlen(argv[i]) >= BUFSIZ) {
|
||||
local_pending_command = realloc(local_pending_command,
|
||||
strlen(local_pending_command) + strlen(argv[i]));
|
||||
if (local_pending_command==NULL)
|
||||
fatalError("sh: commands for -c option too long\n");
|
||||
}
|
||||
strcat(local_pending_command, argv[i]);
|
||||
if ( (i + 1) < argc)
|
||||
strcat(local_pending_command, " ");
|
||||
}
|
||||
input = NULL;
|
||||
|
||||
}
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
else if (argv[1][0]=='-') {
|
||||
usage(shell_usage);
|
||||
}
|
||||
else {
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -143,6 +143,12 @@ void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
/* Debug crap */
|
||||
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
|
||||
//xwrite(outputFd, command, *len);
|
||||
//*cursor = *len;
|
||||
|
||||
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\b \b", 3);
|
||||
--*cursor;
|
||||
@@ -534,7 +540,10 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
rewrite_line:
|
||||
/* erase old command from command line */
|
||||
len = strlen(command)-strlen(hp->s);
|
||||
while (len>0)
|
||||
|
||||
while (len>cursor)
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
while (cursor>0)
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
input_home(outputFd, &cursor);
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#ifndef GETLINE_H
|
||||
#define GETLINE_H
|
||||
#ifndef CMDEDIT_H
|
||||
#define CMDEDIT_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
@@ -34,4 +34,4 @@ extern int (*cmdedit_tab_hook)();
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* GETLINE_H */
|
||||
#endif /* CMDEDIT_H */
|
||||
+158
-67
@@ -41,7 +41,7 @@
|
||||
#include "cmdedit.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_READ 128 /* size of input buffer for `read' builtin */
|
||||
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
|
||||
|
||||
|
||||
@@ -89,18 +89,21 @@ struct builtInCommand {
|
||||
int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
|
||||
};
|
||||
|
||||
/* Some function prototypes */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||
/* function prototypes for builtins */
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk);
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_source(struct job *cmd, struct jobSet *jobList);
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk);
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk);
|
||||
|
||||
|
||||
/* function prototypes for shell stuff */
|
||||
static void checkJobs(struct jobSet *jobList);
|
||||
static int getCommand(FILE * source, char *command);
|
||||
static int parseCommand(char **commandPtr, struct job *job, int *isBg);
|
||||
@@ -111,35 +114,37 @@ static int busy_loop(FILE * input);
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins[] = {
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", shell_cd},
|
||||
{"exit", "Exit from shell()", "exit", shell_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
{"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
|
||||
{"cd", "Change working directory", "cd [dir]", builtin_cd},
|
||||
{"exit", "Exit from shell()", "exit", builtin_exit},
|
||||
{"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
|
||||
{"jobs", "Lists the active jobs", "jobs", builtin_jobs},
|
||||
{"export", "Set environment variable", "export [VAR=value]", builtin_export},
|
||||
{"unset", "Unset environment variable", "unset VAR", builtin_unset},
|
||||
{"read", "Input environment variable", "read [VAR]", builtin_read},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
/* Table of built-in functions */
|
||||
static struct builtInCommand bltins_forking[] = {
|
||||
{"env", "Print all environment variables", "env", shell_env},
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
{"env", "Print all environment variables", "env", builtin_env},
|
||||
{"pwd", "Print current directory", "pwd", builtin_pwd},
|
||||
{".", "Source-in and run commands in a file", ". filename", builtin_source},
|
||||
{"help", "List shell built-in commands", "help", builtin_help},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n"
|
||||
"sh [FILE]...\n"
|
||||
" or: sh -c command [args]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nlash: The BusyBox command interpreter (shell).\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static char cwd[1024];
|
||||
static char *prompt = "# ";
|
||||
static char *cwd = NULL;
|
||||
static char *local_pending_command = NULL;
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
void win_changed(int sig)
|
||||
@@ -154,7 +159,7 @@ void win_changed(int sig)
|
||||
|
||||
|
||||
/* built-in 'cd <path>' handler */
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
@@ -172,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'env' handler */
|
||||
static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_env(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
char **e;
|
||||
|
||||
@@ -183,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'exit' handler */
|
||||
static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
@@ -192,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'fg' and 'bg' handler */
|
||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
{
|
||||
int i, jobNum;
|
||||
struct job *job=NULL;
|
||||
@@ -225,8 +230,9 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
}
|
||||
|
||||
@@ -242,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
}
|
||||
|
||||
/* built-in 'help' handler */
|
||||
static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_help(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
struct builtInCommand *x;
|
||||
|
||||
@@ -259,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'jobs' handler */
|
||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
@@ -277,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
|
||||
|
||||
/* built-in 'pwd' handler */
|
||||
static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
static int builtin_pwd(struct job *dummy, struct jobSet *junk)
|
||||
{
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
fprintf(stdout, "%s\n", cwd);
|
||||
@@ -285,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'export VAR=value' handler */
|
||||
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_export(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
return (shell_env(cmd, junk));
|
||||
return (builtin_env(cmd, junk));
|
||||
}
|
||||
res = putenv(cmd->progs[0].argv[1]);
|
||||
if (res)
|
||||
@@ -298,8 +304,42 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* built-in 'read VAR' handler */
|
||||
static int builtin_read(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
int res = 0, len, newlen;
|
||||
char *s;
|
||||
char string[MAX_READ];
|
||||
|
||||
if (cmd->progs[0].argv[1]) {
|
||||
/* argument (VAR) given: put "VAR=" into buffer */
|
||||
strcpy(string, cmd->progs[0].argv[1]);
|
||||
len = strlen(string);
|
||||
string[len++] = '=';
|
||||
string[len] = '\0';
|
||||
fgets(&string[len], sizeof(string) - len, stdin); /* read string */
|
||||
newlen = strlen(string);
|
||||
if(newlen > len)
|
||||
string[--newlen] = '\0'; /* chomp trailing newline */
|
||||
/*
|
||||
** string should now contain "VAR=<value>"
|
||||
** copy it (putenv() won't do that, so we must make sure
|
||||
** the string resides in a static buffer!)
|
||||
*/
|
||||
res = -1;
|
||||
if((s = strdup(string)))
|
||||
res = putenv(s);
|
||||
if (res)
|
||||
fprintf(stdout, "read: %s\n", strerror(errno));
|
||||
}
|
||||
else
|
||||
fgets(string, sizeof(string), stdin);
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
/* Built-in '.' handler (read-in and execute commands from file) */
|
||||
static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_source(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
FILE *input;
|
||||
int status;
|
||||
@@ -320,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
|
||||
}
|
||||
|
||||
/* built-in 'unset VAR' handler */
|
||||
static int shell_unset(struct job *cmd, struct jobSet *junk)
|
||||
static int builtin_unset(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1) {
|
||||
fprintf(stdout, "unset: parameter required.\n");
|
||||
@@ -411,6 +451,17 @@ static void checkJobs(struct jobSet *jobList)
|
||||
|
||||
static int getCommand(FILE * source, char *command)
|
||||
{
|
||||
if (source == NULL) {
|
||||
if (local_pending_command) {
|
||||
/* a command specified (-c option): return it & mark it done */
|
||||
strcpy(command, local_pending_command);
|
||||
free(local_pending_command);
|
||||
local_pending_command = NULL;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (source == stdin) {
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
int len;
|
||||
@@ -448,7 +499,7 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
int rc;
|
||||
int flags;
|
||||
int i;
|
||||
char *src, *dst;
|
||||
char *src, *dst, *var;
|
||||
|
||||
if (argc > 1) { /* cmd->globResult is already initialized */
|
||||
flags = GLOB_APPEND;
|
||||
@@ -458,6 +509,9 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
||||
flags = 0;
|
||||
i = 0;
|
||||
}
|
||||
/* do shell variable substitution */
|
||||
if(*prog->argv[argc - 1] == '$' && (var = getenv(prog->argv[argc - 1] + 1)))
|
||||
prog->argv[argc - 1] = var;
|
||||
|
||||
rc = glob(prog->argv[argc - 1], flags, NULL, &prog->globResult);
|
||||
if (rc == GLOB_NOSPACE) {
|
||||
@@ -522,12 +576,13 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
job->progs = malloc(sizeof(*job->progs));
|
||||
|
||||
/* We set the argv elements to point inside of this string. The
|
||||
memory is freed by freeJob().
|
||||
memory is freed by freeJob(). Allocate twice the original
|
||||
length in case we need to quote every single character.
|
||||
|
||||
Getting clean memory relieves us of the task of NULL
|
||||
terminating things and makes the rest of this look a bit
|
||||
cleaner (though it is, admittedly, a tad less efficient) */
|
||||
job->cmdBuf = command = calloc(1, strlen(*commandPtr) + 1);
|
||||
job->cmdBuf = command = calloc(1, 2*strlen(*commandPtr) + 1);
|
||||
job->text = NULL;
|
||||
|
||||
prog = job->progs;
|
||||
@@ -570,9 +625,8 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
sizeof(*prog->argv) *
|
||||
argvAlloced);
|
||||
}
|
||||
prog->argv[argc] = buf;
|
||||
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
} else
|
||||
switch (*src) {
|
||||
@@ -602,6 +656,7 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg)
|
||||
if (*chptr && *prog->argv[argc]) {
|
||||
buf++, argc++;
|
||||
globLastArgument(prog, &argc, &argvAlloced);
|
||||
prog->argv[argc] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +791,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
int nextin, nextout;
|
||||
int pipefds[2]; /* pipefd[0] is for reading */
|
||||
struct builtInCommand *x;
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
const struct BB_applet *a = applets;
|
||||
#endif
|
||||
|
||||
@@ -750,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
nextout = 1;
|
||||
}
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any non-forking builtins */
|
||||
for (x = bltins; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
return (x->function(&newJob, jobList));
|
||||
@@ -773,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
/* explicit redirections override pipes */
|
||||
setupRedirections(newJob.progs + i);
|
||||
|
||||
/* Match any built-ins here */
|
||||
/* Check if the command matches any of the other builtins */
|
||||
for (x = bltins_forking; x->cmd; x++) {
|
||||
if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
|
||||
exit (x->function(&newJob, jobList));
|
||||
}
|
||||
}
|
||||
#ifdef BB_FEATURE_STANDALONE_SHELL
|
||||
/* Handle busybox internals here */
|
||||
#ifdef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
/* Check if the command matches any busybox internal commands here */
|
||||
/* TODO: Add matching when paths are appended (i.e. 'cat' currently
|
||||
* works, but '/bin/cat' doesn't ) */
|
||||
while (a->name != 0) {
|
||||
if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
|
||||
int argc;
|
||||
@@ -842,7 +899,8 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
|
||||
jobList->fg = job;
|
||||
|
||||
/* move the new process group into the foreground */
|
||||
if (tcsetpgrp(0, newJob.pgrp))
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, newJob.pgrp) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
|
||||
@@ -894,10 +952,14 @@ static int busy_loop(FILE * input)
|
||||
char *nextCommand = NULL;
|
||||
struct jobSet jobList = { NULL, NULL };
|
||||
struct job newJob;
|
||||
pid_t parent_pgrp;
|
||||
int i;
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
/* save current owner of TTY so we can restore it on exit */
|
||||
parent_pgrp = tcgetpgrp(0);
|
||||
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
@@ -939,10 +1001,6 @@ static int busy_loop(FILE * input)
|
||||
|
||||
removeJob(&jobList, jobList.fg);
|
||||
jobList.fg = NULL;
|
||||
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
} else {
|
||||
/* the child was stopped */
|
||||
@@ -958,13 +1016,22 @@ static int busy_loop(FILE * input)
|
||||
|
||||
if (!jobList.fg) {
|
||||
/* move the shell to the foreground */
|
||||
if (tcsetpgrp(0, getpid()))
|
||||
perror("tcsetpgrp");
|
||||
/* suppress messages when run from /linuxrc mag@sysgo.de */
|
||||
if (tcsetpgrp(0, getpid()) && errno != ENOTTY)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
}
|
||||
}
|
||||
free(command);
|
||||
|
||||
/* return controlling TTY back to parent process group before exiting */
|
||||
if (tcsetpgrp(0, parent_pgrp))
|
||||
perror("tcsetpgrp");
|
||||
|
||||
/* return exit status if called with "-c" */
|
||||
if (input == NULL && WIFEXITED(status))
|
||||
return WEXITSTATUS(status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -973,11 +1040,12 @@ int shell_main(int argc, char **argv)
|
||||
{
|
||||
FILE *input = stdin;
|
||||
|
||||
if (argc > 2) {
|
||||
usage(shell_usage);
|
||||
}
|
||||
/* initialize the cwd */
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
cwd = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (cwd == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
getcwd(cwd, sizeof(char)*BUFSIZ);
|
||||
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
cmdedit_init();
|
||||
@@ -986,20 +1054,43 @@ int shell_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
//if (argv[0] && argv[0][0] == '-') {
|
||||
// shell_source("/etc/profile");
|
||||
// builtin_source("/etc/profile");
|
||||
//}
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
|
||||
fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
|
||||
} else {
|
||||
if (*argv[1]=='-') {
|
||||
usage("sh\n\nlash -- the BusyBox LAme SHell (command interpreter)\n");
|
||||
if (argv[1][0]=='-' && argv[1][1]=='c') {
|
||||
int i;
|
||||
local_pending_command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
if (local_pending_command == 0) {
|
||||
fatalError("sh: out of memory\n");
|
||||
}
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
if (strlen(local_pending_command) + strlen(argv[i]) >= BUFSIZ) {
|
||||
local_pending_command = realloc(local_pending_command,
|
||||
strlen(local_pending_command) + strlen(argv[i]));
|
||||
if (local_pending_command==NULL)
|
||||
fatalError("sh: commands for -c option too long\n");
|
||||
}
|
||||
strcat(local_pending_command, argv[i]);
|
||||
if ( (i + 1) < argc)
|
||||
strcat(local_pending_command, " ");
|
||||
}
|
||||
input = NULL;
|
||||
|
||||
}
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
else if (argv[1][0]=='-') {
|
||||
usage(shell_usage);
|
||||
}
|
||||
else {
|
||||
input = fopen(argv[1], "r");
|
||||
if (!input) {
|
||||
fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ static Line *line_newFromFile(FILE * src)
|
||||
Line *self;
|
||||
char *cstring = NULL;
|
||||
|
||||
if ((cstring = cstring_lineFromFile(src))) {
|
||||
if ((cstring = get_line_from_file(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
@@ -304,4 +304,4 @@ int sort_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.17 2000/06/19 17:25:40 andersen Exp $ */
|
||||
/* $Id: sort.c,v 1.18 2000/06/28 22:15:26 markw Exp $ */
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <mntent.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
_syscall2(int, swapon, const char *, path, int, flags);
|
||||
_syscall1(int, swapoff, const char *, path);
|
||||
|
||||
+6
-7
@@ -40,9 +40,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/param.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
|
||||
typedef unsigned int socklen_t;
|
||||
|
||||
@@ -85,7 +84,7 @@ static const char syslogd_usage[] =
|
||||
"Options:\n"
|
||||
"\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n"
|
||||
"\t-n\t\tRun as a foreground process\n"
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
"\t-K\t\tDo not start up the klogd process\n"
|
||||
#endif
|
||||
"\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n"
|
||||
@@ -316,7 +315,7 @@ static void doSyslogd (void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
|
||||
static void klogd_signal(int sig)
|
||||
{
|
||||
@@ -407,7 +406,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
int pid, klogd_pid;
|
||||
int doFork = TRUE;
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
int startKlogd = TRUE;
|
||||
#endif
|
||||
int stopDoingThat = FALSE;
|
||||
@@ -427,7 +426,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
case 'n':
|
||||
doFork = FALSE;
|
||||
break;
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
case 'K':
|
||||
startKlogd = FALSE;
|
||||
break;
|
||||
@@ -456,7 +455,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
|
||||
umask(0);
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
/* Start up the klogd process */
|
||||
if (startKlogd == TRUE) {
|
||||
klogd_pid = fork();
|
||||
|
||||
@@ -40,9 +40,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/param.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
#if ! defined __GLIBC__ && ! defined __UCLIBC__
|
||||
|
||||
typedef unsigned int socklen_t;
|
||||
|
||||
@@ -85,7 +84,7 @@ static const char syslogd_usage[] =
|
||||
"Options:\n"
|
||||
"\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n"
|
||||
"\t-n\t\tRun as a foreground process\n"
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
"\t-K\t\tDo not start up the klogd process\n"
|
||||
#endif
|
||||
"\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n"
|
||||
@@ -316,7 +315,7 @@ static void doSyslogd (void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
|
||||
static void klogd_signal(int sig)
|
||||
{
|
||||
@@ -407,7 +406,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
int pid, klogd_pid;
|
||||
int doFork = TRUE;
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
int startKlogd = TRUE;
|
||||
#endif
|
||||
int stopDoingThat = FALSE;
|
||||
@@ -427,7 +426,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
case 'n':
|
||||
doFork = FALSE;
|
||||
break;
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
case 'K':
|
||||
startKlogd = FALSE;
|
||||
break;
|
||||
@@ -456,7 +455,7 @@ extern int syslogd_main(int argc, char **argv)
|
||||
|
||||
umask(0);
|
||||
|
||||
#ifdef BB_KLOGD
|
||||
#ifdef BB_FEATURE_KLOGD
|
||||
/* Start up the klogd process */
|
||||
if (startKlogd == TRUE) {
|
||||
klogd_pid = fork();
|
||||
|
||||
@@ -198,6 +198,8 @@ extern int tar_main(int argc, char **argv)
|
||||
tarName = *(++argv);
|
||||
if (tarName == NULL)
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
if (!strcmp(tarName, "-"))
|
||||
tostdoutFlag = TRUE;
|
||||
stopIt=TRUE;
|
||||
break;
|
||||
|
||||
@@ -648,7 +650,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
}
|
||||
|
||||
/* Remove any clutter lying in our way */
|
||||
unlink( header.name);
|
||||
if (extractFlag == TRUE) /* .. but only if we are extracting (as */
|
||||
unlink( header.name); /* opposed to listing) (rob@sysgo.de) */
|
||||
|
||||
/* If we got here, we can be certain we have a legitimate
|
||||
* header to work with. So work with it. */
|
||||
@@ -824,12 +827,15 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
||||
|
||||
/* WARNING/NOTICE: I break Hard Links */
|
||||
if (S_ISLNK(statbuf->st_mode)) {
|
||||
int link_size=0;
|
||||
char buffer[BUFSIZ];
|
||||
header.typeflag = SYMTYPE;
|
||||
if ( readlink(fileName, buffer, sizeof(buffer) - 1) < 0) {
|
||||
link_size = readlink(fileName, buffer, sizeof(buffer) - 1);
|
||||
if ( link_size < 0) {
|
||||
errorMsg("Error reading symlink '%s': %s\n", header.name, strerror(errno));
|
||||
return ( FALSE);
|
||||
}
|
||||
buffer[link_size] = '\0';
|
||||
strncpy(header.linkname, buffer, sizeof(header.linkname));
|
||||
} else if (S_ISDIR(statbuf->st_mode)) {
|
||||
header.typeflag = DIRTYPE;
|
||||
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user