- merge -r15463:15564 from busybox_scratch branch through these changesets:

------------------------------------------------------------------------
r15465 | aldot | 2006-06-21 20:48:06 +0200 (Wed, 21 Jun 2006) | 3 lines

- use CONFIG_BUSYBOX_EXEC_PATH as before it one was broken by a recent revert.
- use xchdir() since all is invain if it fails there anyways, supposedly

------------------------------------------------------------------------
r15466 | aldot | 2006-06-21 20:55:16 +0200 (Wed, 21 Jun 2006) | 2 lines

- adjust docs to take CONFIG_BUSYBOX_EXEC_PATH into account.

------------------------------------------------------------------------
r15467 | aldot | 2006-06-21 21:31:24 +0200 (Wed, 21 Jun 2006) | 18 lines

- partial fallout of my TREE_USED touchup against gcc-4.2: rip unused vars, save
s 144 bytes
   text    data     bss     dec     hex filename
 862434   10156  645924 1518514  172bb2 busybox.old
 862322   10156  645892 1518370  172b22 busybox
function                                             old     new   delta
z_len                                                  4       -      -4
textend                                                4       -      -4
part_nb                                                4       -      -4
insize                                                 4       -      -4
ifile_size                                             4       -      -4
do_link                                                4       -      -4
new_text                                              70      60     -10
ipaddr_list_link                                      33      23     -10
gzip_main                                            898     822     -76
------------------------------------------------------------------------------
(add/remove: 0/6 grow/shrink: 0/3 up/down: 0/-120)           Total: -120 bytes


------------------------------------------------------------------------
r15468 | aldot | 2006-06-21 21:43:05 +0200 (Wed, 21 Jun 2006) | 19 lines

- remove useless global exports
function                                             old     new   delta
rpm_main                                             940    1601    +661
rpm_getstring                                        107     112      +5
rpm_getint                                           148     153      +5
loop_through_files                                   103     106      +3
fileaction_dobackup                                  115     113      -2
fileaction_list                                        5       -      -5
rpm_getcount                                          42       -     -42
extract_cpio_gz                                      161       -    -161
rpm_gettags                                          504       -    -504
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 4/1 up/down: 674/-714)          Total: -40 bytes

   text    data     bss     dec     hex filename
 862322   10156  645892 1518370  172b22 busybox.old
 862290   10156  645892 1518338  172b02 busybox


------------------------------------------------------------------------
r15555 | aldot | 2006-06-30 14:10:11 +0200 (Fri, 30 Jun 2006) | 22 lines

- shrink syslog a little bit, move a big buffer (for 'line') off the bss, fold s
emaphore stuff into single caller manually.
  stats:
function                                             old     new   delta
logMessage                                           395     427     +32
message                                             1245    1257     +12
opts                                                   -       4      +4
small                                                  1       -      -1
local_logging                                          4       -      -4
doRemoteLog                                            4       -      -4
circular_logging                                       4       -      -4
syslogd_main                                        1299    1285     -14
static.res                                            36      16     -20
.rodata                                           186650  186586     -64
static.line                                         1025       -   -1025
------------------------------------------------------------------------------
(add/remove: 1/5 grow/shrink: 2/3 up/down: 48/-1136)        Total: -1088 bytes
cow@s37:~/src/busybox_scratch$ size sysklogd/syslogd.o{.orig,}
   text    data     bss     dec     hex filename
   3723     348    5242    9313    2461 sysklogd/syslogd.o.orig
   3697     348    4188    8233    2029 sysklogd/syslogd.o

==============================================================================
Overall bloatcheck for the changeset mentioned above:
function                                             old     new   delta
rpm_main                                             953    1608    +655
logMessage                                           395     427     +32
message                                             1245    1257     +12
opts                                                   -       4      +4
rpm_getstring                                        107     110      +3
rpm_getint                                           148     151      +3
loop_through_files                                   103     104      +1
small                                                  1       -      -1
fileaction_dobackup                                  115     113      -2
z_len                                                  4       -      -4
textend                                                4       -      -4
part_nb                                                4       -      -4
local_logging                                          4       -      -4
insize                                                 4       -      -4
ifile_size                                             4       -      -4
do_link                                                4       -      -4
doRemoteLog                                            4       -      -4
circular_logging                                       4       -      -4
fileaction_list                                        5       -      -5
new_text                                              70      60     -10
ipaddr_list_link                                      33      23     -10
clear_bufs                                            31      21     -10
syslogd_main                                        1287    1273     -14
builtin_help                                         190     176     -14
static.res                                            36      16     -20
builtin_source                                       229     199     -30
rpm_getcount                                          42       -     -42
gzip_main                                            842     786     -56
.rodata                                           227176  227112     -64
lash_main                                            609     527     -82
busy_loop                                           3883    3739    -144
extract_cpio_gz                                      155       -    -155
rpm_gettags                                          501       -    -501
static.line                                         1025       -   -1025
------------------------------------------------------------------------------
(add/remove: 1/15 grow/shrink: 6/12 up/down: 710/-2221)     Total: -1511 bytes
This commit is contained in:
Bernhard Reutner-Fischer 2006-08-20 17:35:13 +00:00
parent 13068a4fdb
commit d591a360d3
14 changed files with 138 additions and 211 deletions

View File

@ -32,8 +32,10 @@ any built-in busybox applets directly, without looking for external
programs by that name. Supplying an empty command path (as above) means programs by that name. Supplying an empty command path (as above) means
the only commands busybox can find are the built-in ones. the only commands busybox can find are the built-in ones.
(Note that the standalone shell currently requires /proc/self/exe to Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
launch new applets.) to be set appropriately, depending on whether or not /proc/self/exe is
available or not. If you do not have /proc, then point that config option
to the location of your busybox binary, usually /bin/busybox.
Configuring Busybox: Configuring Busybox:
==================== ====================

View File

@ -263,15 +263,14 @@ DECLARE(ush, tab_prefix, 1L << BITS);
static int foreground; /* set if program run in foreground */ static int foreground; /* set if program run in foreground */
static int method = DEFLATED; /* compression method */ static int method = DEFLATED; /* compression method */
static int exit_code = OK; /* program exit code */ static int exit_code = OK; /* program exit code */
static int part_nb; /* number of parts in .gz file */
static long time_stamp; /* original time stamp (modification time) */ static long time_stamp; /* original time stamp (modification time) */
static long ifile_size; /* input file size, -1 for devices (debug only) */
static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */ static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
static int z_len; /* strlen(z_suffix) */
static int ifd; /* input file descriptor */ static int ifd; /* input file descriptor */
static int ofd; /* output file descriptor */ static int ofd; /* output file descriptor */
#ifdef DEBUG
static unsigned insize; /* valid bytes in inbuf */ static unsigned insize; /* valid bytes in inbuf */
#endif
static unsigned outcnt; /* bytes in output buffer */ static unsigned outcnt; /* bytes in output buffer */
static uint32_t *crc_32_tab; static uint32_t *crc_32_tab;
@ -302,7 +301,9 @@ static void abort_gzip(int ATTRIBUTE_UNUSED ignored)
static void clear_bufs(void) static void clear_bufs(void)
{ {
outcnt = 0; outcnt = 0;
#ifdef DEBUG
insize = 0; insize = 0;
#endif
bytes_in = 0L; bytes_in = 0L;
} }
@ -1177,7 +1178,6 @@ int gzip_main(int argc, char **argv)
#endif #endif
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1); strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1);
z_len = strlen(z_suffix);
/* Allocate all global buffers (for DYN_ALLOC option) */ /* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA); ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA);
@ -1188,13 +1188,11 @@ int gzip_main(int argc, char **argv)
/* Initialise the CRC32 table */ /* Initialise the CRC32 table */
crc_32_tab = crc32_filltable(0); crc_32_tab = crc32_filltable(0);
clear_bufs(); clear_bufs();
part_nb = 0;
if (optind == argc) { if (optind == argc) {
time_stamp = 0; time_stamp = 0;
ifile_size = -1L;
zip(STDIN_FILENO, STDOUT_FILENO); zip(STDIN_FILENO, STDOUT_FILENO);
} else { } else {
int i; int i;
@ -1205,7 +1203,6 @@ int gzip_main(int argc, char **argv)
clear_bufs(); clear_bufs();
if (strcmp(argv[i], "-") == 0) { if (strcmp(argv[i], "-") == 0) {
time_stamp = 0; time_stamp = 0;
ifile_size = -1L;
inFileNum = STDIN_FILENO; inFileNum = STDIN_FILENO;
outFileNum = STDOUT_FILENO; outFileNum = STDOUT_FILENO;
} else { } else {
@ -1213,7 +1210,6 @@ int gzip_main(int argc, char **argv)
if (fstat(inFileNum, &statBuf) < 0) if (fstat(inFileNum, &statBuf) < 0)
bb_perror_msg_and_die("%s", argv[i]); bb_perror_msg_and_die("%s", argv[i]);
time_stamp = statBuf.st_ctime; time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size;
if (!tostdout) { if (!tostdout) {
path = xmalloc(strlen(argv[i]) + 4); path = xmalloc(strlen(argv[i]) + 4);

View File

@ -70,17 +70,15 @@ static void *map;
static rpm_index **mytags; static rpm_index **mytags;
static int tagcount; static int tagcount;
void extract_cpio_gz(int fd); static void extract_cpio_gz(int fd);
rpm_index **rpm_gettags(int fd, int *num_tags); static rpm_index **rpm_gettags(int fd, int *num_tags);
int bsearch_rpmtag(const void *key, const void *item); static int bsearch_rpmtag(const void *key, const void *item);
char *rpm_getstring(int tag, int itemindex); static char *rpm_getstring(int tag, int itemindex);
int rpm_getint(int tag, int itemindex); static int rpm_getint(int tag, int itemindex);
int rpm_getcount(int tag); static int rpm_getcount(int tag);
void exec_script(int progtag, int datatag, char *prefix); static void fileaction_dobackup(char *filename, int fileref);
void fileaction_dobackup(char *filename, int fileref); static void fileaction_setowngrp(char *filename, int fileref);
void fileaction_setowngrp(char *filename, int fileref); static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
void fileaction_list(char *filename, int itemno);
void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
int rpm_main(int argc, char **argv) int rpm_main(int argc, char **argv)
{ {
@ -169,7 +167,7 @@ int rpm_main(int argc, char **argv)
return 0; return 0;
} }
void extract_cpio_gz(int fd) { static void extract_cpio_gz(int fd) {
archive_handle_t *archive_handle; archive_handle_t *archive_handle;
unsigned char magic[2]; unsigned char magic[2];
@ -196,7 +194,7 @@ void extract_cpio_gz(int fd) {
} }
rpm_index **rpm_gettags(int fd, int *num_tags) static rpm_index **rpm_gettags(int fd, int *num_tags)
{ {
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */ rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
int pass, tagindex = 0; int pass, tagindex = 0;
@ -235,14 +233,14 @@ rpm_index **rpm_gettags(int fd, int *num_tags)
return tags; /* All done, leave the file at the start of the gzipped cpio archive */ return tags; /* All done, leave the file at the start of the gzipped cpio archive */
} }
int bsearch_rpmtag(const void *key, const void *item) static int bsearch_rpmtag(const void *key, const void *item)
{ {
int *tag = (int *)key; int *tag = (int *)key;
rpm_index **tmp = (rpm_index **) item; rpm_index **tmp = (rpm_index **) item;
return (*tag - tmp[0]->tag); return (*tag - tmp[0]->tag);
} }
int rpm_getcount(int tag) static int rpm_getcount(int tag)
{ {
rpm_index **found; rpm_index **found;
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
@ -250,7 +248,7 @@ int rpm_getcount(int tag)
else return found[0]->count; else return found[0]->count;
} }
char *rpm_getstring(int tag, int itemindex) static char *rpm_getstring(int tag, int itemindex)
{ {
rpm_index **found; rpm_index **found;
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
@ -263,7 +261,7 @@ char *rpm_getstring(int tag, int itemindex)
} else return NULL; } else return NULL;
} }
int rpm_getint(int tag, int itemindex) static int rpm_getint(int tag, int itemindex)
{ {
rpm_index **found; rpm_index **found;
int n, *tmpint; int n, *tmpint;
@ -284,7 +282,7 @@ int rpm_getint(int tag, int itemindex)
} else return -1; } else return -1;
} }
void fileaction_dobackup(char *filename, int fileref) static void fileaction_dobackup(char *filename, int fileref)
{ {
struct stat oldfile; struct stat oldfile;
int stat_res; int stat_res;
@ -301,7 +299,7 @@ void fileaction_dobackup(char *filename, int fileref)
} }
} }
void fileaction_setowngrp(char *filename, int fileref) static void fileaction_setowngrp(char *filename, int fileref)
{ {
int uid, gid; int uid, gid;
uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref)); uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
@ -309,12 +307,7 @@ void fileaction_setowngrp(char *filename, int fileref)
chown (filename, uid, gid); chown (filename, uid, gid);
} }
void fileaction_list(char *filename, int ATTRIBUTE_UNUSED fileref) static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
{
printf("%s\n", filename);
}
void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
{ {
int count = 0; int count = 0;
while (rpm_getstring(filetag, count)) { while (rpm_getstring(filetag, count)) {

View File

@ -29,14 +29,9 @@
* - use bb_default_error_retval * - use bb_default_error_retval
*/ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h> /* struct option */
#include "busybox.h" #include "busybox.h"
#include <errno.h>
#include <getopt.h> /* struct option */
#if ENABLE_FEATURE_ENV_LONG_OPTIONS #if ENABLE_FEATURE_ENV_LONG_OPTIONS
static const struct option env_long_options[] = { static const struct option env_long_options[] = {
@ -50,7 +45,7 @@ int env_main(int argc, char** argv)
{ {
static char *cleanenv[1] = { NULL }; static char *cleanenv[1] = { NULL };
char **ep, *p; char **ep;
unsigned long opt; unsigned long opt;
llist_t *unset_env = NULL; llist_t *unset_env = NULL;
extern char **environ; extern char **environ;
@ -77,7 +72,7 @@ int env_main(int argc, char** argv)
} }
} }
while (*argv && ((p = strchr(*argv, '=')) != NULL)) { while (*argv && (strchr(*argv, '=') != NULL)) {
if (putenv(*argv) < 0) { if (putenv(*argv) < 0) {
bb_perror_msg_and_die("putenv"); bb_perror_msg_and_die("putenv");
} }

View File

@ -129,9 +129,8 @@ int uudecode_main(int argc, char **argv)
FILE *src_stream; FILE *src_stream;
char *outname = NULL; char *outname = NULL;
char *line; char *line;
int opt;
opt = bb_getopt_ulflags(argc, argv, "o:", &outname); bb_getopt_ulflags(argc, argv, "o:", &outname);
if (optind == argc) { if (optind == argc) {
src_stream = stdin; src_stream = stdin;

View File

@ -88,9 +88,13 @@ have additions to this FAQ document, we would love to add them,
the command line "PATH= ./busybox ash". This will blank your command path the command line "PATH= ./busybox ash". This will blank your command path
and run busybox as your command shell, so the only commands it can find and run busybox as your command shell, so the only commands it can find
(without an explicit path such as /bin/ls) are the built-in busybox ones. (without an explicit path such as /bin/ls) are the built-in busybox ones.
This is another good way to see what's built into busybox. (Note that the This is another good way to see what's built into busybox.
standalone shell is dependent on the existence of /proc/self/exe, so before Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
using it in a chroot environment you must mount /proc.) to be set appropriately, depending on whether or not /proc/self/exe is
available or not. If you do not have /proc, then point that config option
to the location of your busybox binary, usually /bin/busybox.
(So if you set it to /proc/self/exe, and happen to be able to chroot into
your rootfs, you must mount /proc beforehand.)
</p> </p>
<hr /> <hr />

View File

@ -116,7 +116,7 @@ static Byte *status_buffer; // mesages to the user
static int have_status_msg; // is default edit status needed? static int have_status_msg; // is default edit status needed?
static int last_status_cksum; // hash of current status line static int last_status_cksum; // hash of current status line
static Byte *cfn; // previous, current, and next file name static Byte *cfn; // previous, current, and next file name
static Byte *text, *end, *textend; // pointers to the user data in memory static Byte *text, *end; // pointers to the user data in memory
static Byte *screen; // pointer to the virtual screen buffer static Byte *screen; // pointer to the virtual screen buffer
static int screensize; // and its size static int screensize; // and its size
static Byte *screenbegin; // index into text[], of top line on the screen static Byte *screenbegin; // index into text[], of top line on the screen
@ -582,7 +582,7 @@ static void colon(Byte * buf)
{ {
Byte c, *orig_buf, *buf1, *q, *r; Byte c, *orig_buf, *buf1, *q, *r;
Byte *fn, cmd[BUFSIZ], args[BUFSIZ]; Byte *fn, cmd[BUFSIZ], args[BUFSIZ];
int i, l, li, ch, st, b, e; int i, l, li, ch, b, e;
int useforce = FALSE, forced = FALSE; int useforce = FALSE, forced = FALSE;
struct stat st_buf; struct stat st_buf;
@ -606,7 +606,7 @@ static void colon(Byte * buf)
if (*buf == ':') if (*buf == ':')
buf++; // move past the ':' buf++; // move past the ':'
li = st = ch = i = 0; li = ch = i = 0;
b = e = -1; b = e = -1;
q = text; // assume 1,$ for the range q = text; // assume 1,$ for the range
r = end - 1; r = end - 1;
@ -1075,14 +1075,13 @@ static void Hit_Return(void)
//----- Synchronize the cursor to Dot -------------------------- //----- Synchronize the cursor to Dot --------------------------
static void sync_cursor(Byte * d, int *row, int *col) static void sync_cursor(Byte * d, int *row, int *col)
{ {
Byte *beg_cur; // begin and end of "d" line Byte *beg_cur; // begin and end of "d" line
Byte *beg_scr, *end_scr; // begin and end of screen Byte *end_scr; // begin and end of screen
Byte *tp; Byte *tp;
int cnt, ro, co; int cnt, ro, co;
beg_cur = begin_line(d); // first char of cur line beg_cur = begin_line(d); // first char of cur line
beg_scr = end_scr = screenbegin; // first char of screen
end_scr = end_screen(); // last char of screen end_scr = end_screen(); // last char of screen
if (beg_cur < screenbegin) { if (beg_cur < screenbegin) {
@ -1385,8 +1384,6 @@ static Byte *new_text(int size)
text = (Byte *) xmalloc(size + 8); text = (Byte *) xmalloc(size + 8);
memset(text, '\0', size); // clear new text[] memset(text, '\0', size); // clear new text[]
//text += 4; // leave some room for "oops" //text += 4; // leave some room for "oops"
textend = text + size - 1;
//textend -= 4; // leave some root for "oops"
return (text); return (text);
} }
@ -1963,9 +1960,7 @@ static Byte *text_yank(Byte * p, Byte * q, int dest) // copy text into a registe
static Byte what_reg(void) static Byte what_reg(void)
{ {
Byte c; Byte c;
int i;
i = 0;
c = 'D'; // default to D-reg c = 'D'; // default to D-reg
if (0 <= YDreg && YDreg <= 25) if (0 <= YDreg && YDreg <= 25)
c = 'a' + (Byte) YDreg; c = 'a' + (Byte) YDreg;

View File

@ -33,7 +33,7 @@ void vfork_daemon_rexec(int nochdir, int noclose,
setsid(); setsid();
if (!nochdir) if (!nochdir)
chdir("/"); xchdir("/");
if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO); dup2(fd, STDIN_FILENO);
@ -44,7 +44,7 @@ void vfork_daemon_rexec(int nochdir, int noclose,
} }
vfork_args = xcalloc(sizeof(char *), argc + 3); vfork_args = xcalloc(sizeof(char *), argc + 3);
vfork_args[a++] = "/bin/busybox"; vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH;
while(*argv) { while(*argv) {
vfork_args[a++] = *argv; vfork_args[a++] = *argv;
argv++; argv++;

View File

@ -872,14 +872,12 @@ static void save_input_to_file(void)
static void add_mark(void) static void add_mark(void)
{ {
int letter; int letter;
int mark_line;
clear_line(); clear_line();
printf("Mark: "); printf("Mark: ");
letter = tless_getch(); letter = tless_getch();
if (isalpha(letter)) { if (isalpha(letter)) {
mark_line = line_pos;
/* If we exceed 15 marks, start overwriting previous ones */ /* If we exceed 15 marks, start overwriting previous ones */
if (num_marks == 14) if (num_marks == 14)
@ -927,19 +925,14 @@ static char opp_bracket(char bracket)
switch (bracket) { switch (bracket) {
case '{': case '[': case '{': case '[':
return bracket + 2; return bracket + 2;
break;
case '(': case '(':
return ')'; return ')';
break;
case '}': case ']': case '}': case ']':
return bracket - 2; return bracket - 2;
break;
case ')': case ')':
return '('; return '(';
break;
default: default:
return 0; return 0;
break;
} }
} }

View File

@ -76,8 +76,7 @@ int makedevs_main(int argc, char **argv)
int linenum = 0; int linenum = 0;
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
unsigned long flags; bb_getopt_ulflags(argc, argv, "d:", &line);
flags = bb_getopt_ulflags(argc, argv, "d:", &line);
if (line) if (line)
table = xfopen(line, "r"); table = xfopen(line, "r");

View File

@ -908,7 +908,6 @@ static void config (int sig ATTRIBUTE_UNUSED)
{ {
servtab_t *sep, *cp, **sepp; servtab_t *sep, *cp, **sepp;
sigset_t omask; sigset_t omask;
int add;
size_t n; size_t n;
char protoname[10]; char protoname[10];
@ -923,7 +922,7 @@ static void config (int sig ATTRIBUTE_UNUSED)
for (sep = servtab; sep; sep = sep->se_next) for (sep = servtab; sep; sep = sep->se_next)
if (matchconf (sep, cp)) if (matchconf (sep, cp))
break; break;
add = 0;
if (sep != 0) { if (sep != 0) {
int i; int i;
@ -958,7 +957,6 @@ static void config (int sig ATTRIBUTE_UNUSED)
#endif #endif
sigprocmask(SIG_UNBLOCK, &omask, NULL); sigprocmask(SIG_UNBLOCK, &omask, NULL);
freeconfig (cp); freeconfig (cp);
add = 1;
} else { } else {
sep = enter (cp); sep = enter (cp);
} }

View File

@ -29,8 +29,6 @@
/* take from linux/sockios.h */ /* take from linux/sockios.h */
#define SIOCSIFNAME 0x8923 /* set interface name */ #define SIOCSIFNAME 0x8923 /* set interface name */
static int do_link;
static int on_off(char *msg) static int on_off(char *msg)
{ {
bb_error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg); bb_error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg);
@ -336,7 +334,6 @@ static int do_set(int argc, char **argv)
static int ipaddr_list_link(int argc, char **argv) static int ipaddr_list_link(int argc, char **argv)
{ {
preferred_family = AF_PACKET; preferred_family = AF_PACKET;
do_link = 1;
return ipaddr_list_or_flush(argc, argv, 0); return ipaddr_list_or_flush(argc, argv, 0);
} }

View File

@ -54,6 +54,9 @@ enum {
ELSE_EXP_CONTEXT = 0x10 ELSE_EXP_CONTEXT = 0x10
}; };
#define LASH_OPT_DONE (1)
#define LASH_OPT_SAW_QUOTE (2)
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS #ifdef CONFIG_LASH_PIPE_N_REDIRECTS
struct redir_struct { struct redir_struct {
enum redir_type type; /* type of redirection */ enum redir_type type; /* type of redirection */
@ -154,7 +157,7 @@ static int shell_context; /* Type prompt trigger (PS1 or PS2) */
/* Globals that are static to this file */ /* Globals that are static to this file */
static const char *cwd; static const char *cwd;
static char *local_pending_command = NULL; static char *local_pending_command;
static struct jobset job_list = { NULL, NULL }; static struct jobset job_list = { NULL, NULL };
static int argc; static int argc;
static char **argv; static char **argv;
@ -176,7 +179,7 @@ static inline void debug_printf(const char *format, ...)
va_end(args); va_end(args);
} }
#else #else
static inline void debug_printf(const char *format, ...) { } static inline void debug_printf(const char ATTRIBUTE_UNUSED *format, ...) { }
#endif #endif
/* /*
@ -304,12 +307,12 @@ static int builtin_fg_bg(struct child_prog *child)
} }
/* built-in 'help' handler */ /* built-in 'help' handler */
static int builtin_help(struct child_prog *dummy) static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
{ {
struct built_in_command *x; struct built_in_command *x;
printf("\nBuilt-in commands:\n"); printf("\nBuilt-in commands:\n"
printf("-------------------\n"); "-------------------\n");
for (x = bltins; x->cmd; x++) { for (x = bltins; x->cmd; x++) {
if (x->descr==NULL) if (x->descr==NULL)
continue; continue;
@ -320,7 +323,7 @@ static int builtin_help(struct child_prog *dummy)
continue; continue;
printf("%s\t%s\n", x->cmd, x->descr); printf("%s\t%s\n", x->cmd, x->descr);
} }
printf("\n\n"); putchar('\n');
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -343,7 +346,7 @@ static int builtin_jobs(struct child_prog *child)
/* built-in 'pwd' handler */ /* built-in 'pwd' handler */
static int builtin_pwd(struct child_prog *dummy) static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy)
{ {
cwd = xgetcwd((char *)cwd); cwd = xgetcwd((char *)cwd);
if (!cwd) if (!cwd)
@ -386,7 +389,7 @@ static int builtin_export(struct child_prog *child)
/* built-in 'read VAR' handler */ /* built-in 'read VAR' handler */
static int builtin_read(struct child_prog *child) static int builtin_read(struct child_prog *child)
{ {
int res = 0, len, newlen; int res = 0, len;
char *s; char *s;
char string[MAX_READ]; char string[MAX_READ];
@ -397,16 +400,16 @@ static int builtin_read(struct child_prog *child)
string[len++] = '='; string[len++] = '=';
string[len] = '\0'; string[len] = '\0';
fgets(&string[len], sizeof(string) - len, stdin); /* read string */ fgets(&string[len], sizeof(string) - len, stdin); /* read string */
newlen = strlen(string); res = strlen(string);
if(newlen > len) if (res > len)
string[--newlen] = '\0'; /* chomp trailing newline */ string[--res] = '\0'; /* chomp trailing newline */
/* /*
** string should now contain "VAR=<value>" ** string should now contain "VAR=<value>"
** copy it (putenv() won't do that, so we must make sure ** copy it (putenv() won't do that, so we must make sure
** the string resides in a static buffer!) ** the string resides in a static buffer!)
*/ */
res = -1; res = -1;
if((s = strdup(string))) if ((s = strdup(string)))
res = putenv(s); res = putenv(s);
if (res) if (res)
bb_perror_msg("read"); bb_perror_msg("read");
@ -423,12 +426,8 @@ static int builtin_source(struct child_prog *child)
FILE *input; FILE *input;
int status; int status;
if (child->argv[1] == NULL) input = bb_wfopen(child->argv[1], "r");
return EXIT_FAILURE;
input = fopen(child->argv[1], "r");
if (!input) { if (!input) {
printf( "Couldn't open file '%s'\n", child->argv[1]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -635,7 +634,7 @@ static inline void setup_prompt_string(char **prompt_str)
if (shell_context == 0) { if (shell_context == 0) {
free(PS1); free(PS1);
PS1=xmalloc(strlen(cwd)+4); PS1=xmalloc(strlen(cwd)+4);
sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# "); sprintf(PS1, "%s %c ", cwd, ( geteuid() != 0 ) ? '$': '#');
*prompt_str = PS1; *prompt_str = PS1;
} else { } else {
*prompt_str = PS2; *prompt_str = PS2;
@ -688,20 +687,18 @@ static int get_command(FILE * source, char *command)
static char * strsep_space( char *string, int * ix) static char * strsep_space( char *string, int * ix)
{ {
char *token;
/* Short circuit the trivial case */ /* Short circuit the trivial case */
if ( !string || ! string[*ix]) if ( !string || ! string[*ix])
return NULL; return NULL;
/* Find the end of the token. */ /* Find the end of the token. */
while( string[*ix] && !isspace(string[*ix]) ) { while (string[*ix] && !isspace(string[*ix]) ) {
(*ix)++; (*ix)++;
} }
/* Find the end of any whitespace trailing behind /* Find the end of any whitespace trailing behind
* the token and let that be part of the token */ * the token and let that be part of the token */
while( string[*ix] && isspace(string[*ix]) ) { while (string[*ix] && (isspace)(string[*ix]) ) {
(*ix)++; (*ix)++;
} }
@ -710,9 +707,7 @@ static char * strsep_space( char *string, int * ix)
return NULL; return NULL;
} }
token = xstrndup(string, *ix); return xstrndup(string, *ix);
return token;
} }
static int expand_arguments(char *command) static int expand_arguments(char *command)
@ -721,7 +716,7 @@ static int expand_arguments(char *command)
expand_t expand_result; expand_t expand_result;
char *tmpcmd, *cmd, *cmd_copy; char *tmpcmd, *cmd, *cmd_copy;
char *src, *dst, *var; char *src, *dst, *var;
const char *out_of_space = "out of space during expansion"; const char * const out_of_space = "out of space during expansion";
int flags = GLOB_NOCHECK int flags = GLOB_NOCHECK
#ifdef GLOB_BRACE #ifdef GLOB_BRACE
| GLOB_BRACE | GLOB_BRACE
@ -846,7 +841,7 @@ static int expand_arguments(char *command)
num_skip_chars=1; num_skip_chars=1;
} else { } else {
src=dst+1; src=dst+1;
while(isalnum(*src) || *src=='_') src++; while((isalnum)(*src) || *src=='_') src++;
} }
if (src == NULL) { if (src == NULL) {
src = dst+dstlen; src = dst+dstlen;
@ -890,10 +885,9 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
char *command; char *command;
char *return_command = NULL; char *return_command = NULL;
char *src, *buf; char *src, *buf;
int argc_l = 0; int argc_l;
int done = 0; int flag;
int argv_alloced; int argv_alloced;
int saw_quote = 0;
char quote = '\0'; char quote = '\0';
struct child_prog *prog; struct child_prog *prog;
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS #ifdef CONFIG_LASH_PIPE_N_REDIRECTS
@ -902,8 +896,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
#endif #endif
/* skip leading white space */ /* skip leading white space */
while (**command_ptr && isspace(**command_ptr)) *command_ptr = skip_whitespace(*command_ptr);
(*command_ptr)++;
/* this handles empty lines or leading '#' characters */ /* this handles empty lines or leading '#' characters */
if (!**command_ptr || (**command_ptr == '#')) { if (!**command_ptr || (**command_ptr == '#')) {
@ -937,9 +930,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced); prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced);
prog->argv[0] = job->cmdbuf; prog->argv[0] = job->cmdbuf;
flag = argc_l = 0;
buf = command; buf = command;
src = *command_ptr; src = *command_ptr;
while (*src && !done) { while (*src && !(flag & LASH_OPT_DONE)) {
if (quote == *src) { if (quote == *src) {
quote = '\0'; quote = '\0';
} else if (quote) { } else if (quote) {
@ -960,7 +954,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
*src == ']') *buf++ = '\\'; *src == ']') *buf++ = '\\';
*buf++ = *src; *buf++ = *src;
} else if (isspace(*src)) { } else if (isspace(*src)) {
if (*prog->argv[argc_l] || saw_quote) { if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE) {
buf++, argc_l++; buf++, argc_l++;
/* +1 here leaves room for the NULL which ends argv */ /* +1 here leaves room for the NULL which ends argv */
if ((argc_l + 1) == argv_alloced) { if ((argc_l + 1) == argv_alloced) {
@ -970,21 +964,21 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
argv_alloced); argv_alloced);
} }
prog->argv[argc_l] = buf; prog->argv[argc_l] = buf;
saw_quote = 0; flag ^= LASH_OPT_SAW_QUOTE;
} }
} else } else
switch (*src) { switch (*src) {
case '"': case '"':
case '\'': case '\'':
quote = *src; quote = *src;
saw_quote = 1; flag |= LASH_OPT_SAW_QUOTE;
break; break;
case '#': /* comment */ case '#': /* comment */
if (*(src-1)== '$') if (*(src-1)== '$')
*buf++ = *src; *buf++ = *src;
else else
done = 1; flag |= LASH_OPT_DONE;
break; break;
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS #ifdef CONFIG_LASH_PIPE_N_REDIRECTS
@ -1027,8 +1021,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
/* This isn't POSIX sh compliant. Oh well. */ /* This isn't POSIX sh compliant. Oh well. */
chptr = src; chptr = src;
while (isspace(*chptr)) chptr = skip_whitespace(chptr);
chptr++;
if (!*chptr) { if (!*chptr) {
bb_error_msg("file name expected after %c", *(src-1)); bb_error_msg("file name expected after %c", *(src-1));
@ -1047,13 +1040,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
case '|': /* pipe */ case '|': /* pipe */
/* finish this command */ /* finish this command */
if (*prog->argv[argc_l] || saw_quote) if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE)
argc_l++; argc_l++;
if (!argc_l) { if (!argc_l) {
bb_error_msg("empty command in pipe"); goto empty_command_in_pipe;
free_job(job);
job->num_progs=0;
return 1;
} }
prog->argv[argc_l] = NULL; prog->argv[argc_l] = NULL;
@ -1073,10 +1063,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
prog->argv[0] = ++buf; prog->argv[0] = ++buf;
src++; src++;
while (*src && isspace(*src)) src = skip_whitespace(src);
src++;
if (!*src) { if (!*src) {
empty_command_in_pipe:
bb_error_msg("empty command in pipe"); bb_error_msg("empty command in pipe");
free_job(job); free_job(job);
job->num_progs=0; job->num_progs=0;
@ -1090,9 +1080,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
#ifdef CONFIG_LASH_JOB_CONTROL #ifdef CONFIG_LASH_JOB_CONTROL
case '&': /* background */ case '&': /* background */
*inbg = 1; *inbg = 1;
/* fallthrough */
#endif #endif
case ';': /* multiple commands */ case ';': /* multiple commands */
done = 1; flag |= LASH_OPT_DONE;
return_command = *command_ptr + (src - *command_ptr) + 1; return_command = *command_ptr + (src - *command_ptr) + 1;
break; break;
@ -1113,7 +1104,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
src++; src++;
} }
if (*prog->argv[argc_l] || saw_quote) { if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE) {
argc_l++; argc_l++;
} }
if (!argc_l) { if (!argc_l) {
@ -1295,7 +1286,7 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2])
signal(SIGTTOU, SIG_DFL); signal(SIGTTOU, SIG_DFL);
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_DFL);
// Close all open filehandles. /* Close all open filehandles. */
while(close_me_list) close((long)llist_pop(&close_me_list)); while(close_me_list) close((long)llist_pop(&close_me_list));
if (outpipe[1]!=-1) { if (outpipe[1]!=-1) {
@ -1512,14 +1503,13 @@ static inline void setup_job_control(void)
int lash_main(int argc_l, char **argv_l) int lash_main(int argc_l, char **argv_l)
{ {
int opt, interactive=FALSE; unsigned long opt;
FILE *input = stdin; FILE *input = stdin;
argc = argc_l; argc = argc_l;
argv = argv_l; argv = argv_l;
/* These variables need re-initializing when recursing */ /* These variables need re-initializing when recursing */
last_jobid = 0; last_jobid = 0;
local_pending_command = NULL;
close_me_list = NULL; close_me_list = NULL;
job_list.head = NULL; job_list.head = NULL;
job_list.fg = NULL; job_list.fg = NULL;
@ -1532,27 +1522,18 @@ int lash_main(int argc_l, char **argv_l)
llist_add_to(&close_me_list, (void *)(long)fileno(prof_input)); llist_add_to(&close_me_list, (void *)(long)fileno(prof_input));
/* Now run the file */ /* Now run the file */
busy_loop(prof_input); busy_loop(prof_input);
fclose(prof_input); bb_fclose_nonstdin(prof_input);
llist_pop(&close_me_list); llist_pop(&close_me_list);
} }
} }
while ((opt = getopt(argc_l, argv_l, "cxi")) > 0) { opt = bb_getopt_ulflags(argc_l, argv_l, "+ic:", &local_pending_command);
switch (opt) { #define LASH_OPT_i (1<<0)
case 'c': #define LASH_OPT_c (1<<2)
input = NULL; if (opt & LASH_OPT_c) {
if (local_pending_command != 0) input = NULL;
bb_error_msg_and_die("multiple -c arguments"); optind++;
local_pending_command = xstrdup(argv[optind]); argv += optind;
optind++;
argv = argv+optind;
break;
case 'i':
interactive++;
break;
default:
bb_show_usage();
}
} }
/* A shell is interactive if the `-i' flag was given, or if all of /* A shell is interactive if the `-i' flag was given, or if all of
* the following conditions are met: * the following conditions are met:
@ -1564,14 +1545,15 @@ int lash_main(int argc_l, char **argv_l)
if (argv[optind]==NULL && input==stdin && if (argv[optind]==NULL && input==stdin &&
isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))
{ {
interactive++; opt |= LASH_OPT_i;
} }
setup_job_control(); setup_job_control();
if (interactive) { if (opt & LASH_OPT_i) {
/* Looks like they want an interactive shell */ /* Looks like they want an interactive shell */
if (!ENABLE_FEATURE_SH_EXTRA_QUIET) { if (!ENABLE_FEATURE_SH_EXTRA_QUIET) {
printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER); printf("\n\n%s Built-in shell (lash)\n"
printf( "Enter 'help' for a list of built-in commands.\n\n"); "Enter 'help' for a list of built-in commands.\n\n",
BB_BANNER);
} }
} else if (!local_pending_command && argv[optind]) { } else if (!local_pending_command && argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);

View File

@ -57,14 +57,14 @@ static char *RemoteHost;
/* what port to log to? */ /* what port to log to? */
static int RemotePort = 514; static int RemotePort = 514;
/* To remote log or not to remote log, that is the question. */
static int doRemoteLog = FALSE;
static int local_logging = FALSE;
#endif #endif
/* Make loging output smaller. */ /* options */
static bool small = false; static unsigned opts;
#define SYSLOG_OPT_small (1)
#define SYSLOG_OPT_remotelog (2)
#define SYSLOG_OPT_locallog (4)
#define SYSLOG_OPT_circularlog (8)
#define MAXLINE 1024 /* maximum line length */ #define MAXLINE 1024 /* maximum line length */
@ -98,28 +98,6 @@ static struct sembuf SMwdn[3] = { {0, 0}, {1, 0}, {1, +1} }; // set SMwdn
static int shmid = -1; // ipc shared memory id static int shmid = -1; // ipc shared memory id
static int s_semid = -1; // ipc semaphore id static int s_semid = -1; // ipc semaphore id
static int shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024); // default shm size static int shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024); // default shm size
static int circular_logging = FALSE;
/*
* sem_up - up()'s a semaphore.
*/
static inline void sem_up(int semid)
{
if (semop(semid, SMwup, 1) == -1) {
bb_perror_msg_and_die("semop[SMwup]");
}
}
/*
* sem_down - down()'s a semaphore
*/
static inline void sem_down(int semid)
{
if (semop(semid, SMwdn, 3) == -1) {
bb_perror_msg_and_die("semop[SMwdn]");
}
}
static void ipcsyslog_cleanup(void) static void ipcsyslog_cleanup(void)
{ {
@ -169,8 +147,11 @@ static void ipcsyslog_init(void)
static void circ_message(const char *msg) static void circ_message(const char *msg)
{ {
int l = strlen(msg) + 1; /* count the whole message w/ '\0' included */ int l = strlen(msg) + 1; /* count the whole message w/ '\0' included */
const char * const fail_msg = "Can't find the terminator token%s?\n";
sem_down(s_semid); if (semop(s_semid, SMwdn, 3) == -1) {
bb_perror_msg_and_die("SMwdn");
}
/* /*
* Circular Buffer Algorithm: * Circular Buffer Algorithm:
@ -220,7 +201,7 @@ static void circ_message(const char *msg)
/* Note: HEAD is only used to "retrieve" messages, it's not used /* Note: HEAD is only used to "retrieve" messages, it's not used
when writing messages into our buffer */ when writing messages into our buffer */
} else { /* show an error message to know we messed up? */ } else { /* show an error message to know we messed up? */
printf("Weird! Can't find the terminator token?\n"); printf(fail_msg,"");
buf->head = 0; buf->head = 0;
} }
} }
@ -256,13 +237,15 @@ static void circ_message(const char *msg)
/* we need to place the TAIL at the end of the message */ /* we need to place the TAIL at the end of the message */
buf->tail = k + 1; buf->tail = k + 1;
} else { } else {
printf printf(fail_msg, " from the beginning");
("Weird! Can't find the terminator token from the beginning?\n");
buf->head = buf->tail = 0; /* reset buffer, since it's probably corrupted */ buf->head = buf->tail = 0; /* reset buffer, since it's probably corrupted */
} }
} }
sem_up(s_semid); if (semop(s_semid, SMwup, 1) == -1) {
bb_perror_msg_and_die("SMwup");
}
} }
#endif /* CONFIG_FEATURE_IPC_SYSLOG */ #endif /* CONFIG_FEATURE_IPC_SYSLOG */
@ -280,7 +263,7 @@ static void message(char *fmt, ...)
fl.l_len = 1; fl.l_len = 1;
#ifdef CONFIG_FEATURE_IPC_SYSLOG #ifdef CONFIG_FEATURE_IPC_SYSLOG
if ((circular_logging == TRUE) && (buf != NULL)) { if ((opts & SYSLOG_OPT_circularlog) && (buf != NULL)) {
char b[1024]; char b[1024];
va_start(arguments, fmt); va_start(arguments, fmt);
@ -295,8 +278,8 @@ static void message(char *fmt, ...)
O_NONBLOCK)) >= 0) { O_NONBLOCK)) >= 0) {
fl.l_type = F_WRLCK; fl.l_type = F_WRLCK;
fcntl(fd, F_SETLKW, &fl); fcntl(fd, F_SETLKW, &fl);
#ifdef CONFIG_FEATURE_ROTATE_LOGFILE
if ( logFileSize > 0 ) { if (ENABLE_FEATURE_ROTATE_LOGFILE && logFileSize > 0 ) {
struct stat statf; struct stat statf;
int r = fstat(fd, &statf); int r = fstat(fd, &statf);
if( !r && (statf.st_mode & S_IFREG) if( !r && (statf.st_mode & S_IFREG)
@ -324,7 +307,7 @@ static void message(char *fmt, ...)
} }
} }
} }
#endif
va_start(arguments, fmt); va_start(arguments, fmt);
vdprintf(fd, fmt, arguments); vdprintf(fd, fmt, arguments);
va_end(arguments); va_end(arguments);
@ -364,10 +347,7 @@ static void logMessage(int pri, char *msg)
{ {
time_t now; time_t now;
char *timestamp; char *timestamp;
static char res[20]; char res[20];
#ifdef CONFIG_FEATURE_REMOTE_LOG
static char line[MAXLINE + 1];
#endif
CODE *c_pri, *c_fac; CODE *c_pri, *c_fac;
if (pri != 0) { if (pri != 0) {
@ -396,7 +376,8 @@ static void logMessage(int pri, char *msg)
/* todo: supress duplicates */ /* todo: supress duplicates */
#ifdef CONFIG_FEATURE_REMOTE_LOG #ifdef CONFIG_FEATURE_REMOTE_LOG
if (doRemoteLog == TRUE) { if (opts & SYSLOG_OPT_remotelog) {
char line[MAXLINE + 1];
/* trying connect the socket */ /* trying connect the socket */
if (-1 == remotefd) { if (-1 == remotefd) {
init_RemoteLog(); init_RemoteLog();
@ -407,7 +388,7 @@ static void logMessage(int pri, char *msg)
now = 1; now = 1;
snprintf(line, sizeof(line), "<%d>%s", pri, msg); snprintf(line, sizeof(line), "<%d>%s", pri, msg);
retry: retry:
/* send message to remote logger */ /* send message to remote logger */
if(( -1 == sendto(remotefd, line, strlen(line), 0, if(( -1 == sendto(remotefd, line, strlen(line), 0,
(struct sockaddr *) &remoteaddr, (struct sockaddr *) &remoteaddr,
@ -420,11 +401,11 @@ static void logMessage(int pri, char *msg)
} }
} }
if (local_logging == TRUE) if (opts & SYSLOG_OPT_locallog)
#endif #endif
{ {
/* now spew out the message to wherever it is supposed to go */ /* now spew out the message to wherever it is supposed to go */
if (small) if (opts & SYSLOG_OPT_small)
message("%s %s\n", timestamp, msg); message("%s %s\n", timestamp, msg);
else else
message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
@ -435,9 +416,8 @@ static void quit_signal(int sig)
{ {
logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting.");
unlink(lfile); unlink(lfile);
#ifdef CONFIG_FEATURE_IPC_SYSLOG if (ENABLE_FEATURE_IPC_SYSLOG)
ipcsyslog_cleanup(); ipcsyslog_cleanup();
#endif
exit(TRUE); exit(TRUE);
} }
@ -531,17 +511,13 @@ static void doSyslogd(void)
if (chmod(lfile, 0666) < 0) { if (chmod(lfile, 0666) < 0) {
bb_perror_msg_and_die("Could not set permission on " _PATH_LOG); bb_perror_msg_and_die("Could not set permission on " _PATH_LOG);
} }
#ifdef CONFIG_FEATURE_IPC_SYSLOG if (ENABLE_FEATURE_IPC_SYSLOG && opts & SYSLOG_OPT_circularlog) {
if (circular_logging == TRUE) {
ipcsyslog_init(); ipcsyslog_init();
} }
#endif
#ifdef CONFIG_FEATURE_REMOTE_LOG if (ENABLE_FEATURE_REMOTE_LOG && opts & SYSLOG_OPT_remotelog) {
if (doRemoteLog == TRUE) {
init_RemoteLog(); init_RemoteLog();
} }
#endif
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER ); logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER );
@ -613,10 +589,10 @@ int syslogd_main(int argc, char **argv)
RemotePort = atoi(p + 1); RemotePort = atoi(p + 1);
*p = '\0'; *p = '\0';
} }
doRemoteLog = TRUE; opts |= SYSLOG_OPT_remotelog;
break; break;
case 'L': case 'L':
local_logging = TRUE; opts |= SYSLOG_OPT_locallog;
break; break;
#endif #endif
#ifdef CONFIG_FEATURE_IPC_SYSLOG #ifdef CONFIG_FEATURE_IPC_SYSLOG
@ -627,22 +603,20 @@ int syslogd_main(int argc, char **argv)
shm_size = buf_size * 1024; shm_size = buf_size * 1024;
} }
} }
circular_logging = TRUE; opts |= SYSLOG_OPT_circularlog;
break; break;
#endif #endif
case 'S': case 'S':
small = true; opts |= SYSLOG_OPT_small;
break; break;
default: default:
bb_show_usage(); bb_show_usage();
} }
} }
#ifdef CONFIG_FEATURE_REMOTE_LOG
/* If they have not specified remote logging, then log locally */ /* If they have not specified remote logging, then log locally */
if (doRemoteLog == FALSE) if (ENABLE_FEATURE_REMOTE_LOG && !(opts & SYSLOG_OPT_remotelog))
local_logging = TRUE; opts |= SYSLOG_OPT_locallog;
#endif
/* Store away localhost's name before the fork */ /* Store away localhost's name before the fork */