Stuf
This commit is contained in:
parent
77619b9dda
commit
b186d980d6
@ -3,6 +3,11 @@
|
|||||||
file existed.
|
file existed.
|
||||||
* df will not exit on error, but will try to stat all mounted filesystems.
|
* df will not exit on error, but will try to stat all mounted filesystems.
|
||||||
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
|
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
|
||||||
|
* Fixed find -name so it properly uses shell wildcard patterns
|
||||||
|
(i.e. `*', `?', and `[]') instead of regular expressions, which
|
||||||
|
was causing some confusing and unexpected behavior.
|
||||||
|
|
||||||
|
-Erik Andrsen, Dec 2, 1999
|
||||||
|
|
||||||
0.37
|
0.37
|
||||||
* Wrote a micro syslogd, and a logger util (to log things to the syslog
|
* Wrote a micro syslogd, and a logger util (to log things to the syslog
|
||||||
|
2
Makefile
2
Makefile
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
PROG=busybox
|
PROG=busybox
|
||||||
VERSION=0.37
|
VERSION=0.38
|
||||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||||
|
|
||||||
# Comment out the following to make a debuggable build
|
# Comment out the following to make a debuggable build
|
||||||
|
31
TODO
31
TODO
@ -1,10 +1,31 @@
|
|||||||
TODO list for busybox in no particular order
|
TODO list for busybox in no particular order. Just because something
|
||||||
|
is listed here doesn't mean that it is going to be added to busybox,
|
||||||
|
or that doing so is even a good idea. It just means that I _might_ get
|
||||||
|
around to it some time. If you have any good ideas, please let me know.
|
||||||
|
|
||||||
If you have any good ideas, please let me know.
|
-Erik
|
||||||
|
|
||||||
|
-----------
|
||||||
|
|
||||||
* Allow tar to create archives with sockets, devices, and other special files
|
* Allow tar to create archives with sockets, devices, and other special files
|
||||||
* Add in a mini modprobe, insmod, rmmod
|
* Add in a mini insmod, rmmod, lsmod
|
||||||
* poweroff
|
|
||||||
* Change init so halt, reboot (and poweroff) work with an initrd
|
* Change init so halt, reboot (and poweroff) work with an initrd
|
||||||
when init is not PID 1
|
when init is not PID 1
|
||||||
*
|
* poweroff
|
||||||
|
* du
|
||||||
|
* mkfifo
|
||||||
|
* hostname/dnsdomainname
|
||||||
|
* ping/traceroute/nslookup/netstat
|
||||||
|
* rdate
|
||||||
|
* hwclock
|
||||||
|
* login/getty
|
||||||
|
* free
|
||||||
|
* killall
|
||||||
|
* tee
|
||||||
|
* stty
|
||||||
|
* head/tail
|
||||||
|
* sort/uniq
|
||||||
|
* wc
|
||||||
|
* tr
|
||||||
|
* expr (maybe)?
|
||||||
|
|
||||||
|
@ -10,11 +10,10 @@ fi
|
|||||||
h=`sort busybox.links | uniq`
|
h=`sort busybox.links | uniq`
|
||||||
|
|
||||||
for i in $h ; do
|
for i in $h ; do
|
||||||
mypath=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `;
|
echo " $1$i -> /bin/busybox"
|
||||||
myapp=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `;
|
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||||
echo " $1$mypath$myapp -> /bin/busybox"
|
rm -f $1$i
|
||||||
mkdir -p $1$mypath
|
ln -s /bin/busybox $1$i
|
||||||
(cd $1$mypath && rm -f $1$mypath$myapp && ln -s /bin/busybox $1$mypath$myapp )
|
|
||||||
done
|
done
|
||||||
rm -f $1/bin/busybox
|
rm -f $1/bin/busybox
|
||||||
install -m 755 busybox $1/bin/busybox
|
install -m 755 busybox $1/bin/busybox
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Name: busybox
|
Name: busybox
|
||||||
Version: 0.37
|
Version: 0.38
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: System/Utilities
|
Group: System/Utilities
|
||||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||||
|
@ -185,6 +185,10 @@ extern int dd_main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||||
|
//
|
||||||
|
//TODO: Convert to using fullRead & fullWrite
|
||||||
|
// from utilitity.c
|
||||||
|
// -Erik
|
||||||
while (outTotal < count * blockSize) {
|
while (outTotal < count * blockSize) {
|
||||||
inCc = read (inFd, buf, blockSize);
|
inCc = read (inFd, buf, blockSize);
|
||||||
if (inCc < 0) {
|
if (inCc < 0) {
|
||||||
|
4
dd.c
4
dd.c
@ -185,6 +185,10 @@ extern int dd_main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||||
|
//
|
||||||
|
//TODO: Convert to using fullRead & fullWrite
|
||||||
|
// from utilitity.c
|
||||||
|
// -Erik
|
||||||
while (outTotal < count * blockSize) {
|
while (outTotal < count * blockSize) {
|
||||||
inCc = read (inFd, buf, blockSize);
|
inCc = read (inFd, buf, blockSize);
|
||||||
if (inCc < 0) {
|
if (inCc < 0) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Name: busybox
|
Name: busybox
|
||||||
Version: 0.37
|
Version: 0.38
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: System/Utilities
|
Group: System/Utilities
|
||||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||||
|
11
find.c
11
find.c
@ -51,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
|||||||
{
|
{
|
||||||
if (pattern==NULL)
|
if (pattern==NULL)
|
||||||
fprintf(stdout, "%s\n", fileName);
|
fprintf(stdout, "%s\n", fileName);
|
||||||
else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
|
else {
|
||||||
fprintf(stdout, "%s\n", fileName);
|
char* tmp = strrchr( fileName, '/');
|
||||||
|
if (tmp == NULL)
|
||||||
|
tmp = (char*)fileName;
|
||||||
|
else
|
||||||
|
tmp++;
|
||||||
|
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||||
|
fprintf(stdout, "%s\n", fileName);
|
||||||
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
|||||||
{
|
{
|
||||||
if (pattern==NULL)
|
if (pattern==NULL)
|
||||||
fprintf(stdout, "%s\n", fileName);
|
fprintf(stdout, "%s\n", fileName);
|
||||||
else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
|
else {
|
||||||
fprintf(stdout, "%s\n", fileName);
|
char* tmp = strrchr( fileName, '/');
|
||||||
|
if (tmp == NULL)
|
||||||
|
tmp = (char*)fileName;
|
||||||
|
else
|
||||||
|
tmp++;
|
||||||
|
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||||
|
fprintf(stdout, "%s\n", fileName);
|
||||||
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
init.c
15
init.c
@ -29,6 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -44,7 +45,6 @@
|
|||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEV_CONSOLE "/dev/console" /* Logical system console */
|
|
||||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||||
@ -52,11 +52,10 @@
|
|||||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||||
#define SHELL "/bin/sh" /* Default shell */
|
#define SHELL "/bin/sh" /* Default shell */
|
||||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
|
||||||
|
|
||||||
#define LOG 0x1
|
#define LOG 0x1
|
||||||
#define CONSOLE 0x2
|
#define CONSOLE 0x2
|
||||||
static char *console = DEV_CONSOLE;
|
static char *console = _PATH_CONSOLE;
|
||||||
static char *second_console = VT_SECONDARY;
|
static char *second_console = VT_SECONDARY;
|
||||||
static char *log = VT_LOG;
|
static char *log = VT_LOG;
|
||||||
static int kernel_version = 0;
|
static int kernel_version = 0;
|
||||||
@ -126,7 +125,7 @@ void message(int device, char *fmt, ...)
|
|||||||
|
|
||||||
if (device & CONSOLE) {
|
if (device & CONSOLE) {
|
||||||
/* Always send console messages to /dev/console so people will see them. */
|
/* Always send console messages to /dev/console so people will see them. */
|
||||||
if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
vdprintf(fd, fmt, arguments);
|
vdprintf(fd, fmt, arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
@ -242,7 +241,7 @@ static void console_init()
|
|||||||
/* this is linux virtual tty */
|
/* this is linux virtual tty */
|
||||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||||
} else {
|
} else {
|
||||||
console = DEV_CONSOLE;
|
console = _PATH_CONSOLE;
|
||||||
tried_devcons++;
|
tried_devcons++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +250,7 @@ static void console_init()
|
|||||||
/* Can't open selected console -- try /dev/console */
|
/* Can't open selected console -- try /dev/console */
|
||||||
if (!tried_devcons) {
|
if (!tried_devcons) {
|
||||||
tried_devcons++;
|
tried_devcons++;
|
||||||
console = DEV_CONSOLE;
|
console = _PATH_CONSOLE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Can't open selected console -- try vt1 */
|
/* Can't open selected console -- try vt1 */
|
||||||
@ -421,6 +420,7 @@ static void halt_signal(int sig)
|
|||||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||||
sync();
|
sync();
|
||||||
#ifndef DEBUG_INIT
|
#ifndef DEBUG_INIT
|
||||||
|
while (1) sleep(1);
|
||||||
reboot(RB_HALT_SYSTEM);
|
reboot(RB_HALT_SYSTEM);
|
||||||
//reboot(RB_POWER_OFF);
|
//reboot(RB_POWER_OFF);
|
||||||
#endif
|
#endif
|
||||||
@ -432,6 +432,7 @@ static void reboot_signal(int sig)
|
|||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
||||||
sync();
|
sync();
|
||||||
|
while (1) sleep(1);
|
||||||
#ifndef DEBUG_INIT
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_AUTOBOOT);
|
reboot(RB_AUTOBOOT);
|
||||||
#endif
|
#endif
|
||||||
@ -502,7 +503,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
/* Make sure PATH is set to something sane */
|
/* Make sure PATH is set to something sane */
|
||||||
putenv(PATH_DEFAULT);
|
putenv(_PATH_STDPATH);
|
||||||
|
|
||||||
|
|
||||||
/* Hello world */
|
/* Hello world */
|
||||||
|
15
init/init.c
15
init/init.c
@ -29,6 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -44,7 +45,6 @@
|
|||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEV_CONSOLE "/dev/console" /* Logical system console */
|
|
||||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||||
@ -52,11 +52,10 @@
|
|||||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||||
#define SHELL "/bin/sh" /* Default shell */
|
#define SHELL "/bin/sh" /* Default shell */
|
||||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
|
||||||
|
|
||||||
#define LOG 0x1
|
#define LOG 0x1
|
||||||
#define CONSOLE 0x2
|
#define CONSOLE 0x2
|
||||||
static char *console = DEV_CONSOLE;
|
static char *console = _PATH_CONSOLE;
|
||||||
static char *second_console = VT_SECONDARY;
|
static char *second_console = VT_SECONDARY;
|
||||||
static char *log = VT_LOG;
|
static char *log = VT_LOG;
|
||||||
static int kernel_version = 0;
|
static int kernel_version = 0;
|
||||||
@ -126,7 +125,7 @@ void message(int device, char *fmt, ...)
|
|||||||
|
|
||||||
if (device & CONSOLE) {
|
if (device & CONSOLE) {
|
||||||
/* Always send console messages to /dev/console so people will see them. */
|
/* Always send console messages to /dev/console so people will see them. */
|
||||||
if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
vdprintf(fd, fmt, arguments);
|
vdprintf(fd, fmt, arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
@ -242,7 +241,7 @@ static void console_init()
|
|||||||
/* this is linux virtual tty */
|
/* this is linux virtual tty */
|
||||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||||
} else {
|
} else {
|
||||||
console = DEV_CONSOLE;
|
console = _PATH_CONSOLE;
|
||||||
tried_devcons++;
|
tried_devcons++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +250,7 @@ static void console_init()
|
|||||||
/* Can't open selected console -- try /dev/console */
|
/* Can't open selected console -- try /dev/console */
|
||||||
if (!tried_devcons) {
|
if (!tried_devcons) {
|
||||||
tried_devcons++;
|
tried_devcons++;
|
||||||
console = DEV_CONSOLE;
|
console = _PATH_CONSOLE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Can't open selected console -- try vt1 */
|
/* Can't open selected console -- try vt1 */
|
||||||
@ -421,6 +420,7 @@ static void halt_signal(int sig)
|
|||||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||||
sync();
|
sync();
|
||||||
#ifndef DEBUG_INIT
|
#ifndef DEBUG_INIT
|
||||||
|
while (1) sleep(1);
|
||||||
reboot(RB_HALT_SYSTEM);
|
reboot(RB_HALT_SYSTEM);
|
||||||
//reboot(RB_POWER_OFF);
|
//reboot(RB_POWER_OFF);
|
||||||
#endif
|
#endif
|
||||||
@ -432,6 +432,7 @@ static void reboot_signal(int sig)
|
|||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
|
||||||
sync();
|
sync();
|
||||||
|
while (1) sleep(1);
|
||||||
#ifndef DEBUG_INIT
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_AUTOBOOT);
|
reboot(RB_AUTOBOOT);
|
||||||
#endif
|
#endif
|
||||||
@ -502,7 +503,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
/* Make sure PATH is set to something sane */
|
/* Make sure PATH is set to something sane */
|
||||||
putenv(PATH_DEFAULT);
|
putenv(_PATH_STDPATH);
|
||||||
|
|
||||||
|
|
||||||
/* Hello world */
|
/* Hello world */
|
||||||
|
@ -10,11 +10,10 @@ fi
|
|||||||
h=`sort busybox.links | uniq`
|
h=`sort busybox.links | uniq`
|
||||||
|
|
||||||
for i in $h ; do
|
for i in $h ; do
|
||||||
mypath=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `;
|
echo " $1$i -> /bin/busybox"
|
||||||
myapp=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `;
|
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||||
echo " $1$mypath$myapp -> /bin/busybox"
|
rm -f $1$i
|
||||||
mkdir -p $1$mypath
|
ln -s /bin/busybox $1$i
|
||||||
(cd $1$mypath && rm -f $1$mypath$myapp && ln -s /bin/busybox $1$mypath$myapp )
|
|
||||||
done
|
done
|
||||||
rm -f $1/bin/busybox
|
rm -f $1/bin/busybox
|
||||||
install -m 755 busybox $1/bin/busybox
|
install -m 755 busybox $1/bin/busybox
|
||||||
|
@ -150,6 +150,7 @@ extern struct mntent *findMountPoint(const char *name, const char *table);
|
|||||||
extern void write_mtab(char* blockDevice, char* directory,
|
extern void write_mtab(char* blockDevice, char* directory,
|
||||||
char* filesystemType, long flags, char* string_flags);
|
char* filesystemType, long flags, char* string_flags);
|
||||||
extern void erase_mtab(const char * name);
|
extern void erase_mtab(const char * name);
|
||||||
|
extern int check_wildcard_match(const char* text, const char* pattern);
|
||||||
|
|
||||||
|
|
||||||
#if defined BB_MTAB
|
#if defined BB_MTAB
|
||||||
|
2
regexp.c
2
regexp.c
@ -7,7 +7,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
#if ( defined BB_GREP || defined BB_FIND || defined BB_SED)
|
#if ( defined BB_GREP || defined BB_SED)
|
||||||
|
|
||||||
/* This also tries to find a needle in a haystack, but uses
|
/* This also tries to find a needle in a haystack, but uses
|
||||||
* real regular expressions.... The fake regular expression
|
* real regular expressions.... The fake regular expression
|
||||||
|
@ -32,6 +32,12 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <sys/klog.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <paths.h>
|
||||||
|
|
||||||
|
#define ksyslog klogctl
|
||||||
|
extern int ksyslog(int type, char *buf, int len);
|
||||||
|
|
||||||
|
|
||||||
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
|
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
|
||||||
@ -40,8 +46,6 @@
|
|||||||
|
|
||||||
/* Path for the file where all log messages are written */
|
/* Path for the file where all log messages are written */
|
||||||
#define __LOG_FILE "/var/log/messages"
|
#define __LOG_FILE "/var/log/messages"
|
||||||
/* Path to the current console device */
|
|
||||||
#define __DEV_CONSOLE "/dev/console"
|
|
||||||
|
|
||||||
|
|
||||||
static char* logFilePath = __LOG_FILE;
|
static char* logFilePath = __LOG_FILE;
|
||||||
@ -58,7 +62,7 @@ static const char syslogd_usage[] =
|
|||||||
"\t-n\tDo not fork into the background (for when run by init)\n"
|
"\t-n\tDo not fork into the background (for when run by init)\n"
|
||||||
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
|
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
|
||||||
|
|
||||||
|
static int kmsg;
|
||||||
|
|
||||||
/* try to open up the specified device */
|
/* try to open up the specified device */
|
||||||
static int device_open(char *device, int mode)
|
static int device_open(char *device, int mode)
|
||||||
@ -92,7 +96,7 @@ static void message(char *fmt, ...)
|
|||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
/* Always send console messages to /dev/console so people will see them. */
|
/* Always send console messages to /dev/console so people will see them. */
|
||||||
if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
|
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
vdprintf(fd, fmt, arguments);
|
vdprintf(fd, fmt, arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
@ -250,20 +254,112 @@ static void doSyslogd(void)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void klogd_signal(int sig)
|
||||||
|
{
|
||||||
|
//ksyslog(7, NULL, 0);
|
||||||
|
//ksyslog(0, 0, 0);
|
||||||
|
logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating.");
|
||||||
|
exit( TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void doKlogd(void)
|
||||||
|
{
|
||||||
|
int priority=LOG_INFO;
|
||||||
|
struct stat sb;
|
||||||
|
char log_buffer[4096];
|
||||||
|
|
||||||
|
/* Set up sig handlers */
|
||||||
|
signal(SIGINT, klogd_signal);
|
||||||
|
signal(SIGKILL, klogd_signal);
|
||||||
|
signal(SIGTERM, klogd_signal);
|
||||||
|
signal(SIGHUP, klogd_signal);
|
||||||
|
logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: "
|
||||||
|
"BusyBox v" BB_VER " (" BB_BT ") multi-call binary");
|
||||||
|
|
||||||
|
//ksyslog(1, NULL, 0);
|
||||||
|
if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
|
||||||
|
( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
|
||||||
|
char message[80];
|
||||||
|
snprintf(message, 79, "klogd: Cannot open %s, " \
|
||||||
|
"%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
klogd_signal(0);
|
||||||
|
}
|
||||||
|
while (1) {
|
||||||
|
memset(log_buffer, '\0', sizeof(log_buffer));
|
||||||
|
if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
|
||||||
|
char message[80];
|
||||||
|
if ( errno == EINTR )
|
||||||
|
continue;
|
||||||
|
snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
|
||||||
|
errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
klogd_signal(0);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
|
||||||
|
char message[80];
|
||||||
|
if ( errno == EINTR )
|
||||||
|
continue;
|
||||||
|
snprintf(message, 79, "klogd: Error return from sys_sycall: " \
|
||||||
|
"%d - %s.\n", errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, "the kernel says '%s'\n", log_buffer);
|
||||||
|
if ( *log_buffer == '<' )
|
||||||
|
{
|
||||||
|
switch ( *(log_buffer+1) )
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
priority = LOG_EMERG;
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
priority = LOG_ALERT;
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
priority = LOG_CRIT;
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
priority = LOG_ERR;
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
priority = LOG_WARNING;
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
priority = LOG_NOTICE;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
priority = LOG_INFO;
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
default:
|
||||||
|
priority = LOG_DEBUG;
|
||||||
|
}
|
||||||
|
*log_buffer += 3;
|
||||||
|
}
|
||||||
|
logMessage(LOG_KERN|priority, log_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int syslogd_main(int argc, char **argv)
|
extern int syslogd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid, klogd_pid;
|
||||||
int doFork = TRUE;
|
int doFork = TRUE;
|
||||||
|
char **argv1=argv;
|
||||||
|
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv1) == '-') {
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv1))) {
|
||||||
switch (**argv) {
|
switch (**argv1) {
|
||||||
case 'm':
|
case 'm':
|
||||||
if (--argc == 0) {
|
if (--argc == 0) {
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
MarkInterval = atoi(*(++argv))*60;
|
MarkInterval = atoi(*(++argv1))*60;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
doFork = FALSE;
|
doFork = FALSE;
|
||||||
@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
if (--argc == 0) {
|
if (--argc == 0) {
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
logFilePath = *(++argv);
|
logFilePath = *(++argv1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
if ( pid < 0 )
|
if ( pid < 0 )
|
||||||
exit( pid);
|
exit( pid);
|
||||||
else if ( pid == 0 ) {
|
else if ( pid == 0 ) {
|
||||||
|
strncpy(argv[0], "syslogd",strlen(argv[0]));
|
||||||
doSyslogd();
|
doSyslogd();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
doSyslogd();
|
doSyslogd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start klogd process */
|
||||||
|
klogd_pid = fork();
|
||||||
|
if (klogd_pid == 0 ) {
|
||||||
|
strncpy(argv[0], "klogd", strlen(argv[0]));
|
||||||
|
doKlogd();
|
||||||
|
}
|
||||||
|
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
125
syslogd.c
125
syslogd.c
@ -32,6 +32,12 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <sys/klog.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <paths.h>
|
||||||
|
|
||||||
|
#define ksyslog klogctl
|
||||||
|
extern int ksyslog(int type, char *buf, int len);
|
||||||
|
|
||||||
|
|
||||||
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
|
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
|
||||||
@ -40,8 +46,6 @@
|
|||||||
|
|
||||||
/* Path for the file where all log messages are written */
|
/* Path for the file where all log messages are written */
|
||||||
#define __LOG_FILE "/var/log/messages"
|
#define __LOG_FILE "/var/log/messages"
|
||||||
/* Path to the current console device */
|
|
||||||
#define __DEV_CONSOLE "/dev/console"
|
|
||||||
|
|
||||||
|
|
||||||
static char* logFilePath = __LOG_FILE;
|
static char* logFilePath = __LOG_FILE;
|
||||||
@ -58,7 +62,7 @@ static const char syslogd_usage[] =
|
|||||||
"\t-n\tDo not fork into the background (for when run by init)\n"
|
"\t-n\tDo not fork into the background (for when run by init)\n"
|
||||||
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
|
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
|
||||||
|
|
||||||
|
static int kmsg;
|
||||||
|
|
||||||
/* try to open up the specified device */
|
/* try to open up the specified device */
|
||||||
static int device_open(char *device, int mode)
|
static int device_open(char *device, int mode)
|
||||||
@ -92,7 +96,7 @@ static void message(char *fmt, ...)
|
|||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
/* Always send console messages to /dev/console so people will see them. */
|
/* Always send console messages to /dev/console so people will see them. */
|
||||||
if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
|
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
vdprintf(fd, fmt, arguments);
|
vdprintf(fd, fmt, arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
@ -250,20 +254,112 @@ static void doSyslogd(void)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void klogd_signal(int sig)
|
||||||
|
{
|
||||||
|
//ksyslog(7, NULL, 0);
|
||||||
|
//ksyslog(0, 0, 0);
|
||||||
|
logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating.");
|
||||||
|
exit( TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void doKlogd(void)
|
||||||
|
{
|
||||||
|
int priority=LOG_INFO;
|
||||||
|
struct stat sb;
|
||||||
|
char log_buffer[4096];
|
||||||
|
|
||||||
|
/* Set up sig handlers */
|
||||||
|
signal(SIGINT, klogd_signal);
|
||||||
|
signal(SIGKILL, klogd_signal);
|
||||||
|
signal(SIGTERM, klogd_signal);
|
||||||
|
signal(SIGHUP, klogd_signal);
|
||||||
|
logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: "
|
||||||
|
"BusyBox v" BB_VER " (" BB_BT ") multi-call binary");
|
||||||
|
|
||||||
|
//ksyslog(1, NULL, 0);
|
||||||
|
if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
|
||||||
|
( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
|
||||||
|
char message[80];
|
||||||
|
snprintf(message, 79, "klogd: Cannot open %s, " \
|
||||||
|
"%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
klogd_signal(0);
|
||||||
|
}
|
||||||
|
while (1) {
|
||||||
|
memset(log_buffer, '\0', sizeof(log_buffer));
|
||||||
|
if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
|
||||||
|
char message[80];
|
||||||
|
if ( errno == EINTR )
|
||||||
|
continue;
|
||||||
|
snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
|
||||||
|
errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
klogd_signal(0);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
|
||||||
|
char message[80];
|
||||||
|
if ( errno == EINTR )
|
||||||
|
continue;
|
||||||
|
snprintf(message, 79, "klogd: Error return from sys_sycall: " \
|
||||||
|
"%d - %s.\n", errno, strerror(errno));
|
||||||
|
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, "the kernel says '%s'\n", log_buffer);
|
||||||
|
if ( *log_buffer == '<' )
|
||||||
|
{
|
||||||
|
switch ( *(log_buffer+1) )
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
priority = LOG_EMERG;
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
priority = LOG_ALERT;
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
priority = LOG_CRIT;
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
priority = LOG_ERR;
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
priority = LOG_WARNING;
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
priority = LOG_NOTICE;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
priority = LOG_INFO;
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
default:
|
||||||
|
priority = LOG_DEBUG;
|
||||||
|
}
|
||||||
|
*log_buffer += 3;
|
||||||
|
}
|
||||||
|
logMessage(LOG_KERN|priority, log_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int syslogd_main(int argc, char **argv)
|
extern int syslogd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid, klogd_pid;
|
||||||
int doFork = TRUE;
|
int doFork = TRUE;
|
||||||
|
char **argv1=argv;
|
||||||
|
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv1) == '-') {
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv1))) {
|
||||||
switch (**argv) {
|
switch (**argv1) {
|
||||||
case 'm':
|
case 'm':
|
||||||
if (--argc == 0) {
|
if (--argc == 0) {
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
MarkInterval = atoi(*(++argv))*60;
|
MarkInterval = atoi(*(++argv1))*60;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
doFork = FALSE;
|
doFork = FALSE;
|
||||||
@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
if (--argc == 0) {
|
if (--argc == 0) {
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
}
|
}
|
||||||
logFilePath = *(++argv);
|
logFilePath = *(++argv1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(syslogd_usage);
|
usage(syslogd_usage);
|
||||||
@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv)
|
|||||||
if ( pid < 0 )
|
if ( pid < 0 )
|
||||||
exit( pid);
|
exit( pid);
|
||||||
else if ( pid == 0 ) {
|
else if ( pid == 0 ) {
|
||||||
|
strncpy(argv[0], "syslogd",strlen(argv[0]));
|
||||||
doSyslogd();
|
doSyslogd();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
doSyslogd();
|
doSyslogd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start klogd process */
|
||||||
|
klogd_pid = fork();
|
||||||
|
if (klogd_pid == 0 ) {
|
||||||
|
strncpy(argv[0], "klogd", strlen(argv[0]));
|
||||||
|
doKlogd();
|
||||||
|
}
|
||||||
|
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
111
utility.c
111
utility.c
@ -771,7 +771,7 @@ int get_console_fd(char* tty_name)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND || defined BB_SED)
|
#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
|
||||||
|
|
||||||
/* Do a case insensitive strstr() */
|
/* Do a case insensitive strstr() */
|
||||||
char* stristr(char *haystack, const char *needle)
|
char* stristr(char *haystack, const char *needle)
|
||||||
@ -851,6 +851,108 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined BB_FIND
|
||||||
|
/*
|
||||||
|
* Routine to see if a text string is matched by a wildcard pattern.
|
||||||
|
* Returns TRUE if the text is matched, or FALSE if it is not matched
|
||||||
|
* or if the pattern is invalid.
|
||||||
|
* * matches zero or more characters
|
||||||
|
* ? matches a single character
|
||||||
|
* [abc] matches 'a', 'b' or 'c'
|
||||||
|
* \c quotes character c
|
||||||
|
* Adapted from code written by Ingo Wilken, and
|
||||||
|
* then taken from sash, Copyright (c) 1999 by David I. Bell
|
||||||
|
* Permission is granted to use, distribute, or modify this source,
|
||||||
|
* provided that this copyright notice remains intact.
|
||||||
|
* Permission to distribute this code under the GPL has been granted.
|
||||||
|
*/
|
||||||
|
extern int
|
||||||
|
check_wildcard_match(const char* text, const char* pattern)
|
||||||
|
{
|
||||||
|
const char* retryPat;
|
||||||
|
const char* retryText;
|
||||||
|
int ch;
|
||||||
|
int found;
|
||||||
|
|
||||||
|
retryPat = NULL;
|
||||||
|
retryText = NULL;
|
||||||
|
|
||||||
|
while (*text || *pattern)
|
||||||
|
{
|
||||||
|
ch = *pattern++;
|
||||||
|
|
||||||
|
switch (ch)
|
||||||
|
{
|
||||||
|
case '*':
|
||||||
|
retryPat = pattern;
|
||||||
|
retryText = text;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '[':
|
||||||
|
found = FALSE;
|
||||||
|
|
||||||
|
while ((ch = *pattern++) != ']')
|
||||||
|
{
|
||||||
|
if (ch == '\\')
|
||||||
|
ch = *pattern++;
|
||||||
|
|
||||||
|
if (ch == '\0')
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (*text == ch)
|
||||||
|
found = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (!found)
|
||||||
|
if (found==TRUE)
|
||||||
|
{
|
||||||
|
pattern = retryPat;
|
||||||
|
text = ++retryText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fall into next case */
|
||||||
|
|
||||||
|
case '?':
|
||||||
|
if (*text++ == '\0')
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\\':
|
||||||
|
ch = *pattern++;
|
||||||
|
|
||||||
|
if (ch == '\0')
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* fall into next case */
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (*text == ch)
|
||||||
|
{
|
||||||
|
if (*text)
|
||||||
|
text++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*text)
|
||||||
|
{
|
||||||
|
pattern = retryPat;
|
||||||
|
text = ++retryText;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pattern == NULL)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined BB_DF | defined BB_MTAB
|
#if defined BB_DF | defined BB_MTAB
|
||||||
@ -910,3 +1012,10 @@ extern void whine_if_fstab_is_missing()
|
|||||||
/* END CODE */
|
/* END CODE */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user