aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-12-03 09:19:54 +0000
committerEric Andersen <andersen@codepoet.org>1999-12-03 09:19:54 +0000
commitb186d980d6060195d01048bb3a083739137b6c21 (patch)
treef64b2d63850be12ce3081b2000784aa57ac29656
parent77619b9dda2b0550fea519fba05f7d9790ef7eaf (diff)
downloadbusybox-w32-b186d980d6060195d01048bb3a083739137b6c21.tar.gz
busybox-w32-b186d980d6060195d01048bb3a083739137b6c21.tar.bz2
busybox-w32-b186d980d6060195d01048bb3a083739137b6c21.zip
Stuf
-rw-r--r--Changelog5
-rw-r--r--Makefile2
-rw-r--r--TODO31
-rwxr-xr-xapplets/install.sh9
-rw-r--r--busybox.spec2
-rw-r--r--coreutils/dd.c4
-rw-r--r--dd.c4
-rw-r--r--examples/busybox.spec2
-rw-r--r--find.c11
-rw-r--r--findutils/find.c11
-rw-r--r--init.c15
-rw-r--r--init/init.c15
-rwxr-xr-xinstall.sh9
-rw-r--r--internal.h1
-rw-r--r--regexp.c2
-rw-r--r--sysklogd/syslogd.c125
-rw-r--r--syslogd.c125
-rw-r--r--utility.c111
18 files changed, 426 insertions, 58 deletions
diff --git a/Changelog b/Changelog
index b3f6c45fe..23dbfa7dd 100644
--- a/Changelog
+++ b/Changelog
@@ -3,6 +3,11 @@
3 file existed. 3 file existed.
4 * df will not exit on error, but will try to stat all mounted filesystems. 4 * df will not exit on error, but will try to stat all mounted filesystems.
5 * Fixed tar so uid/gid/permissions on extracted tarballs will be correct. 5 * Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
6 * Fixed find -name so it properly uses shell wildcard patterns
7 (i.e. `*', `?', and `[]') instead of regular expressions, which
8 was causing some confusing and unexpected behavior.
9
10 -Erik Andrsen, Dec 2, 1999
6 11
70.37 120.37
8 * Wrote a micro syslogd, and a logger util (to log things to the syslog 13 * Wrote a micro syslogd, and a logger util (to log things to the syslog
diff --git a/Makefile b/Makefile
index 085ad8126..4b174c313 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@
17 17
18 18
19PROG=busybox 19PROG=busybox
20VERSION=0.37 20VERSION=0.38
21BUILDTIME=$(shell date "+%Y%m%d-%H%M") 21BUILDTIME=$(shell date "+%Y%m%d-%H%M")
22 22
23# Comment out the following to make a debuggable build 23# Comment out the following to make a debuggable build
diff --git a/TODO b/TODO
index 44525cf32..1a65a57a8 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,31 @@
1TODO list for busybox in no particular order 1TODO list for busybox in no particular order. Just because something
2is listed here doesn't mean that it is going to be added to busybox,
3or that doing so is even a good idea. It just means that I _might_ get
4around to it some time. If you have any good ideas, please let me know.
2 5
3If you have any good ideas, please let me know. 6 -Erik
7
8-----------
4 9
5* Allow tar to create archives with sockets, devices, and other special files 10* Allow tar to create archives with sockets, devices, and other special files
6* Add in a mini modprobe, insmod, rmmod 11* Add in a mini insmod, rmmod, lsmod
7* poweroff
8* Change init so halt, reboot (and poweroff) work with an initrd 12* Change init so halt, reboot (and poweroff) work with an initrd
9 when init is not PID 1 13 when init is not PID 1
10* 14* poweroff
15* du
16* mkfifo
17* hostname/dnsdomainname
18* ping/traceroute/nslookup/netstat
19* rdate
20* hwclock
21* login/getty
22* free
23* killall
24* tee
25* stty
26* head/tail
27* sort/uniq
28* wc
29* tr
30* expr (maybe)?
31
diff --git a/applets/install.sh b/applets/install.sh
index 458e65ce9..670c0c6e1 100755
--- a/applets/install.sh
+++ b/applets/install.sh
@@ -10,11 +10,10 @@ fi
10h=`sort busybox.links | uniq` 10h=`sort busybox.links | uniq`
11 11
12for i in $h ; do 12for i in $h ; do
13 mypath=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `; 13 echo " $1$i -> /bin/busybox"
14 myapp=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `; 14 mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
15 echo " $1$mypath$myapp -> /bin/busybox" 15 rm -f $1$i
16 mkdir -p $1$mypath 16 ln -s /bin/busybox $1$i
17 (cd $1$mypath && rm -f $1$mypath$myapp && ln -s /bin/busybox $1$mypath$myapp )
18done 17done
19rm -f $1/bin/busybox 18rm -f $1/bin/busybox
20install -m 755 busybox $1/bin/busybox 19install -m 755 busybox $1/bin/busybox
diff --git a/busybox.spec b/busybox.spec
index 92000e7f4..690c7f206 100644
--- a/busybox.spec
+++ b/busybox.spec
@@ -1,5 +1,5 @@
1Name: busybox 1Name: busybox
2Version: 0.37 2Version: 0.38
3Release: 1 3Release: 1
4Group: System/Utilities 4Group: System/Utilities
5Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary. 5Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
diff --git a/coreutils/dd.c b/coreutils/dd.c
index a2dc1c396..b37038748 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -185,6 +185,10 @@ extern int dd_main (int argc, char **argv)
185 } 185 }
186 186
187 //lseek(inFd, skipBlocks*blockSize, SEEK_SET); 187 //lseek(inFd, skipBlocks*blockSize, SEEK_SET);
188 //
189 //TODO: Convert to using fullRead & fullWrite
190 // from utilitity.c
191 // -Erik
188 while (outTotal < count * blockSize) { 192 while (outTotal < count * blockSize) {
189 inCc = read (inFd, buf, blockSize); 193 inCc = read (inFd, buf, blockSize);
190 if (inCc < 0) { 194 if (inCc < 0) {
diff --git a/dd.c b/dd.c
index a2dc1c396..b37038748 100644
--- a/dd.c
+++ b/dd.c
@@ -185,6 +185,10 @@ extern int dd_main (int argc, char **argv)
185 } 185 }
186 186
187 //lseek(inFd, skipBlocks*blockSize, SEEK_SET); 187 //lseek(inFd, skipBlocks*blockSize, SEEK_SET);
188 //
189 //TODO: Convert to using fullRead & fullWrite
190 // from utilitity.c
191 // -Erik
188 while (outTotal < count * blockSize) { 192 while (outTotal < count * blockSize) {
189 inCc = read (inFd, buf, blockSize); 193 inCc = read (inFd, buf, blockSize);
190 if (inCc < 0) { 194 if (inCc < 0) {
diff --git a/examples/busybox.spec b/examples/busybox.spec
index 92000e7f4..690c7f206 100644
--- a/examples/busybox.spec
+++ b/examples/busybox.spec
@@ -1,5 +1,5 @@
1Name: busybox 1Name: busybox
2Version: 0.37 2Version: 0.38
3Release: 1 3Release: 1
4Group: System/Utilities 4Group: System/Utilities
5Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary. 5Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
diff --git a/find.c b/find.c
index 0f1f5f189..40a508f05 100644
--- a/find.c
+++ b/find.c
@@ -51,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
51{ 51{
52 if (pattern==NULL) 52 if (pattern==NULL)
53 fprintf(stdout, "%s\n", fileName); 53 fprintf(stdout, "%s\n", fileName);
54 else if (find_match((char*)fileName, pattern, TRUE) == TRUE) 54 else {
55 fprintf(stdout, "%s\n", fileName); 55 char* tmp = strrchr( fileName, '/');
56 if (tmp == NULL)
57 tmp = (char*)fileName;
58 else
59 tmp++;
60 if (check_wildcard_match(tmp, pattern) == TRUE)
61 fprintf(stdout, "%s\n", fileName);
62 }
56 return( TRUE); 63 return( TRUE);
57} 64}
58 65
diff --git a/findutils/find.c b/findutils/find.c
index 0f1f5f189..40a508f05 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -51,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
51{ 51{
52 if (pattern==NULL) 52 if (pattern==NULL)
53 fprintf(stdout, "%s\n", fileName); 53 fprintf(stdout, "%s\n", fileName);
54 else if (find_match((char*)fileName, pattern, TRUE) == TRUE) 54 else {
55 fprintf(stdout, "%s\n", fileName); 55 char* tmp = strrchr( fileName, '/');
56 if (tmp == NULL)
57 tmp = (char*)fileName;
58 else
59 tmp++;
60 if (check_wildcard_match(tmp, pattern) == TRUE)
61 fprintf(stdout, "%s\n", fileName);
62 }
56 return( TRUE); 63 return( TRUE);
57} 64}
58 65
diff --git a/init.c b/init.c
index 7258d3151..088a890cc 100644
--- a/init.c
+++ b/init.c
@@ -29,6 +29,7 @@
29#include <errno.h> 29#include <errno.h>
30#include <signal.h> 30#include <signal.h>
31#include <termios.h> 31#include <termios.h>
32#include <paths.h>
32#include <sys/types.h> 33#include <sys/types.h>
33#include <sys/fcntl.h> 34#include <sys/fcntl.h>
34#include <sys/wait.h> 35#include <sys/wait.h>
@@ -44,7 +45,6 @@
44#include <sys/syslog.h> 45#include <sys/syslog.h>
45#endif 46#endif
46 47
47#define DEV_CONSOLE "/dev/console" /* Logical system console */
48#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */ 48#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
49#define VT_SECONDARY "/dev/tty2" /* Virtual console */ 49#define VT_SECONDARY "/dev/tty2" /* Virtual console */
50#define VT_LOG "/dev/tty3" /* Virtual console */ 50#define VT_LOG "/dev/tty3" /* Virtual console */
@@ -52,11 +52,10 @@
52#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 52#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
53#define SHELL "/bin/sh" /* Default shell */ 53#define SHELL "/bin/sh" /* Default shell */
54#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */ 54#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
55#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
56 55
57#define LOG 0x1 56#define LOG 0x1
58#define CONSOLE 0x2 57#define CONSOLE 0x2
59static char *console = DEV_CONSOLE; 58static char *console = _PATH_CONSOLE;
60static char *second_console = VT_SECONDARY; 59static char *second_console = VT_SECONDARY;
61static char *log = VT_LOG; 60static char *log = VT_LOG;
62static int kernel_version = 0; 61static int kernel_version = 0;
@@ -126,7 +125,7 @@ void message(int device, char *fmt, ...)
126 125
127 if (device & CONSOLE) { 126 if (device & CONSOLE) {
128 /* Always send console messages to /dev/console so people will see them. */ 127 /* Always send console messages to /dev/console so people will see them. */
129 if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) { 128 if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
130 va_start(arguments, fmt); 129 va_start(arguments, fmt);
131 vdprintf(fd, fmt, arguments); 130 vdprintf(fd, fmt, arguments);
132 va_end(arguments); 131 va_end(arguments);
@@ -242,7 +241,7 @@ static void console_init()
242 /* this is linux virtual tty */ 241 /* this is linux virtual tty */
243 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active ); 242 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
244 } else { 243 } else {
245 console = DEV_CONSOLE; 244 console = _PATH_CONSOLE;
246 tried_devcons++; 245 tried_devcons++;
247 } 246 }
248 } 247 }
@@ -251,7 +250,7 @@ static void console_init()
251 /* Can't open selected console -- try /dev/console */ 250 /* Can't open selected console -- try /dev/console */
252 if (!tried_devcons) { 251 if (!tried_devcons) {
253 tried_devcons++; 252 tried_devcons++;
254 console = DEV_CONSOLE; 253 console = _PATH_CONSOLE;
255 continue; 254 continue;
256 } 255 }
257 /* Can't open selected console -- try vt1 */ 256 /* Can't open selected console -- try vt1 */
@@ -421,6 +420,7 @@ static void halt_signal(int sig)
421 "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); 420 "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
422 sync(); 421 sync();
423#ifndef DEBUG_INIT 422#ifndef DEBUG_INIT
423 while (1) sleep(1);
424 reboot(RB_HALT_SYSTEM); 424 reboot(RB_HALT_SYSTEM);
425 //reboot(RB_POWER_OFF); 425 //reboot(RB_POWER_OFF);
426#endif 426#endif
@@ -432,6 +432,7 @@ static void reboot_signal(int sig)
432 shutdown_system(); 432 shutdown_system();
433 message(CONSOLE, "Please stand by while rebooting the system.\r\n"); 433 message(CONSOLE, "Please stand by while rebooting the system.\r\n");
434 sync(); 434 sync();
435 while (1) sleep(1);
435#ifndef DEBUG_INIT 436#ifndef DEBUG_INIT
436 reboot(RB_AUTOBOOT); 437 reboot(RB_AUTOBOOT);
437#endif 438#endif
@@ -502,7 +503,7 @@ extern int init_main(int argc, char **argv)
502 setsid(); 503 setsid();
503 504
504 /* Make sure PATH is set to something sane */ 505 /* Make sure PATH is set to something sane */
505 putenv(PATH_DEFAULT); 506 putenv(_PATH_STDPATH);
506 507
507 508
508 /* Hello world */ 509 /* Hello world */
diff --git a/init/init.c b/init/init.c
index 7258d3151..088a890cc 100644
--- a/init/init.c
+++ b/init/init.c
@@ -29,6 +29,7 @@
29#include <errno.h> 29#include <errno.h>
30#include <signal.h> 30#include <signal.h>
31#include <termios.h> 31#include <termios.h>
32#include <paths.h>
32#include <sys/types.h> 33#include <sys/types.h>
33#include <sys/fcntl.h> 34#include <sys/fcntl.h>
34#include <sys/wait.h> 35#include <sys/wait.h>
@@ -44,7 +45,6 @@
44#include <sys/syslog.h> 45#include <sys/syslog.h>
45#endif 46#endif
46 47
47#define DEV_CONSOLE "/dev/console" /* Logical system console */
48#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */ 48#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
49#define VT_SECONDARY "/dev/tty2" /* Virtual console */ 49#define VT_SECONDARY "/dev/tty2" /* Virtual console */
50#define VT_LOG "/dev/tty3" /* Virtual console */ 50#define VT_LOG "/dev/tty3" /* Virtual console */
@@ -52,11 +52,10 @@
52#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 52#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
53#define SHELL "/bin/sh" /* Default shell */ 53#define SHELL "/bin/sh" /* Default shell */
54#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */ 54#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
55#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
56 55
57#define LOG 0x1 56#define LOG 0x1
58#define CONSOLE 0x2 57#define CONSOLE 0x2
59static char *console = DEV_CONSOLE; 58static char *console = _PATH_CONSOLE;
60static char *second_console = VT_SECONDARY; 59static char *second_console = VT_SECONDARY;
61static char *log = VT_LOG; 60static char *log = VT_LOG;
62static int kernel_version = 0; 61static int kernel_version = 0;
@@ -126,7 +125,7 @@ void message(int device, char *fmt, ...)
126 125
127 if (device & CONSOLE) { 126 if (device & CONSOLE) {
128 /* Always send console messages to /dev/console so people will see them. */ 127 /* Always send console messages to /dev/console so people will see them. */
129 if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) { 128 if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
130 va_start(arguments, fmt); 129 va_start(arguments, fmt);
131 vdprintf(fd, fmt, arguments); 130 vdprintf(fd, fmt, arguments);
132 va_end(arguments); 131 va_end(arguments);
@@ -242,7 +241,7 @@ static void console_init()
242 /* this is linux virtual tty */ 241 /* this is linux virtual tty */
243 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active ); 242 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
244 } else { 243 } else {
245 console = DEV_CONSOLE; 244 console = _PATH_CONSOLE;
246 tried_devcons++; 245 tried_devcons++;
247 } 246 }
248 } 247 }
@@ -251,7 +250,7 @@ static void console_init()
251 /* Can't open selected console -- try /dev/console */ 250 /* Can't open selected console -- try /dev/console */
252 if (!tried_devcons) { 251 if (!tried_devcons) {
253 tried_devcons++; 252 tried_devcons++;
254 console = DEV_CONSOLE; 253 console = _PATH_CONSOLE;
255 continue; 254 continue;
256 } 255 }
257 /* Can't open selected console -- try vt1 */ 256 /* Can't open selected console -- try vt1 */
@@ -421,6 +420,7 @@ static void halt_signal(int sig)
421 "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n"); 420 "The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
422 sync(); 421 sync();
423#ifndef DEBUG_INIT 422#ifndef DEBUG_INIT
423 while (1) sleep(1);
424 reboot(RB_HALT_SYSTEM); 424 reboot(RB_HALT_SYSTEM);
425 //reboot(RB_POWER_OFF); 425 //reboot(RB_POWER_OFF);
426#endif 426#endif
@@ -432,6 +432,7 @@ static void reboot_signal(int sig)
432 shutdown_system(); 432 shutdown_system();
433 message(CONSOLE, "Please stand by while rebooting the system.\r\n"); 433 message(CONSOLE, "Please stand by while rebooting the system.\r\n");
434 sync(); 434 sync();
435 while (1) sleep(1);
435#ifndef DEBUG_INIT 436#ifndef DEBUG_INIT
436 reboot(RB_AUTOBOOT); 437 reboot(RB_AUTOBOOT);
437#endif 438#endif
@@ -502,7 +503,7 @@ extern int init_main(int argc, char **argv)
502 setsid(); 503 setsid();
503 504
504 /* Make sure PATH is set to something sane */ 505 /* Make sure PATH is set to something sane */
505 putenv(PATH_DEFAULT); 506 putenv(_PATH_STDPATH);
506 507
507 508
508 /* Hello world */ 509 /* Hello world */
diff --git a/install.sh b/install.sh
index 458e65ce9..670c0c6e1 100755
--- a/install.sh
+++ b/install.sh
@@ -10,11 +10,10 @@ fi
10h=`sort busybox.links | uniq` 10h=`sort busybox.links | uniq`
11 11
12for i in $h ; do 12for i in $h ; do
13 mypath=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `; 13 echo " $1$i -> /bin/busybox"
14 myapp=`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `; 14 mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
15 echo " $1$mypath$myapp -> /bin/busybox" 15 rm -f $1$i
16 mkdir -p $1$mypath 16 ln -s /bin/busybox $1$i
17 (cd $1$mypath && rm -f $1$mypath$myapp && ln -s /bin/busybox $1$mypath$myapp )
18done 17done
19rm -f $1/bin/busybox 18rm -f $1/bin/busybox
20install -m 755 busybox $1/bin/busybox 19install -m 755 busybox $1/bin/busybox
diff --git a/internal.h b/internal.h
index 5cca663b4..85c37c429 100644
--- a/internal.h
+++ b/internal.h
@@ -150,6 +150,7 @@ extern struct mntent *findMountPoint(const char *name, const char *table);
150extern void write_mtab(char* blockDevice, char* directory, 150extern void write_mtab(char* blockDevice, char* directory,
151 char* filesystemType, long flags, char* string_flags); 151 char* filesystemType, long flags, char* string_flags);
152extern void erase_mtab(const char * name); 152extern void erase_mtab(const char * name);
153extern int check_wildcard_match(const char* text, const char* pattern);
153 154
154 155
155#if defined BB_MTAB 156#if defined BB_MTAB
diff --git a/regexp.c b/regexp.c
index 9f9b5c28c..02b1fe505 100644
--- a/regexp.c
+++ b/regexp.c
@@ -7,7 +7,7 @@
7#include <ctype.h> 7#include <ctype.h>
8 8
9 9
10#if ( defined BB_GREP || defined BB_FIND || defined BB_SED) 10#if ( defined BB_GREP || defined BB_SED)
11 11
12/* This also tries to find a needle in a haystack, but uses 12/* This also tries to find a needle in a haystack, but uses
13 * real regular expressions.... The fake regular expression 13 * real regular expressions.... The fake regular expression
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 736adf7d1..3c7b0170d 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -32,6 +32,12 @@
32#include <signal.h> 32#include <signal.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <netdb.h> 34#include <netdb.h>
35#include <sys/klog.h>
36#include <errno.h>
37#include <paths.h>
38
39#define ksyslog klogctl
40extern int ksyslog(int type, char *buf, int len);
35 41
36 42
37/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ 43/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
@@ -40,8 +46,6 @@
40 46
41/* Path for the file where all log messages are written */ 47/* Path for the file where all log messages are written */
42#define __LOG_FILE "/var/log/messages" 48#define __LOG_FILE "/var/log/messages"
43/* Path to the current console device */
44#define __DEV_CONSOLE "/dev/console"
45 49
46 50
47static char* logFilePath = __LOG_FILE; 51static char* logFilePath = __LOG_FILE;
@@ -58,7 +62,7 @@ static const char syslogd_usage[] =
58 "\t-n\tDo not fork into the background (for when run by init)\n" 62 "\t-n\tDo not fork into the background (for when run by init)\n"
59 "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; 63 "\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
60 64
61 65static int kmsg;
62 66
63/* try to open up the specified device */ 67/* try to open up the specified device */
64static int device_open(char *device, int mode) 68static int device_open(char *device, int mode)
@@ -92,7 +96,7 @@ static void message(char *fmt, ...)
92 close(fd); 96 close(fd);
93 } else { 97 } else {
94 /* Always send console messages to /dev/console so people will see them. */ 98 /* Always send console messages to /dev/console so people will see them. */
95 if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { 99 if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
96 va_start(arguments, fmt); 100 va_start(arguments, fmt);
97 vdprintf(fd, fmt, arguments); 101 vdprintf(fd, fmt, arguments);
98 va_end(arguments); 102 va_end(arguments);
@@ -250,20 +254,112 @@ static void doSyslogd(void)
250 close(fd); 254 close(fd);
251} 255}
252 256
257static void klogd_signal(int sig)
258{
259 //ksyslog(7, NULL, 0);
260 //ksyslog(0, 0, 0);
261 logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating.");
262 exit( TRUE);
263}
264
265
266static void doKlogd(void)
267{
268 int priority=LOG_INFO;
269 struct stat sb;
270 char log_buffer[4096];
271
272 /* Set up sig handlers */
273 signal(SIGINT, klogd_signal);
274 signal(SIGKILL, klogd_signal);
275 signal(SIGTERM, klogd_signal);
276 signal(SIGHUP, klogd_signal);
277 logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: "
278 "BusyBox v" BB_VER " (" BB_BT ") multi-call binary");
279
280 //ksyslog(1, NULL, 0);
281 if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
282 ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
283 char message[80];
284 snprintf(message, 79, "klogd: Cannot open %s, " \
285 "%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
286 logMessage(LOG_SYSLOG|LOG_ERR, message);
287 klogd_signal(0);
288 }
289 while (1) {
290 memset(log_buffer, '\0', sizeof(log_buffer));
291 if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
292 char message[80];
293 if ( errno == EINTR )
294 continue;
295 snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
296 errno, strerror(errno));
297 logMessage(LOG_SYSLOG|LOG_ERR, message);
298 klogd_signal(0);
299 }
300#if 0
301 if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
302 char message[80];
303 if ( errno == EINTR )
304 continue;
305 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
306 "%d - %s.\n", errno, strerror(errno));
307 logMessage(LOG_SYSLOG|LOG_ERR, message);
308 exit(1);
309 }
310#endif
311 fprintf(stderr, "the kernel says '%s'\n", log_buffer);
312 if ( *log_buffer == '<' )
313 {
314 switch ( *(log_buffer+1) )
315 {
316 case '0':
317 priority = LOG_EMERG;
318 break;
319 case '1':
320 priority = LOG_ALERT;
321 break;
322 case '2':
323 priority = LOG_CRIT;
324 break;
325 case '3':
326 priority = LOG_ERR;
327 break;
328 case '4':
329 priority = LOG_WARNING;
330 break;
331 case '5':
332 priority = LOG_NOTICE;
333 break;
334 case '6':
335 priority = LOG_INFO;
336 break;
337 case '7':
338 default:
339 priority = LOG_DEBUG;
340 }
341 *log_buffer += 3;
342 }
343 logMessage(LOG_KERN|priority, log_buffer);
344 }
345
346}
347
253 348
254extern int syslogd_main(int argc, char **argv) 349extern int syslogd_main(int argc, char **argv)
255{ 350{
256 int pid; 351 int pid, klogd_pid;
257 int doFork = TRUE; 352 int doFork = TRUE;
353 char **argv1=argv;
258 354
259 while (--argc > 0 && **(++argv) == '-') { 355 while (--argc > 0 && **(++argv1) == '-') {
260 while (*(++(*argv))) { 356 while (*(++(*argv1))) {
261 switch (**argv) { 357 switch (**argv1) {
262 case 'm': 358 case 'm':
263 if (--argc == 0) { 359 if (--argc == 0) {
264 usage(syslogd_usage); 360 usage(syslogd_usage);
265 } 361 }
266 MarkInterval = atoi(*(++argv))*60; 362 MarkInterval = atoi(*(++argv1))*60;
267 break; 363 break;
268 case 'n': 364 case 'n':
269 doFork = FALSE; 365 doFork = FALSE;
@@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv)
272 if (--argc == 0) { 368 if (--argc == 0) {
273 usage(syslogd_usage); 369 usage(syslogd_usage);
274 } 370 }
275 logFilePath = *(++argv); 371 logFilePath = *(++argv1);
276 break; 372 break;
277 default: 373 default:
278 usage(syslogd_usage); 374 usage(syslogd_usage);
@@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv)
285 if ( pid < 0 ) 381 if ( pid < 0 )
286 exit( pid); 382 exit( pid);
287 else if ( pid == 0 ) { 383 else if ( pid == 0 ) {
384 strncpy(argv[0], "syslogd",strlen(argv[0]));
288 doSyslogd(); 385 doSyslogd();
289 } 386 }
290 } else { 387 } else {
291 doSyslogd(); 388 doSyslogd();
292 } 389 }
390
391 /* Start klogd process */
392 klogd_pid = fork();
393 if (klogd_pid == 0 ) {
394 strncpy(argv[0], "klogd", strlen(argv[0]));
395 doKlogd();
396 }
397
293 exit( TRUE); 398 exit( TRUE);
294} 399}
295 400
diff --git a/syslogd.c b/syslogd.c
index 736adf7d1..3c7b0170d 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -32,6 +32,12 @@
32#include <signal.h> 32#include <signal.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <netdb.h> 34#include <netdb.h>
35#include <sys/klog.h>
36#include <errno.h>
37#include <paths.h>
38
39#define ksyslog klogctl
40extern int ksyslog(int type, char *buf, int len);
35 41
36 42
37/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ 43/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
@@ -40,8 +46,6 @@
40 46
41/* Path for the file where all log messages are written */ 47/* Path for the file where all log messages are written */
42#define __LOG_FILE "/var/log/messages" 48#define __LOG_FILE "/var/log/messages"
43/* Path to the current console device */
44#define __DEV_CONSOLE "/dev/console"
45 49
46 50
47static char* logFilePath = __LOG_FILE; 51static char* logFilePath = __LOG_FILE;
@@ -58,7 +62,7 @@ static const char syslogd_usage[] =
58 "\t-n\tDo not fork into the background (for when run by init)\n" 62 "\t-n\tDo not fork into the background (for when run by init)\n"
59 "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; 63 "\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
60 64
61 65static int kmsg;
62 66
63/* try to open up the specified device */ 67/* try to open up the specified device */
64static int device_open(char *device, int mode) 68static int device_open(char *device, int mode)
@@ -92,7 +96,7 @@ static void message(char *fmt, ...)
92 close(fd); 96 close(fd);
93 } else { 97 } else {
94 /* Always send console messages to /dev/console so people will see them. */ 98 /* Always send console messages to /dev/console so people will see them. */
95 if ((fd = device_open(__DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { 99 if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) {
96 va_start(arguments, fmt); 100 va_start(arguments, fmt);
97 vdprintf(fd, fmt, arguments); 101 vdprintf(fd, fmt, arguments);
98 va_end(arguments); 102 va_end(arguments);
@@ -250,20 +254,112 @@ static void doSyslogd(void)
250 close(fd); 254 close(fd);
251} 255}
252 256
257static void klogd_signal(int sig)
258{
259 //ksyslog(7, NULL, 0);
260 //ksyslog(0, 0, 0);
261 logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon terminating.");
262 exit( TRUE);
263}
264
265
266static void doKlogd(void)
267{
268 int priority=LOG_INFO;
269 struct stat sb;
270 char log_buffer[4096];
271
272 /* Set up sig handlers */
273 signal(SIGINT, klogd_signal);
274 signal(SIGKILL, klogd_signal);
275 signal(SIGTERM, klogd_signal);
276 signal(SIGHUP, klogd_signal);
277 logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: "
278 "BusyBox v" BB_VER " (" BB_BT ") multi-call binary");
279
280 //ksyslog(1, NULL, 0);
281 if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
282 ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
283 char message[80];
284 snprintf(message, 79, "klogd: Cannot open %s, " \
285 "%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
286 logMessage(LOG_SYSLOG|LOG_ERR, message);
287 klogd_signal(0);
288 }
289 while (1) {
290 memset(log_buffer, '\0', sizeof(log_buffer));
291 if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
292 char message[80];
293 if ( errno == EINTR )
294 continue;
295 snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
296 errno, strerror(errno));
297 logMessage(LOG_SYSLOG|LOG_ERR, message);
298 klogd_signal(0);
299 }
300#if 0
301 if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
302 char message[80];
303 if ( errno == EINTR )
304 continue;
305 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
306 "%d - %s.\n", errno, strerror(errno));
307 logMessage(LOG_SYSLOG|LOG_ERR, message);
308 exit(1);
309 }
310#endif
311 fprintf(stderr, "the kernel says '%s'\n", log_buffer);
312 if ( *log_buffer == '<' )
313 {
314 switch ( *(log_buffer+1) )
315 {
316 case '0':
317 priority = LOG_EMERG;
318 break;
319 case '1':
320 priority = LOG_ALERT;
321 break;
322 case '2':
323 priority = LOG_CRIT;
324 break;
325 case '3':
326 priority = LOG_ERR;
327 break;
328 case '4':
329 priority = LOG_WARNING;
330 break;
331 case '5':
332 priority = LOG_NOTICE;
333 break;
334 case '6':
335 priority = LOG_INFO;
336 break;
337 case '7':
338 default:
339 priority = LOG_DEBUG;
340 }
341 *log_buffer += 3;
342 }
343 logMessage(LOG_KERN|priority, log_buffer);
344 }
345
346}
347
253 348
254extern int syslogd_main(int argc, char **argv) 349extern int syslogd_main(int argc, char **argv)
255{ 350{
256 int pid; 351 int pid, klogd_pid;
257 int doFork = TRUE; 352 int doFork = TRUE;
353 char **argv1=argv;
258 354
259 while (--argc > 0 && **(++argv) == '-') { 355 while (--argc > 0 && **(++argv1) == '-') {
260 while (*(++(*argv))) { 356 while (*(++(*argv1))) {
261 switch (**argv) { 357 switch (**argv1) {
262 case 'm': 358 case 'm':
263 if (--argc == 0) { 359 if (--argc == 0) {
264 usage(syslogd_usage); 360 usage(syslogd_usage);
265 } 361 }
266 MarkInterval = atoi(*(++argv))*60; 362 MarkInterval = atoi(*(++argv1))*60;
267 break; 363 break;
268 case 'n': 364 case 'n':
269 doFork = FALSE; 365 doFork = FALSE;
@@ -272,7 +368,7 @@ extern int syslogd_main(int argc, char **argv)
272 if (--argc == 0) { 368 if (--argc == 0) {
273 usage(syslogd_usage); 369 usage(syslogd_usage);
274 } 370 }
275 logFilePath = *(++argv); 371 logFilePath = *(++argv1);
276 break; 372 break;
277 default: 373 default:
278 usage(syslogd_usage); 374 usage(syslogd_usage);
@@ -285,11 +381,20 @@ extern int syslogd_main(int argc, char **argv)
285 if ( pid < 0 ) 381 if ( pid < 0 )
286 exit( pid); 382 exit( pid);
287 else if ( pid == 0 ) { 383 else if ( pid == 0 ) {
384 strncpy(argv[0], "syslogd",strlen(argv[0]));
288 doSyslogd(); 385 doSyslogd();
289 } 386 }
290 } else { 387 } else {
291 doSyslogd(); 388 doSyslogd();
292 } 389 }
390
391 /* Start klogd process */
392 klogd_pid = fork();
393 if (klogd_pid == 0 ) {
394 strncpy(argv[0], "klogd", strlen(argv[0]));
395 doKlogd();
396 }
397
293 exit( TRUE); 398 exit( TRUE);
294} 399}
295 400
diff --git a/utility.c b/utility.c
index 011c0cf41..9e56dbe8a 100644
--- a/utility.c
+++ b/utility.c
@@ -771,7 +771,7 @@ int get_console_fd(char* tty_name)
771#endif 771#endif
772 772
773 773
774#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND || defined BB_SED) 774#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
775 775
776/* Do a case insensitive strstr() */ 776/* Do a case insensitive strstr() */
777char* stristr(char *haystack, const char *needle) 777char* stristr(char *haystack, const char *needle)
@@ -851,6 +851,108 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
851#endif 851#endif
852 852
853 853
854#if defined BB_FIND
855/*
856 * Routine to see if a text string is matched by a wildcard pattern.
857 * Returns TRUE if the text is matched, or FALSE if it is not matched
858 * or if the pattern is invalid.
859 * * matches zero or more characters
860 * ? matches a single character
861 * [abc] matches 'a', 'b' or 'c'
862 * \c quotes character c
863 * Adapted from code written by Ingo Wilken, and
864 * then taken from sash, Copyright (c) 1999 by David I. Bell
865 * Permission is granted to use, distribute, or modify this source,
866 * provided that this copyright notice remains intact.
867 * Permission to distribute this code under the GPL has been granted.
868 */
869extern int
870check_wildcard_match(const char* text, const char* pattern)
871{
872 const char* retryPat;
873 const char* retryText;
874 int ch;
875 int found;
876
877 retryPat = NULL;
878 retryText = NULL;
879
880 while (*text || *pattern)
881 {
882 ch = *pattern++;
883
884 switch (ch)
885 {
886 case '*':
887 retryPat = pattern;
888 retryText = text;
889 break;
890
891 case '[':
892 found = FALSE;
893
894 while ((ch = *pattern++) != ']')
895 {
896 if (ch == '\\')
897 ch = *pattern++;
898
899 if (ch == '\0')
900 return FALSE;
901
902 if (*text == ch)
903 found = TRUE;
904 }
905
906 //if (!found)
907 if (found==TRUE)
908 {
909 pattern = retryPat;
910 text = ++retryText;
911 }
912
913 /* fall into next case */
914
915 case '?':
916 if (*text++ == '\0')
917 return FALSE;
918
919 break;
920
921 case '\\':
922 ch = *pattern++;
923
924 if (ch == '\0')
925 return FALSE;
926
927 /* fall into next case */
928
929 default:
930 if (*text == ch)
931 {
932 if (*text)
933 text++;
934 break;
935 }
936
937 if (*text)
938 {
939 pattern = retryPat;
940 text = ++retryText;
941 break;
942 }
943
944 return FALSE;
945 }
946
947 if (pattern == NULL)
948 return FALSE;
949 }
950
951 return TRUE;
952}
953#endif
954
955
854 956
855 957
856#if defined BB_DF | defined BB_MTAB 958#if defined BB_DF | defined BB_MTAB
@@ -910,3 +1012,10 @@ extern void whine_if_fstab_is_missing()
910/* END CODE */ 1012/* END CODE */
911 1013
912 1014
1015
1016
1017
1018
1019
1020
1021