Compare commits

...
30 Commits
Author SHA1 Message Date
Erik Andersen 269bba2514 Change BB_FEATURE_USE_DEVPS_N_DEVMTAB to the simpler
BB_FEATURE_USE_DEVPS_PATCH.
 -Erik
2000-03-08 14:50:47 +00:00
Erik Andersen 47d3bb3b6d First edition of my Busybox kernel patch. implements devps, devmtab, and
devmodules.  With this patch, you can enable BB_FEATURE_USE_DEVPS_N_DEVMTAB and
have a completely full featured busybox without having to even compile /proc
into the kernel.  I'm pretty proud of this patch.  It has a few loose ends that
should be filled in sometime, but arn't used by busybox (so they arn't very
important).

 -Erik
2000-03-08 06:52:04 +00:00
Erik Andersen 54969a1f64 Fixed up lsmod so it works with my devmodules kernel driver,
and with /proc.
 -Erik
2000-03-08 06:42:34 +00:00
John Beppu 692a4502b0 + changed a static array (FileList) into a dynamically allocated one
in an attempt to make the .bss section smaller.
2000-03-08 00:14:35 +00:00
Erik Andersen 2ac2fae728 Fix bugs related to finding PIDs.
-Erik
2000-03-07 23:32:17 +00:00
Erik Andersen cbd0d625c7 Fix up some #define stuff to ensure the Right Thing(tm)
happens with all combinations of BB_KILL and BB_KILLALL
being defined.
 -Erik
2000-03-07 07:58:57 +00:00
Erik Andersen 06249f24f3 Add some description
-Erik
2000-03-07 07:48:53 +00:00
Erik Andersen ea6b67de65 Add a #define to make init extra quiet on boot.
-Erik
2000-03-07 07:47:10 +00:00
Erik Andersen 246cc6dddd Wrote killall.
Adjusted mount, ps, utility.c, etc to handle my nifty new kernel
patches the allow busybox to run perfectly without /proc.
 -Erik
2000-03-07 07:41:42 +00:00
Erik Andersen e916d24805 Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a -e)
would go into an infinite loop.
 -Erik
2000-03-06 19:20:35 +00:00
Erik Andersen 9c5c29d442 Oops. I left debugging turned on...
-Erik
2000-03-06 18:34:48 +00:00
Erik Andersen 65fc1c70f7 Oops. Forgot to add in uptime when I added uptime.
Here it is in all its /proc free glory.
 -Erik
2000-03-05 08:16:03 +00:00
Erik Andersen fb002d0df0 Add in tr and dirname
-Erik
2000-03-05 08:07:00 +00:00
Erik Andersen 66be5e7e29 Wrote uptime. Doesn't use /proc. :)
-Erik
2000-03-05 07:52:05 +00:00
Erik Andersen 6437170cb3 Add in freeramdisk.c, which (duh) frees ramdisks. If you have any
ramdisks lying about and want to free up the memory they have used,
this baby is the answar you have been waiting for.
 -Erik
2000-03-04 22:23:27 +00:00
Erik Andersen 029011b9ee A few updates (including the cp fix the Craig has been looking for)
-Erik
2000-03-04 21:19:32 +00:00
Erik Andersen 7c4b2f3fe5 Minor makefile and todo updates
-Erik
2000-02-29 21:49:22 +00:00
Erik Andersen a51ecdd9e4 Minor tweak to argv[0] handling for linuxrc
-Erik
2000-02-24 18:09:58 +00:00
Erik Andersen 5b911ddd57 Fixed rebooting when init runs as /linuxrc
-Erik
2000-02-23 22:49:58 +00:00
John Beppu dc75a739ac + this is a small script for helping TargetWizard auto-generate
busybox.defs.h
2000-02-23 18:17:35 +00:00
Erik Andersen f7c49ef2d1 Sync up a few things. Add in a new telnet implementation (still
not perfect though).
 -Erik
2000-02-22 17:17:45 +00:00
Erik Andersen 3b9522f2af Add in a TODO item,
-Erik
2000-02-22 17:12:00 +00:00
Erik Andersen 6e769df47d Update the changelog
-Erik
2000-02-21 21:35:11 +00:00
Erik Andersen d07ee46919 Removed proc dependancies for init and free (which maintaining exactly
the same functionality).  /proc takes up 90k of kernel space, so it is
nice to avoid using it at all costs.  The only places where it is depended
on is for cetain optional mount/umount features, and for ps and lsmod.
 -Erik
2000-02-21 21:26:32 +00:00
Erik Andersen fa4718efcf Minor update for handling TERM with serial consoles.
-Erik
2000-02-21 19:25:12 +00:00
Erik Andersen 42387e4964 Forgot to add basename. More fixes to du from
Friedrich Vedder <fwv@myrtle.lahn.de>.
 -Erik
2000-02-21 17:27:17 +00:00
Erik Andersen 27fdd081ef Fixed du. Now behaves just like GNU du (only less so).
-Erik
2000-02-19 18:16:49 +00:00
Erik Andersen e272915e1f Some updates for the day,
-Erik
2000-02-18 21:34:17 +00:00
Erik Andersen bf5f009862 Formatting fix
-Erik
2000-02-14 18:44:33 +00:00
John Beppu 08c965a0a1 - I suspect the problem has something to do w/ symlinks.
- It's not completely in agreement w/ GNU/du, but
+ the answer is much closer than before.
- Some of the right-shifts seem to have mysteriously disappeared.
  I put them back in.
2000-02-13 04:10:57 +00:00
79 changed files with 7425 additions and 882 deletions

No files matched your search

+5 -1
View File
@@ -28,6 +28,9 @@ Dave Cinege <dcinege@psychosis.com>
more(v2), makedevs, dutmp, modularization, auto links file,
various fixes, Linux Router Project maintenance
John Lombardo <john@deltanet.com>
dirname, tr
Linus Torvalds <torvalds@transmeta.com>
mkswap, fsck.minix, mkfs.minix
@@ -37,4 +40,5 @@ Charles P. Wright <cpwright@villagenet.com>
Enrique Zanardi <ezanardi@ull.es>
tarcat (since removed), loadkmap, various fixes, Debian maintenance
Karl M. Hegbloom <karlheg@debian.org>
cp_mv.c, the test suite, various fixes to utility.c, &c.
+58 -6
View File
@@ -1,3 +1,55 @@
0.43
* Busybox can now work perfectly when /proc is disabled, thereby
saving a bunch of memory (kernel /proc support is not thin). This
is done by making use of some nice kernel patches I wrote up to
support the features that busybox requires and that /proc usually
provides. To enable this, turn on BB_FEATURE_USE_DEVPS_PATCH and
patch your kernel with the devps patch in the kernel-patches/
directory.
* Wrote basename, killall, and uptime.
* Added freeramdisk, which will free up all memory associated
with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
and then adjusted a bit by me.
* Added tr and dirname from John Lombardo <john@deltanet.com>
* tar wouldn't create directory entries that don't end in '/',
now it does (thanks to Avery Pennarun <apenwarr@worldvisions.ca>)
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
- When `tail' fails to open a file it now exits.
- When `syslogd' is given the `-n' option it should still use
fork() for running klogd.
* nslookup types are now changed to u_int32_t (instead of uint32_t)
changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
* Fixed "du" so it gives the same answers as GNU "du" (busybox du used
to count hard-linked files more then once). Many thanks to
Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
* Removed /proc dependancies for init and free (while maintaining
exactly the same functionality). /proc takes up 90k of kernel
space, so it is nice to avoid using it at all costs.
* init no longer tries to mount /proc (unless there is less the 1 meg
free). Use of /proc (or not) is policy that should be set up in
/etc/fstab (or in hardcoded scripts), not in init.
* Fixed rebooting when init runs as an initrd.
* Fixes and updates from Karl M. Hegbloom <karlheg@debian.org>
- update.c rewritten to look more like update-2.11
- moveed the inode hash out of du.c and into utility.c to make
it a common resource that can be used by other apps.
- cp_mv.c now checks inodes to see if a source and dest are
the same, and prints an error (instead of endlessly looping).
- mv now attempts to do a rename, and will fall back to doing
a copy only if the rename fails.
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
- Fixes to sort. Removed "-g", fixed and added "-r"
- Fixes to the makefile for handling "strip"
* An initial telnet implementation was added by
Randolph Chung <tausq@debian.org>.
* Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
* ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
to match the terminal (defaults to width=79 when this is off).
-Erik Andersen
0.42
* Fairly massive restructuring of umount.c to deal with remounting
@@ -61,8 +113,8 @@
* Fixed a bug where init could have reference already freed memory.
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
* Added (and documented) "-n" option for head - Cleanup for a number of
* usage messages -- also
* Added (and documented) "-n" option for head
* Cleanup for a number of usage messages -- also
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
* Cosmetic fix to busybox.c (Don't print a comma at the
end of line if there are no more application names).
@@ -73,7 +125,7 @@
* Created a tiny tail implementation, removing -c, -q, -v, and making
tail -f work only with a single file. This reduced tail from 6k to
2.4k. The bigger/more featured tail can still be had by disabling
BB_FEATURE_SIMPLE_TAIL in dusybox.defs.h
BB_FEATURE_SIMPLE_TAIL in busybox.defs.h
* Ping now falls back to doing the right thing if /etc/protocols
turns up missing.
* Fixed mount and umount. Previously they could leak loop device
@@ -90,9 +142,9 @@
- added "skip" and "seek" to dd.
- ls no longer messus up output when combining files and
directories on the command line
* swapoff -a was not working. Now it is. init did not cleanly unmount
* filesystems on reboot. Now it does. "sed -ne s/foo/bar/" worked but
* "sed -n -e s/foo/bar/" didn't.
* swapoff -a was not working. Now it is.
* init did not cleanly unmount filesystems on reboot. Now it does.
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't.
Now both work.
* Some architectures (PowerPc) assume chars are unsigned, so they could
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
+5 -5
View File
@@ -18,8 +18,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# PROG := busybox
VERSION := 0.42
PROG := busybox
VERSION := 0.43
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
# Set the following to `true' to make a debuggable build.
@@ -77,7 +77,7 @@ ifeq ($(DODEBUG),true)
else
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS = -s
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
#Only staticly link when _not_ debugging
ifeq ($(DOSTATIC),true)
LDFLAGS += --static
@@ -89,7 +89,7 @@ ifndef $(PREFIX)
endif
LIBRARIES =
OBJECTS = $(shell ./busybox.sh) messages.o utility.o
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
CFLAGS += -DBB_VER='"$(VERSION)"'
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
ifdef BB_INIT_SCRIPT
@@ -101,7 +101,7 @@ all: busybox busybox.links
busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
$(STRIP) $@
$(STRIP)
busybox.links: busybox.def.h
- ./busybox.mkll | sort >$@
+68 -7
View File
@@ -24,25 +24,35 @@ around to it some time. If you have any good ideas, please let me know.
* killall
* stty
* tr
* cut
* expr (maybe?) (ash builtin?)
-----------------------
Compile with debugging on, run 'nm --size-sort ./busybox'
and then start with the biggest things and make them smaller...
Some known bugs, todo items, etc...
-----------------------
[andersen@slag busybox]$ ./busybox du /bin
6213 /bin
[andersen@slag busybox]$ du /bin
2971 /bin
[andersen@slag busybox]$ du --block-size=512 /bin
5943 /bin
busybox.defs.h is too big and hard to follow.
I either need to add a better build system (like the Linux kernel?)
or I need to split up busybox.defs.h into coherent chunks (i.e.
busybox.defs.h just has a bunch of:
#include "fileutils.h"
#include "shellutils.h"
which would then have smaller sets of #defines...
Hmm. Needs to be carefully thought out.
-----------------------
-rw-r--r-- 1000/1000 4398 2000-01-06 21:55 uniq.c
-rw-r--r-- 1000/1000 1568 1999-10-20 18:08 update.c
-rw-r----- 0/1000 1168 2000-01-29 21:03 update.o
@@ -67,3 +77,54 @@ think???)
There is no exclude file(s) option to tar. LRP's packaging system can not
function without this. Will you have the time to add this soon?
-----------------------
cd /mnt
mkdir BACKUP
mv * BACKUP
Today, "mv" behaved as a cp -a and my disk becomed full. It does not
work properly either when renaming a directory into something else
(it produces a lot of disk activity when doing this).
-----------------------
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,
-----------------------
In utility.c:copyFile: It uses followLinks for both source and
destination files... is that right for `mv'? Will need to revisit
the GNU, freeBSD, and MINIX versions for this... Should read the
Unix98 and POSIX specs also.
-----------------------
I think that the add_inode &c in utility.c needs to also stow the
st_dev field, and that du.c should NOT call `reset_inode_list'
because there can be hard links from inside one argv/ to inside
another argv/. du.c probably ought to have an -x switch like GNU du
does also...
+37 -6
View File
@@ -37,6 +37,9 @@ void *__libc_stack_end;
static const struct Applet applets[] = {
#ifdef BB_BASENAME //usr/bin/basename
{"basename", basename_main},
#endif
#ifdef BB_BUSYBOX //bin
{"busybox", busybox_main},
#endif
@@ -73,6 +76,9 @@ static const struct Applet applets[] = {
#ifdef BB_DF //bin
{"df", df_main},
#endif
#ifdef BB_DIRNAME //usr/bin
{"dirname", dirname_main},
#endif
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#endif
@@ -94,6 +100,9 @@ static const struct Applet applets[] = {
#ifdef BB_FREE //usr/bin
{"free", free_main},
#endif
#ifdef BB_FREERAMDISK //sbin
{"freeramdisk", freeramdisk_main},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#endif
@@ -130,6 +139,9 @@ static const struct Applet applets[] = {
#ifdef BB_KILL //bin
{"kill", kill_main},
#endif
#ifdef BB_KILLALL //usr/bin
{"killall", kill_main},
#endif
#ifdef BB_LENGTH //usr/bin
{"length", length_main},
#endif
@@ -246,12 +258,18 @@ static const struct Applet applets[] = {
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_TELNET //usr/bin
{"telnet", telnet_main},
#endif
#ifdef BB_TEE //bin
{"tee", tee_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#endif
#ifdef BB_TR //usr/bin
{"tr", tr_main},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
@@ -259,11 +277,14 @@ static const struct Applet applets[] = {
#ifdef BB_TTY //usr/bin
{"tty", tty_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#ifdef BB_UPTIME //usr/bin
{"uptime", uptime_main},
#endif
#ifdef BB_UNIQ //bin
{"uniq", uniq_main},
@@ -294,15 +315,17 @@ static const struct Applet applets[] = {
int main(int argc, char **argv)
{
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
while (*s != '\0') {
if (*s++ == '/')
name = s;
}
*argv = name;
while (a->name != 0) {
if (strcmp(name, a->name) == 0) {
int status;
@@ -335,7 +358,7 @@ int busybox_main(int argc, char **argv)
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a link to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
@@ -356,3 +379,11 @@ int busybox_main(int argc, char **argv)
return (main(argc, argv));
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+6
View File
@@ -596,6 +596,12 @@ readHeader(const TarHeader * hp, int fileCount, char **fileTable)
*/
if (S_ISDIR(mode)) {
if (createPath(outName, mode) == TRUE) {
/* make the final component, just in case it was
* omitted by createPath() (which will skip the
* directory if it doesn't have a terminating '/')
*/
mkdir(outName, mode);
/* Set the file time */
utb.actime = mtime;
utb.modtime = mtime;
+40
View File
@@ -0,0 +1,40 @@
/* vi: set sw=4 ts=4: */
/*
* Mini basename implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
char* s;
if ((argc < 2) || (**(argv + 1) == '-')) {
usage("basename [file ...]\n");
}
argv++;
s = strrchr(*argv, '/');
printf("%s\n", (s)? s + 1 : *argv);
exit(TRUE);
}
+37 -6
View File
@@ -37,6 +37,9 @@ void *__libc_stack_end;
static const struct Applet applets[] = {
#ifdef BB_BASENAME //usr/bin/basename
{"basename", basename_main},
#endif
#ifdef BB_BUSYBOX //bin
{"busybox", busybox_main},
#endif
@@ -73,6 +76,9 @@ static const struct Applet applets[] = {
#ifdef BB_DF //bin
{"df", df_main},
#endif
#ifdef BB_DIRNAME //usr/bin
{"dirname", dirname_main},
#endif
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#endif
@@ -94,6 +100,9 @@ static const struct Applet applets[] = {
#ifdef BB_FREE //usr/bin
{"free", free_main},
#endif
#ifdef BB_FREERAMDISK //sbin
{"freeramdisk", freeramdisk_main},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#endif
@@ -130,6 +139,9 @@ static const struct Applet applets[] = {
#ifdef BB_KILL //bin
{"kill", kill_main},
#endif
#ifdef BB_KILLALL //usr/bin
{"killall", kill_main},
#endif
#ifdef BB_LENGTH //usr/bin
{"length", length_main},
#endif
@@ -246,12 +258,18 @@ static const struct Applet applets[] = {
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_TELNET //usr/bin
{"telnet", telnet_main},
#endif
#ifdef BB_TEE //bin
{"tee", tee_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#endif
#ifdef BB_TR //usr/bin
{"tr", tr_main},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
@@ -259,11 +277,14 @@ static const struct Applet applets[] = {
#ifdef BB_TTY //usr/bin
{"tty", tty_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#ifdef BB_UPTIME //usr/bin
{"uptime", uptime_main},
#endif
#ifdef BB_UNIQ //bin
{"uniq", uniq_main},
@@ -294,15 +315,17 @@ static const struct Applet applets[] = {
int main(int argc, char **argv)
{
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
while (*s != '\0') {
if (*s++ == '/')
name = s;
}
*argv = name;
while (a->name != 0) {
if (strcmp(name, a->name) == 0) {
int status;
@@ -335,7 +358,7 @@ int busybox_main(int argc, char **argv)
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a link to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
@@ -356,3 +379,11 @@ int busybox_main(int argc, char **argv)
return (main(argc, argv));
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+27 -3
View File
@@ -7,7 +7,7 @@
//
//
// BusyBox Applications
#define BB_BUSYBOX
//#define BB_BASENAME
#define BB_CAT
#define BB_CHMOD_CHOWN_CHGRP
#define BB_CHROOT
@@ -18,6 +18,7 @@
#define BB_DD
#define BB_DEALLOCVT
#define BB_DF
#define BB_DIRNAME
#define BB_DMESG
//#define BB_DUTMP
#define BB_DU
@@ -25,6 +26,7 @@
//#define BB_FDFLUSH
#define BB_FIND
#define BB_FREE
#define BB_FREERAMDISK
#define BB_FSCK_MINIX
#define BB_GREP
#define BB_GUNZIP
@@ -37,6 +39,9 @@
// Don't turn BB_INSMOD on. It doesn't work.
//#define BB_INSMOD
#define BB_KILL
#ifdef BB_KILL
#define BB_KILLALL
#endif
#define BB_KLOGD
//#define BB_LENGTH
#define BB_LN
@@ -46,7 +51,7 @@
//#define BB_LOGGER
#define BB_LOGNAME
#define BB_LS
#define BB_LSMOD
//#define BB_LSMOD
//#define BB_MAKEDEVS
#define BB_MKFS_MINIX
//#define BB_MATH
@@ -80,9 +85,13 @@
#define BB_TAIL
#define BB_TAR
#define BB_TEE
// Don't turn BB_TELNET on. It doesn't work.
#define BB_TELNET
#define BB_TOUCH
#define BB_TR
#define BB_TRUE_FALSE
#define BB_TTY
#define BB_UPTIME
#define BB_WC
#define BB_WHOAMI
#define BB_UMOUNT
@@ -100,8 +109,17 @@
// 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...
//#define BB_FEATURE_USE_DEVPS_PATCH
//
//
// enable features that use the /proc filesystem (apps that
// break without this will tell you on compile)...
// You can't use this and DEVPS_N_DEVMTAB at the same time...
#define BB_FEATURE_USE_PROCFS
//
// Use termios to manipulate the screen ('more' is prettier with this on)
@@ -148,10 +166,16 @@
// Enable support for creation of tar files.
//#define BB_FEATURE_TAR_CREATE
//
//// Enable reverse sort
//#define BB_FEATURE_SORT_REVERSE
//
// Allow init to permenently chroot, and umount the old root fs
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
#ifdef BB_MOUNT
#define BB_FEATURE_INIT_CHROOT
//#define BB_FEATURE_INIT_CHROOT
#endif
//
//Make sure nothing is printed to the console on boot
#define BB_FEATURE_EXTRA_QUIET
+1 -1
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.42
Version: 0.43
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
+8
View File
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
}
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+10 -4
View File
@@ -98,13 +98,11 @@ int chmod_chown_chgrp_main(int argc, char **argv)
char *p;
const char *appUsage;
whichApp =
(strcmp(*argv, "chown") == 0)?
whichApp = (strcmp(*argv, "chown") == 0)?
CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
CHMOD_APP : CHGRP_APP;
appUsage =
(whichApp == CHOWN_APP)?
appUsage = (whichApp == CHOWN_APP)?
chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
if (argc < 2)
@@ -181,3 +179,11 @@ int chmod_chown_chgrp_main(int argc, char **argv)
bad_group:
fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+9
View File
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
*argv, strerror(errno));
exit(FALSE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+9
View File
@@ -34,3 +34,12 @@ int chvt_main(int argc, char **argv)
}
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+9
View File
@@ -34,3 +34,12 @@ int chvt_main(int argc, char **argv)
}
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+40
View File
@@ -0,0 +1,40 @@
/* vi: set sw=4 ts=4: */
/*
* Mini basename implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
char* s;
if ((argc < 2) || (**(argv + 1) == '-')) {
usage("basename [file ...]\n");
}
argv++;
s = strrchr(*argv, '/');
printf("%s\n", (s)? s + 1 : *argv);
exit(TRUE);
}
+8
View File
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
}
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+9
View File
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
*argv, strerror(errno));
exit(FALSE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+8
View File
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+146
View File
@@ -0,0 +1,146 @@
/* vi: set sw=4 ts=4: */
/*
* This is temporary -- needs to be rewritten to be tighter */
/*
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95";
#endif /* not lint */
#endif /* #if 0 */
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void dirname_usage()
{
(void) fprintf(stderr, "usage: dirname path\n");
exit(1);
}
extern int dirname_main(argc, argv)
int argc;
char **argv;
{
char *p;
int ch;
while ((ch = getopt(argc, argv, "")) != -1)
switch (ch) {
case '?':
default:
dirname_usage();
}
argc -= optind;
argv += optind;
if (argc != 1)
dirname_usage();
/*
* (1) If string is //, skip steps (2) through (5).
* (2) If string consists entirely of slash characters, string
* shall be set to a single slash character. In this case,
* skip steps (3) through (8).
*/
for (p = *argv;; ++p) {
if (!*p) {
if (p > *argv)
(void) printf("/\n");
else
(void) printf(".\n");
exit(0);
}
if (*p != '/')
break;
}
/*
* (3) If there are any trailing slash characters in string, they
* shall be removed.
*/
for (; *p; ++p);
while (*--p == '/')
continue;
*++p = '\0';
/*
* (4) If there are no slash characters remaining in string,
* string shall be set to a single period character. In this
* case skip steps (5) through (8).
*
* (5) If there are any trailing nonslash characters in string,
* they shall be removed.
*/
while (--p >= *argv)
if (*p == '/')
break;
++p;
if (p == *argv) {
(void) printf(".\n");
exit(0);
}
/*
* (6) If the remaining string is //, it is implementation defined
* whether steps (7) and (8) are skipped or processed.
*
* This case has already been handled, as part of steps (1) and (2).
*/
/*
* (7) If there are any trailing slash characters in string, they
* shall be removed.
*/
while (--p >= *argv)
if (*p != '/')
break;
++p;
/*
* (8) If the remaining string is empty, string shall be set to
* a single slash character.
*/
*p = '\0';
(void) printf("%s\n", p == *argv ? "/" : *argv);
exit(0);
}
+46 -10
View File
@@ -37,17 +37,21 @@
typedef void (Display) (long, char *);
static const char du_usage[] =
"du [OPTION]... [FILE]...\n\n"
"Summarize disk space used for each FILE and/or directory.\n"
"Disk space is printed in units of 1024 bytes.\n\n"
"Options:\n"
"\t-l\tcount sizes many times if hard linked\n"
"\t-s\tdisplay only a total for each argument\n";
static int du_depth = 0;
static int count_hardlinks = 0;
static Display *print;
static void print_normal(long size, char *filename)
{
fprintf(stdout, "%-7ld %s\n", size, filename);
fprintf(stdout, "%ld\t%s\n", size, filename);
}
static void print_summary(long size, char *filename)
@@ -57,24 +61,26 @@ static void print_summary(long size, char *filename)
}
}
/* tiny recursive du */
static long du(char *filename)
{
struct stat statbuf;
long sum;
int len;
if ((lstat(filename, &statbuf)) != 0) {
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
printf("du: %s: %s\n", filename, strerror(errno));
return 0;
}
du_depth++;
sum = statbuf.st_blocks;
sum = (statbuf.st_blocks >> 1);
/* Don't add in stuff pointed to by links */
/* Don't add in stuff pointed to by symbolic links */
if (S_ISLNK(statbuf.st_mode)) {
return 0;
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
if (S_ISDIR(statbuf.st_mode)) {
DIR *dir;
@@ -82,8 +88,14 @@ static long du(char *filename)
dir = opendir(filename);
if (!dir) {
du_depth--;
return 0;
}
len = strlen(filename);
if (filename[len - 1] == '/')
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[PATH_MAX + 1];
char *name = entry->d_name;
@@ -93,8 +105,9 @@ static long du(char *filename)
continue;
}
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
if (len + strlen(name) + 1 > PATH_MAX) {
fprintf(stderr, name_too_long, "du");
du_depth--;
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
@@ -104,6 +117,17 @@ static long du(char *filename)
closedir(dir);
print(sum, filename);
}
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
/* Add files with hard links only once */
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
else {
add_to_ino_dev_hashtable(&statbuf, NULL);
}
}
du_depth--;
return sum;
}
@@ -124,7 +148,11 @@ int du_main(int argc, char **argv)
case 's':
print = print_summary;
break;
case 'l':
count_hardlinks = 1;
break;
case 'h':
case '-':
usage(du_usage);
break;
default:
@@ -144,13 +172,21 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) {
sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]);
}
reset_ino_dev_hashtable();
}
}
exit(0);
}
/* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */
/* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+8
View File
@@ -128,3 +128,11 @@ extern int ln_main(int argc, char **argv)
}
exit TRUE;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+19 -9
View File
@@ -29,7 +29,18 @@
#include <stdio.h>
#include <errno.h>
static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
static const char sort_usage[] = "sort [-n]"
#ifdef BB_FEATURE_SORT_REVERSE
" [-r]"
#endif
" [FILE]...\n\n";
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
static int reverse = 0;
#else
#define APPLY_REVERSE(x) (x)
#endif
/* typedefs _______________________________________________________________ */
@@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b)
y = *doh;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return strcmp(x->data, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
}
/* numeric order */
@@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b)
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
return (xint - yint);
return APPLY_REVERSE(xint - yint);
}
@@ -254,20 +265,19 @@ int sort_main(int argc, char **argv)
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'g':
/* what's the diff between -g && -n? */
compare = compare_numeric;
break;
case 'h':
usage(sort_usage);
break;
case 'n':
/* what's the diff between -g && -n? */
/* numeric comparison */
compare = compare_numeric;
break;
#ifdef BB_FEATURE_SORT_REVERSE
case 'r':
/* reverse */
reverse = 1;
break;
#endif
default:
fprintf(stderr, "sort: invalid option -- %c\n", opt);
usage(sort_usage);
@@ -310,4 +320,4 @@ int sort_main(int argc, char **argv)
exit(0);
}
/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */
+1 -1
View File
@@ -330,7 +330,7 @@ static int tail_file(const char *filename, off_t n_units)
/* Not standard input. */
fd = open(filename, O_RDONLY);
if (fd == -1)
errorMsg("open error");
fatalError("open error");
errors = tail_lines(filename, fd, (long) n_units);
close(fd);
+9 -2
View File
@@ -23,6 +23,7 @@
*/
#include "internal.h"
#include <errno.h>
#include <stdio.h>
static const char tee_usage[] =
@@ -38,7 +39,7 @@ static const char tee_usage[] =
/* FileList _______________________________________________________________ */
#define FL_MAX 1024
static FILE *FileList[FL_MAX];
static FILE **FileList;
static int FL_end;
typedef void (FL_Function) (FILE * file, char c);
@@ -99,6 +100,11 @@ int tee_main(int argc, char **argv)
}
/* init FILE pointers */
FileList = calloc(FL_MAX, sizeof(FILE*));
if (!FileList) {
fprintf(stderr, "tee: %s\n", strerror(errno));
exit(1);
}
FL_end = 0;
FileList[0] = stdout;
for (; i < argc; i++) {
@@ -119,7 +125,8 @@ int tee_main(int argc, char **argv)
/* clean up */
FL_apply(tee_fclose, 0);
free(FileList);
exit(0);
}
/* $Id: tee.c,v 1.6 2000/02/08 19:58:47 erik Exp $ */
/* $Id: tee.c,v 1.7 2000/03/08 00:14:35 beppu Exp $ */
+578
View File
@@ -0,0 +1,578 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: tr.c,v 1.1 2000/03/05 08:07:00 erik Exp $";
#endif /* not lint */
#endif /* #if 0 */
#include "internal.h"
#include <locale.h>
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <err.h>
#include <stddef.h>
typedef struct {
enum { STRING1, STRING2 } which;
enum { EOS, INFINITE, NORMAL, RANGE, SEQUENCE, SET } state;
int cnt; /* character count */
int lastch; /* last character */
int equiv[2]; /* equivalence set */
int *set; /* set of characters */
char *str; /* user's string */
} STR;
#include <limits.h>
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
static int next __P((STR *));
static int string1[NCHARS] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
}, string2[NCHARS];
STR s1 = { STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
STR s2 = { STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
static void setup(string, arg, str, cflag)
int *string;
char *arg;
STR *str;
int cflag;
{
register int cnt, *p;
str->str = arg;
bzero(string, NCHARS * sizeof(int));
while (next(str))
string[str->lastch] = 1;
if (cflag)
for (p = string, cnt = NCHARS; cnt--; ++p)
*p = !*p;
}
static void tr_usage()
{
(void) fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: tr [-csu] string1 string2",
" tr [-cu] -d string1",
" tr [-cu] -s string1",
" tr [-cu] -ds string1 string2");
exit(1);
}
extern int tr_main(argc, argv)
int argc;
char **argv;
{
register int ch, cnt, lastch, *p;
int cflag, dflag, sflag, isstring2;
(void) setlocale(LC_CTYPE, "");
cflag = dflag = sflag = 0;
while ((ch = getopt(argc, argv, "cdsu")) != -1)
switch ((char) ch) {
case 'c':
cflag = 1;
break;
case 'd':
dflag = 1;
break;
case 's':
sflag = 1;
break;
case 'u':
setbuf(stdout, (char *) NULL);
break;
case '?':
default:
tr_usage();
}
argc -= optind;
argv += optind;
switch (argc) {
case 0:
default:
tr_usage();
/* NOTREACHED */
case 1:
isstring2 = 0;
break;
case 2:
isstring2 = 1;
break;
}
/*
* tr -ds [-c] string1 string2
* Delete all characters (or complemented characters) in string1.
* Squeeze all characters in string2.
*/
if (dflag && sflag) {
if (!isstring2)
tr_usage();
setup(string1, argv[0], &s1, cflag);
setup(string2, argv[1], &s2, 0);
for (lastch = OOBCH; (ch = getchar()) != EOF;)
if (!string1[ch] && (!string2[ch] || lastch != ch)) {
lastch = ch;
(void) putchar(ch);
}
exit(0);
}
/*
* tr -d [-c] string1
* Delete all characters (or complemented characters) in string1.
*/
if (dflag) {
if (isstring2)
tr_usage();
setup(string1, argv[0], &s1, cflag);
while ((ch = getchar()) != EOF)
if (!string1[ch])
(void) putchar(ch);
exit(0);
}
/*
* tr -s [-c] string1
* Squeeze all characters (or complemented characters) in string1.
*/
if (sflag && !isstring2) {
setup(string1, argv[0], &s1, cflag);
for (lastch = OOBCH; (ch = getchar()) != EOF;)
if (!string1[ch] || lastch != ch) {
lastch = ch;
(void) putchar(ch);
}
exit(0);
}
/*
* tr [-cs] string1 string2
* Replace all characters (or complemented characters) in string1 with
* the character in the same position in string2. If the -s option is
* specified, squeeze all the characters in string2.
*/
if (!isstring2)
tr_usage();
s1.str = argv[0];
s2.str = argv[1];
if (cflag)
for (cnt = NCHARS, p = string1; cnt--;)
*p++ = OOBCH;
if (!next(&s2))
errx(1, "empty string2");
/* If string2 runs out of characters, use the last one specified. */
if (sflag)
while (next(&s1)) {
string1[s1.lastch] = ch = s2.lastch;
string2[ch] = 1;
(void) next(&s2);
} else
while (next(&s1)) {
string1[s1.lastch] = ch = s2.lastch;
(void) next(&s2);
}
if (cflag)
for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
*p = *p == OOBCH ? ch : cnt;
if (sflag)
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
ch = string1[ch];
if (!string2[ch] || lastch != ch) {
lastch = ch;
(void) putchar(ch);
}
} else
while ((ch = getchar()) != EOF)
(void) putchar(string1[ch]);
exit(0);
}
static int backslash __P((STR *));
static int bracket __P((STR *));
static int c_class __P((const void *, const void *));
static void genclass __P((STR *));
static void genequiv __P((STR *));
static int genrange __P((STR *));
static void genseq __P((STR *));
static int next(s)
register STR *s;
{
register int ch;
switch (s->state) {
case EOS:
return (0);
case INFINITE:
return (1);
case NORMAL:
switch (ch = (u_char) * s->str) {
case '\0':
s->state = EOS;
return (0);
case '\\':
s->lastch = backslash(s);
break;
case '[':
if (bracket(s))
return (next(s));
/* FALLTHROUGH */
default:
++s->str;
s->lastch = ch;
break;
}
/* We can start a range at any time. */
if (s->str[0] == '-' && genrange(s))
return (next(s));
return (1);
case RANGE:
if (s->cnt-- == 0) {
s->state = NORMAL;
return (next(s));
}
++s->lastch;
return (1);
case SEQUENCE:
if (s->cnt-- == 0) {
s->state = NORMAL;
return (next(s));
}
return (1);
case SET:
if ((s->lastch = s->set[s->cnt++]) == OOBCH) {
s->state = NORMAL;
return (next(s));
}
return (1);
}
/* NOTREACHED */
return (0);
}
static int bracket(s)
register STR *s;
{
register char *p;
switch (s->str[1]) {
case ':': /* "[:class:]" */
if ((p = strstr(s->str + 2, ":]")) == NULL)
return (0);
*p = '\0';
s->str += 2;
genclass(s);
s->str = p + 2;
return (1);
case '=': /* "[=equiv=]" */
if ((p = strstr(s->str + 2, "=]")) == NULL)
return (0);
s->str += 2;
genequiv(s);
return (1);
default: /* "[\###*n]" or "[#*n]" */
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
return (0);
if (p[0] != '*' || index(p, ']') == NULL)
return (0);
s->str += 1;
genseq(s);
return (1);
}
/* NOTREACHED */
}
typedef struct {
char *name;
int (*func) __P((int));
int *set;
} CLASS;
static CLASS classes[] = {
#undef isalnum
{"alnum", isalnum,},
#undef isalpha
{"alpha", isalpha,},
/*#undef isblank
{ "blank", isblank, },*/
#undef iscntrl
{"cntrl", iscntrl,},
#undef isdigit
{"digit", isdigit,},
#undef isgraph
{"graph", isgraph,},
#undef islower
{"lower", islower,},
#undef isprint
{"print", isprint,},
#undef ispunct
{"punct", ispunct,},
#undef isspace
{"space", isspace,},
#undef isupper
{"upper", isupper,},
#undef isxdigit
{"xdigit", isxdigit,},
};
static void genclass(s)
STR *s;
{
register int cnt, (*func) __P((int));
CLASS *cp, tmp;
int *p;
tmp.name = s->str;
if ((cp = (CLASS *) bsearch(&tmp, classes, sizeof(classes) /
sizeof(CLASS), sizeof(CLASS),
c_class)) == NULL) errx(1,
"unknown class %s",
s->str);
if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL)
errx(1, "malloc");
bzero(p, (NCHARS + 1) * sizeof(int));
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
if ((func) (cnt))
*p++ = cnt;
*p = OOBCH;
s->cnt = 0;
s->state = SET;
s->set = cp->set;
}
static int c_class(a, b)
const void *a, *b;
{
return (strcmp(((CLASS *) a)->name, ((CLASS *) b)->name));
}
/*
* English doesn't have any equivalence classes, so for now
* we just syntax check and grab the character.
*/
static void genequiv(s)
STR *s;
{
if (*s->str == '\\') {
s->equiv[0] = backslash(s);
if (*s->str != '=')
errx(1, "misplaced equivalence equals sign");
} else {
s->equiv[0] = s->str[0];
if (s->str[1] != '=')
errx(1, "misplaced equivalence equals sign");
}
s->str += 2;
s->cnt = 0;
s->state = SET;
s->set = s->equiv;
}
static int genrange(s)
STR *s;
{
int stopval;
char *savestart;
savestart = s->str;
stopval = *++s->str == '\\' ? backslash(s) : (u_char) * s->str++;
if (stopval < (u_char) s->lastch) {
s->str = savestart;
return (0);
}
s->cnt = stopval - s->lastch + 1;
s->state = RANGE;
--s->lastch;
return (1);
}
static void genseq(s)
STR *s;
{
char *ep;
if (s->which == STRING1)
errx(1, "sequences only valid in string2");
if (*s->str == '\\')
s->lastch = backslash(s);
else
s->lastch = *s->str++;
if (*s->str != '*')
errx(1, "misplaced sequence asterisk");
switch (*++s->str) {
case '\\':
s->cnt = backslash(s);
break;
case ']':
s->cnt = 0;
++s->str;
break;
default:
if (isdigit((u_char) * s->str)) {
s->cnt = strtol(s->str, &ep, 0);
if (*ep == ']') {
s->str = ep + 1;
break;
}
}
errx(1, "illegal sequence count");
/* NOTREACHED */
}
s->state = s->cnt ? SEQUENCE : INFINITE;
}
/*
* Translate \??? into a character. Up to 3 octal digits, if no digits either
* an escape code or a literal character.
*/
static int backslash(s)
register STR *s;
{
register int ch, cnt, val;
for (cnt = val = 0;;) {
ch = (u_char) * ++s->str;
if (!isascii(ch) || !isdigit(ch))
break;
val = val * 8 + ch - '0';
if (++cnt == 3) {
++s->str;
break;
}
}
if (cnt)
return (val);
if (ch != '\0')
++s->str;
switch (ch) {
case 'a': /* escape characters */
return ('\7');
case 'b':
return ('\b');
case 'f':
return ('\f');
case 'n':
return ('\n');
case 'r':
return ('\r');
case 't':
return ('\t');
case 'v':
return ('\13');
case '\0': /* \" -> \ */
s->state = EOS;
return ('\\');
default: /* \x" -> x */
return (ch);
}
}
+196 -113
View File
@@ -37,11 +37,15 @@
#include <utime.h>
#include <dirent.h>
#include <sys/param.h>
#include <setjmp.h> /* Ok to use this since `ash' does, therefore it's in the libc subset already. */
#include <string.h>
#include <unistd.h>
#include <errno.h>
#define is_cp 0
#define is_mv 1
static int dz_i; /* index into cp_mv_usage */
static const char *dz; /* dollar zero, .bss */
static int dz_i; /* index, .bss */
static const char *cp_mv_usage[] = /* .rodata */
{
"cp [OPTION]... SOURCE DEST\n"
@@ -55,92 +59,131 @@ static const char *cp_mv_usage[] = /* .rodata */
"mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
"Warning!! This is not GNU `mv'. It does not preserve hard links.\n"
};
static int recursiveFlag;
static int followLinks;
static int preserveFlag;
static const char *baseSrcName;
static int srcDirFlag;
static struct stat srcStatBuf;
static char baseDestName[PATH_MAX + 1];
static size_t baseDestLen;
static int destDirFlag;
static struct stat destStatBuf;
static jmp_buf catch;
static volatile int mv_Action_first_time;
static void name_too_long__exit (void) __attribute__((noreturn));
static
void name_too_long__exit (void)
{
fprintf(stderr, name_too_long, dz);
exit FALSE;
}
static void
fill_baseDest_buf(char *_buf, size_t * _buflen) {
const char *srcBasename;
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
srcBasename = baseSrcName;
if (_buf[*_buflen - 1] != '/') {
if (++(*_buflen) > PATH_MAX)
name_too_long__exit();
strcat(_buf, "/");
}
}
if (*_buflen + strlen(srcBasename) > PATH_MAX)
name_too_long__exit();
strcat(_buf, srcBasename);
return;
}
static int
cp_mv_Action(const char *fileName, struct stat *statbuf)
{
char destName[PATH_MAX + 1];
size_t destLen;
const char *srcBasename;
char *name;
strcpy(destName, baseDestName);
destLen = strlen(destName);
if (srcDirFlag == TRUE) {
if (recursiveFlag == FALSE) {
fprintf(stderr, omitting_directory, dz, baseSrcName);
return TRUE;
}
srcBasename = (strstr(fileName, baseSrcName)
+ strlen(baseSrcName));
if (destLen + strlen(srcBasename) > PATH_MAX) {
fprintf(stderr, name_too_long, dz);
return FALSE;
}
strcat(destName, srcBasename);
}
else if (destDirFlag == TRUE) {
fill_baseDest_buf(&destName[0], &destLen);
}
else {
srcBasename = baseSrcName;
}
if (mv_Action_first_time && (dz_i == is_mv)) {
mv_Action_first_time = errno = 0;
if (rename(fileName, destName) < 0 && errno != EXDEV) {
fprintf(stderr, "%s: rename(%s, %s): %s\n",
dz, fileName, destName, strerror(errno));
goto do_copyFile; /* Try anyway... */
}
else if (errno == EXDEV)
goto do_copyFile;
else
longjmp(catch, 1); /* succeeded with rename() */
}
do_copyFile:
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
if (is_in_ino_dev_hashtable(statbuf, &name)) {
if (link(name, destName) < 0) {
fprintf(stderr, "%s: link(%s, %s): %s\n",
dz, name, destName, strerror(errno));
return FALSE;
}
return TRUE;
}
else {
add_to_ino_dev_hashtable(statbuf, destName);
}
}
return copyFile(fileName, destName, preserveFlag, followLinks);
}
static int
rm_Action(const char *fileName, struct stat *statbuf)
{
int status = TRUE;
if (S_ISDIR(statbuf->st_mode)) {
if (rmdir(fileName) < 0) {
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno));
status = FALSE;
}
} else if (unlink(fileName) < 0) {
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno));
status = FALSE;
}
return status;
}
extern int cp_mv_main(int argc, char **argv)
{
__label__ name_too_long__exit;
__label__ exit_false;
int recursiveFlag;
int followLinks;
int preserveFlag;
const char *baseSrcName;
int srcDirFlag;
struct stat srcStatBuf;
char baseDestName[PATH_MAX + 1];
size_t baseDestLen;
int destDirFlag;
struct stat destStatBuf;
void fill_baseDest_buf(char *_buf, size_t * _buflen) {
const char *srcBasename;
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
srcBasename = baseSrcName;
if (_buf[*_buflen - 1] != '/') {
if (++(*_buflen) > PATH_MAX)
goto name_too_long__exit;
strcat(_buf, "/");
}
}
if (*_buflen + strlen(srcBasename) > PATH_MAX)
goto name_too_long__exit;
strcat(_buf, srcBasename);
return;
}
int fileAction(const char *fileName, struct stat *statbuf) {
char destName[PATH_MAX + 1];
size_t destLen;
const char *srcBasename;
strcpy(destName, baseDestName);
destLen = strlen(destName);
if (srcDirFlag == TRUE) {
if (recursiveFlag == FALSE) {
fprintf(stderr, omitting_directory, "cp", baseSrcName);
return TRUE;
}
srcBasename = (strstr(fileName, baseSrcName)
+ strlen(baseSrcName));
if (destLen + strlen(srcBasename) > PATH_MAX) {
fprintf(stderr, name_too_long, "cp");
return FALSE;
}
strcat(destName, srcBasename);
} else if (destDirFlag == TRUE) {
fill_baseDest_buf(&destName[0], &destLen);
} else {
srcBasename = baseSrcName;
}
return copyFile(fileName, destName, preserveFlag, followLinks);
}
int rmfileAction(const char *fileName, struct stat *statbuf) {
if (unlink(fileName) < 0) {
perror(fileName);
return FALSE;
}
return TRUE;
}
int rmdirAction(const char *fileName, struct stat *statbuf) {
if (rmdir(fileName) < 0) {
perror(fileName);
return FALSE;
}
return TRUE;
}
if ((dz = strrchr(*argv, '/')) == NULL)
dz = *argv;
else
dz++;
dz = *argv; /* already basename'd by busybox.c:main */
if (*dz == 'c' && *(dz + 1) == 'p')
dz_i = is_cp;
else
@@ -199,53 +242,93 @@ extern int cp_mv_main(int argc, char **argv)
while (argc-- > 1) {
size_t srcLen;
int flags_memo;
volatile int flags_memo;
int status;
baseSrcName = *(argv++);
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
goto name_too_long__exit;
name_too_long__exit();
if (srcLen == 0)
continue;
if (srcLen == 0) continue; /* "" */
srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
if ((flags_memo = (recursiveFlag == TRUE &&
srcDirFlag == TRUE && destDirFlag == TRUE))) {
if ((destStatBuf.st_ino == srcStatBuf.st_ino) &&
(destStatBuf.st_rdev == srcStatBuf.st_rdev)) {
fprintf(stderr,
"%s: Cannot %s `%s' into a subdirectory of itself, `%s/%s'\n",
dz, dz, baseSrcName, baseDestName, baseSrcName);
continue;
struct stat sb;
int state = 0;
char *pushd, *d, *p;
if ((pushd = getcwd(NULL, PATH_MAX + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
continue;
}
if (chdir(baseDestName) < 0) {
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
continue;
}
if ((d = getcwd(NULL, PATH_MAX + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
continue;
}
while (!state && *d != '\0') {
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno));
state = -1;
continue;
}
if ((sb.st_ino == srcStatBuf.st_ino) &&
(sb.st_dev == srcStatBuf.st_dev)) {
fprintf(stderr,
"%s: Cannot %s `%s' "
"into a subdirectory of itself, `%s/%s'\n",
dz, dz, baseSrcName, baseDestName, baseSrcName);
state = -1;
continue;
}
if ((p = strrchr(d, '/')) != NULL) {
*p = '\0';
}
}
if (chdir(pushd) < 0) {
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno));
free(pushd);
free(d);
continue;
}
free(pushd);
free(d);
if (state < 0)
continue;
else
fill_baseDest_buf(baseDestName, &baseDestLen);
}
if (recursiveAction(baseSrcName,
recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE)
goto exit_false;
if (dz_i == is_mv &&
recursiveAction(baseSrcName,
recursiveFlag, followLinks, TRUE,
rmfileAction, rmdirAction) == FALSE)
goto exit_false;
status = setjmp(catch);
if (status == 0) {
mv_Action_first_time = 1;
if (recursiveAction(baseSrcName,
recursiveFlag, followLinks, FALSE,
cp_mv_Action, cp_mv_Action) == FALSE) goto exit_false;
if (dz_i == is_mv &&
recursiveAction(baseSrcName,
recursiveFlag, followLinks, TRUE,
rm_Action, rm_Action) == FALSE) goto exit_false;
}
if (flags_memo)
*(baseDestName + baseDestLen) = '\0';
}
// exit_true:
exit TRUE;
name_too_long__exit:
fprintf(stderr, name_too_long, "cp");
exit_false:
exit_false:
exit FALSE;
}
// Local Variables:
// c-file-style: "linux"
// tab-width: 4
// End:
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
Executable
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# define.sh - creates an include file full of #defines
#
# SYNOPSIS
#
# define.sh POSIX_ME_HARDER ...
#
# <GPL>
for i ; do
case $1 in
!!*!!)
echo "// #define" `echo $1 | sed 's/^!!\(.*\)!!$/\1/'`
shift
;;
*)
echo "#define $1"
shift
;;
esac
done
# </GPL>
+8
View File
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+146
View File
@@ -0,0 +1,146 @@
/* vi: set sw=4 ts=4: */
/*
* This is temporary -- needs to be rewritten to be tighter */
/*
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95";
#endif /* not lint */
#endif /* #if 0 */
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void dirname_usage()
{
(void) fprintf(stderr, "usage: dirname path\n");
exit(1);
}
extern int dirname_main(argc, argv)
int argc;
char **argv;
{
char *p;
int ch;
while ((ch = getopt(argc, argv, "")) != -1)
switch (ch) {
case '?':
default:
dirname_usage();
}
argc -= optind;
argv += optind;
if (argc != 1)
dirname_usage();
/*
* (1) If string is //, skip steps (2) through (5).
* (2) If string consists entirely of slash characters, string
* shall be set to a single slash character. In this case,
* skip steps (3) through (8).
*/
for (p = *argv;; ++p) {
if (!*p) {
if (p > *argv)
(void) printf("/\n");
else
(void) printf(".\n");
exit(0);
}
if (*p != '/')
break;
}
/*
* (3) If there are any trailing slash characters in string, they
* shall be removed.
*/
for (; *p; ++p);
while (*--p == '/')
continue;
*++p = '\0';
/*
* (4) If there are no slash characters remaining in string,
* string shall be set to a single period character. In this
* case skip steps (5) through (8).
*
* (5) If there are any trailing nonslash characters in string,
* they shall be removed.
*/
while (--p >= *argv)
if (*p == '/')
break;
++p;
if (p == *argv) {
(void) printf(".\n");
exit(0);
}
/*
* (6) If the remaining string is //, it is implementation defined
* whether steps (7) and (8) are skipped or processed.
*
* This case has already been handled, as part of steps (1) and (2).
*/
/*
* (7) If there are any trailing slash characters in string, they
* shall be removed.
*/
while (--p >= *argv)
if (*p != '/')
break;
++p;
/*
* (8) If the remaining string is empty, string shall be set to
* a single slash character.
*/
*p = '\0';
(void) printf("%s\n", p == *argv ? "/" : *argv);
exit(0);
}
+46 -10
View File
@@ -37,17 +37,21 @@
typedef void (Display) (long, char *);
static const char du_usage[] =
"du [OPTION]... [FILE]...\n\n"
"Summarize disk space used for each FILE and/or directory.\n"
"Disk space is printed in units of 1024 bytes.\n\n"
"Options:\n"
"\t-l\tcount sizes many times if hard linked\n"
"\t-s\tdisplay only a total for each argument\n";
static int du_depth = 0;
static int count_hardlinks = 0;
static Display *print;
static void print_normal(long size, char *filename)
{
fprintf(stdout, "%-7ld %s\n", size, filename);
fprintf(stdout, "%ld\t%s\n", size, filename);
}
static void print_summary(long size, char *filename)
@@ -57,24 +61,26 @@ static void print_summary(long size, char *filename)
}
}
/* tiny recursive du */
static long du(char *filename)
{
struct stat statbuf;
long sum;
int len;
if ((lstat(filename, &statbuf)) != 0) {
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
printf("du: %s: %s\n", filename, strerror(errno));
return 0;
}
du_depth++;
sum = statbuf.st_blocks;
sum = (statbuf.st_blocks >> 1);
/* Don't add in stuff pointed to by links */
/* Don't add in stuff pointed to by symbolic links */
if (S_ISLNK(statbuf.st_mode)) {
return 0;
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
if (S_ISDIR(statbuf.st_mode)) {
DIR *dir;
@@ -82,8 +88,14 @@ static long du(char *filename)
dir = opendir(filename);
if (!dir) {
du_depth--;
return 0;
}
len = strlen(filename);
if (filename[len - 1] == '/')
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[PATH_MAX + 1];
char *name = entry->d_name;
@@ -93,8 +105,9 @@ static long du(char *filename)
continue;
}
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
if (len + strlen(name) + 1 > PATH_MAX) {
fprintf(stderr, name_too_long, "du");
du_depth--;
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
@@ -104,6 +117,17 @@ static long du(char *filename)
closedir(dir);
print(sum, filename);
}
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
/* Add files with hard links only once */
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
else {
add_to_ino_dev_hashtable(&statbuf, NULL);
}
}
du_depth--;
return sum;
}
@@ -124,7 +148,11 @@ int du_main(int argc, char **argv)
case 's':
print = print_summary;
break;
case 'l':
count_hardlinks = 1;
break;
case 'h':
case '-':
usage(du_usage);
break;
default:
@@ -144,13 +172,21 @@ int du_main(int argc, char **argv)
for (; i < argc; i++) {
sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]);
}
reset_ino_dev_hashtable();
}
}
exit(0);
}
/* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */
/* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+122 -122
View File
@@ -184,129 +184,129 @@ extern int sed_main(int argc, char **argv)
}
while (argc > 1) {
if (**argv == '-') {
argc--;
cp = *argv++;
stopNow = FALSE;
if (**argv != '-')
usage(sed_usage);
argc--;
cp = *argv++;
stopNow = FALSE;
while (*++cp && stopNow == FALSE) {
switch (*cp) {
case 'n':
quietFlag = TRUE;
break;
case 'e':
if (*(cp + 1) == 0 && --argc < 0) {
usage(sed_usage);
}
if (*++cp != 's')
cp = *argv++;
/* Read address if present */
SKIPSPACES(cp);
if (*cp == '$') {
addr_line = LAST_LINE;
cp++;
} else {
if (isdigit(*cp)) { /* LINE ADDRESS */
line_s = cp;
while (isdigit(*cp))
cp++;
if (cp > line_s) {
/* numeric line */
saved = *cp;
*cp = '\0';
addr_line = atoi(line_s);
*cp = saved;
}
} else if (*cp == '/') { /* PATTERN ADDRESS */
pos = addr_pattern = cp + 1;
pos = strchr(pos, '/');
if (!pos)
usage(sed_usage);
*pos = '\0';
cp = pos + 1;
}
}
SKIPSPACES(cp);
if (*cp == '!') {
negated++;
cp++;
}
/* Read command */
SKIPSPACES(cp);
switch (*cp) {
case 's': /* REPLACE */
if (strlen(cp) <= 3 || *(cp + 1) != '/')
break;
sed_f = f_replace;
pos = needle = cp + 2;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
newNeedle = ++pos;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
if (pos + 2 != 0) {
while (*++pos) {
switch (*pos) {
case 'i':
ignoreCase = TRUE;
break;
case 'p':
printFlag = TRUE;
break;
case 'g':
break;
default:
usage(sed_usage);
}
}
}
cp = pos;
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
break;
case 'a': /* APPEND */
if (strlen(cp) < 2)
break;
sed_f = f_append;
appendline = ++cp;
/* fprintf(stderr, "append '%s'\n", appendline); */
break;
}
stopNow = TRUE;
break;
default:
usage(sed_usage);
}
}
}
while (*++cp && stopNow == FALSE) {
switch (*cp) {
case 'n':
quietFlag = TRUE;
break;
case 'e':
if (*(cp + 1) == 0 && --argc < 0) {
usage(sed_usage);
}
if (*++cp != 's')
cp = *argv++;
/* Read address if present */
SKIPSPACES(cp);
if (*cp == '$') {
addr_line = LAST_LINE;
cp++;
} else {
if (isdigit(*cp)) { /* LINE ADDRESS */
line_s = cp;
while (isdigit(*cp))
cp++;
if (cp > line_s) {
/* numeric line */
saved = *cp;
*cp = '\0';
addr_line = atoi(line_s);
*cp = saved;
}
} else if (*cp == '/') { /* PATTERN ADDRESS */
pos = addr_pattern = cp + 1;
pos = strchr(pos, '/');
if (!pos)
usage(sed_usage);
*pos = '\0';
cp = pos + 1;
}
}
SKIPSPACES(cp);
if (*cp == '!') {
negated++;
cp++;
}
/* Read command */
SKIPSPACES(cp);
switch (*cp) {
case 's': /* REPLACE */
if (strlen(cp) <= 3 || *(cp + 1) != '/')
break;
sed_f = f_replace;
pos = needle = cp + 2;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
newNeedle = ++pos;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
if (pos + 2 != 0) {
while (*++pos) {
switch (*pos) {
case 'i':
ignoreCase = TRUE;
break;
case 'p':
printFlag = TRUE;
break;
case 'g':
break;
default:
usage(sed_usage);
}
}
}
cp = pos;
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
break;
case 'a': /* APPEND */
if (strlen(cp) < 2)
break;
sed_f = f_append;
appendline = ++cp;
/* fprintf(stderr, "append '%s'\n", appendline); */
break;
}
stopNow = TRUE;
break;
default:
usage(sed_usage);
}
}
}
if (argc == 0) {
+1 -1
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.42
Version: 0.43
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
File diff suppressed because it is too large. Load diff
+25 -7
View File
@@ -23,15 +23,33 @@
#include "internal.h"
#include <stdio.h>
#include <sys/sysinfo.h>
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
#define DIVISOR 1024
extern int free_main(int argc, char **argv)
{
char *cmd[] = { "cat", "/proc/meminfo", "\0" };
struct sysinfo info;
sysinfo(&info);
info.totalram/=DIVISOR;
info.freeram/=DIVISOR;
info.totalswap/=DIVISOR;
info.freeswap/=DIVISOR;
info.sharedram/=DIVISOR;
info.bufferram/=DIVISOR;
exit(cat_main(3, cmd));
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
"shared", "buffers");
printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
info.totalram-info.freeram, info.freeram,
info.sharedram, info.bufferram);
printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
info.totalswap-info.freeswap, info.freeswap);
printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
(info.totalram-info.freeram)+(info.totalswap-info.freeswap),
info.freeram+info.freeswap);
exit(TRUE);
}
+69
View File
@@ -0,0 +1,69 @@
/* vi: set sw=4 ts=4: */
/*
* freeramdisk implementation for busybox
*
* Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
* Adjusted a bit by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "internal.h"
static const char freeramdisk_usage[] =
"freeramdisk DEVICE\n\n"
"Frees all memory used by the specified ramdisk.\n";
extern int
freeramdisk_main(int argc, char **argv)
{
char rname[256] = "/dev/ram";
int f;
if (argc >= 2 || ( argv[1] && *argv[1] == '-')) {
usage(freeramdisk_usage);
}
if (argc >1)
strcpy(rname, argv[1]);
if ((f = open(rname, O_RDWR)) == -1) {
fatalError( "freeramdisk: cannot open %s: %s", rname, strerror(errno));
}
if (ioctl(f, BLKFLSBUF) < 0) {
fatalError( "freeramdisk: failed ioctl on %s: %s", rname, strerror(errno));
}
close(f);
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+5 -1
View File
@@ -26,6 +26,10 @@
extern int halt_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGUSR1));
exit(kill(findPidByName("init"), SIGUSR1));
#else
exit(kill(1, SIGUSR1));
#endif
}
+51 -42
View File
@@ -49,15 +49,12 @@
#include <linux/serial.h> /* for serial_struct */
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#include <linux/version.h>
#ifdef BB_SYSLOGD
#include <sys/syslog.h>
#endif
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
@@ -118,7 +115,7 @@ initAction *initActionList = NULL;
static char *secondConsole = VT_SECONDARY;
static char *log = VT_LOG;
static int kernelVersion = 0;
static char termType[32] = "TERM=ansi";
static char termType[32] = "TERM=linux";
static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
@@ -226,25 +223,18 @@ void set_term(int fd)
}
/* How much memory does this machine have? */
static int mem_total()
static int check_free_memory()
{
char s[80];
char *p = "/proc/meminfo";
FILE *f;
const char pattern[] = "MemTotal:";
struct sysinfo info;
if ((f = fopen(p, "r")) < 0) {
message(LOG, "Error opening %s: %s\n", p, strerror(errno));
sysinfo(&info);
if (sysinfo(&info) != 0) {
message(LOG, "Error checking free memory: %s\n", strerror(errno));
return -1;
}
while (NULL != fgets(s, 79, f)) {
p = strstr(s, pattern);
if (NULL != p) {
fclose(f);
return (atoi(p + strlen(pattern)));
}
}
return -1;
return(info.freeram/1024);
}
static void console_init()
@@ -252,6 +242,7 @@ static void console_init()
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
struct vt_stat vt;
struct serial_struct sr;
char *s;
@@ -274,8 +265,6 @@ static void console_init()
}
#endif
else {
struct vt_stat vt;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
@@ -314,6 +303,10 @@ static void console_init()
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
log = NULL;
secondConsole = NULL;
/* Force the TERM setting to vt102 for serial console --
* iff TERM is set to linux (the default) */
if (strcmp( termType, "TERM=linux" ) == 0)
snprintf(termType, sizeof(termType) - 1, "TERM=vt102");
message(LOG | CONSOLE,
"serial console detected. Disabling virtual terminals.\r\n");
}
@@ -343,10 +336,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
if ((pid = fork()) == 0) {
#ifdef DEBUG_INIT
pid_t shell_pgid = getpid();
#endif
/* Clean up */
close(0);
close(1);
@@ -380,8 +369,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
* specifies.
*/
char c;
#ifdef DEBUG_INIT
pid_t shell_pgid = getpid();
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
command, shell_pgid, terminal);
#endif
@@ -450,13 +439,13 @@ static void check_memory()
{
struct stat statBuf;
if (mem_total() > 3500)
if (check_free_memory() > 1000)
return;
if (stat("/etc/fstab", &statBuf) == 0) {
/* Try to turn on swap */
system("/sbin/swapon -a");
if (mem_total() < 3500)
if (check_free_memory() < 1000)
goto goodnight;
} else
goto goodnight;
@@ -551,6 +540,11 @@ static void reboot_signal(int sig)
}
#if defined BB_FEATURE_INIT_CHROOT
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
static void check_chroot(int sig)
{
char *argv_init[2] = { "init", NULL, };
@@ -804,10 +798,16 @@ extern int init_main(int argc, char **argv)
int status;
#ifndef DEBUG_INIT
/* Expect to be PID 1 if we are run as init (not linuxrc) */
if (getpid() != 1 && strstr(argv[0], "init") != NULL) {
usage("init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\n");
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
#ifdef BB_FEATURE_LINUXRC
&& strstr(argv[0], "linuxrc") == NULL
#endif
)
{
usage("init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only "
"by the kernel.\n");
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
@@ -839,23 +839,24 @@ extern int init_main(int argc, char **argv)
/* Hello world */
#ifndef DEBUG_INIT
message(LOG | CONSOLE,
message(
#if ! defined BB_FEATURE_EXTRA_QUIET
CONSOLE|
#endif
LOG,
"init started: BusyBox v%s (%s) multi-call binary\r\n",
BB_VER, BB_BT);
#else
message(LOG | CONSOLE,
message(
#if ! defined BB_FEATURE_EXTRA_QUIET
CONSOLE|
#endif
LOG,
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
getpid(), BB_VER, BB_BT);
#endif
/* Mount /proc */
if (mount("proc", "/proc", "proc", 0, 0) == 0) {
message(LOG | CONSOLE, "Mounting /proc: done.\n");
kernelVersion = get_kernel_revision();
} else
message(LOG | CONSOLE, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
check_memory();
@@ -953,3 +954,11 @@ extern int init_main(int argc, char **argv)
sleep(1);
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+5 -1
View File
@@ -26,6 +26,10 @@
extern int halt_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGUSR1));
exit(kill(findPidByName("init"), SIGUSR1));
#else
exit(kill(1, SIGUSR1));
#endif
}
+51 -42
View File
@@ -49,15 +49,12 @@
#include <linux/serial.h> /* for serial_struct */
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#include <linux/version.h>
#ifdef BB_SYSLOGD
#include <sys/syslog.h>
#endif
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
@@ -118,7 +115,7 @@ initAction *initActionList = NULL;
static char *secondConsole = VT_SECONDARY;
static char *log = VT_LOG;
static int kernelVersion = 0;
static char termType[32] = "TERM=ansi";
static char termType[32] = "TERM=linux";
static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
@@ -226,25 +223,18 @@ void set_term(int fd)
}
/* How much memory does this machine have? */
static int mem_total()
static int check_free_memory()
{
char s[80];
char *p = "/proc/meminfo";
FILE *f;
const char pattern[] = "MemTotal:";
struct sysinfo info;
if ((f = fopen(p, "r")) < 0) {
message(LOG, "Error opening %s: %s\n", p, strerror(errno));
sysinfo(&info);
if (sysinfo(&info) != 0) {
message(LOG, "Error checking free memory: %s\n", strerror(errno));
return -1;
}
while (NULL != fgets(s, 79, f)) {
p = strstr(s, pattern);
if (NULL != p) {
fclose(f);
return (atoi(p + strlen(pattern)));
}
}
return -1;
return(info.freeram/1024);
}
static void console_init()
@@ -252,6 +242,7 @@ static void console_init()
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
struct vt_stat vt;
struct serial_struct sr;
char *s;
@@ -274,8 +265,6 @@ static void console_init()
}
#endif
else {
struct vt_stat vt;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
@@ -314,6 +303,10 @@ static void console_init()
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
log = NULL;
secondConsole = NULL;
/* Force the TERM setting to vt102 for serial console --
* iff TERM is set to linux (the default) */
if (strcmp( termType, "TERM=linux" ) == 0)
snprintf(termType, sizeof(termType) - 1, "TERM=vt102");
message(LOG | CONSOLE,
"serial console detected. Disabling virtual terminals.\r\n");
}
@@ -343,10 +336,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
if ((pid = fork()) == 0) {
#ifdef DEBUG_INIT
pid_t shell_pgid = getpid();
#endif
/* Clean up */
close(0);
close(1);
@@ -380,8 +369,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
* specifies.
*/
char c;
#ifdef DEBUG_INIT
pid_t shell_pgid = getpid();
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
command, shell_pgid, terminal);
#endif
@@ -450,13 +439,13 @@ static void check_memory()
{
struct stat statBuf;
if (mem_total() > 3500)
if (check_free_memory() > 1000)
return;
if (stat("/etc/fstab", &statBuf) == 0) {
/* Try to turn on swap */
system("/sbin/swapon -a");
if (mem_total() < 3500)
if (check_free_memory() < 1000)
goto goodnight;
} else
goto goodnight;
@@ -551,6 +540,11 @@ static void reboot_signal(int sig)
}
#if defined BB_FEATURE_INIT_CHROOT
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
static void check_chroot(int sig)
{
char *argv_init[2] = { "init", NULL, };
@@ -804,10 +798,16 @@ extern int init_main(int argc, char **argv)
int status;
#ifndef DEBUG_INIT
/* Expect to be PID 1 if we are run as init (not linuxrc) */
if (getpid() != 1 && strstr(argv[0], "init") != NULL) {
usage("init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\n");
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
#ifdef BB_FEATURE_LINUXRC
&& strstr(argv[0], "linuxrc") == NULL
#endif
)
{
usage("init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only "
"by the kernel.\n");
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
@@ -839,23 +839,24 @@ extern int init_main(int argc, char **argv)
/* Hello world */
#ifndef DEBUG_INIT
message(LOG | CONSOLE,
message(
#if ! defined BB_FEATURE_EXTRA_QUIET
CONSOLE|
#endif
LOG,
"init started: BusyBox v%s (%s) multi-call binary\r\n",
BB_VER, BB_BT);
#else
message(LOG | CONSOLE,
message(
#if ! defined BB_FEATURE_EXTRA_QUIET
CONSOLE|
#endif
LOG,
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n",
getpid(), BB_VER, BB_BT);
#endif
/* Mount /proc */
if (mount("proc", "/proc", "proc", 0, 0) == 0) {
message(LOG | CONSOLE, "Mounting /proc: done.\n");
kernelVersion = get_kernel_revision();
} else
message(LOG | CONSOLE, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
check_memory();
@@ -953,3 +954,11 @@ extern int init_main(int argc, char **argv)
sleep(1);
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+5 -1
View File
@@ -26,6 +26,10 @@
extern int poweroff_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGUSR2));
exit(kill(findPidByName("init"), SIGUSR2));
#else
exit(kill(1, SIGUSR2));
#endif
}
+13 -1
View File
@@ -26,6 +26,18 @@
extern int reboot_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGINT));
exit(kill(findPidByName("init"), SIGINT));
#else
exit(kill(1, SIGINT));
#endif
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+18 -1
View File
@@ -57,6 +57,7 @@ struct Applet {
int (*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);
@@ -67,6 +68,7 @@ extern int chvt_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
extern int dd_main(int argc, char** argv);
extern int dirname_main(int argc, char** argv);
extern int deallocvt_main(int argc, char** argv);
extern int df_main(int argc, char** argv);
extern int dmesg_main(int argc, char** argv);
@@ -79,6 +81,7 @@ extern int fdflush_main(int argc, char **argv);
extern int fsck_minix_main(int argc, char **argv);
extern int find_main(int argc, char** argv);
extern int free_main(int argc, char** argv);
extern int freeramdisk_main(int argc, char** argv);
extern int grep_main(int argc, char** argv);
extern int gunzip_main (int argc, char** argv);
extern int gzip_main(int argc, char** argv);
@@ -130,13 +133,16 @@ extern int syslogd_main(int argc, char **argv);
extern int tail_main(int argc, char** argv);
extern int tar_main(int argc, char** argv);
extern int tee_main(int argc, char** argv);
extern int telnet_main(int argc, char** argv);
extern int touch_main(int argc, char** argv);
extern int tr_main(int argc, char** argv);
extern int true_main(int argc, char** argv);
extern int tput_main(int argc, char** argv);
extern int tryopen_main(int argc, char** argv);
extern int tty_main(int argc, char** argv);
extern int umount_main(int argc, char** argv);
extern int uname_main(int argc, char** argv);
extern int uptime_main(int argc, char** argv);
extern int uniq_main(int argc, char** argv);
extern int update_main(int argc, char** argv);
extern int wc_main(int argc, char** argv);
@@ -152,6 +158,17 @@ const char *modeString(int mode);
const char *timeString(time_t timeVal);
int isDirectory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name);
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
char name[1];
} ino_dev_hashtable_bucket_t;
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
int copyFile(const char *srcName, const char *destName, int setModes,
int followLinks);
char *buildName(const char *dirName, const char *fileName);
@@ -186,7 +203,7 @@ extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern);
extern long getNum (const char *cp);
extern pid_t findInitPid();
extern pid_t findPidByName( char* pidName);
extern void *xmalloc (size_t size);
#if defined BB_INIT || defined BB_SYSLOGD
extern int device_open(char *device, int mode);
+40 -23
View File
@@ -24,6 +24,7 @@
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
@@ -35,6 +36,14 @@ static const char *kill_usage =
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
static const char *killall_usage =
"killall [-signal] process-name [process-name ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
#define KILL 0
#define KILLALL 1
struct signal_name {
const char *name;
@@ -120,13 +129,19 @@ const struct signal_name signames[] = {
extern int kill_main(int argc, char **argv)
{
int sig = SIGTERM;
int whichApp, sig = SIGTERM;
const char *appUsage;
/* Figure out what we are trying to do here */
whichApp = (strcmp(*argv, "killall") == 0)?
KILLALL : KILL;
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
argc--;
argv++;
/* Parse any options */
if (argc < 1)
usage(kill_usage);
usage(appUsage);
while (argc > 0 && **argv == '-') {
while (*++(*argv)) {
@@ -150,7 +165,7 @@ extern int kill_main(int argc, char **argv)
}
break;
case '-':
usage(kill_usage);
usage(appUsage);
default:
{
if (isdigit(**argv)) {
@@ -186,32 +201,34 @@ extern int kill_main(int argc, char **argv)
do_it_now:
while (--argc >= 0) {
int pid;
struct stat statbuf;
char pidpath[20] = "/proc/";
if (whichApp == KILL) {
/* Looks like they want to do a kill. Do that */
while (--argc >= 0) {
int pid;
if (!isdigit(**argv)) {
fprintf(stderr, "bad PID: %s\n", *argv);
exit(FALSE);
if (!isdigit(**argv))
fatalError( "Bad PID: %s\n", strerror(errno));
pid = strtol(*argv, NULL, 0);
if (kill(pid, sig) != 0)
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
argv++;
}
pid = atoi(*argv);
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
if (stat(pidpath, &statbuf) != 0) {
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
exit(FALSE);
} else {
/* Looks like they want to do a killall. Do that */
while (--argc >= 0) {
int pid;
while((pid = findPidByName( *argv))) {
if (kill(pid, sig) != 0)
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
}
argv++;
}
fprintf(stderr, "sig = %d\n", sig);
if (kill(pid, sig) != 0) {
perror(*argv);
exit(FALSE);
}
argv++;
}
exit(TRUE);
end:
fprintf(stderr, "bad signal name: %s\n", *argv);
exit(TRUE);
fatalError( "bad signal name: %s\n", *argv);
}
+8
View File
@@ -128,3 +128,11 @@ extern int ln_main(int argc, char **argv)
}
exit TRUE;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+6 -3
View File
@@ -25,13 +25,16 @@
#include <stdio.h>
extern int lsmod_main(int argc, char **argv)
{
#if defined BB_FEATURE_USE_DEVPS_PATCH
char *cmd[] = { "cat", "/dev/modules", "\0" };
#else
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
extern int lsmod_main(int argc, char **argv)
{
char *cmd[] = { "cat", "/proc/modules", "\0" };
#endif
exit(cat_main(3, cmd));
}
+66 -20
View File
@@ -1,9 +1,11 @@
/* vi: set sw=4 ts=4: */
/*
* Mini update implementation for busybox
* Mini update implementation for busybox; much pasted from update-2.11
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Copyright (c) 1996, 1997, 1999 Torsten Poulin.
* Copyright (c) 2000 by Karl M. Hegbloom <karlheg@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +25,8 @@
#include "internal.h"
#include <linux/unistd.h>
#include <sys/param.h>
#include <sys/syslog.h>
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
@@ -30,37 +34,79 @@
_syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
static char update_usage[] =
"update [options]\n"
" -S\tforce use of sync(2) instead of flushing\n"
" -s SECS\tcall sync this often (default 30)\n"
" -f SECS\tflush some buffers this often (default 5)\n";
static unsigned int sync_duration = 30;
static unsigned int flush_duration = 5;
static int use_sync = 0;
extern int update_main(int argc, char **argv)
{
/*
* Update is actually two daemons, bdflush and update.
*/
int pid;
while (**argv == '-') {
while (*++(*argv)) {
switch (**argv) {
case 'S':
use_sync = 1;
break;
case 's':
if (--argc < 1) usage(update_usage);
sync_duration = atoi(*(++argv));
break;
case 'f':
if (--argc < 1) usage(update_usage);
flush_duration = atoi(*(++argv));
break;
}
}
argc--;
argv++;
}
pid = fork();
if (pid < 0)
return pid;
exit(FALSE);
else if (pid == 0) {
/* Become a proper daemon */
setsid();
chdir("/");
for (pid = 0; pid < OPEN_MAX; pid++) close(pid);
/*
* This is no longer necessary since 1.3.5x, but it will harmlessly
* exit if that is the case.
*/
strcpy(argv[0], "bdflush (update)");
argv[1] = 0;
argv[2] = 0;
bdflush(1, 0);
_exit(0);
}
pid = fork();
if (pid < 0)
return pid;
else if (pid == 0) {
argv[0] = "update";
argv[0] = "bdflush (update)";
argv[1] = NULL;
argv[2] = NULL;
for (;;) {
sync();
sleep(30);
if (use_sync) {
sleep(sync_duration);
sync();
} else {
sleep(flush_duration);
if (bdflush(1, 0) < 0) {
openlog("update", LOG_CONS, LOG_DAEMON);
syslog(LOG_INFO,
"This kernel does not need update(8). Exiting.");
closelog();
exit(TRUE);
}
}
}
}
return 0;
return TRUE;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+6 -3
View File
@@ -25,13 +25,16 @@
#include <stdio.h>
extern int lsmod_main(int argc, char **argv)
{
#if defined BB_FEATURE_USE_DEVPS_PATCH
char *cmd[] = { "cat", "/dev/modules", "\0" };
#else
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
extern int lsmod_main(int argc, char **argv)
{
char *cmd[] = { "cat", "/proc/modules", "\0" };
#endif
exit(cat_main(3, cmd));
}
+79 -7
View File
@@ -46,6 +46,10 @@
#include <sys/mount.h>
#include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h>
#endif
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
@@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
{
int status = 0;
char buf[255];
#if defined BB_FEATURE_USE_PROCFS
char buf[255];
if (strcmp(filesystemType, "auto") == 0) {
FILE *f = fopen("/proc/filesystems", "r");
@@ -251,6 +254,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
}
fclose(f);
} else
#endif
#if defined BB_FEATURE_USE_DEVPS_PATCH
if (strcmp(filesystemType, "auto") == 0) {
int fd, i, numfilesystems;
char device[] = "/dev/mtab";
struct k_fstype *fslist;
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError("open failed for `%s': %s\n", device, strerror (errno));
/* How many filesystems? We need to know to allocate enough space */
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
if (status<0)
fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno));
/* Walk the list trying to mount filesystems
* that do not claim to be nodev filesystems */
for( i = 0 ; i < numfilesystems ; i++) {
if (fslist[i].mnt_nodev)
continue;
status = do_mount(blockDevice, directory, fslist[i].mnt_type,
flags | MS_MGC_VAL, string_flags,
useMtab, fakeIt, mtab_opts);
if (status == TRUE)
break;
}
free( fslist);
close(fd);
} else
#endif
{
status = do_mount(blockDevice, directory, filesystemType,
@@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv)
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
#if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) {
int fd, i, numfilesystems;
char device[] = "/dev/mtab";
struct k_mntent *mntentlist;
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError("open failed for `%s': %s\n", device, strerror (errno));
/* How many mounted filesystems? We need to know to
* allocate enough space for later... */
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno));
for( i = 0 ; i < numfilesystems ; i++) {
fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
mntentlist[i].mnt_passno);
}
free( mntentlist);
close(fd);
exit(TRUE);
}
#else
if (argc == 1) {
FILE *mountTable = setmntent(mtab_file, "r");
@@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv)
}
exit(TRUE);
}
#endif
/* Parse options */
i = --argc;
@@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv)
struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r");
if (f == NULL) {
perror("/etc/fstab");
exit(FALSE);
}
if (f == NULL)
fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto,
// and isn't swap or nfs, then mount it
+8 -8
View File
@@ -58,9 +58,9 @@ static void server_fprint(FILE * dst)
/* only works for IPv4 */
static int addr_fprint(char *addr, FILE * dst)
{
uint8_t split[4];
uint32_t ip;
uint32_t *x = (uint32_t *) addr;
u_int8_t split[4];
u_int32_t ip;
u_int32_t *x = (u_int32_t *) addr;
ip = ntohl(*x);
split[0] = (ip & 0xff000000) >> 24;
@@ -73,12 +73,12 @@ static int addr_fprint(char *addr, FILE * dst)
}
/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
* into a uint32_t
* into a u_int32_t
*/
static uint32_t str_to_addr(const char *addr)
static u_int32_t str_to_addr(const char *addr)
{
uint32_t split[4];
uint32_t ip;
u_int32_t split[4];
u_int32_t ip;
sscanf(addr, "%d.%d.%d.%d",
&split[0], &split[1], &split[2], &split[3]);
@@ -174,4 +174,4 @@ int nslookup_main(int argc, char **argv)
return 0;
}
/* $Id: nslookup.c,v 1.4 2000/02/08 19:58:47 erik Exp $ */
/* $Id: nslookup.c,v 1.5 2000/02/18 21:34:17 erik Exp $ */
+503
View File
@@ -0,0 +1,503 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: telnet.c,v 1.1 2000/02/22 17:17:45 erik Exp $
* Mini telnet implementation for busybox
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This version of telnet is adapted (but very heavily modified) from the
* telnet in netkit-telnet 0.16, which is:
*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Original copyright notice is retained at the end of this file.
*/
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <netdb.h>
#include <termios.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#define TELOPTS
#include <arpa/telnet.h>
#include <arpa/inet.h>
static int STDIN = 0;
static int STDOUT = 1;
static const char *telnet_usage = "telnet host [port]\n\n";
static struct termios saved_tc;
static unsigned char options[NTELOPTS];
static char tr_state = 0; /* telnet send and receive state */
static unsigned char subbuffer[256];
static unsigned char *subpointer, *subend;
#define SB_CLEAR() subpointer = subbuffer;
#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { *subpointer++ = (c); }
#define SB_GET() (*subpointer++)
#define SB_PEEK() (*subpointer)
#define SB_EOF() (subpointer >= subend)
#define SB_LEN() (subend - subpointer)
#define TELNETPORT 23
#define MASK_WILL 0x01
#define MASK_WONT 0x04
#define MASK_DO 0x10
#define MASK_DONT 0x40
#define TFLAG_ISSET(opt, flag) (options[opt] & MASK_##flag)
#define TFLAG_SET(opt, flag) (options[opt] |= MASK_##flag)
#define TFLAG_CLR(opt, flag) (options[opt] &= ~MASK_##flag)
#define PERROR(ctx) do { fprintf(stderr, "%s: %s\n", ctx, strerror(errno)); \
return; } while (0)
#define TS_DATA 0
#define TS_IAC 1
#define TS_WILL 2
#define TS_WONT 3
#define TS_DO 4
#define TS_DONT 5
#define TS_CR 6
#define TS_SB 7 /* sub-option collection */
#define TS_SE 8 /* looking for sub-option end */
/* prototypes */
static void telnet_init(void);
static void telnet_start(char *host, int port);
static void telnet_shutdown(void);
/* ******************************************************************* */
#define SENDCOMMAND(c,o) \
char buf[3]; \
buf[0] = IAC; buf[1] = c; buf[2] = o; \
write(s, buf, sizeof(buf));
static inline void telnet_sendwill(int s, int c) { SENDCOMMAND(WILL, c); }
static inline void telnet_sendwont(int s, int c) { SENDCOMMAND(WONT, c); }
static inline void telnet_senddo(int s, int c) { SENDCOMMAND(DO, c); }
static inline void telnet_senddont(int s, int c) { SENDCOMMAND(DONT, c); }
static void telnet_setoptions(int s)
{
/*
telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO);
telnet_sendwill(s, TELOPT_NAWS); TFLAG_SET(TELOPT_NAWS, WILL);
telnet_sendwill(s, TELOPT_TSPEED); TFLAG_SET(TELOPT_TSPEED, WILL);
telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL);
telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL);
telnet_sendwill(s, TELOPT_NEW_ENVIRON); TFLAG_SET(TELOPT_NEW_ENVIRON, WILL);
telnet_senddo(s, TELOPT_STATUS); TFLAG_SET(TELOPT_STATUS, DO);
telnet_sendwill(s, TELOPT_TTYPE); TFLAG_SET(TELOPT_TTYPE, WILL);
*/
telnet_senddo(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, DO);
telnet_sendwill(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, WILL);
}
static void telnet_suboptions(int net)
{
char buf[256];
switch (SB_GET()) {
case TELOPT_TTYPE:
if (TFLAG_ISSET(TELOPT_TTYPE, WONT)) return;
if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
return;
} else {
const char *name = getenv("TERM");
if (name) {
snprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c", IAC, SB,
TELOPT_TTYPE, TELQUAL_IS, name, IAC, SE);
write(net, buf, strlen(name)+6);
}
}
break;
case TELOPT_TSPEED:
if (TFLAG_ISSET(TELOPT_TSPEED, WONT)) return;
if (SB_EOF()) return;
if (SB_GET() == TELQUAL_SEND) {
/*
long oospeed, iispeed;
netoring.printf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
TELQUAL_IS, oospeed, iispeed, IAC, SE);
*/
}
break;
/*
case TELOPT_LFLOW:
if (TFLAG_ISSET(TELOPT_LFLOW, WONT)) return;
if (SB_EOF()) return;
switch(SB_GET()) {
case 1: localflow = 1; break;
case 0: localflow = 0; break;
default: return;
}
break;
case TELOPT_LINEMODE:
if (TFLAG_ISSET(TELOPT_LINEMODE, WONT)) return;
if (SB_EOF()) return;
switch (SB_GET()) {
case WILL: lm_will(subpointer, SB_LEN()); break;
case WONT: lm_wont(subpointer, SB_LEN()); break;
case DO: lm_do(subpointer, SB_LEN()); break;
case DONT: lm_dont(subpointer, SB_LEN()); break;
case LM_SLC: slc(subpointer, SB_LEN()); break;
case LM_MODE: lm_mode(subpointer, SB_LEN(), 0); break;
default: break;
}
break;
case TELOPT_ENVIRON:
if (SB_EOF()) return;
switch(SB_PEEK()) {
case TELQUAL_IS:
case TELQUAL_INFO:
if (TFLAG_ISSET(TELOPT_ENVIRON, DONT)) return;
break;
case TELQUAL_SEND:
if (TFLAG_ISSET(TELOPT_ENVIRON, WONT)) return;
break;
default:
return;
}
env_opt(subpointer, SB_LEN());
break;
*/
case TELOPT_XDISPLOC:
if (TFLAG_ISSET(TELOPT_XDISPLOC, WONT)) return;
if (SB_EOF()) return;
if (SB_GET() == TELQUAL_SEND) {
const char *dp = getenv("DISPLAY");
if (dp) {
snprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c", IAC, SB,
TELOPT_XDISPLOC, TELQUAL_IS, dp, IAC, SE);
write(net, buf, strlen(dp)+6);
}
}
break;
default:
break;
}
}
static void sighandler(int sig)
{
telnet_shutdown();
exit(0);
}
static int telnet_send(int tty, int net)
{
int ret;
unsigned char ch;
while ((ret = read(tty, &ch, 1)) > 0) {
if (ch == 29) { /* 29 -- ctrl-] */
/* do something here? */
exit(0);
} else {
ret = write(net, &ch, 1);
break;
}
}
if (ret == -1 && errno == EWOULDBLOCK) return 1;
return ret;
}
static int telnet_recv(int net, int tty)
{
/* globals: tr_state - telnet receive state */
int ret, c = 0;
unsigned char ch;
while ((ret = read(net, &ch, 1)) > 0) {
c = ch;
/* printf("%02X ", c); fflush(stdout); */
switch (tr_state) {
case TS_DATA:
if (c == IAC) {
tr_state = TS_IAC;
break;
} else {
write(tty, &c, 1);
}
break;
case TS_IAC:
switch (c) {
case WILL:
tr_state = TS_WILL; break;
case WONT:
tr_state = TS_WONT; break;
case DO:
tr_state = TS_DO; break;
case DONT:
tr_state = TS_DONT; break;
case SB:
SB_CLEAR();
tr_state = TS_SB; break;
case IAC:
write(tty, &c, 1); /* fallthrough */
default:
tr_state = TS_DATA;
}
/* subnegotiation -- ignored for now */
case TS_SB:
if (c == IAC) tr_state = TS_SE;
else SB_ACCUM(c);
break;
case TS_SE:
if (c == IAC) {
SB_ACCUM(IAC);
tr_state = TS_SB;
} else if (c == SE) {
SB_ACCUM(IAC);
SB_ACCUM(SE);
subpointer -= 2;
SB_TERM();
telnet_suboptions(net);
tr_state = TS_DATA;
}
/* otherwise this is an error, but we ignore it for now */
break;
/* handle incoming requests */
case TS_WILL:
printf("WILL %s\n", telopts[c]);
if (!TFLAG_ISSET(c, DO)) {
if (c == TELOPT_BINARY) {
TFLAG_SET(c, DO);
TFLAG_CLR(c, DONT);
telnet_senddo(net, c);
} else {
TFLAG_SET(c, DONT);
telnet_senddont(net, c);
}
}
telnet_senddont(net, c);
tr_state = TS_DATA;
break;
case TS_WONT:
printf("WONT %s\n", telopts[c]);
if (!TFLAG_ISSET(c, DONT)) {
TFLAG_SET(c, DONT);
TFLAG_CLR(c, DO);
telnet_senddont(net, c);
}
tr_state = TS_DATA;
break;
case TS_DO:
printf("DO %s\n", telopts[c]);
if (!TFLAG_ISSET(c, WILL)) {
if (c == TELOPT_BINARY) {
TFLAG_SET(c, WILL);
TFLAG_CLR(c, WONT);
telnet_sendwill(net, c);
} else {
TFLAG_SET(c, WONT);
telnet_sendwont(net, c);
}
}
tr_state = TS_DATA;
break;
case TS_DONT:
printf("DONT %s\n", telopts[c]);
if (!TFLAG_ISSET(c, WONT)) {
TFLAG_SET(c, WONT);
TFLAG_CLR(c, WILL);
telnet_sendwont(net, c);
}
tr_state = TS_DATA;
break;
}
}
if (ret == -1 && errno == EWOULDBLOCK) return 1;
return ret;
}
/* ******************************************************************* */
static void telnet_init(void)
{
struct termios tmp_tc;
cc_t esc = (']' & 0x1f); /* ctrl-] */
memset(options, 0, sizeof(options));
SB_CLEAR();
tcgetattr(STDIN, &saved_tc);
tmp_tc = saved_tc;
tmp_tc.c_lflag &= ~ECHO; /* echo */
tmp_tc.c_oflag |= ONLCR; /* NL->CRLF translation */
tmp_tc.c_iflag |= ICRNL;
tmp_tc.c_iflag &= ~(IXANY|IXOFF|IXON); /* no flow control */
tmp_tc.c_lflag |= ISIG; /* trap signals */
tmp_tc.c_lflag &= ~ICANON; /* edit mode */
/* misc settings, compat with default telnet stuff */
tmp_tc.c_oflag &= ~TABDLY;
/* 8-bit clean */
tmp_tc.c_iflag &= ~ISTRIP;
tmp_tc.c_cflag &= ~(CSIZE|PARENB);
tmp_tc.c_cflag |= saved_tc.c_cflag & (CSIZE|PARENB);
tmp_tc.c_oflag |= OPOST;
/* set escape character */
tmp_tc.c_cc[VEOL] = esc;
tcsetattr(STDIN, TCSADRAIN, &tmp_tc);
}
static void telnet_start(char *hostname, int port)
{
struct hostent *host = 0;
struct sockaddr_in addr;
int s, c;
fd_set rfds, wfds;
memset(&addr, 0, sizeof(addr));
host = gethostbyname(hostname);
if (!host) {
fprintf(stderr, "Unknown host: %s\n", hostname);
return;
}
addr.sin_family = host->h_addrtype;
memcpy(&addr.sin_addr, host->h_addr, sizeof(addr.sin_addr));
addr.sin_port = htons(port);
printf("Trying %s...\n", inet_ntoa(addr.sin_addr));
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) PERROR("socket");
if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
PERROR("connect");
printf("Connected to %s\n", hostname);
printf("Escape character is ^]\n");
signal(SIGINT, sighandler);
signal(SIGQUIT, sighandler);
signal(SIGPIPE, sighandler);
signal(SIGWINCH, sighandler);
/* make inputs nonblocking */
c = 1;
ioctl(s, FIONBIO, &c);
ioctl(STDIN, FIONBIO, &c);
if (port == TELNETPORT) telnet_setoptions(s);
/* shuttle data back and forth between tty and socket */
while (1) {
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(s, &rfds);
/* FD_SET(s, &wfds); */
FD_SET(STDIN, &rfds);
/* FD_SET(STDOUT, &wfds); */
if ((c = select(s+1, &rfds, &wfds, 0, 0))) {
if (c == -1) {
/* handle errors */
PERROR("select");
}
if (FD_ISSET(s, &rfds)) {
/* input from network */
FD_CLR(s, &rfds);
c = telnet_recv(s, STDOUT);
if (c == 0) break;
if (c < 0) PERROR("telnet_recv");
}
if (FD_ISSET(STDIN, &rfds)) {
/* input from tty */
FD_CLR(STDIN, &rfds);
c = telnet_send(STDIN, s);
if (c == 0) break;
if (c < 0) PERROR("telnet_send");
}
}
}
return;
}
static void telnet_shutdown(void)
{
printf("\n");
tcsetattr(STDIN, TCSANOW, &saved_tc);
}
#ifdef STANDALONE_TELNET
void usage(const char *msg)
{
printf("%s", msg);
exit(0);
}
int main(int argc, char **argv)
#else
int telnet_main(int argc, char **argv)
#endif
{
int port = TELNETPORT;
argc--; argv++;
if (argc < 1) usage(telnet_usage);
if (argc > 1) port = atoi(argv[1]);
telnet_init();
atexit(telnet_shutdown);
telnet_start(argv[0], port);
return 0;
}
/*
* Copyright (c) 1988, 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+8 -8
View File
@@ -58,9 +58,9 @@ static void server_fprint(FILE * dst)
/* only works for IPv4 */
static int addr_fprint(char *addr, FILE * dst)
{
uint8_t split[4];
uint32_t ip;
uint32_t *x = (uint32_t *) addr;
u_int8_t split[4];
u_int32_t ip;
u_int32_t *x = (u_int32_t *) addr;
ip = ntohl(*x);
split[0] = (ip & 0xff000000) >> 24;
@@ -73,12 +73,12 @@ static int addr_fprint(char *addr, FILE * dst)
}
/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
* into a uint32_t
* into a u_int32_t
*/
static uint32_t str_to_addr(const char *addr)
static u_int32_t str_to_addr(const char *addr)
{
uint32_t split[4];
uint32_t ip;
u_int32_t split[4];
u_int32_t ip;
sscanf(addr, "%d.%d.%d.%d",
&split[0], &split[1], &split[2], &split[3]);
@@ -174,4 +174,4 @@ int nslookup_main(int argc, char **argv)
return 0;
}
/* $Id: nslookup.c,v 1.4 2000/02/08 19:58:47 erik Exp $ */
/* $Id: nslookup.c,v 1.5 2000/02/18 21:34:17 erik Exp $ */
+5 -1
View File
@@ -26,6 +26,10 @@
extern int poweroff_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGUSR2));
exit(kill(findPidByName("init"), SIGUSR2));
#else
exit(kill(1, SIGUSR2));
#endif
}
+25 -7
View File
@@ -23,15 +23,33 @@
#include "internal.h"
#include <stdio.h>
#include <sys/sysinfo.h>
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
#define DIVISOR 1024
extern int free_main(int argc, char **argv)
{
char *cmd[] = { "cat", "/proc/meminfo", "\0" };
struct sysinfo info;
sysinfo(&info);
info.totalram/=DIVISOR;
info.freeram/=DIVISOR;
info.totalswap/=DIVISOR;
info.freeswap/=DIVISOR;
info.sharedram/=DIVISOR;
info.bufferram/=DIVISOR;
exit(cat_main(3, cmd));
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
"shared", "buffers");
printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
info.totalram-info.freeram, info.freeram,
info.sharedram, info.bufferram);
printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
info.totalswap-info.freeswap, info.freeswap);
printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
(info.totalram-info.freeram)+(info.totalswap-info.freeswap),
info.freeram+info.freeswap);
exit(TRUE);
}
+40 -23
View File
@@ -24,6 +24,7 @@
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
@@ -35,6 +36,14 @@ static const char *kill_usage =
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
static const char *killall_usage =
"killall [-signal] process-name [process-name ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
#define KILL 0
#define KILLALL 1
struct signal_name {
const char *name;
@@ -120,13 +129,19 @@ const struct signal_name signames[] = {
extern int kill_main(int argc, char **argv)
{
int sig = SIGTERM;
int whichApp, sig = SIGTERM;
const char *appUsage;
/* Figure out what we are trying to do here */
whichApp = (strcmp(*argv, "killall") == 0)?
KILLALL : KILL;
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
argc--;
argv++;
/* Parse any options */
if (argc < 1)
usage(kill_usage);
usage(appUsage);
while (argc > 0 && **argv == '-') {
while (*++(*argv)) {
@@ -150,7 +165,7 @@ extern int kill_main(int argc, char **argv)
}
break;
case '-':
usage(kill_usage);
usage(appUsage);
default:
{
if (isdigit(**argv)) {
@@ -186,32 +201,34 @@ extern int kill_main(int argc, char **argv)
do_it_now:
while (--argc >= 0) {
int pid;
struct stat statbuf;
char pidpath[20] = "/proc/";
if (whichApp == KILL) {
/* Looks like they want to do a kill. Do that */
while (--argc >= 0) {
int pid;
if (!isdigit(**argv)) {
fprintf(stderr, "bad PID: %s\n", *argv);
exit(FALSE);
if (!isdigit(**argv))
fatalError( "Bad PID: %s\n", strerror(errno));
pid = strtol(*argv, NULL, 0);
if (kill(pid, sig) != 0)
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
argv++;
}
pid = atoi(*argv);
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
if (stat(pidpath, &statbuf) != 0) {
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
exit(FALSE);
} else {
/* Looks like they want to do a killall. Do that */
while (--argc >= 0) {
int pid;
while((pid = findPidByName( *argv))) {
if (kill(pid, sig) != 0)
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
}
argv++;
}
fprintf(stderr, "sig = %d\n", sig);
if (kill(pid, sig) != 0) {
perror(*argv);
exit(FALSE);
}
argv++;
}
exit(TRUE);
end:
fprintf(stderr, "bad signal name: %s\n", *argv);
exit(TRUE);
fatalError( "bad signal name: %s\n", *argv);
}
+159 -32
View File
@@ -1,33 +1,48 @@
/* vi: set sw=4 ts=4: */
/*
* Mini ps implementation for busybox
* Mini ps implementation(s) for busybox
*
* Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen
* <andersen@lineo.com>, <andersee@debian.org>
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* This contains _two_ implementations of ps for Linux. One uses the
* traditional /proc virtual filesystem, and the other use the devps kernel
* driver (written by Erik Andersen to avoid using /proc thereby saving 100k+).
*
* 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
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#if ! defined BB_FEATURE_USE_DEVPS_PATCH
/* The following is the first ps implementation --
* the one using the /proc virtual filesystem.
*/
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
@@ -103,18 +118,28 @@ extern int ps_main(int argc, char **argv)
char path[32], sbuf[512];
char uidName[10] = "";
char groupName[10] = "";
int i, c;
int len, i, c;
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
int terminal_width = 0;
#else
#define terminal_width 79
#endif
if (argc > 1 && **(argv + 1) == '-') {
usage
("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
}
if (argc > 1 && **(argv + 1) == '-')
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
dir = opendir("/proc");
if (!dir) {
perror("Can't open /proc");
exit(FALSE);
}
if (!dir)
fatalError("Can't open /proc");
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
"State", "Command");
@@ -131,31 +156,133 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid);
my_getgrgid(groupName, p.rgid);
if (*uidName == '\0')
sprintf(uidName, "%d", p.ruid);
my_getgrgid(groupName, p.rgid);
if (*groupName == '\0')
sprintf(groupName, "%d", p.rgid);
fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
p.state);
sprintf(path, "/proc/%s/cmdline", entry->d_name);
file = fopen(path, "r");
if (file == NULL) {
perror(path);
exit(FALSE);
}
if (file == NULL)
fatalError("Can't open %s: %s\n", path, strerror(errno));
i = 0;
while (((c = getc(file)) != EOF) && (i < 53)) {
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
i++;
if (c == '\0')
c = ' ';
putc(c, stdout);
}
if (i == 0)
fprintf(stdout, "%s", p.cmd);
fprintf(stdout, "[%s]", p.cmd);
fprintf(stdout, "\n");
}
closedir(dir);
exit(TRUE);
}
#else /* BB_FEATURE_USE_DEVPS_PATCH */
/* The following is the second ps implementation --
* this one uses the nifty new devps kernel device.
*/
#include <linux/devps.h>
extern int ps_main(int argc, char **argv)
{
char device[] = "/dev/ps";
int i, j, len, fd;
pid_t num_pids;
pid_t* pid_array = NULL;
struct pid_info info;
char uidName[10] = "";
char groupName[10] = "";
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
int terminal_width = 0;
#else
#define terminal_width 79
#endif
if (argc > 1 && **(argv + 1) == '-')
usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError( "open failed for `%s': %s\n", device, strerror (errno));
/* Find out how many processes there are */
if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
/* Allocate some memory -- grab a few extras just in case
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
/* Print up a ps listing */
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
"State", "Command");
for (i=1; i<pid_array[0] ; i++) {
uidName[0] = '\0';
groupName[0] = '\0';
info.pid = pid_array[i];
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
fatalError("\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
/* Make some adjustments as needed */
my_getpwuid(uidName, info.euid);
if (*uidName == '\0')
sprintf(uidName, "%ld", info.euid);
my_getgrgid(groupName, info.egid);
if (*groupName == '\0')
sprintf(groupName, "%ld", info.egid);
len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
if (strlen(info.command_line) > 1) {
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
*(info.command_line+j) = ' ';
}
}
*(info.command_line+j) = '\0';
fprintf(stdout, "%s\n", info.command_line);
} else {
fprintf(stdout, "[%s]\n", info.name);
}
}
/* Free memory */
free( pid_array);
/* close device */
if (close (fd) != 0)
fatalError("close failed for `%s': %s\n", device, strerror (errno));
exit (0);
}
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
+73
View File
@@ -0,0 +1,73 @@
/* vi: set sw=4 ts=4: */
/*
* Mini uptime implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* This version of uptime doesn't display the number of users on the system,
* since busybox init doesn't mess with utmp. For folks using utmp that are
* just dying to have # of users reported, feel free to write it as some type
* of BB_FEATURE_UMTP_SUPPORT #define
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <sys/sysinfo.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;
struct sysinfo info;
struct tm *current_time;
time_t current_secs;
time(&current_secs);
current_time = localtime(&current_secs);
sysinfo(&info);
fprintf(stdout, " %2d:%02d%s up ",
current_time->tm_hour%12 ? current_time->tm_hour%12 : 12,
current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am");
updays = (int) info.uptime / (60*60*24);
if (updays)
fprintf(stdout, "%d day%s, ", updays, (updays != 1) ? "s" : "");
upminutes = (int) info.uptime / 60;
uphours = (upminutes / 60) % 24;
upminutes %= 60;
if(uphours)
fprintf(stdout, "%2d:%02d, ", uphours, upminutes);
else
fprintf(stdout, "%d min, ", upminutes);
printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
exit(TRUE);
}
+159 -32
View File
@@ -1,33 +1,48 @@
/* vi: set sw=4 ts=4: */
/*
* Mini ps implementation for busybox
* Mini ps implementation(s) for busybox
*
* Copyright (C) 1999 by Lineo, inc. Written by Erik Andersen
* <andersen@lineo.com>, <andersee@debian.org>
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* This contains _two_ implementations of ps for Linux. One uses the
* traditional /proc virtual filesystem, and the other use the devps kernel
* driver (written by Erik Andersen to avoid using /proc thereby saving 100k+).
*
* 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
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#if ! defined BB_FEATURE_USE_DEVPS_PATCH
/* The following is the first ps implementation --
* the one using the /proc virtual filesystem.
*/
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
@@ -103,18 +118,28 @@ extern int ps_main(int argc, char **argv)
char path[32], sbuf[512];
char uidName[10] = "";
char groupName[10] = "";
int i, c;
int len, i, c;
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
int terminal_width = 0;
#else
#define terminal_width 79
#endif
if (argc > 1 && **(argv + 1) == '-') {
usage
("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
}
if (argc > 1 && **(argv + 1) == '-')
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
dir = opendir("/proc");
if (!dir) {
perror("Can't open /proc");
exit(FALSE);
}
if (!dir)
fatalError("Can't open /proc");
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
"State", "Command");
@@ -131,31 +156,133 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid);
my_getgrgid(groupName, p.rgid);
if (*uidName == '\0')
sprintf(uidName, "%d", p.ruid);
my_getgrgid(groupName, p.rgid);
if (*groupName == '\0')
sprintf(groupName, "%d", p.rgid);
fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
p.state);
sprintf(path, "/proc/%s/cmdline", entry->d_name);
file = fopen(path, "r");
if (file == NULL) {
perror(path);
exit(FALSE);
}
if (file == NULL)
fatalError("Can't open %s: %s\n", path, strerror(errno));
i = 0;
while (((c = getc(file)) != EOF) && (i < 53)) {
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
i++;
if (c == '\0')
c = ' ';
putc(c, stdout);
}
if (i == 0)
fprintf(stdout, "%s", p.cmd);
fprintf(stdout, "[%s]", p.cmd);
fprintf(stdout, "\n");
}
closedir(dir);
exit(TRUE);
}
#else /* BB_FEATURE_USE_DEVPS_PATCH */
/* The following is the second ps implementation --
* this one uses the nifty new devps kernel device.
*/
#include <linux/devps.h>
extern int ps_main(int argc, char **argv)
{
char device[] = "/dev/ps";
int i, j, len, fd;
pid_t num_pids;
pid_t* pid_array = NULL;
struct pid_info info;
char uidName[10] = "";
char groupName[10] = "";
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
int terminal_width = 0;
#else
#define terminal_width 79
#endif
if (argc > 1 && **(argv + 1) == '-')
usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError( "open failed for `%s': %s\n", device, strerror (errno));
/* Find out how many processes there are */
if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
/* Allocate some memory -- grab a few extras just in case
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
fatalError("\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
/* Print up a ps listing */
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
"State", "Command");
for (i=1; i<pid_array[0] ; i++) {
uidName[0] = '\0';
groupName[0] = '\0';
info.pid = pid_array[i];
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
fatalError("\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
/* Make some adjustments as needed */
my_getpwuid(uidName, info.euid);
if (*uidName == '\0')
sprintf(uidName, "%ld", info.euid);
my_getgrgid(groupName, info.egid);
if (*groupName == '\0')
sprintf(groupName, "%ld", info.egid);
len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
if (strlen(info.command_line) > 1) {
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
*(info.command_line+j) = ' ';
}
}
*(info.command_line+j) = '\0';
fprintf(stdout, "%s\n", info.command_line);
} else {
fprintf(stdout, "[%s]\n", info.name);
}
}
/* Free memory */
free( pid_array);
/* close device */
if (close (fd) != 0)
fatalError("close failed for `%s': %s\n", device, strerror (errno));
exit (0);
}
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
+13 -1
View File
@@ -26,6 +26,18 @@
extern int reboot_main(int argc, char **argv)
{
#ifdef BB_FEATURE_LINUXRC
/* don't assume init's pid == 1 */
exit(kill(findInitPid(), SIGINT));
exit(kill(findPidByName("init"), SIGINT));
#else
exit(kill(1, SIGINT));
#endif
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+122 -122
View File
@@ -184,129 +184,129 @@ extern int sed_main(int argc, char **argv)
}
while (argc > 1) {
if (**argv == '-') {
argc--;
cp = *argv++;
stopNow = FALSE;
if (**argv != '-')
usage(sed_usage);
argc--;
cp = *argv++;
stopNow = FALSE;
while (*++cp && stopNow == FALSE) {
switch (*cp) {
case 'n':
quietFlag = TRUE;
break;
case 'e':
if (*(cp + 1) == 0 && --argc < 0) {
usage(sed_usage);
}
if (*++cp != 's')
cp = *argv++;
/* Read address if present */
SKIPSPACES(cp);
if (*cp == '$') {
addr_line = LAST_LINE;
cp++;
} else {
if (isdigit(*cp)) { /* LINE ADDRESS */
line_s = cp;
while (isdigit(*cp))
cp++;
if (cp > line_s) {
/* numeric line */
saved = *cp;
*cp = '\0';
addr_line = atoi(line_s);
*cp = saved;
}
} else if (*cp == '/') { /* PATTERN ADDRESS */
pos = addr_pattern = cp + 1;
pos = strchr(pos, '/');
if (!pos)
usage(sed_usage);
*pos = '\0';
cp = pos + 1;
}
}
SKIPSPACES(cp);
if (*cp == '!') {
negated++;
cp++;
}
/* Read command */
SKIPSPACES(cp);
switch (*cp) {
case 's': /* REPLACE */
if (strlen(cp) <= 3 || *(cp + 1) != '/')
break;
sed_f = f_replace;
pos = needle = cp + 2;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
newNeedle = ++pos;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
if (pos + 2 != 0) {
while (*++pos) {
switch (*pos) {
case 'i':
ignoreCase = TRUE;
break;
case 'p':
printFlag = TRUE;
break;
case 'g':
break;
default:
usage(sed_usage);
}
}
}
cp = pos;
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
break;
case 'a': /* APPEND */
if (strlen(cp) < 2)
break;
sed_f = f_append;
appendline = ++cp;
/* fprintf(stderr, "append '%s'\n", appendline); */
break;
}
stopNow = TRUE;
break;
default:
usage(sed_usage);
}
}
}
while (*++cp && stopNow == FALSE) {
switch (*cp) {
case 'n':
quietFlag = TRUE;
break;
case 'e':
if (*(cp + 1) == 0 && --argc < 0) {
usage(sed_usage);
}
if (*++cp != 's')
cp = *argv++;
/* Read address if present */
SKIPSPACES(cp);
if (*cp == '$') {
addr_line = LAST_LINE;
cp++;
} else {
if (isdigit(*cp)) { /* LINE ADDRESS */
line_s = cp;
while (isdigit(*cp))
cp++;
if (cp > line_s) {
/* numeric line */
saved = *cp;
*cp = '\0';
addr_line = atoi(line_s);
*cp = saved;
}
} else if (*cp == '/') { /* PATTERN ADDRESS */
pos = addr_pattern = cp + 1;
pos = strchr(pos, '/');
if (!pos)
usage(sed_usage);
*pos = '\0';
cp = pos + 1;
}
}
SKIPSPACES(cp);
if (*cp == '!') {
negated++;
cp++;
}
/* Read command */
SKIPSPACES(cp);
switch (*cp) {
case 's': /* REPLACE */
if (strlen(cp) <= 3 || *(cp + 1) != '/')
break;
sed_f = f_replace;
pos = needle = cp + 2;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
newNeedle = ++pos;
for (;;) {
pos = strchr(pos, '/');
if (pos == NULL) {
usage(sed_usage);
}
if (*(pos - 1) == '\\') {
pos++;
continue;
}
break;
}
*pos = 0;
if (pos + 2 != 0) {
while (*++pos) {
switch (*pos) {
case 'i':
ignoreCase = TRUE;
break;
case 'p':
printFlag = TRUE;
break;
case 'g':
break;
default:
usage(sed_usage);
}
}
}
cp = pos;
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
break;
case 'a': /* APPEND */
if (strlen(cp) < 2)
break;
sed_f = f_append;
appendline = ++cp;
/* fprintf(stderr, "append '%s'\n", appendline); */
break;
}
stopNow = TRUE;
break;
default:
usage(sed_usage);
}
}
}
if (argc == 0) {
+19 -9
View File
@@ -29,7 +29,18 @@
#include <stdio.h>
#include <errno.h>
static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
static const char sort_usage[] = "sort [-n]"
#ifdef BB_FEATURE_SORT_REVERSE
" [-r]"
#endif
" [FILE]...\n\n";
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
static int reverse = 0;
#else
#define APPLY_REVERSE(x) (x)
#endif
/* typedefs _______________________________________________________________ */
@@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b)
y = *doh;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return strcmp(x->data, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
}
/* numeric order */
@@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b)
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
return (xint - yint);
return APPLY_REVERSE(xint - yint);
}
@@ -254,20 +265,19 @@ int sort_main(int argc, char **argv)
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'g':
/* what's the diff between -g && -n? */
compare = compare_numeric;
break;
case 'h':
usage(sort_usage);
break;
case 'n':
/* what's the diff between -g && -n? */
/* numeric comparison */
compare = compare_numeric;
break;
#ifdef BB_FEATURE_SORT_REVERSE
case 'r':
/* reverse */
reverse = 1;
break;
#endif
default:
fprintf(stderr, "sort: invalid option -- %c\n", opt);
usage(sort_usage);
@@ -310,4 +320,4 @@ int sort_main(int argc, char **argv)
exit(0);
}
/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */
+11 -11
View File
@@ -365,6 +365,17 @@ extern int syslogd_main(int argc, char **argv)
*p++ = '\0';
}
#ifdef BB_KLOGD
/* Start up the klogd process */
if (startKlogd == TRUE) {
klogd_pid = fork();
if (klogd_pid == 0) {
strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
}
#endif
if (doFork == TRUE) {
pid = fork();
if (pid < 0)
@@ -377,16 +388,5 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd();
}
#ifdef BB_KLOGD
/* Start up the klogd process */
if (startKlogd == TRUE) {
klogd_pid = fork();
if (klogd_pid == 0) {
strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
}
#endif
exit(TRUE);
}
+11 -11
View File
@@ -365,6 +365,17 @@ extern int syslogd_main(int argc, char **argv)
*p++ = '\0';
}
#ifdef BB_KLOGD
/* Start up the klogd process */
if (startKlogd == TRUE) {
klogd_pid = fork();
if (klogd_pid == 0) {
strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
}
#endif
if (doFork == TRUE) {
pid = fork();
if (pid < 0)
@@ -377,16 +388,5 @@ extern int syslogd_main(int argc, char **argv)
doSyslogd();
}
#ifdef BB_KLOGD
/* Start up the klogd process */
if (startKlogd == TRUE) {
klogd_pid = fork();
if (klogd_pid == 0) {
strncpy(argv[0], "klogd", strlen(argv[0]));
doKlogd();
}
}
#endif
exit(TRUE);
}
+1 -1
View File
@@ -330,7 +330,7 @@ static int tail_file(const char *filename, off_t n_units)
/* Not standard input. */
fd = open(filename, O_RDONLY);
if (fd == -1)
errorMsg("open error");
fatalError("open error");
errors = tail_lines(filename, fd, (long) n_units);
close(fd);
+6
View File
@@ -596,6 +596,12 @@ readHeader(const TarHeader * hp, int fileCount, char **fileTable)
*/
if (S_ISDIR(mode)) {
if (createPath(outName, mode) == TRUE) {
/* make the final component, just in case it was
* omitted by createPath() (which will skip the
* directory if it doesn't have a terminating '/')
*/
mkdir(outName, mode);
/* Set the file time */
utb.actime = mtime;
utb.modtime = mtime;
+9 -2
View File
@@ -23,6 +23,7 @@
*/
#include "internal.h"
#include <errno.h>
#include <stdio.h>
static const char tee_usage[] =
@@ -38,7 +39,7 @@ static const char tee_usage[] =
/* FileList _______________________________________________________________ */
#define FL_MAX 1024
static FILE *FileList[FL_MAX];
static FILE **FileList;
static int FL_end;
typedef void (FL_Function) (FILE * file, char c);
@@ -99,6 +100,11 @@ int tee_main(int argc, char **argv)
}
/* init FILE pointers */
FileList = calloc(FL_MAX, sizeof(FILE*));
if (!FileList) {
fprintf(stderr, "tee: %s\n", strerror(errno));
exit(1);
}
FL_end = 0;
FileList[0] = stdout;
for (; i < argc; i++) {
@@ -119,7 +125,8 @@ int tee_main(int argc, char **argv)
/* clean up */
FL_apply(tee_fclose, 0);
free(FileList);
exit(0);
}
/* $Id: tee.c,v 1.6 2000/02/08 19:58:47 erik Exp $ */
/* $Id: tee.c,v 1.7 2000/03/08 00:14:35 beppu Exp $ */
+503
View File
@@ -0,0 +1,503 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: telnet.c,v 1.1 2000/02/22 17:17:45 erik Exp $
* Mini telnet implementation for busybox
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This version of telnet is adapted (but very heavily modified) from the
* telnet in netkit-telnet 0.16, which is:
*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Original copyright notice is retained at the end of this file.
*/
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <netdb.h>
#include <termios.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#define TELOPTS
#include <arpa/telnet.h>
#include <arpa/inet.h>
static int STDIN = 0;
static int STDOUT = 1;
static const char *telnet_usage = "telnet host [port]\n\n";
static struct termios saved_tc;
static unsigned char options[NTELOPTS];
static char tr_state = 0; /* telnet send and receive state */
static unsigned char subbuffer[256];
static unsigned char *subpointer, *subend;
#define SB_CLEAR() subpointer = subbuffer;
#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { *subpointer++ = (c); }
#define SB_GET() (*subpointer++)
#define SB_PEEK() (*subpointer)
#define SB_EOF() (subpointer >= subend)
#define SB_LEN() (subend - subpointer)
#define TELNETPORT 23
#define MASK_WILL 0x01
#define MASK_WONT 0x04
#define MASK_DO 0x10
#define MASK_DONT 0x40
#define TFLAG_ISSET(opt, flag) (options[opt] & MASK_##flag)
#define TFLAG_SET(opt, flag) (options[opt] |= MASK_##flag)
#define TFLAG_CLR(opt, flag) (options[opt] &= ~MASK_##flag)
#define PERROR(ctx) do { fprintf(stderr, "%s: %s\n", ctx, strerror(errno)); \
return; } while (0)
#define TS_DATA 0
#define TS_IAC 1
#define TS_WILL 2
#define TS_WONT 3
#define TS_DO 4
#define TS_DONT 5
#define TS_CR 6
#define TS_SB 7 /* sub-option collection */
#define TS_SE 8 /* looking for sub-option end */
/* prototypes */
static void telnet_init(void);
static void telnet_start(char *host, int port);
static void telnet_shutdown(void);
/* ******************************************************************* */
#define SENDCOMMAND(c,o) \
char buf[3]; \
buf[0] = IAC; buf[1] = c; buf[2] = o; \
write(s, buf, sizeof(buf));
static inline void telnet_sendwill(int s, int c) { SENDCOMMAND(WILL, c); }
static inline void telnet_sendwont(int s, int c) { SENDCOMMAND(WONT, c); }
static inline void telnet_senddo(int s, int c) { SENDCOMMAND(DO, c); }
static inline void telnet_senddont(int s, int c) { SENDCOMMAND(DONT, c); }
static void telnet_setoptions(int s)
{
/*
telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO);
telnet_sendwill(s, TELOPT_NAWS); TFLAG_SET(TELOPT_NAWS, WILL);
telnet_sendwill(s, TELOPT_TSPEED); TFLAG_SET(TELOPT_TSPEED, WILL);
telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL);
telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL);
telnet_sendwill(s, TELOPT_NEW_ENVIRON); TFLAG_SET(TELOPT_NEW_ENVIRON, WILL);
telnet_senddo(s, TELOPT_STATUS); TFLAG_SET(TELOPT_STATUS, DO);
telnet_sendwill(s, TELOPT_TTYPE); TFLAG_SET(TELOPT_TTYPE, WILL);
*/
telnet_senddo(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, DO);
telnet_sendwill(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, WILL);
}
static void telnet_suboptions(int net)
{
char buf[256];
switch (SB_GET()) {
case TELOPT_TTYPE:
if (TFLAG_ISSET(TELOPT_TTYPE, WONT)) return;
if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
return;
} else {
const char *name = getenv("TERM");
if (name) {
snprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c", IAC, SB,
TELOPT_TTYPE, TELQUAL_IS, name, IAC, SE);
write(net, buf, strlen(name)+6);
}
}
break;
case TELOPT_TSPEED:
if (TFLAG_ISSET(TELOPT_TSPEED, WONT)) return;
if (SB_EOF()) return;
if (SB_GET() == TELQUAL_SEND) {
/*
long oospeed, iispeed;
netoring.printf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
TELQUAL_IS, oospeed, iispeed, IAC, SE);
*/
}
break;
/*
case TELOPT_LFLOW:
if (TFLAG_ISSET(TELOPT_LFLOW, WONT)) return;
if (SB_EOF()) return;
switch(SB_GET()) {
case 1: localflow = 1; break;
case 0: localflow = 0; break;
default: return;
}
break;
case TELOPT_LINEMODE:
if (TFLAG_ISSET(TELOPT_LINEMODE, WONT)) return;
if (SB_EOF()) return;
switch (SB_GET()) {
case WILL: lm_will(subpointer, SB_LEN()); break;
case WONT: lm_wont(subpointer, SB_LEN()); break;
case DO: lm_do(subpointer, SB_LEN()); break;
case DONT: lm_dont(subpointer, SB_LEN()); break;
case LM_SLC: slc(subpointer, SB_LEN()); break;
case LM_MODE: lm_mode(subpointer, SB_LEN(), 0); break;
default: break;
}
break;
case TELOPT_ENVIRON:
if (SB_EOF()) return;
switch(SB_PEEK()) {
case TELQUAL_IS:
case TELQUAL_INFO:
if (TFLAG_ISSET(TELOPT_ENVIRON, DONT)) return;
break;
case TELQUAL_SEND:
if (TFLAG_ISSET(TELOPT_ENVIRON, WONT)) return;
break;
default:
return;
}
env_opt(subpointer, SB_LEN());
break;
*/
case TELOPT_XDISPLOC:
if (TFLAG_ISSET(TELOPT_XDISPLOC, WONT)) return;
if (SB_EOF()) return;
if (SB_GET() == TELQUAL_SEND) {
const char *dp = getenv("DISPLAY");
if (dp) {
snprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c", IAC, SB,
TELOPT_XDISPLOC, TELQUAL_IS, dp, IAC, SE);
write(net, buf, strlen(dp)+6);
}
}
break;
default:
break;
}
}
static void sighandler(int sig)
{
telnet_shutdown();
exit(0);
}
static int telnet_send(int tty, int net)
{
int ret;
unsigned char ch;
while ((ret = read(tty, &ch, 1)) > 0) {
if (ch == 29) { /* 29 -- ctrl-] */
/* do something here? */
exit(0);
} else {
ret = write(net, &ch, 1);
break;
}
}
if (ret == -1 && errno == EWOULDBLOCK) return 1;
return ret;
}
static int telnet_recv(int net, int tty)
{
/* globals: tr_state - telnet receive state */
int ret, c = 0;
unsigned char ch;
while ((ret = read(net, &ch, 1)) > 0) {
c = ch;
/* printf("%02X ", c); fflush(stdout); */
switch (tr_state) {
case TS_DATA:
if (c == IAC) {
tr_state = TS_IAC;
break;
} else {
write(tty, &c, 1);
}
break;
case TS_IAC:
switch (c) {
case WILL:
tr_state = TS_WILL; break;
case WONT:
tr_state = TS_WONT; break;
case DO:
tr_state = TS_DO; break;
case DONT:
tr_state = TS_DONT; break;
case SB:
SB_CLEAR();
tr_state = TS_SB; break;
case IAC:
write(tty, &c, 1); /* fallthrough */
default:
tr_state = TS_DATA;
}
/* subnegotiation -- ignored for now */
case TS_SB:
if (c == IAC) tr_state = TS_SE;
else SB_ACCUM(c);
break;
case TS_SE:
if (c == IAC) {
SB_ACCUM(IAC);
tr_state = TS_SB;
} else if (c == SE) {
SB_ACCUM(IAC);
SB_ACCUM(SE);
subpointer -= 2;
SB_TERM();
telnet_suboptions(net);
tr_state = TS_DATA;
}
/* otherwise this is an error, but we ignore it for now */
break;
/* handle incoming requests */
case TS_WILL:
printf("WILL %s\n", telopts[c]);
if (!TFLAG_ISSET(c, DO)) {
if (c == TELOPT_BINARY) {
TFLAG_SET(c, DO);
TFLAG_CLR(c, DONT);
telnet_senddo(net, c);
} else {
TFLAG_SET(c, DONT);
telnet_senddont(net, c);
}
}
telnet_senddont(net, c);
tr_state = TS_DATA;
break;
case TS_WONT:
printf("WONT %s\n", telopts[c]);
if (!TFLAG_ISSET(c, DONT)) {
TFLAG_SET(c, DONT);
TFLAG_CLR(c, DO);
telnet_senddont(net, c);
}
tr_state = TS_DATA;
break;
case TS_DO:
printf("DO %s\n", telopts[c]);
if (!TFLAG_ISSET(c, WILL)) {
if (c == TELOPT_BINARY) {
TFLAG_SET(c, WILL);
TFLAG_CLR(c, WONT);
telnet_sendwill(net, c);
} else {
TFLAG_SET(c, WONT);
telnet_sendwont(net, c);
}
}
tr_state = TS_DATA;
break;
case TS_DONT:
printf("DONT %s\n", telopts[c]);
if (!TFLAG_ISSET(c, WONT)) {
TFLAG_SET(c, WONT);
TFLAG_CLR(c, WILL);
telnet_sendwont(net, c);
}
tr_state = TS_DATA;
break;
}
}
if (ret == -1 && errno == EWOULDBLOCK) return 1;
return ret;
}
/* ******************************************************************* */
static void telnet_init(void)
{
struct termios tmp_tc;
cc_t esc = (']' & 0x1f); /* ctrl-] */
memset(options, 0, sizeof(options));
SB_CLEAR();
tcgetattr(STDIN, &saved_tc);
tmp_tc = saved_tc;
tmp_tc.c_lflag &= ~ECHO; /* echo */
tmp_tc.c_oflag |= ONLCR; /* NL->CRLF translation */
tmp_tc.c_iflag |= ICRNL;
tmp_tc.c_iflag &= ~(IXANY|IXOFF|IXON); /* no flow control */
tmp_tc.c_lflag |= ISIG; /* trap signals */
tmp_tc.c_lflag &= ~ICANON; /* edit mode */
/* misc settings, compat with default telnet stuff */
tmp_tc.c_oflag &= ~TABDLY;
/* 8-bit clean */
tmp_tc.c_iflag &= ~ISTRIP;
tmp_tc.c_cflag &= ~(CSIZE|PARENB);
tmp_tc.c_cflag |= saved_tc.c_cflag & (CSIZE|PARENB);
tmp_tc.c_oflag |= OPOST;
/* set escape character */
tmp_tc.c_cc[VEOL] = esc;
tcsetattr(STDIN, TCSADRAIN, &tmp_tc);
}
static void telnet_start(char *hostname, int port)
{
struct hostent *host = 0;
struct sockaddr_in addr;
int s, c;
fd_set rfds, wfds;
memset(&addr, 0, sizeof(addr));
host = gethostbyname(hostname);
if (!host) {
fprintf(stderr, "Unknown host: %s\n", hostname);
return;
}
addr.sin_family = host->h_addrtype;
memcpy(&addr.sin_addr, host->h_addr, sizeof(addr.sin_addr));
addr.sin_port = htons(port);
printf("Trying %s...\n", inet_ntoa(addr.sin_addr));
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) PERROR("socket");
if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
PERROR("connect");
printf("Connected to %s\n", hostname);
printf("Escape character is ^]\n");
signal(SIGINT, sighandler);
signal(SIGQUIT, sighandler);
signal(SIGPIPE, sighandler);
signal(SIGWINCH, sighandler);
/* make inputs nonblocking */
c = 1;
ioctl(s, FIONBIO, &c);
ioctl(STDIN, FIONBIO, &c);
if (port == TELNETPORT) telnet_setoptions(s);
/* shuttle data back and forth between tty and socket */
while (1) {
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(s, &rfds);
/* FD_SET(s, &wfds); */
FD_SET(STDIN, &rfds);
/* FD_SET(STDOUT, &wfds); */
if ((c = select(s+1, &rfds, &wfds, 0, 0))) {
if (c == -1) {
/* handle errors */
PERROR("select");
}
if (FD_ISSET(s, &rfds)) {
/* input from network */
FD_CLR(s, &rfds);
c = telnet_recv(s, STDOUT);
if (c == 0) break;
if (c < 0) PERROR("telnet_recv");
}
if (FD_ISSET(STDIN, &rfds)) {
/* input from tty */
FD_CLR(STDIN, &rfds);
c = telnet_send(STDIN, s);
if (c == 0) break;
if (c < 0) PERROR("telnet_send");
}
}
}
return;
}
static void telnet_shutdown(void)
{
printf("\n");
tcsetattr(STDIN, TCSANOW, &saved_tc);
}
#ifdef STANDALONE_TELNET
void usage(const char *msg)
{
printf("%s", msg);
exit(0);
}
int main(int argc, char **argv)
#else
int telnet_main(int argc, char **argv)
#endif
{
int port = TELNETPORT;
argc--; argv++;
if (argc < 1) usage(telnet_usage);
if (argc > 1) port = atoi(argv[1]);
telnet_init();
atexit(telnet_shutdown);
telnet_start(argv[0], port);
return 0;
}
/*
* Copyright (c) 1988, 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+13 -10
View File
@@ -1,16 +1,21 @@
all test_all: message_header cp_tests mv_tests ln_tests
# busybox/tests/Makefile - Run through all defined tests.
# ------------------------
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
clean: cp_clean mv_clean ln_clean
all:: message_header
message_header:
@echo
@echo If tests faile due to differences in timestamps in commands that are not set
@echo to preserve timestamps, just run the tests again.
@echo BusyBox Test Suite.
@echo
include cp_tests.mk
include mv_tests.mk
include ln_tests.mk
clean::
distclean: clean
.PHONY: all clean distclean message_header
include $(wildcard *_tests.mk)
BBL := $(shell pushd .. >/dev/null && \
${MAKE} busybox.links >/dev/null && \
@@ -21,8 +26,6 @@ BBL := $(shell pushd .. >/dev/null && \
../busybox:
cd .. && ${MAKE} busybox
$(BBL): ../busybox
${BBL}: ../busybox
rm -f $@
ln ../busybox $@
.PHONY: all test_all message_header
+127 -77
View File
@@ -1,18 +1,23 @@
# This is a -*- makefile -*-
# cp_tests.mk - Set of test cases for busybox cp
# -------------
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
#
# GNU `cp'
GCP = /bin/cp
# BusyBox `cp'
BCP = $(shell pwd)/cp
.PHONY: cp_clean
all:: cp_tests
clean:: cp_clean
cp_clean:
rm -rf cp_tests cp_*.{gnu,bb} cp
- rm -rf cp_tests cp_*.{gnu,bb} cp
.PHONY: cp_tests
cp_tests: cp_clean cp
@echo;
@echo "No output from diff means busybox cp is functioning properly.";
@echo "Some tests might show timestamp differences that are Ok.";
@echo;
${BCP} || true;
@@ -20,7 +25,8 @@ cp_tests: cp_clean cp
@echo;
mkdir cp_tests;
@echo;
# Copy a file to a copy of the file
@echo ------------------------------;
cd cp_tests; \
echo A file > afile; \
ls -l afile > ../cp_afile_afilecopy.gnu; \
@@ -28,7 +34,7 @@ cp_tests: cp_clean cp
ls -l afile afilecopy >> ../cp_afile_afilecopy.gnu;
@echo;
rm -f cp_tests/afile*;
rm -rf cp_tests/*;
@echo;
cd cp_tests; \
@@ -38,118 +44,135 @@ cp_tests: cp_clean cp
ls -l afile afilecopy >> ../cp_afile_afilecopy.bb;
@echo;
diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
@echo Might show timestamp differences.
-diff -u cp_afile_afilecopy.gnu cp_afile_afilecopy.bb;
@echo;
rm -f cp_tests/afile*;
rm -rf cp_tests/*;
@echo; echo;
# Copy a file pointed to by a symlink
@echo; echo ------------------------------;
cd cp_tests; \
mkdir there there1; \
cd there; \
ln -s ../afile .;
mkdir here there; \
echo A file > afile; \
cd here; \
ln -s ../afile .; \
@echo;
cd cp_tests; \
ls -lR . > ../cp_symlink.gnu; \
${GCP} here/afile there; \
ls -lR . >> ../cp_symlink.gnu;
@echo;
rm -rf cp_tests/there/*;
sleep 1;
@echo;
cd cp_tests; \
ls -lR . > ../cp_symlink.bb; \
${BCP} here/afile there; \
ls -lR . >> ../cp_symlink.bb;
@echo;
@echo Will show timestamp difference.
-diff -u cp_symlink.gnu cp_symlink.bb;
@echo;
rm -rf cp_tests/*
# Copy a symlink, useing the -a switch.
@echo; echo ------------------------------;
cd cp_tests; \
echo A file > afile; \
mkdir here there; \
cd here; \
ln -s ../afile .
cd cp_test; \
ls -lR . > ../cp_a_symlink.gnu; \
${GCP} -a here/afile there; \
ls -lR . >> ../cp_a_symlink.gnu;
@echo;
rm -f cp_tests/there/*;
sleep 1;
@echo;
cd cp_tests; \
echo A file > afile; \
ls -l afile > ../cp_symlink.gnu; \
${GCP} there/afile there1/; \
ls -l afile there/afile there1/afile >> ../cp_symlink.gnu;
@echo;
rm -f cp_tests/afile cp_tests/there1/afile;
@echo;
cd cp_tests; \
echo A file > afile; \
ls -l afile > ../cp_symlink.bb; \
${BCP} there/afile there1/; \
ls -l afile there/afile there1/afile >> ../cp_symlink.bb;
@echo;
diff -u cp_symlink.gnu cp_symlink.bb;
@echo;
rm -f cp_tests/afile cp_tests/there1/afile;
@echo; echo;
cd cp_tests; \
echo A file > afile; \
ls -l afile > ../cp_a_symlink.gnu; \
${GCP} -a there/afile there1/; \
ls -l afile there/afile there1/afile >> ../cp_a_symlink.gnu;
@echo;
rm -f cp_tests/afile cp_tests/there1/afile;
@echo;
cd cp_tests; \
echo A file > afile; \
ls -l afile > ../cp_a_symlink.bb; \
${BCP} -a there/afile there1/; \
ls -l afile there/afile there1/afile >> ../cp_a_symlink.bb;
ls -lR . > ../cp_a_symlink.bb; \
${BCP} -a here/afile there; \
ls -lR . >> ../cp_a_symlink.bb;
@echo;
diff -u cp_a_symlink.gnu cp_a_symlink.bb;
@echo;
rm -f cp_tests/afile
rm -rf cp_tests/there{,1};
rm -f cp_tests/*;
@echo; echo;
# Copy a directory into another directory with the -a switch
@echo; echo ------------------------------;
cd cp_tests; \
echo A file > there/afile; \
mkdir there/adir; \
touch there/adir/afileinadir; \
ln -s $(shell pwd) there/alink;
mkdir here there; \
echo A file > here/afile; \
mkdir here/adir; \
touch here/adir/afileinadir; \
ln -s $$(pwd) here/alink;
@echo;
cd cp_tests; \
${GCP} -a there/ there1/; \
ls -lR there/ there1/ > ../cp_a_dir_dir.gnu;
ls -lR . > ../cp_a_dir_dir.gnu; \
${GCP} -a here/ there/; \
ls -lR . >> ../cp_a_dir_dir.gnu;
@echo;
rm -rf cp_tests/there1;
rm -rf cp_tests/there/*;
sleep 1;
@echo;
cd cp_tests; \
${BCP} -a there/ there1/; \
ls -lR there/ there1/ > ../cp_a_dir_dir.bb;
ls -lR . > ../cp_a_dir_dir.bb; \
${BCP} -a here/ there/; \
ls -lR . >> ../cp_a_dir_dir.bb;
@echo;
diff -u cp_a_dir_dir.gnu cp_a_dir_dir.bb;
@echo;
rm -rf cp_tests/there1/;
rm -rf cp_tests/*;
@echo; echo;
# Copy a set of files to a directory.
@echo; echo ------------------------------;
cd cp_tests; \
echo A file number one > afile1; \
echo A file number two, blah. > afile2; \
ln -s afile1 symlink1; \
mkdir there1; \
${GCP} afile1 afile2 symlink1 there1/; \
mkdir there;
cd cp_tests; \
${GCP} afile1 afile2 symlink1 there/; \
ls -lR > ../cp_files_dir.gnu;
@echo;
rm -rf cp_tests/{afile{1,2},symlink1,there1};
rm -rf cp_tests/there/*;
@echo;
cd cp_tests; \
echo A file number one > afile1; \
echo A file number two, blah. > afile2; \
ln -s afile1 symlink1; \
mkdir there1; \
${BCP} afile1 afile2 symlink1 there1/; \
${BCP} afile1 afile2 symlink1 there/; \
ls -lR > ../cp_files_dir.bb;
@echo;
diff -u cp_files_dir.gnu cp_files_dir.bb;
@echo;
rm -rf cp_tests/{afile{1,2},symlink1,there1};
rm -rf cp_tests/*;
@echo; echo;
# Copy a set of files to a directory with the -d switch.
@echo; echo ------------------------------;
cd cp_tests; \
echo A file number one > afile1; \
echo A file number two, blah. > afile2; \
@@ -176,7 +199,8 @@ cp_tests: cp_clean cp
@echo;
rm -rf cp_tests/{afile{1,2},symlink1,there1};
@echo; echo;
# Copy a set of files to a directory with the -p switch.
@echo; echo ------------------------------;
cd cp_tests; \
echo A file number one > afile1; \
echo A file number two, blah. > afile2; \
@@ -205,7 +229,8 @@ cp_tests: cp_clean cp
@echo;
rm -rf cp_tests/{afile{1,2},symlink1,there1};
@echo; echo;
# Copy a set of files to a directory with -p and -d switches.
@echo; echo ------------------------------;
cd cp_tests; \
echo A file number one > afile1; \
echo A file number two, blah. > afile2; \
@@ -234,7 +259,8 @@ cp_tests: cp_clean cp
@echo;
rm -rf cp_tests/{afile{1,2},symlink1,there1};
@echo; echo;
# Copy a directory into another directory with the -a switch.
@echo; echo ------------------------------;
cd cp_tests; \
mkdir dir{a,b}; \
echo A file > dira/afile; \
@@ -246,7 +272,6 @@ cp_tests: cp_clean cp
${GCP} -a dira dirb; \
ls -lR . >> ../cp_a_dira_dirb.gnu;
# false;
@echo;
rm -rf cp_tests/dir{a,b};
@@ -265,6 +290,31 @@ cp_tests: cp_clean cp
@echo;
diff -u cp_a_dira_dirb.gnu cp_a_dira_dirb.bb;
# false;
@echo;
rm -rf cp_tests/dir{a,b};
# Copy a directory to another directory, without the -a switch.
@echo; echo ------------------------------;
@echo There should be an error message about cannot cp a dir to a subdir of itself.
cd cp_tests; \
touch a b c; \
mkdir adir; \
ls -lR . > ../cp_a_star_adir.gnu; \
${GCP} -a * adir; \
ls -lR . >> ../cp_a_star_adir.gnu;
@echo
@echo There should be an error message about cannot cp a dir to a subdir of itself.
cd cp_tests; \
rm -rf adir; \
mkdir adir; \
ls -lR . > ../cp_a_star_adir.bb; \
${BCP} -a * adir; \
ls -lR . >> ../cp_a_star_adir.bb;
@echo;
diff -u cp_a_star_adir.gnu cp_a_star_adir.bb;
@echo;
rm -rf cp_tests;
@echo; echo Done.
+7 -2
View File
@@ -1,14 +1,19 @@
# ln_tests.mk - Set of tests for busybox ln
# -------------
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
#
# GNU `ln'
GLN = /bin/ln
# BusyBox `ln'
BLN = $(shell pwd)/ln
.PHONY: ln_clean
all:: ln_tests
clean:: ln_clean
ln_clean:
rm -rf ln_tests ln_*.{gnu,bb} ln
.PHONY: ln_tests
ln_tests: ln_clean ln
@echo;
@echo "No output from diff means busybox ln is functioning properly.";
+35 -6
View File
@@ -1,14 +1,19 @@
# mv_tests.mk - Set of tests cases for busybox mv
# -------------
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org> GPL
#
# GNU `mv'
GMV = /bin/mv
# BusyBox `mv'
BMV = $(shell pwd)/mv
.PHONY: mv_clean
all:: mv_tests
clean:: mv_clean
mv_clean:
rm -rf mv_tests mv_*.{gnu,bb} mv
.PHONY: mv_tests
mv_tests: mv_clean mv
@echo;
@echo "No output from diff means busybox mv is functioning properly.";
@@ -45,7 +50,7 @@ mv_tests: mv_clean mv
@echo;
rm -f mv_tests/{afile,newname};
@echo; echo;
@echo; echo ------------------------------;
cd mv_tests; \
echo A file > afile; \
ln -s afile symlink; \
@@ -72,7 +77,7 @@ mv_tests: mv_clean mv
@echo;
rm -rf mv_tests/*;
@echo; echo;
@echo; echo ------------------------------;
cd mv_tests; \
echo A file > afile; \
ln -s afile symlink; \
@@ -85,7 +90,7 @@ mv_tests: mv_clean mv
@echo;
rm -rf mv_tests/*
@echo; echo;
@echo; echo ------------------------------;
cd mv_tests; \
echo A file > afile; \
ln -s afile symlink; \
@@ -101,7 +106,7 @@ mv_tests: mv_clean mv
@echo;
rm -rf mv_tests/*;
@echo; echo;
@echo; echo ------------------------------;
cd mv_tests; \
mkdir dir{a,b}; \
echo A file > dira/afile; \
@@ -135,3 +140,27 @@ mv_tests: mv_clean mv
# false;
@echo;
rm -rf mv_tests/dir{a,b};
@echo; echo ------------------------------;
@echo There should be an error message about cannot mv a dir to a subdir of itself.
cd mv_tests; \
touch a b c; \
mkdir adir; \
ls -lR . > ../mv_a_star_adir.gnu; \
${GMV} * adir; \
ls -lR . >> ../mv_a_star_adir.gnu;
@echo
@echo There should be an error message about cannot mv a dir to a subdir of itself.
cd mv_tests; \
rm -rf adir; \
mkdir adir; \
ls -lR . > ../mv_a_star_adir.bb; \
${BMV} * adir; \
ls -lR . >> ../mv_a_star_adir.bb;
@echo;
diff -u mv_a_star_adir.gnu mv_a_star_adir.bb;
@echo;
rm -rf mv_test/*;
+578
View File
@@ -0,0 +1,578 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: tr.c,v 1.1 2000/03/05 08:07:00 erik Exp $";
#endif /* not lint */
#endif /* #if 0 */
#include "internal.h"
#include <locale.h>
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <err.h>
#include <stddef.h>
typedef struct {
enum { STRING1, STRING2 } which;
enum { EOS, INFINITE, NORMAL, RANGE, SEQUENCE, SET } state;
int cnt; /* character count */
int lastch; /* last character */
int equiv[2]; /* equivalence set */
int *set; /* set of characters */
char *str; /* user's string */
} STR;
#include <limits.h>
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
static int next __P((STR *));
static int string1[NCHARS] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
}, string2[NCHARS];
STR s1 = { STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
STR s2 = { STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
static void setup(string, arg, str, cflag)
int *string;
char *arg;
STR *str;
int cflag;
{
register int cnt, *p;
str->str = arg;
bzero(string, NCHARS * sizeof(int));
while (next(str))
string[str->lastch] = 1;
if (cflag)
for (p = string, cnt = NCHARS; cnt--; ++p)
*p = !*p;
}
static void tr_usage()
{
(void) fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: tr [-csu] string1 string2",
" tr [-cu] -d string1",
" tr [-cu] -s string1",
" tr [-cu] -ds string1 string2");
exit(1);
}
extern int tr_main(argc, argv)
int argc;
char **argv;
{
register int ch, cnt, lastch, *p;
int cflag, dflag, sflag, isstring2;
(void) setlocale(LC_CTYPE, "");
cflag = dflag = sflag = 0;
while ((ch = getopt(argc, argv, "cdsu")) != -1)
switch ((char) ch) {
case 'c':
cflag = 1;
break;
case 'd':
dflag = 1;
break;
case 's':
sflag = 1;
break;
case 'u':
setbuf(stdout, (char *) NULL);
break;
case '?':
default:
tr_usage();
}
argc -= optind;
argv += optind;
switch (argc) {
case 0:
default:
tr_usage();
/* NOTREACHED */
case 1:
isstring2 = 0;
break;
case 2:
isstring2 = 1;
break;
}
/*
* tr -ds [-c] string1 string2
* Delete all characters (or complemented characters) in string1.
* Squeeze all characters in string2.
*/
if (dflag && sflag) {
if (!isstring2)
tr_usage();
setup(string1, argv[0], &s1, cflag);
setup(string2, argv[1], &s2, 0);
for (lastch = OOBCH; (ch = getchar()) != EOF;)
if (!string1[ch] && (!string2[ch] || lastch != ch)) {
lastch = ch;
(void) putchar(ch);
}
exit(0);
}
/*
* tr -d [-c] string1
* Delete all characters (or complemented characters) in string1.
*/
if (dflag) {
if (isstring2)
tr_usage();
setup(string1, argv[0], &s1, cflag);
while ((ch = getchar()) != EOF)
if (!string1[ch])
(void) putchar(ch);
exit(0);
}
/*
* tr -s [-c] string1
* Squeeze all characters (or complemented characters) in string1.
*/
if (sflag && !isstring2) {
setup(string1, argv[0], &s1, cflag);
for (lastch = OOBCH; (ch = getchar()) != EOF;)
if (!string1[ch] || lastch != ch) {
lastch = ch;
(void) putchar(ch);
}
exit(0);
}
/*
* tr [-cs] string1 string2
* Replace all characters (or complemented characters) in string1 with
* the character in the same position in string2. If the -s option is
* specified, squeeze all the characters in string2.
*/
if (!isstring2)
tr_usage();
s1.str = argv[0];
s2.str = argv[1];
if (cflag)
for (cnt = NCHARS, p = string1; cnt--;)
*p++ = OOBCH;
if (!next(&s2))
errx(1, "empty string2");
/* If string2 runs out of characters, use the last one specified. */
if (sflag)
while (next(&s1)) {
string1[s1.lastch] = ch = s2.lastch;
string2[ch] = 1;
(void) next(&s2);
} else
while (next(&s1)) {
string1[s1.lastch] = ch = s2.lastch;
(void) next(&s2);
}
if (cflag)
for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
*p = *p == OOBCH ? ch : cnt;
if (sflag)
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
ch = string1[ch];
if (!string2[ch] || lastch != ch) {
lastch = ch;
(void) putchar(ch);
}
} else
while ((ch = getchar()) != EOF)
(void) putchar(string1[ch]);
exit(0);
}
static int backslash __P((STR *));
static int bracket __P((STR *));
static int c_class __P((const void *, const void *));
static void genclass __P((STR *));
static void genequiv __P((STR *));
static int genrange __P((STR *));
static void genseq __P((STR *));
static int next(s)
register STR *s;
{
register int ch;
switch (s->state) {
case EOS:
return (0);
case INFINITE:
return (1);
case NORMAL:
switch (ch = (u_char) * s->str) {
case '\0':
s->state = EOS;
return (0);
case '\\':
s->lastch = backslash(s);
break;
case '[':
if (bracket(s))
return (next(s));
/* FALLTHROUGH */
default:
++s->str;
s->lastch = ch;
break;
}
/* We can start a range at any time. */
if (s->str[0] == '-' && genrange(s))
return (next(s));
return (1);
case RANGE:
if (s->cnt-- == 0) {
s->state = NORMAL;
return (next(s));
}
++s->lastch;
return (1);
case SEQUENCE:
if (s->cnt-- == 0) {
s->state = NORMAL;
return (next(s));
}
return (1);
case SET:
if ((s->lastch = s->set[s->cnt++]) == OOBCH) {
s->state = NORMAL;
return (next(s));
}
return (1);
}
/* NOTREACHED */
return (0);
}
static int bracket(s)
register STR *s;
{
register char *p;
switch (s->str[1]) {
case ':': /* "[:class:]" */
if ((p = strstr(s->str + 2, ":]")) == NULL)
return (0);
*p = '\0';
s->str += 2;
genclass(s);
s->str = p + 2;
return (1);
case '=': /* "[=equiv=]" */
if ((p = strstr(s->str + 2, "=]")) == NULL)
return (0);
s->str += 2;
genequiv(s);
return (1);
default: /* "[\###*n]" or "[#*n]" */
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
return (0);
if (p[0] != '*' || index(p, ']') == NULL)
return (0);
s->str += 1;
genseq(s);
return (1);
}
/* NOTREACHED */
}
typedef struct {
char *name;
int (*func) __P((int));
int *set;
} CLASS;
static CLASS classes[] = {
#undef isalnum
{"alnum", isalnum,},
#undef isalpha
{"alpha", isalpha,},
/*#undef isblank
{ "blank", isblank, },*/
#undef iscntrl
{"cntrl", iscntrl,},
#undef isdigit
{"digit", isdigit,},
#undef isgraph
{"graph", isgraph,},
#undef islower
{"lower", islower,},
#undef isprint
{"print", isprint,},
#undef ispunct
{"punct", ispunct,},
#undef isspace
{"space", isspace,},
#undef isupper
{"upper", isupper,},
#undef isxdigit
{"xdigit", isxdigit,},
};
static void genclass(s)
STR *s;
{
register int cnt, (*func) __P((int));
CLASS *cp, tmp;
int *p;
tmp.name = s->str;
if ((cp = (CLASS *) bsearch(&tmp, classes, sizeof(classes) /
sizeof(CLASS), sizeof(CLASS),
c_class)) == NULL) errx(1,
"unknown class %s",
s->str);
if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL)
errx(1, "malloc");
bzero(p, (NCHARS + 1) * sizeof(int));
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
if ((func) (cnt))
*p++ = cnt;
*p = OOBCH;
s->cnt = 0;
s->state = SET;
s->set = cp->set;
}
static int c_class(a, b)
const void *a, *b;
{
return (strcmp(((CLASS *) a)->name, ((CLASS *) b)->name));
}
/*
* English doesn't have any equivalence classes, so for now
* we just syntax check and grab the character.
*/
static void genequiv(s)
STR *s;
{
if (*s->str == '\\') {
s->equiv[0] = backslash(s);
if (*s->str != '=')
errx(1, "misplaced equivalence equals sign");
} else {
s->equiv[0] = s->str[0];
if (s->str[1] != '=')
errx(1, "misplaced equivalence equals sign");
}
s->str += 2;
s->cnt = 0;
s->state = SET;
s->set = s->equiv;
}
static int genrange(s)
STR *s;
{
int stopval;
char *savestart;
savestart = s->str;
stopval = *++s->str == '\\' ? backslash(s) : (u_char) * s->str++;
if (stopval < (u_char) s->lastch) {
s->str = savestart;
return (0);
}
s->cnt = stopval - s->lastch + 1;
s->state = RANGE;
--s->lastch;
return (1);
}
static void genseq(s)
STR *s;
{
char *ep;
if (s->which == STRING1)
errx(1, "sequences only valid in string2");
if (*s->str == '\\')
s->lastch = backslash(s);
else
s->lastch = *s->str++;
if (*s->str != '*')
errx(1, "misplaced sequence asterisk");
switch (*++s->str) {
case '\\':
s->cnt = backslash(s);
break;
case ']':
s->cnt = 0;
++s->str;
break;
default:
if (isdigit((u_char) * s->str)) {
s->cnt = strtol(s->str, &ep, 0);
if (*ep == ']') {
s->str = ep + 1;
break;
}
}
errx(1, "illegal sequence count");
/* NOTREACHED */
}
s->state = s->cnt ? SEQUENCE : INFINITE;
}
/*
* Translate \??? into a character. Up to 3 octal digits, if no digits either
* an escape code or a literal character.
*/
static int backslash(s)
register STR *s;
{
register int ch, cnt, val;
for (cnt = val = 0;;) {
ch = (u_char) * ++s->str;
if (!isascii(ch) || !isdigit(ch))
break;
val = val * 8 + ch - '0';
if (++cnt == 3) {
++s->str;
break;
}
}
if (cnt)
return (val);
if (ch != '\0')
++s->str;
switch (ch) {
case 'a': /* escape characters */
return ('\7');
case 'b':
return ('\b');
case 'f':
return ('\f');
case 'n':
return ('\n');
case 'r':
return ('\r');
case 't':
return ('\t');
case 'v':
return ('\13');
case '\0': /* \" -> \ */
s->state = EOS;
return ('\\');
default: /* \x" -> x */
return (ch);
}
}
+4
View File
@@ -59,9 +59,13 @@ static int doRemount = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
/* These functions are here because the getmntent functions do not appear
* to be re-entrant, which leads to all sorts of problems when we try to
* use them recursively - randolph
*
* TODO: Perhaps switch to using Glibc's getmntent_r
* -Erik
*/
void mtab_read(void)
{
+66 -20
View File
@@ -1,9 +1,11 @@
/* vi: set sw=4 ts=4: */
/*
* Mini update implementation for busybox
* Mini update implementation for busybox; much pasted from update-2.11
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Copyright (c) 1996, 1997, 1999 Torsten Poulin.
* Copyright (c) 2000 by Karl M. Hegbloom <karlheg@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +25,8 @@
#include "internal.h"
#include <linux/unistd.h>
#include <sys/param.h>
#include <sys/syslog.h>
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
@@ -30,37 +34,79 @@
_syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
static char update_usage[] =
"update [options]\n"
" -S\tforce use of sync(2) instead of flushing\n"
" -s SECS\tcall sync this often (default 30)\n"
" -f SECS\tflush some buffers this often (default 5)\n";
static unsigned int sync_duration = 30;
static unsigned int flush_duration = 5;
static int use_sync = 0;
extern int update_main(int argc, char **argv)
{
/*
* Update is actually two daemons, bdflush and update.
*/
int pid;
while (**argv == '-') {
while (*++(*argv)) {
switch (**argv) {
case 'S':
use_sync = 1;
break;
case 's':
if (--argc < 1) usage(update_usage);
sync_duration = atoi(*(++argv));
break;
case 'f':
if (--argc < 1) usage(update_usage);
flush_duration = atoi(*(++argv));
break;
}
}
argc--;
argv++;
}
pid = fork();
if (pid < 0)
return pid;
exit(FALSE);
else if (pid == 0) {
/* Become a proper daemon */
setsid();
chdir("/");
for (pid = 0; pid < OPEN_MAX; pid++) close(pid);
/*
* This is no longer necessary since 1.3.5x, but it will harmlessly
* exit if that is the case.
*/
strcpy(argv[0], "bdflush (update)");
argv[1] = 0;
argv[2] = 0;
bdflush(1, 0);
_exit(0);
}
pid = fork();
if (pid < 0)
return pid;
else if (pid == 0) {
argv[0] = "update";
argv[0] = "bdflush (update)";
argv[1] = NULL;
argv[2] = NULL;
for (;;) {
sync();
sleep(30);
if (use_sync) {
sleep(sync_duration);
sync();
} else {
sleep(flush_duration);
if (bdflush(1, 0) < 0) {
openlog("update", LOG_CONS, LOG_DAEMON);
syslog(LOG_INFO,
"This kernel does not need update(8). Exiting.");
closelog();
exit(TRUE);
}
}
}
}
return 0;
return TRUE;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+73
View File
@@ -0,0 +1,73 @@
/* vi: set sw=4 ts=4: */
/*
* Mini uptime implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* This version of uptime doesn't display the number of users on the system,
* since busybox init doesn't mess with utmp. For folks using utmp that are
* just dying to have # of users reported, feel free to write it as some type
* of BB_FEATURE_UMTP_SUPPORT #define
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <sys/sysinfo.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;
struct sysinfo info;
struct tm *current_time;
time_t current_secs;
time(&current_secs);
current_time = localtime(&current_secs);
sysinfo(&info);
fprintf(stdout, " %2d:%02d%s up ",
current_time->tm_hour%12 ? current_time->tm_hour%12 : 12,
current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am");
updays = (int) info.uptime / (60*60*24);
if (updays)
fprintf(stdout, "%d day%s, ", updays, (updays != 1) ? "s" : "");
upminutes = (int) info.uptime / 60;
uphours = (upminutes / 60) % 24;
upminutes %= 60;
if(uphours)
fprintf(stdout, "%2d:%02d, ", uphours, upminutes);
else
fprintf(stdout, "%d min, ", upminutes);
printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
exit(TRUE);
}
+69
View File
@@ -0,0 +1,69 @@
/* vi: set sw=4 ts=4: */
/*
* freeramdisk implementation for busybox
*
* Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
* Adjusted a bit by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "internal.h"
static const char freeramdisk_usage[] =
"freeramdisk DEVICE\n\n"
"Frees all memory used by the specified ramdisk.\n";
extern int
freeramdisk_main(int argc, char **argv)
{
char rname[256] = "/dev/ram";
int f;
if (argc >= 2 || ( argv[1] && *argv[1] == '-')) {
usage(freeramdisk_usage);
}
if (argc >1)
strcpy(rname, argv[1]);
if ((f = open(rname, O_RDWR)) == -1) {
fatalError( "freeramdisk: cannot open %s: %s", rname, strerror(errno));
}
if (ioctl(f, BLKFLSBUF) < 0) {
fatalError( "freeramdisk: failed ioctl on %s: %s", rname, strerror(errno));
}
close(f);
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+79 -7
View File
@@ -46,6 +46,10 @@
#include <sys/mount.h>
#include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h>
#endif
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
@@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
{
int status = 0;
char buf[255];
#if defined BB_FEATURE_USE_PROCFS
char buf[255];
if (strcmp(filesystemType, "auto") == 0) {
FILE *f = fopen("/proc/filesystems", "r");
@@ -251,6 +254,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
}
fclose(f);
} else
#endif
#if defined BB_FEATURE_USE_DEVPS_PATCH
if (strcmp(filesystemType, "auto") == 0) {
int fd, i, numfilesystems;
char device[] = "/dev/mtab";
struct k_fstype *fslist;
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError("open failed for `%s': %s\n", device, strerror (errno));
/* How many filesystems? We need to know to allocate enough space */
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
if (status<0)
fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno));
/* Walk the list trying to mount filesystems
* that do not claim to be nodev filesystems */
for( i = 0 ; i < numfilesystems ; i++) {
if (fslist[i].mnt_nodev)
continue;
status = do_mount(blockDevice, directory, fslist[i].mnt_type,
flags | MS_MGC_VAL, string_flags,
useMtab, fakeIt, mtab_opts);
if (status == TRUE)
break;
}
free( fslist);
close(fd);
} else
#endif
{
status = do_mount(blockDevice, directory, filesystemType,
@@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv)
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
#if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) {
int fd, i, numfilesystems;
char device[] = "/dev/mtab";
struct k_mntent *mntentlist;
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError("open failed for `%s': %s\n", device, strerror (errno));
/* How many mounted filesystems? We need to know to
* allocate enough space for later... */
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno));
for( i = 0 ; i < numfilesystems ; i++) {
fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
mntentlist[i].mnt_passno);
}
free( mntentlist);
close(fd);
exit(TRUE);
}
#else
if (argc == 1) {
FILE *mountTable = setmntent(mtab_file, "r");
@@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv)
}
exit(TRUE);
}
#endif
/* Parse options */
i = --argc;
@@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv)
struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r");
if (f == NULL) {
perror("/etc/fstab");
exit(FALSE);
}
if (f == NULL)
fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto,
// and isn't swap or nfs, then mount it
+4
View File
@@ -59,9 +59,13 @@ static int doRemount = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
/* These functions are here because the getmntent functions do not appear
* to be re-entrant, which leads to all sorts of problems when we try to
* use them recursively - randolph
*
* TODO: Perhaps switch to using Glibc's getmntent_r
* -Erik
*/
void mtab_read(void)
{
+189 -33
View File
@@ -48,6 +48,7 @@
#include <unistd.h>
#include <ctype.h>
#include <sys/param.h> /* for PATH_MAX */
#include <sys/utsname.h> /* for uname(2) */
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
@@ -55,6 +56,13 @@
#include <linux/loop.h>
#endif
/* Busybox mount uses either /proc/filesystems or /dev/mtab to get the
* list of available filesystems used for the -t auto option */
#if defined BB_FEATURE_USE_PROCFS && defined BB_FEATURE_USE_DEVPS_PATCH
//#error Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again.
#error "Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again."
#endif
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
# if defined BB_FEATURE_USE_PROCFS
@@ -63,9 +71,13 @@ const char mtab_file[] = "/proc/mounts";
# if defined BB_MTAB
const char mtab_file[] = "/etc/mtab";
# else
# error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or BB_FEATURE_USE_PROCFS
# if defined BB_FEATURE_USE_DEVPS_PATCH
const char mtab_file[] = "/dev/mtab";
# else
# error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or ( BB_FEATURE_USE_PROCFS | BB_FEATURE_USE_DEVPS_PATCH)
# endif
# endif
# endif
#endif
@@ -83,7 +95,6 @@ extern void errorMsg(char *s, ...)
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n");
vfprintf(stderr, s, p);
fprintf(stderr, "\n");
va_end(p);
@@ -95,7 +106,6 @@ extern void fatalError(char *s, ...)
va_start(p, s);
fflush(stdout);
fprintf(stderr, "\n");
vfprintf(stderr, s, p);
fprintf(stderr, "\n");
va_end(p);
@@ -103,31 +113,94 @@ extern void fatalError(char *s, ...)
}
#if defined (BB_INIT) || defined (BB_PS)
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
/* Returns kernel version encoded as major*65536 + minor*256 + patch,
* so, for example, to check if the kernel is greater than 2.2.11:
* if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
*/
int get_kernel_revision()
{
FILE *file;
struct utsname name;
int major = 0, minor = 0, patch = 0;
file = fopen("/proc/sys/kernel/osrelease", "r");
if (file == NULL) {
/* bummer, /proc must not be mounted... */
if (uname(&name) == -1) {
perror("cannot get system information");
return (0);
}
fscanf(file, "%d.%d.%d", &major, &minor, &patch);
fclose(file);
sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
return major * 65536 + minor * 256 + patch;
}
#endif /* BB_INIT || BB_PS */
#if defined (BB_CP_MV) || defined (BB_DU)
#define HASH_SIZE 311 /* Should be prime */
#define hash_inode(i) ((i) % HASH_SIZE)
static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
/*
* Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
* `ino_dev_hashtable', else return 0
*
* If NAME is a non-NULL pointer to a character pointer, and there is
* a match, then set *NAME to the value of the name slot in that
* bucket.
*/
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
{
ino_dev_hashtable_bucket_t *bucket;
bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
while (bucket != NULL) {
if ((bucket->ino == statbuf->st_ino) &&
(bucket->dev == statbuf->st_dev))
{
if (name) *name = bucket->name;
return 1;
}
bucket = bucket->next;
}
return 0;
}
/* Add statbuf to statbuf hash table */
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
{
int i;
size_t s;
ino_dev_hashtable_bucket_t *bucket;
i = hash_inode(statbuf->st_ino);
s = name ? strlen(name) : 0;
bucket = malloc(sizeof(ino_dev_hashtable_bucket_t) + s);
if (bucket == NULL)
fatalError("Not enough memory.");
bucket->ino = statbuf->st_ino;
bucket->dev = statbuf->st_dev;
if (name)
strcpy(bucket->name, name);
else
bucket->name[0] = '\0';
bucket->next = ino_dev_hashtable[i];
ino_dev_hashtable[i] = bucket;
}
/* Clear statbuf hash table */
void reset_ino_dev_hashtable(void)
{
int i;
ino_dev_hashtable_bucket_t *bucket;
for (i = 0; i < HASH_SIZE; i++) {
while (ino_dev_hashtable[i] != NULL) {
bucket = ino_dev_hashtable[i]->next;
free(ino_dev_hashtable[i]);
ino_dev_hashtable[i] = bucket;
}
}
}
#endif /* BB_CP_MV || BB_DU */
#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN)
/*
@@ -166,7 +239,7 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu
/*
* Copy one file to another, while possibly preserving its modes, times,
* and modes. Returns TRUE if successful, or FALSE on a failure with an
* error message output. (Failure is not indicted if the attributes cannot
* error message output. (Failure is not indicated if the attributes cannot
* be set.)
* -Erik Andersen
*/
@@ -1174,31 +1247,108 @@ extern int device_open(char *device, int mode)
#endif /* BB_INIT BB_SYSLOGD */
#if defined BB_INIT || defined BB_HALT || defined BB_REBOOT
#if defined BB_KILLALL || defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#ifdef BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devps.h>
#endif
/* findInitPid()
#if defined BB_FEATURE_USE_DEVPS_PATCH
/* findPidByName()
*
* This finds the pid of init (which is not always 1).
* Currently, it's implemented by rummaging through the proc filesystem.
* This finds the pid of the specified process,
* by using the /dev/ps device driver.
*
* [return]
* 0 failure
* pid when init's pid is found.
* pid when the pid is found.
*/
extern pid_t findInitPid()
extern pid_t findPidByName( char* pidName)
{
pid_t init_pid;
char filename[256];
char buffer[256];
int fd, i;
char device[] = "/dev/ps";
pid_t thePid = 0;
pid_t num_pids;
pid_t* pid_array = NULL;
/* no need to opendir ;) */
for (init_pid = 1; init_pid < 65536; init_pid++) {
/* open device */
fd = open(device, O_RDONLY);
if (fd < 0)
fatalError( "open failed for `%s': %s\n", device, strerror (errno));
/* Find out how many processes there are */
if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
/* Allocate some memory -- grab a few extras just in case
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
/* Now search for a match */
for (i=1; i<pid_array[0] ; i++) {
struct pid_info info;
info.pid = pid_array[i];
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
if ((strstr(info.command_line, pidName) != NULL)) {
thePid = info.pid;
break;
}
}
/* Free memory */
free( pid_array);
/* close device */
if (close (fd) != 0)
fatalError( "close failed for `%s': %s\n",device, strerror (errno));
return thePid;
}
#else /* BB_FEATURE_USE_DEVPS_PATCH */
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
/* findPidByName()
*
* This finds the pid of the specified process.
* Currently, it's implemented by rummaging through
* the proc filesystem.
*
* [return]
* 0 failure
* pid when the pid is found.
*/
extern pid_t findPidByName( char* pidName)
{
DIR *dir;
struct dirent *next;
dir = opendir("/proc");
if (!dir)
fatalError( "Cannot open /proc: %s\n", strerror (errno));
while ((next = readdir(dir)) != NULL) {
FILE *status;
char filename[256];
char buffer[256];
sprintf(filename, "/proc/%d/status", init_pid);
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
/* Now open the command line file */
sprintf(filename, "/proc/%s/status", next->d_name);
status = fopen(filename, "r");
if (!status) {
continue;
@@ -1206,13 +1356,14 @@ extern pid_t findInitPid()
fgets(buffer, 256, status);
fclose(status);
if ((strstr(buffer, "init\n") != NULL)) {
return init_pid;
if ((strstr(buffer, pidName) != NULL)) {
return strtol(next->d_name, NULL, 0);
}
}
return 0;
}
#endif /* BB_INIT || BB_HALT || BB_REBOOT */
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
#endif /* BB_INIT || BB_HALT || BB_REBOOT || BB_KILLALL || BB_POWEROFF */
#if defined BB_GUNZIP \
|| defined BB_GZIP \
@@ -1340,6 +1491,11 @@ extern void whine_if_fstab_is_missing()
}
#endif
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/