diff options
-rw-r--r-- | INSTALL | 6 | ||||
-rw-r--r-- | archival/gzip.c | 14 | ||||
-rw-r--r-- | archival/rpm.c | 43 | ||||
-rw-r--r-- | coreutils/env.c | 11 | ||||
-rw-r--r-- | coreutils/uudecode.c | 3 | ||||
-rw-r--r-- | docs/busybox.net/FAQ.html | 10 | ||||
-rw-r--r-- | editors/vi.c | 15 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 4 | ||||
-rw-r--r-- | miscutils/less.c | 7 | ||||
-rw-r--r-- | miscutils/makedevs.c | 3 | ||||
-rw-r--r-- | networking/inetd.c | 4 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 3 | ||||
-rw-r--r-- | shell/lash.c | 126 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 98 |
14 files changed, 137 insertions, 210 deletions
@@ -32,8 +32,10 @@ any built-in busybox applets directly, without looking for external | |||
32 | programs by that name. Supplying an empty command path (as above) means | 32 | programs by that name. Supplying an empty command path (as above) means |
33 | the only commands busybox can find are the built-in ones. | 33 | the only commands busybox can find are the built-in ones. |
34 | 34 | ||
35 | (Note that the standalone shell currently requires /proc/self/exe to | 35 | Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH |
36 | launch new applets.) | 36 | to be set appropriately, depending on whether or not /proc/self/exe is |
37 | available or not. If you do not have /proc, then point that config option | ||
38 | to the location of your busybox binary, usually /bin/busybox. | ||
37 | 39 | ||
38 | Configuring Busybox: | 40 | Configuring Busybox: |
39 | ==================== | 41 | ==================== |
diff --git a/archival/gzip.c b/archival/gzip.c index 0962a00a7..37fefbf6a 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -263,15 +263,14 @@ DECLARE(ush, tab_prefix, 1L << BITS); | |||
263 | static int foreground; /* set if program run in foreground */ | 263 | static int foreground; /* set if program run in foreground */ |
264 | static int method = DEFLATED; /* compression method */ | 264 | static int method = DEFLATED; /* compression method */ |
265 | static int exit_code = OK; /* program exit code */ | 265 | static int exit_code = OK; /* program exit code */ |
266 | static int part_nb; /* number of parts in .gz file */ | ||
267 | static long time_stamp; /* original time stamp (modification time) */ | 266 | static long time_stamp; /* original time stamp (modification time) */ |
268 | static long ifile_size; /* input file size, -1 for devices (debug only) */ | ||
269 | static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */ | 267 | static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */ |
270 | static int z_len; /* strlen(z_suffix) */ | ||
271 | 268 | ||
272 | static int ifd; /* input file descriptor */ | 269 | static int ifd; /* input file descriptor */ |
273 | static int ofd; /* output file descriptor */ | 270 | static int ofd; /* output file descriptor */ |
271 | #ifdef DEBUG | ||
274 | static unsigned insize; /* valid bytes in inbuf */ | 272 | static unsigned insize; /* valid bytes in inbuf */ |
273 | #endif | ||
275 | static unsigned outcnt; /* bytes in output buffer */ | 274 | static unsigned outcnt; /* bytes in output buffer */ |
276 | 275 | ||
277 | static uint32_t *crc_32_tab; | 276 | static uint32_t *crc_32_tab; |
@@ -302,7 +301,9 @@ static void abort_gzip(int ATTRIBUTE_UNUSED ignored) | |||
302 | static void clear_bufs(void) | 301 | static void clear_bufs(void) |
303 | { | 302 | { |
304 | outcnt = 0; | 303 | outcnt = 0; |
304 | #ifdef DEBUG | ||
305 | insize = 0; | 305 | insize = 0; |
306 | #endif | ||
306 | bytes_in = 0L; | 307 | bytes_in = 0L; |
307 | } | 308 | } |
308 | 309 | ||
@@ -1177,7 +1178,6 @@ int gzip_main(int argc, char **argv) | |||
1177 | #endif | 1178 | #endif |
1178 | 1179 | ||
1179 | strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1); | 1180 | strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1); |
1180 | z_len = strlen(z_suffix); | ||
1181 | 1181 | ||
1182 | /* Allocate all global buffers (for DYN_ALLOC option) */ | 1182 | /* Allocate all global buffers (for DYN_ALLOC option) */ |
1183 | ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA); | 1183 | ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA); |
@@ -1188,13 +1188,11 @@ int gzip_main(int argc, char **argv) | |||
1188 | 1188 | ||
1189 | /* Initialise the CRC32 table */ | 1189 | /* Initialise the CRC32 table */ |
1190 | crc_32_tab = crc32_filltable(0); | 1190 | crc_32_tab = crc32_filltable(0); |
1191 | 1191 | ||
1192 | clear_bufs(); | 1192 | clear_bufs(); |
1193 | part_nb = 0; | ||
1194 | 1193 | ||
1195 | if (optind == argc) { | 1194 | if (optind == argc) { |
1196 | time_stamp = 0; | 1195 | time_stamp = 0; |
1197 | ifile_size = -1L; | ||
1198 | zip(STDIN_FILENO, STDOUT_FILENO); | 1196 | zip(STDIN_FILENO, STDOUT_FILENO); |
1199 | } else { | 1197 | } else { |
1200 | int i; | 1198 | int i; |
@@ -1205,7 +1203,6 @@ int gzip_main(int argc, char **argv) | |||
1205 | clear_bufs(); | 1203 | clear_bufs(); |
1206 | if (strcmp(argv[i], "-") == 0) { | 1204 | if (strcmp(argv[i], "-") == 0) { |
1207 | time_stamp = 0; | 1205 | time_stamp = 0; |
1208 | ifile_size = -1L; | ||
1209 | inFileNum = STDIN_FILENO; | 1206 | inFileNum = STDIN_FILENO; |
1210 | outFileNum = STDOUT_FILENO; | 1207 | outFileNum = STDOUT_FILENO; |
1211 | } else { | 1208 | } else { |
@@ -1213,7 +1210,6 @@ int gzip_main(int argc, char **argv) | |||
1213 | if (fstat(inFileNum, &statBuf) < 0) | 1210 | if (fstat(inFileNum, &statBuf) < 0) |
1214 | bb_perror_msg_and_die("%s", argv[i]); | 1211 | bb_perror_msg_and_die("%s", argv[i]); |
1215 | time_stamp = statBuf.st_ctime; | 1212 | time_stamp = statBuf.st_ctime; |
1216 | ifile_size = statBuf.st_size; | ||
1217 | 1213 | ||
1218 | if (!tostdout) { | 1214 | if (!tostdout) { |
1219 | path = xmalloc(strlen(argv[i]) + 4); | 1215 | path = xmalloc(strlen(argv[i]) + 4); |
diff --git a/archival/rpm.c b/archival/rpm.c index 7b27c0250..d399e0ea2 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -70,17 +70,15 @@ static void *map; | |||
70 | static rpm_index **mytags; | 70 | static rpm_index **mytags; |
71 | static int tagcount; | 71 | static int tagcount; |
72 | 72 | ||
73 | void extract_cpio_gz(int fd); | 73 | static void extract_cpio_gz(int fd); |
74 | rpm_index **rpm_gettags(int fd, int *num_tags); | 74 | static rpm_index **rpm_gettags(int fd, int *num_tags); |
75 | int bsearch_rpmtag(const void *key, const void *item); | 75 | static int bsearch_rpmtag(const void *key, const void *item); |
76 | char *rpm_getstring(int tag, int itemindex); | 76 | static char *rpm_getstring(int tag, int itemindex); |
77 | int rpm_getint(int tag, int itemindex); | 77 | static int rpm_getint(int tag, int itemindex); |
78 | int rpm_getcount(int tag); | 78 | static int rpm_getcount(int tag); |
79 | void exec_script(int progtag, int datatag, char *prefix); | 79 | static void fileaction_dobackup(char *filename, int fileref); |
80 | void fileaction_dobackup(char *filename, int fileref); | 80 | static void fileaction_setowngrp(char *filename, int fileref); |
81 | void fileaction_setowngrp(char *filename, int fileref); | 81 | static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)); |
82 | void fileaction_list(char *filename, int itemno); | ||
83 | void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)); | ||
84 | 82 | ||
85 | int rpm_main(int argc, char **argv) | 83 | int rpm_main(int argc, char **argv) |
86 | { | 84 | { |
@@ -169,7 +167,7 @@ int rpm_main(int argc, char **argv) | |||
169 | return 0; | 167 | return 0; |
170 | } | 168 | } |
171 | 169 | ||
172 | void extract_cpio_gz(int fd) { | 170 | static void extract_cpio_gz(int fd) { |
173 | archive_handle_t *archive_handle; | 171 | archive_handle_t *archive_handle; |
174 | unsigned char magic[2]; | 172 | unsigned char magic[2]; |
175 | 173 | ||
@@ -196,7 +194,7 @@ void extract_cpio_gz(int fd) { | |||
196 | } | 194 | } |
197 | 195 | ||
198 | 196 | ||
199 | rpm_index **rpm_gettags(int fd, int *num_tags) | 197 | static rpm_index **rpm_gettags(int fd, int *num_tags) |
200 | { | 198 | { |
201 | rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */ | 199 | rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */ |
202 | int pass, tagindex = 0; | 200 | int pass, tagindex = 0; |
@@ -235,14 +233,14 @@ rpm_index **rpm_gettags(int fd, int *num_tags) | |||
235 | return tags; /* All done, leave the file at the start of the gzipped cpio archive */ | 233 | return tags; /* All done, leave the file at the start of the gzipped cpio archive */ |
236 | } | 234 | } |
237 | 235 | ||
238 | int bsearch_rpmtag(const void *key, const void *item) | 236 | static int bsearch_rpmtag(const void *key, const void *item) |
239 | { | 237 | { |
240 | int *tag = (int *)key; | 238 | int *tag = (int *)key; |
241 | rpm_index **tmp = (rpm_index **) item; | 239 | rpm_index **tmp = (rpm_index **) item; |
242 | return (*tag - tmp[0]->tag); | 240 | return (*tag - tmp[0]->tag); |
243 | } | 241 | } |
244 | 242 | ||
245 | int rpm_getcount(int tag) | 243 | static int rpm_getcount(int tag) |
246 | { | 244 | { |
247 | rpm_index **found; | 245 | rpm_index **found; |
248 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); | 246 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); |
@@ -250,7 +248,7 @@ int rpm_getcount(int tag) | |||
250 | else return found[0]->count; | 248 | else return found[0]->count; |
251 | } | 249 | } |
252 | 250 | ||
253 | char *rpm_getstring(int tag, int itemindex) | 251 | static char *rpm_getstring(int tag, int itemindex) |
254 | { | 252 | { |
255 | rpm_index **found; | 253 | rpm_index **found; |
256 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); | 254 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); |
@@ -263,7 +261,7 @@ char *rpm_getstring(int tag, int itemindex) | |||
263 | } else return NULL; | 261 | } else return NULL; |
264 | } | 262 | } |
265 | 263 | ||
266 | int rpm_getint(int tag, int itemindex) | 264 | static int rpm_getint(int tag, int itemindex) |
267 | { | 265 | { |
268 | rpm_index **found; | 266 | rpm_index **found; |
269 | int n, *tmpint; | 267 | int n, *tmpint; |
@@ -284,7 +282,7 @@ int rpm_getint(int tag, int itemindex) | |||
284 | } else return -1; | 282 | } else return -1; |
285 | } | 283 | } |
286 | 284 | ||
287 | void fileaction_dobackup(char *filename, int fileref) | 285 | static void fileaction_dobackup(char *filename, int fileref) |
288 | { | 286 | { |
289 | struct stat oldfile; | 287 | struct stat oldfile; |
290 | int stat_res; | 288 | int stat_res; |
@@ -301,7 +299,7 @@ void fileaction_dobackup(char *filename, int fileref) | |||
301 | } | 299 | } |
302 | } | 300 | } |
303 | 301 | ||
304 | void fileaction_setowngrp(char *filename, int fileref) | 302 | static void fileaction_setowngrp(char *filename, int fileref) |
305 | { | 303 | { |
306 | int uid, gid; | 304 | int uid, gid; |
307 | uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref)); | 305 | uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref)); |
@@ -309,12 +307,7 @@ void fileaction_setowngrp(char *filename, int fileref) | |||
309 | chown (filename, uid, gid); | 307 | chown (filename, uid, gid); |
310 | } | 308 | } |
311 | 309 | ||
312 | void fileaction_list(char *filename, int ATTRIBUTE_UNUSED fileref) | 310 | static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)) |
313 | { | ||
314 | printf("%s\n", filename); | ||
315 | } | ||
316 | |||
317 | void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)) | ||
318 | { | 311 | { |
319 | int count = 0; | 312 | int count = 0; |
320 | while (rpm_getstring(filetag, count)) { | 313 | while (rpm_getstring(filetag, count)) { |
diff --git a/coreutils/env.c b/coreutils/env.c index eb1f0b268..4cdbeae6a 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -29,14 +29,9 @@ | |||
29 | * - use bb_default_error_retval | 29 | * - use bb_default_error_retval |
30 | */ | 30 | */ |
31 | 31 | ||
32 | 32 | #include "busybox.h" | |
33 | #include <stdio.h> | ||
34 | #include <string.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <errno.h> | 33 | #include <errno.h> |
37 | #include <unistd.h> | ||
38 | #include <getopt.h> /* struct option */ | 34 | #include <getopt.h> /* struct option */ |
39 | #include "busybox.h" | ||
40 | 35 | ||
41 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 36 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
42 | static const struct option env_long_options[] = { | 37 | static const struct option env_long_options[] = { |
@@ -50,7 +45,7 @@ int env_main(int argc, char** argv) | |||
50 | { | 45 | { |
51 | static char *cleanenv[1] = { NULL }; | 46 | static char *cleanenv[1] = { NULL }; |
52 | 47 | ||
53 | char **ep, *p; | 48 | char **ep; |
54 | unsigned long opt; | 49 | unsigned long opt; |
55 | llist_t *unset_env = NULL; | 50 | llist_t *unset_env = NULL; |
56 | extern char **environ; | 51 | extern char **environ; |
@@ -77,7 +72,7 @@ int env_main(int argc, char** argv) | |||
77 | } | 72 | } |
78 | } | 73 | } |
79 | 74 | ||
80 | while (*argv && ((p = strchr(*argv, '=')) != NULL)) { | 75 | while (*argv && (strchr(*argv, '=') != NULL)) { |
81 | if (putenv(*argv) < 0) { | 76 | if (putenv(*argv) < 0) { |
82 | bb_perror_msg_and_die("putenv"); | 77 | bb_perror_msg_and_die("putenv"); |
83 | } | 78 | } |
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 6050c0af7..2ec4306d0 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c | |||
@@ -129,9 +129,8 @@ int uudecode_main(int argc, char **argv) | |||
129 | FILE *src_stream; | 129 | FILE *src_stream; |
130 | char *outname = NULL; | 130 | char *outname = NULL; |
131 | char *line; | 131 | char *line; |
132 | int opt; | ||
133 | 132 | ||
134 | opt = bb_getopt_ulflags(argc, argv, "o:", &outname); | 133 | bb_getopt_ulflags(argc, argv, "o:", &outname); |
135 | 134 | ||
136 | if (optind == argc) { | 135 | if (optind == argc) { |
137 | src_stream = stdin; | 136 | src_stream = stdin; |
diff --git a/docs/busybox.net/FAQ.html b/docs/busybox.net/FAQ.html index 34250a33e..fee207486 100644 --- a/docs/busybox.net/FAQ.html +++ b/docs/busybox.net/FAQ.html | |||
@@ -88,9 +88,13 @@ have additions to this FAQ document, we would love to add them, | |||
88 | the command line "PATH= ./busybox ash". This will blank your command path | 88 | the command line "PATH= ./busybox ash". This will blank your command path |
89 | and run busybox as your command shell, so the only commands it can find | 89 | and run busybox as your command shell, so the only commands it can find |
90 | (without an explicit path such as /bin/ls) are the built-in busybox ones. | 90 | (without an explicit path such as /bin/ls) are the built-in busybox ones. |
91 | This is another good way to see what's built into busybox. (Note that the | 91 | This is another good way to see what's built into busybox. |
92 | standalone shell is dependent on the existence of /proc/self/exe, so before | 92 | Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH |
93 | using it in a chroot environment you must mount /proc.) | 93 | to be set appropriately, depending on whether or not /proc/self/exe is |
94 | available or not. If you do not have /proc, then point that config option | ||
95 | to the location of your busybox binary, usually /bin/busybox. | ||
96 | (So if you set it to /proc/self/exe, and happen to be able to chroot into | ||
97 | your rootfs, you must mount /proc beforehand.) | ||
94 | </p> | 98 | </p> |
95 | 99 | ||
96 | <hr /> | 100 | <hr /> |
diff --git a/editors/vi.c b/editors/vi.c index 593dc8520..3cbf6937d 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -116,7 +116,7 @@ static Byte *status_buffer; // mesages to the user | |||
116 | static int have_status_msg; // is default edit status needed? | 116 | static int have_status_msg; // is default edit status needed? |
117 | static int last_status_cksum; // hash of current status line | 117 | static int last_status_cksum; // hash of current status line |
118 | static Byte *cfn; // previous, current, and next file name | 118 | static Byte *cfn; // previous, current, and next file name |
119 | static Byte *text, *end, *textend; // pointers to the user data in memory | 119 | static Byte *text, *end; // pointers to the user data in memory |
120 | static Byte *screen; // pointer to the virtual screen buffer | 120 | static Byte *screen; // pointer to the virtual screen buffer |
121 | static int screensize; // and its size | 121 | static int screensize; // and its size |
122 | static Byte *screenbegin; // index into text[], of top line on the screen | 122 | static Byte *screenbegin; // index into text[], of top line on the screen |
@@ -582,7 +582,7 @@ static void colon(Byte * buf) | |||
582 | { | 582 | { |
583 | Byte c, *orig_buf, *buf1, *q, *r; | 583 | Byte c, *orig_buf, *buf1, *q, *r; |
584 | Byte *fn, cmd[BUFSIZ], args[BUFSIZ]; | 584 | Byte *fn, cmd[BUFSIZ], args[BUFSIZ]; |
585 | int i, l, li, ch, st, b, e; | 585 | int i, l, li, ch, b, e; |
586 | int useforce = FALSE, forced = FALSE; | 586 | int useforce = FALSE, forced = FALSE; |
587 | struct stat st_buf; | 587 | struct stat st_buf; |
588 | 588 | ||
@@ -606,7 +606,7 @@ static void colon(Byte * buf) | |||
606 | if (*buf == ':') | 606 | if (*buf == ':') |
607 | buf++; // move past the ':' | 607 | buf++; // move past the ':' |
608 | 608 | ||
609 | li = st = ch = i = 0; | 609 | li = ch = i = 0; |
610 | b = e = -1; | 610 | b = e = -1; |
611 | q = text; // assume 1,$ for the range | 611 | q = text; // assume 1,$ for the range |
612 | r = end - 1; | 612 | r = end - 1; |
@@ -1075,14 +1075,13 @@ static void Hit_Return(void) | |||
1075 | //----- Synchronize the cursor to Dot -------------------------- | 1075 | //----- Synchronize the cursor to Dot -------------------------- |
1076 | static void sync_cursor(Byte * d, int *row, int *col) | 1076 | static void sync_cursor(Byte * d, int *row, int *col) |
1077 | { | 1077 | { |
1078 | Byte *beg_cur; // begin and end of "d" line | 1078 | Byte *beg_cur; // begin and end of "d" line |
1079 | Byte *beg_scr, *end_scr; // begin and end of screen | 1079 | Byte *end_scr; // begin and end of screen |
1080 | Byte *tp; | 1080 | Byte *tp; |
1081 | int cnt, ro, co; | 1081 | int cnt, ro, co; |
1082 | 1082 | ||
1083 | beg_cur = begin_line(d); // first char of cur line | 1083 | beg_cur = begin_line(d); // first char of cur line |
1084 | 1084 | ||
1085 | beg_scr = end_scr = screenbegin; // first char of screen | ||
1086 | end_scr = end_screen(); // last char of screen | 1085 | end_scr = end_screen(); // last char of screen |
1087 | 1086 | ||
1088 | if (beg_cur < screenbegin) { | 1087 | if (beg_cur < screenbegin) { |
@@ -1385,8 +1384,6 @@ static Byte *new_text(int size) | |||
1385 | text = (Byte *) xmalloc(size + 8); | 1384 | text = (Byte *) xmalloc(size + 8); |
1386 | memset(text, '\0', size); // clear new text[] | 1385 | memset(text, '\0', size); // clear new text[] |
1387 | //text += 4; // leave some room for "oops" | 1386 | //text += 4; // leave some room for "oops" |
1388 | textend = text + size - 1; | ||
1389 | //textend -= 4; // leave some root for "oops" | ||
1390 | return (text); | 1387 | return (text); |
1391 | } | 1388 | } |
1392 | 1389 | ||
@@ -1963,9 +1960,7 @@ static Byte *text_yank(Byte * p, Byte * q, int dest) // copy text into a registe | |||
1963 | static Byte what_reg(void) | 1960 | static Byte what_reg(void) |
1964 | { | 1961 | { |
1965 | Byte c; | 1962 | Byte c; |
1966 | int i; | ||
1967 | 1963 | ||
1968 | i = 0; | ||
1969 | c = 'D'; // default to D-reg | 1964 | c = 'D'; // default to D-reg |
1970 | if (0 <= YDreg && YDreg <= 25) | 1965 | if (0 <= YDreg && YDreg <= 25) |
1971 | c = 'a' + (Byte) YDreg; | 1966 | c = 'a' + (Byte) YDreg; |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 59a2287b0..7e4b0c097 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -33,7 +33,7 @@ void vfork_daemon_rexec(int nochdir, int noclose, | |||
33 | setsid(); | 33 | setsid(); |
34 | 34 | ||
35 | if (!nochdir) | 35 | if (!nochdir) |
36 | chdir("/"); | 36 | xchdir("/"); |
37 | 37 | ||
38 | if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { | 38 | if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { |
39 | dup2(fd, STDIN_FILENO); | 39 | dup2(fd, STDIN_FILENO); |
@@ -44,7 +44,7 @@ void vfork_daemon_rexec(int nochdir, int noclose, | |||
44 | } | 44 | } |
45 | 45 | ||
46 | vfork_args = xcalloc(sizeof(char *), argc + 3); | 46 | vfork_args = xcalloc(sizeof(char *), argc + 3); |
47 | vfork_args[a++] = "/bin/busybox"; | 47 | vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH; |
48 | while(*argv) { | 48 | while(*argv) { |
49 | vfork_args[a++] = *argv; | 49 | vfork_args[a++] = *argv; |
50 | argv++; | 50 | argv++; |
diff --git a/miscutils/less.c b/miscutils/less.c index 9dd9b9e56..c13d7b8a2 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -872,14 +872,12 @@ static void save_input_to_file(void) | |||
872 | static void add_mark(void) | 872 | static void add_mark(void) |
873 | { | 873 | { |
874 | int letter; | 874 | int letter; |
875 | int mark_line; | ||
876 | 875 | ||
877 | clear_line(); | 876 | clear_line(); |
878 | printf("Mark: "); | 877 | printf("Mark: "); |
879 | letter = tless_getch(); | 878 | letter = tless_getch(); |
880 | 879 | ||
881 | if (isalpha(letter)) { | 880 | if (isalpha(letter)) { |
882 | mark_line = line_pos; | ||
883 | 881 | ||
884 | /* If we exceed 15 marks, start overwriting previous ones */ | 882 | /* If we exceed 15 marks, start overwriting previous ones */ |
885 | if (num_marks == 14) | 883 | if (num_marks == 14) |
@@ -927,19 +925,14 @@ static char opp_bracket(char bracket) | |||
927 | switch (bracket) { | 925 | switch (bracket) { |
928 | case '{': case '[': | 926 | case '{': case '[': |
929 | return bracket + 2; | 927 | return bracket + 2; |
930 | break; | ||
931 | case '(': | 928 | case '(': |
932 | return ')'; | 929 | return ')'; |
933 | break; | ||
934 | case '}': case ']': | 930 | case '}': case ']': |
935 | return bracket - 2; | 931 | return bracket - 2; |
936 | break; | ||
937 | case ')': | 932 | case ')': |
938 | return '('; | 933 | return '('; |
939 | break; | ||
940 | default: | 934 | default: |
941 | return 0; | 935 | return 0; |
942 | break; | ||
943 | } | 936 | } |
944 | } | 937 | } |
945 | 938 | ||
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 0ebb0538f..70dfc4205 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -76,8 +76,7 @@ int makedevs_main(int argc, char **argv) | |||
76 | int linenum = 0; | 76 | int linenum = 0; |
77 | int ret = EXIT_SUCCESS; | 77 | int ret = EXIT_SUCCESS; |
78 | 78 | ||
79 | unsigned long flags; | 79 | bb_getopt_ulflags(argc, argv, "d:", &line); |
80 | flags = bb_getopt_ulflags(argc, argv, "d:", &line); | ||
81 | if (line) | 80 | if (line) |
82 | table = xfopen(line, "r"); | 81 | table = xfopen(line, "r"); |
83 | 82 | ||
diff --git a/networking/inetd.c b/networking/inetd.c index 49ca7a36e..a17d28ebf 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -908,7 +908,6 @@ static void config (int sig ATTRIBUTE_UNUSED) | |||
908 | { | 908 | { |
909 | servtab_t *sep, *cp, **sepp; | 909 | servtab_t *sep, *cp, **sepp; |
910 | sigset_t omask; | 910 | sigset_t omask; |
911 | int add; | ||
912 | size_t n; | 911 | size_t n; |
913 | char protoname[10]; | 912 | char protoname[10]; |
914 | 913 | ||
@@ -923,7 +922,7 @@ static void config (int sig ATTRIBUTE_UNUSED) | |||
923 | for (sep = servtab; sep; sep = sep->se_next) | 922 | for (sep = servtab; sep; sep = sep->se_next) |
924 | if (matchconf (sep, cp)) | 923 | if (matchconf (sep, cp)) |
925 | break; | 924 | break; |
926 | add = 0; | 925 | |
927 | if (sep != 0) { | 926 | if (sep != 0) { |
928 | int i; | 927 | int i; |
929 | 928 | ||
@@ -958,7 +957,6 @@ static void config (int sig ATTRIBUTE_UNUSED) | |||
958 | #endif | 957 | #endif |
959 | sigprocmask(SIG_UNBLOCK, &omask, NULL); | 958 | sigprocmask(SIG_UNBLOCK, &omask, NULL); |
960 | freeconfig (cp); | 959 | freeconfig (cp); |
961 | add = 1; | ||
962 | } else { | 960 | } else { |
963 | sep = enter (cp); | 961 | sep = enter (cp); |
964 | } | 962 | } |
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index 1948efe37..d9f28374b 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c | |||
@@ -29,8 +29,6 @@ | |||
29 | /* take from linux/sockios.h */ | 29 | /* take from linux/sockios.h */ |
30 | #define SIOCSIFNAME 0x8923 /* set interface name */ | 30 | #define SIOCSIFNAME 0x8923 /* set interface name */ |
31 | 31 | ||
32 | static int do_link; | ||
33 | |||
34 | static int on_off(char *msg) | 32 | static int on_off(char *msg) |
35 | { | 33 | { |
36 | bb_error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg); | 34 | 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) | |||
336 | static int ipaddr_list_link(int argc, char **argv) | 334 | static int ipaddr_list_link(int argc, char **argv) |
337 | { | 335 | { |
338 | preferred_family = AF_PACKET; | 336 | preferred_family = AF_PACKET; |
339 | do_link = 1; | ||
340 | return ipaddr_list_or_flush(argc, argv, 0); | 337 | return ipaddr_list_or_flush(argc, argv, 0); |
341 | } | 338 | } |
342 | 339 | ||
diff --git a/shell/lash.c b/shell/lash.c index eae949e18..fd6bea177 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -54,6 +54,9 @@ enum { | |||
54 | ELSE_EXP_CONTEXT = 0x10 | 54 | ELSE_EXP_CONTEXT = 0x10 |
55 | }; | 55 | }; |
56 | 56 | ||
57 | #define LASH_OPT_DONE (1) | ||
58 | #define LASH_OPT_SAW_QUOTE (2) | ||
59 | |||
57 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS | 60 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS |
58 | struct redir_struct { | 61 | struct redir_struct { |
59 | enum redir_type type; /* type of redirection */ | 62 | enum redir_type type; /* type of redirection */ |
@@ -154,7 +157,7 @@ static int shell_context; /* Type prompt trigger (PS1 or PS2) */ | |||
154 | 157 | ||
155 | /* Globals that are static to this file */ | 158 | /* Globals that are static to this file */ |
156 | static const char *cwd; | 159 | static const char *cwd; |
157 | static char *local_pending_command = NULL; | 160 | static char *local_pending_command; |
158 | static struct jobset job_list = { NULL, NULL }; | 161 | static struct jobset job_list = { NULL, NULL }; |
159 | static int argc; | 162 | static int argc; |
160 | static char **argv; | 163 | static char **argv; |
@@ -176,7 +179,7 @@ static inline void debug_printf(const char *format, ...) | |||
176 | va_end(args); | 179 | va_end(args); |
177 | } | 180 | } |
178 | #else | 181 | #else |
179 | static inline void debug_printf(const char *format, ...) { } | 182 | static inline void debug_printf(const char ATTRIBUTE_UNUSED *format, ...) { } |
180 | #endif | 183 | #endif |
181 | 184 | ||
182 | /* | 185 | /* |
@@ -304,12 +307,12 @@ static int builtin_fg_bg(struct child_prog *child) | |||
304 | } | 307 | } |
305 | 308 | ||
306 | /* built-in 'help' handler */ | 309 | /* built-in 'help' handler */ |
307 | static int builtin_help(struct child_prog *dummy) | 310 | static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy) |
308 | { | 311 | { |
309 | struct built_in_command *x; | 312 | struct built_in_command *x; |
310 | 313 | ||
311 | printf("\nBuilt-in commands:\n"); | 314 | printf("\nBuilt-in commands:\n" |
312 | printf("-------------------\n"); | 315 | "-------------------\n"); |
313 | for (x = bltins; x->cmd; x++) { | 316 | for (x = bltins; x->cmd; x++) { |
314 | if (x->descr==NULL) | 317 | if (x->descr==NULL) |
315 | continue; | 318 | continue; |
@@ -320,7 +323,7 @@ static int builtin_help(struct child_prog *dummy) | |||
320 | continue; | 323 | continue; |
321 | printf("%s\t%s\n", x->cmd, x->descr); | 324 | printf("%s\t%s\n", x->cmd, x->descr); |
322 | } | 325 | } |
323 | printf("\n\n"); | 326 | putchar('\n'); |
324 | return EXIT_SUCCESS; | 327 | return EXIT_SUCCESS; |
325 | } | 328 | } |
326 | 329 | ||
@@ -343,7 +346,7 @@ static int builtin_jobs(struct child_prog *child) | |||
343 | 346 | ||
344 | 347 | ||
345 | /* built-in 'pwd' handler */ | 348 | /* built-in 'pwd' handler */ |
346 | static int builtin_pwd(struct child_prog *dummy) | 349 | static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy) |
347 | { | 350 | { |
348 | cwd = xgetcwd((char *)cwd); | 351 | cwd = xgetcwd((char *)cwd); |
349 | if (!cwd) | 352 | if (!cwd) |
@@ -386,7 +389,7 @@ static int builtin_export(struct child_prog *child) | |||
386 | /* built-in 'read VAR' handler */ | 389 | /* built-in 'read VAR' handler */ |
387 | static int builtin_read(struct child_prog *child) | 390 | static int builtin_read(struct child_prog *child) |
388 | { | 391 | { |
389 | int res = 0, len, newlen; | 392 | int res = 0, len; |
390 | char *s; | 393 | char *s; |
391 | char string[MAX_READ]; | 394 | char string[MAX_READ]; |
392 | 395 | ||
@@ -397,16 +400,16 @@ static int builtin_read(struct child_prog *child) | |||
397 | string[len++] = '='; | 400 | string[len++] = '='; |
398 | string[len] = '\0'; | 401 | string[len] = '\0'; |
399 | fgets(&string[len], sizeof(string) - len, stdin); /* read string */ | 402 | fgets(&string[len], sizeof(string) - len, stdin); /* read string */ |
400 | newlen = strlen(string); | 403 | res = strlen(string); |
401 | if(newlen > len) | 404 | if (res > len) |
402 | string[--newlen] = '\0'; /* chomp trailing newline */ | 405 | string[--res] = '\0'; /* chomp trailing newline */ |
403 | /* | 406 | /* |
404 | ** string should now contain "VAR=<value>" | 407 | ** string should now contain "VAR=<value>" |
405 | ** copy it (putenv() won't do that, so we must make sure | 408 | ** copy it (putenv() won't do that, so we must make sure |
406 | ** the string resides in a static buffer!) | 409 | ** the string resides in a static buffer!) |
407 | */ | 410 | */ |
408 | res = -1; | 411 | res = -1; |
409 | if((s = strdup(string))) | 412 | if ((s = strdup(string))) |
410 | res = putenv(s); | 413 | res = putenv(s); |
411 | if (res) | 414 | if (res) |
412 | bb_perror_msg("read"); | 415 | bb_perror_msg("read"); |
@@ -423,12 +426,8 @@ static int builtin_source(struct child_prog *child) | |||
423 | FILE *input; | 426 | FILE *input; |
424 | int status; | 427 | int status; |
425 | 428 | ||
426 | if (child->argv[1] == NULL) | 429 | input = bb_wfopen(child->argv[1], "r"); |
427 | return EXIT_FAILURE; | ||
428 | |||
429 | input = fopen(child->argv[1], "r"); | ||
430 | if (!input) { | 430 | if (!input) { |
431 | printf( "Couldn't open file '%s'\n", child->argv[1]); | ||
432 | return EXIT_FAILURE; | 431 | return EXIT_FAILURE; |
433 | } | 432 | } |
434 | 433 | ||
@@ -635,7 +634,7 @@ static inline void setup_prompt_string(char **prompt_str) | |||
635 | if (shell_context == 0) { | 634 | if (shell_context == 0) { |
636 | free(PS1); | 635 | free(PS1); |
637 | PS1=xmalloc(strlen(cwd)+4); | 636 | PS1=xmalloc(strlen(cwd)+4); |
638 | sprintf(PS1, "%s %s", cwd, ( geteuid() != 0 ) ? "$ ":"# "); | 637 | sprintf(PS1, "%s %c ", cwd, ( geteuid() != 0 ) ? '$': '#'); |
639 | *prompt_str = PS1; | 638 | *prompt_str = PS1; |
640 | } else { | 639 | } else { |
641 | *prompt_str = PS2; | 640 | *prompt_str = PS2; |
@@ -688,20 +687,18 @@ static int get_command(FILE * source, char *command) | |||
688 | 687 | ||
689 | static char * strsep_space( char *string, int * ix) | 688 | static char * strsep_space( char *string, int * ix) |
690 | { | 689 | { |
691 | char *token; | ||
692 | |||
693 | /* Short circuit the trivial case */ | 690 | /* Short circuit the trivial case */ |
694 | if ( !string || ! string[*ix]) | 691 | if ( !string || ! string[*ix]) |
695 | return NULL; | 692 | return NULL; |
696 | 693 | ||
697 | /* Find the end of the token. */ | 694 | /* Find the end of the token. */ |
698 | while( string[*ix] && !isspace(string[*ix]) ) { | 695 | while (string[*ix] && !isspace(string[*ix]) ) { |
699 | (*ix)++; | 696 | (*ix)++; |
700 | } | 697 | } |
701 | 698 | ||
702 | /* Find the end of any whitespace trailing behind | 699 | /* Find the end of any whitespace trailing behind |
703 | * the token and let that be part of the token */ | 700 | * the token and let that be part of the token */ |
704 | while( string[*ix] && isspace(string[*ix]) ) { | 701 | while (string[*ix] && (isspace)(string[*ix]) ) { |
705 | (*ix)++; | 702 | (*ix)++; |
706 | } | 703 | } |
707 | 704 | ||
@@ -710,9 +707,7 @@ static char * strsep_space( char *string, int * ix) | |||
710 | return NULL; | 707 | return NULL; |
711 | } | 708 | } |
712 | 709 | ||
713 | token = xstrndup(string, *ix); | 710 | return xstrndup(string, *ix); |
714 | |||
715 | return token; | ||
716 | } | 711 | } |
717 | 712 | ||
718 | static int expand_arguments(char *command) | 713 | static int expand_arguments(char *command) |
@@ -721,7 +716,7 @@ static int expand_arguments(char *command) | |||
721 | expand_t expand_result; | 716 | expand_t expand_result; |
722 | char *tmpcmd, *cmd, *cmd_copy; | 717 | char *tmpcmd, *cmd, *cmd_copy; |
723 | char *src, *dst, *var; | 718 | char *src, *dst, *var; |
724 | const char *out_of_space = "out of space during expansion"; | 719 | const char * const out_of_space = "out of space during expansion"; |
725 | int flags = GLOB_NOCHECK | 720 | int flags = GLOB_NOCHECK |
726 | #ifdef GLOB_BRACE | 721 | #ifdef GLOB_BRACE |
727 | | GLOB_BRACE | 722 | | GLOB_BRACE |
@@ -846,7 +841,7 @@ static int expand_arguments(char *command) | |||
846 | num_skip_chars=1; | 841 | num_skip_chars=1; |
847 | } else { | 842 | } else { |
848 | src=dst+1; | 843 | src=dst+1; |
849 | while(isalnum(*src) || *src=='_') src++; | 844 | while((isalnum)(*src) || *src=='_') src++; |
850 | } | 845 | } |
851 | if (src == NULL) { | 846 | if (src == NULL) { |
852 | src = dst+dstlen; | 847 | src = dst+dstlen; |
@@ -890,10 +885,9 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
890 | char *command; | 885 | char *command; |
891 | char *return_command = NULL; | 886 | char *return_command = NULL; |
892 | char *src, *buf; | 887 | char *src, *buf; |
893 | int argc_l = 0; | 888 | int argc_l; |
894 | int done = 0; | 889 | int flag; |
895 | int argv_alloced; | 890 | int argv_alloced; |
896 | int saw_quote = 0; | ||
897 | char quote = '\0'; | 891 | char quote = '\0'; |
898 | struct child_prog *prog; | 892 | struct child_prog *prog; |
899 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS | 893 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS |
@@ -902,8 +896,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
902 | #endif | 896 | #endif |
903 | 897 | ||
904 | /* skip leading white space */ | 898 | /* skip leading white space */ |
905 | while (**command_ptr && isspace(**command_ptr)) | 899 | *command_ptr = skip_whitespace(*command_ptr); |
906 | (*command_ptr)++; | ||
907 | 900 | ||
908 | /* this handles empty lines or leading '#' characters */ | 901 | /* this handles empty lines or leading '#' characters */ |
909 | if (!**command_ptr || (**command_ptr == '#')) { | 902 | if (!**command_ptr || (**command_ptr == '#')) { |
@@ -937,9 +930,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
937 | prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced); | 930 | prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced); |
938 | prog->argv[0] = job->cmdbuf; | 931 | prog->argv[0] = job->cmdbuf; |
939 | 932 | ||
933 | flag = argc_l = 0; | ||
940 | buf = command; | 934 | buf = command; |
941 | src = *command_ptr; | 935 | src = *command_ptr; |
942 | while (*src && !done) { | 936 | while (*src && !(flag & LASH_OPT_DONE)) { |
943 | if (quote == *src) { | 937 | if (quote == *src) { |
944 | quote = '\0'; | 938 | quote = '\0'; |
945 | } else if (quote) { | 939 | } else if (quote) { |
@@ -960,7 +954,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
960 | *src == ']') *buf++ = '\\'; | 954 | *src == ']') *buf++ = '\\'; |
961 | *buf++ = *src; | 955 | *buf++ = *src; |
962 | } else if (isspace(*src)) { | 956 | } else if (isspace(*src)) { |
963 | if (*prog->argv[argc_l] || saw_quote) { | 957 | if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE) { |
964 | buf++, argc_l++; | 958 | buf++, argc_l++; |
965 | /* +1 here leaves room for the NULL which ends argv */ | 959 | /* +1 here leaves room for the NULL which ends argv */ |
966 | if ((argc_l + 1) == argv_alloced) { | 960 | if ((argc_l + 1) == argv_alloced) { |
@@ -970,21 +964,21 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
970 | argv_alloced); | 964 | argv_alloced); |
971 | } | 965 | } |
972 | prog->argv[argc_l] = buf; | 966 | prog->argv[argc_l] = buf; |
973 | saw_quote = 0; | 967 | flag ^= LASH_OPT_SAW_QUOTE; |
974 | } | 968 | } |
975 | } else | 969 | } else |
976 | switch (*src) { | 970 | switch (*src) { |
977 | case '"': | 971 | case '"': |
978 | case '\'': | 972 | case '\'': |
979 | quote = *src; | 973 | quote = *src; |
980 | saw_quote = 1; | 974 | flag |= LASH_OPT_SAW_QUOTE; |
981 | break; | 975 | break; |
982 | 976 | ||
983 | case '#': /* comment */ | 977 | case '#': /* comment */ |
984 | if (*(src-1)== '$') | 978 | if (*(src-1)== '$') |
985 | *buf++ = *src; | 979 | *buf++ = *src; |
986 | else | 980 | else |
987 | done = 1; | 981 | flag |= LASH_OPT_DONE; |
988 | break; | 982 | break; |
989 | 983 | ||
990 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS | 984 | #ifdef CONFIG_LASH_PIPE_N_REDIRECTS |
@@ -1027,8 +1021,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
1027 | 1021 | ||
1028 | /* This isn't POSIX sh compliant. Oh well. */ | 1022 | /* This isn't POSIX sh compliant. Oh well. */ |
1029 | chptr = src; | 1023 | chptr = src; |
1030 | while (isspace(*chptr)) | 1024 | chptr = skip_whitespace(chptr); |
1031 | chptr++; | ||
1032 | 1025 | ||
1033 | if (!*chptr) { | 1026 | if (!*chptr) { |
1034 | bb_error_msg("file name expected after %c", *(src-1)); | 1027 | 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) | |||
1047 | 1040 | ||
1048 | case '|': /* pipe */ | 1041 | case '|': /* pipe */ |
1049 | /* finish this command */ | 1042 | /* finish this command */ |
1050 | if (*prog->argv[argc_l] || saw_quote) | 1043 | if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE) |
1051 | argc_l++; | 1044 | argc_l++; |
1052 | if (!argc_l) { | 1045 | if (!argc_l) { |
1053 | bb_error_msg("empty command in pipe"); | 1046 | goto empty_command_in_pipe; |
1054 | free_job(job); | ||
1055 | job->num_progs=0; | ||
1056 | return 1; | ||
1057 | } | 1047 | } |
1058 | prog->argv[argc_l] = NULL; | 1048 | prog->argv[argc_l] = NULL; |
1059 | 1049 | ||
@@ -1073,10 +1063,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
1073 | prog->argv[0] = ++buf; | 1063 | prog->argv[0] = ++buf; |
1074 | 1064 | ||
1075 | src++; | 1065 | src++; |
1076 | while (*src && isspace(*src)) | 1066 | src = skip_whitespace(src); |
1077 | src++; | ||
1078 | 1067 | ||
1079 | if (!*src) { | 1068 | if (!*src) { |
1069 | empty_command_in_pipe: | ||
1080 | bb_error_msg("empty command in pipe"); | 1070 | bb_error_msg("empty command in pipe"); |
1081 | free_job(job); | 1071 | free_job(job); |
1082 | job->num_progs=0; | 1072 | job->num_progs=0; |
@@ -1090,9 +1080,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
1090 | #ifdef CONFIG_LASH_JOB_CONTROL | 1080 | #ifdef CONFIG_LASH_JOB_CONTROL |
1091 | case '&': /* background */ | 1081 | case '&': /* background */ |
1092 | *inbg = 1; | 1082 | *inbg = 1; |
1083 | /* fallthrough */ | ||
1093 | #endif | 1084 | #endif |
1094 | case ';': /* multiple commands */ | 1085 | case ';': /* multiple commands */ |
1095 | done = 1; | 1086 | flag |= LASH_OPT_DONE; |
1096 | return_command = *command_ptr + (src - *command_ptr) + 1; | 1087 | return_command = *command_ptr + (src - *command_ptr) + 1; |
1097 | break; | 1088 | break; |
1098 | 1089 | ||
@@ -1113,7 +1104,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg) | |||
1113 | src++; | 1104 | src++; |
1114 | } | 1105 | } |
1115 | 1106 | ||
1116 | if (*prog->argv[argc_l] || saw_quote) { | 1107 | if (*prog->argv[argc_l] || flag & LASH_OPT_SAW_QUOTE) { |
1117 | argc_l++; | 1108 | argc_l++; |
1118 | } | 1109 | } |
1119 | if (!argc_l) { | 1110 | if (!argc_l) { |
@@ -1295,7 +1286,7 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2]) | |||
1295 | signal(SIGTTOU, SIG_DFL); | 1286 | signal(SIGTTOU, SIG_DFL); |
1296 | signal(SIGCHLD, SIG_DFL); | 1287 | signal(SIGCHLD, SIG_DFL); |
1297 | 1288 | ||
1298 | // Close all open filehandles. | 1289 | /* Close all open filehandles. */ |
1299 | while(close_me_list) close((long)llist_pop(&close_me_list)); | 1290 | while(close_me_list) close((long)llist_pop(&close_me_list)); |
1300 | 1291 | ||
1301 | if (outpipe[1]!=-1) { | 1292 | if (outpipe[1]!=-1) { |
@@ -1512,14 +1503,13 @@ static inline void setup_job_control(void) | |||
1512 | 1503 | ||
1513 | int lash_main(int argc_l, char **argv_l) | 1504 | int lash_main(int argc_l, char **argv_l) |
1514 | { | 1505 | { |
1515 | int opt, interactive=FALSE; | 1506 | unsigned long opt; |
1516 | FILE *input = stdin; | 1507 | FILE *input = stdin; |
1517 | argc = argc_l; | 1508 | argc = argc_l; |
1518 | argv = argv_l; | 1509 | argv = argv_l; |
1519 | 1510 | ||
1520 | /* These variables need re-initializing when recursing */ | 1511 | /* These variables need re-initializing when recursing */ |
1521 | last_jobid = 0; | 1512 | last_jobid = 0; |
1522 | local_pending_command = NULL; | ||
1523 | close_me_list = NULL; | 1513 | close_me_list = NULL; |
1524 | job_list.head = NULL; | 1514 | job_list.head = NULL; |
1525 | job_list.fg = NULL; | 1515 | job_list.fg = NULL; |
@@ -1532,27 +1522,18 @@ int lash_main(int argc_l, char **argv_l) | |||
1532 | llist_add_to(&close_me_list, (void *)(long)fileno(prof_input)); | 1522 | llist_add_to(&close_me_list, (void *)(long)fileno(prof_input)); |
1533 | /* Now run the file */ | 1523 | /* Now run the file */ |
1534 | busy_loop(prof_input); | 1524 | busy_loop(prof_input); |
1535 | fclose(prof_input); | 1525 | bb_fclose_nonstdin(prof_input); |
1536 | llist_pop(&close_me_list); | 1526 | llist_pop(&close_me_list); |
1537 | } | 1527 | } |
1538 | } | 1528 | } |
1539 | 1529 | ||
1540 | while ((opt = getopt(argc_l, argv_l, "cxi")) > 0) { | 1530 | opt = bb_getopt_ulflags(argc_l, argv_l, "+ic:", &local_pending_command); |
1541 | switch (opt) { | 1531 | #define LASH_OPT_i (1<<0) |
1542 | case 'c': | 1532 | #define LASH_OPT_c (1<<2) |
1543 | input = NULL; | 1533 | if (opt & LASH_OPT_c) { |
1544 | if (local_pending_command != 0) | 1534 | input = NULL; |
1545 | bb_error_msg_and_die("multiple -c arguments"); | 1535 | optind++; |
1546 | local_pending_command = xstrdup(argv[optind]); | 1536 | argv += optind; |
1547 | optind++; | ||
1548 | argv = argv+optind; | ||
1549 | break; | ||
1550 | case 'i': | ||
1551 | interactive++; | ||
1552 | break; | ||
1553 | default: | ||
1554 | bb_show_usage(); | ||
1555 | } | ||
1556 | } | 1537 | } |
1557 | /* A shell is interactive if the `-i' flag was given, or if all of | 1538 | /* A shell is interactive if the `-i' flag was given, or if all of |
1558 | * the following conditions are met: | 1539 | * the following conditions are met: |
@@ -1564,14 +1545,15 @@ int lash_main(int argc_l, char **argv_l) | |||
1564 | if (argv[optind]==NULL && input==stdin && | 1545 | if (argv[optind]==NULL && input==stdin && |
1565 | isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) | 1546 | isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) |
1566 | { | 1547 | { |
1567 | interactive++; | 1548 | opt |= LASH_OPT_i; |
1568 | } | 1549 | } |
1569 | setup_job_control(); | 1550 | setup_job_control(); |
1570 | if (interactive) { | 1551 | if (opt & LASH_OPT_i) { |
1571 | /* Looks like they want an interactive shell */ | 1552 | /* Looks like they want an interactive shell */ |
1572 | if (!ENABLE_FEATURE_SH_EXTRA_QUIET) { | 1553 | if (!ENABLE_FEATURE_SH_EXTRA_QUIET) { |
1573 | printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER); | 1554 | printf("\n\n%s Built-in shell (lash)\n" |
1574 | printf( "Enter 'help' for a list of built-in commands.\n\n"); | 1555 | "Enter 'help' for a list of built-in commands.\n\n", |
1556 | BB_BANNER); | ||
1575 | } | 1557 | } |
1576 | } else if (!local_pending_command && argv[optind]) { | 1558 | } else if (!local_pending_command && argv[optind]) { |
1577 | //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); | 1559 | //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 87313af43..fc3845606 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -57,14 +57,14 @@ static char *RemoteHost; | |||
57 | /* what port to log to? */ | 57 | /* what port to log to? */ |
58 | static int RemotePort = 514; | 58 | static int RemotePort = 514; |
59 | 59 | ||
60 | /* To remote log or not to remote log, that is the question. */ | ||
61 | static int doRemoteLog = FALSE; | ||
62 | static int local_logging = FALSE; | ||
63 | #endif | 60 | #endif |
64 | 61 | ||
65 | /* Make loging output smaller. */ | 62 | /* options */ |
66 | static bool small = false; | 63 | static unsigned opts; |
67 | 64 | #define SYSLOG_OPT_small (1) | |
65 | #define SYSLOG_OPT_remotelog (2) | ||
66 | #define SYSLOG_OPT_locallog (4) | ||
67 | #define SYSLOG_OPT_circularlog (8) | ||
68 | 68 | ||
69 | #define MAXLINE 1024 /* maximum line length */ | 69 | #define MAXLINE 1024 /* maximum line length */ |
70 | 70 | ||
@@ -98,28 +98,6 @@ static struct sembuf SMwdn[3] = { {0, 0}, {1, 0}, {1, +1} }; // set SMwdn | |||
98 | static int shmid = -1; // ipc shared memory id | 98 | static int shmid = -1; // ipc shared memory id |
99 | static int s_semid = -1; // ipc semaphore id | 99 | static int s_semid = -1; // ipc semaphore id |
100 | static int shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024); // default shm size | 100 | static int shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024); // default shm size |
101 | static int circular_logging = FALSE; | ||
102 | |||
103 | /* | ||
104 | * sem_up - up()'s a semaphore. | ||
105 | */ | ||
106 | static inline void sem_up(int semid) | ||
107 | { | ||
108 | if (semop(semid, SMwup, 1) == -1) { | ||
109 | bb_perror_msg_and_die("semop[SMwup]"); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * sem_down - down()'s a semaphore | ||
115 | */ | ||
116 | static inline void sem_down(int semid) | ||
117 | { | ||
118 | if (semop(semid, SMwdn, 3) == -1) { | ||
119 | bb_perror_msg_and_die("semop[SMwdn]"); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | 101 | ||
124 | static void ipcsyslog_cleanup(void) | 102 | static void ipcsyslog_cleanup(void) |
125 | { | 103 | { |
@@ -169,8 +147,11 @@ static void ipcsyslog_init(void) | |||
169 | static void circ_message(const char *msg) | 147 | static void circ_message(const char *msg) |
170 | { | 148 | { |
171 | int l = strlen(msg) + 1; /* count the whole message w/ '\0' included */ | 149 | int l = strlen(msg) + 1; /* count the whole message w/ '\0' included */ |
150 | const char * const fail_msg = "Can't find the terminator token%s?\n"; | ||
172 | 151 | ||
173 | sem_down(s_semid); | 152 | if (semop(s_semid, SMwdn, 3) == -1) { |
153 | bb_perror_msg_and_die("SMwdn"); | ||
154 | } | ||
174 | 155 | ||
175 | /* | 156 | /* |
176 | * Circular Buffer Algorithm: | 157 | * Circular Buffer Algorithm: |
@@ -220,7 +201,7 @@ static void circ_message(const char *msg) | |||
220 | /* Note: HEAD is only used to "retrieve" messages, it's not used | 201 | /* Note: HEAD is only used to "retrieve" messages, it's not used |
221 | when writing messages into our buffer */ | 202 | when writing messages into our buffer */ |
222 | } else { /* show an error message to know we messed up? */ | 203 | } else { /* show an error message to know we messed up? */ |
223 | printf("Weird! Can't find the terminator token?\n"); | 204 | printf(fail_msg,""); |
224 | buf->head = 0; | 205 | buf->head = 0; |
225 | } | 206 | } |
226 | } | 207 | } |
@@ -256,13 +237,15 @@ static void circ_message(const char *msg) | |||
256 | /* we need to place the TAIL at the end of the message */ | 237 | /* we need to place the TAIL at the end of the message */ |
257 | buf->tail = k + 1; | 238 | buf->tail = k + 1; |
258 | } else { | 239 | } else { |
259 | printf | 240 | printf(fail_msg, " from the beginning"); |
260 | ("Weird! Can't find the terminator token from the beginning?\n"); | ||
261 | buf->head = buf->tail = 0; /* reset buffer, since it's probably corrupted */ | 241 | buf->head = buf->tail = 0; /* reset buffer, since it's probably corrupted */ |
262 | } | 242 | } |
263 | 243 | ||
264 | } | 244 | } |
265 | sem_up(s_semid); | 245 | if (semop(s_semid, SMwup, 1) == -1) { |
246 | bb_perror_msg_and_die("SMwup"); | ||
247 | } | ||
248 | |||
266 | } | 249 | } |
267 | #endif /* CONFIG_FEATURE_IPC_SYSLOG */ | 250 | #endif /* CONFIG_FEATURE_IPC_SYSLOG */ |
268 | 251 | ||
@@ -280,7 +263,7 @@ static void message(char *fmt, ...) | |||
280 | fl.l_len = 1; | 263 | fl.l_len = 1; |
281 | 264 | ||
282 | #ifdef CONFIG_FEATURE_IPC_SYSLOG | 265 | #ifdef CONFIG_FEATURE_IPC_SYSLOG |
283 | if ((circular_logging == TRUE) && (buf != NULL)) { | 266 | if ((opts & SYSLOG_OPT_circularlog) && (buf != NULL)) { |
284 | char b[1024]; | 267 | char b[1024]; |
285 | 268 | ||
286 | va_start(arguments, fmt); | 269 | va_start(arguments, fmt); |
@@ -295,8 +278,8 @@ static void message(char *fmt, ...) | |||
295 | O_NONBLOCK)) >= 0) { | 278 | O_NONBLOCK)) >= 0) { |
296 | fl.l_type = F_WRLCK; | 279 | fl.l_type = F_WRLCK; |
297 | fcntl(fd, F_SETLKW, &fl); | 280 | fcntl(fd, F_SETLKW, &fl); |
298 | #ifdef CONFIG_FEATURE_ROTATE_LOGFILE | 281 | |
299 | if ( logFileSize > 0 ) { | 282 | if (ENABLE_FEATURE_ROTATE_LOGFILE && logFileSize > 0 ) { |
300 | struct stat statf; | 283 | struct stat statf; |
301 | int r = fstat(fd, &statf); | 284 | int r = fstat(fd, &statf); |
302 | if( !r && (statf.st_mode & S_IFREG) | 285 | if( !r && (statf.st_mode & S_IFREG) |
@@ -324,7 +307,7 @@ static void message(char *fmt, ...) | |||
324 | } | 307 | } |
325 | } | 308 | } |
326 | } | 309 | } |
327 | #endif | 310 | |
328 | va_start(arguments, fmt); | 311 | va_start(arguments, fmt); |
329 | vdprintf(fd, fmt, arguments); | 312 | vdprintf(fd, fmt, arguments); |
330 | va_end(arguments); | 313 | va_end(arguments); |
@@ -364,10 +347,7 @@ static void logMessage(int pri, char *msg) | |||
364 | { | 347 | { |
365 | time_t now; | 348 | time_t now; |
366 | char *timestamp; | 349 | char *timestamp; |
367 | static char res[20]; | 350 | char res[20]; |
368 | #ifdef CONFIG_FEATURE_REMOTE_LOG | ||
369 | static char line[MAXLINE + 1]; | ||
370 | #endif | ||
371 | CODE *c_pri, *c_fac; | 351 | CODE *c_pri, *c_fac; |
372 | 352 | ||
373 | if (pri != 0) { | 353 | if (pri != 0) { |
@@ -396,7 +376,8 @@ static void logMessage(int pri, char *msg) | |||
396 | /* todo: supress duplicates */ | 376 | /* todo: supress duplicates */ |
397 | 377 | ||
398 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 378 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
399 | if (doRemoteLog == TRUE) { | 379 | if (opts & SYSLOG_OPT_remotelog) { |
380 | char line[MAXLINE + 1]; | ||
400 | /* trying connect the socket */ | 381 | /* trying connect the socket */ |
401 | if (-1 == remotefd) { | 382 | if (-1 == remotefd) { |
402 | init_RemoteLog(); | 383 | init_RemoteLog(); |
@@ -407,7 +388,7 @@ static void logMessage(int pri, char *msg) | |||
407 | now = 1; | 388 | now = 1; |
408 | snprintf(line, sizeof(line), "<%d>%s", pri, msg); | 389 | snprintf(line, sizeof(line), "<%d>%s", pri, msg); |
409 | 390 | ||
410 | retry: | 391 | retry: |
411 | /* send message to remote logger */ | 392 | /* send message to remote logger */ |
412 | if(( -1 == sendto(remotefd, line, strlen(line), 0, | 393 | if(( -1 == sendto(remotefd, line, strlen(line), 0, |
413 | (struct sockaddr *) &remoteaddr, | 394 | (struct sockaddr *) &remoteaddr, |
@@ -420,11 +401,11 @@ static void logMessage(int pri, char *msg) | |||
420 | } | 401 | } |
421 | } | 402 | } |
422 | 403 | ||
423 | if (local_logging == TRUE) | 404 | if (opts & SYSLOG_OPT_locallog) |
424 | #endif | 405 | #endif |
425 | { | 406 | { |
426 | /* now spew out the message to wherever it is supposed to go */ | 407 | /* now spew out the message to wherever it is supposed to go */ |
427 | if (small) | 408 | if (opts & SYSLOG_OPT_small) |
428 | message("%s %s\n", timestamp, msg); | 409 | message("%s %s\n", timestamp, msg); |
429 | else | 410 | else |
430 | message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); | 411 | message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); |
@@ -435,9 +416,8 @@ static void quit_signal(int sig) | |||
435 | { | 416 | { |
436 | logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); | 417 | logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); |
437 | unlink(lfile); | 418 | unlink(lfile); |
438 | #ifdef CONFIG_FEATURE_IPC_SYSLOG | 419 | if (ENABLE_FEATURE_IPC_SYSLOG) |
439 | ipcsyslog_cleanup(); | 420 | ipcsyslog_cleanup(); |
440 | #endif | ||
441 | 421 | ||
442 | exit(TRUE); | 422 | exit(TRUE); |
443 | } | 423 | } |
@@ -531,17 +511,13 @@ static void doSyslogd(void) | |||
531 | if (chmod(lfile, 0666) < 0) { | 511 | if (chmod(lfile, 0666) < 0) { |
532 | bb_perror_msg_and_die("Could not set permission on " _PATH_LOG); | 512 | bb_perror_msg_and_die("Could not set permission on " _PATH_LOG); |
533 | } | 513 | } |
534 | #ifdef CONFIG_FEATURE_IPC_SYSLOG | 514 | if (ENABLE_FEATURE_IPC_SYSLOG && opts & SYSLOG_OPT_circularlog) { |
535 | if (circular_logging == TRUE) { | ||
536 | ipcsyslog_init(); | 515 | ipcsyslog_init(); |
537 | } | 516 | } |
538 | #endif | ||
539 | 517 | ||
540 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 518 | if (ENABLE_FEATURE_REMOTE_LOG && opts & SYSLOG_OPT_remotelog) { |
541 | if (doRemoteLog == TRUE) { | ||
542 | init_RemoteLog(); | 519 | init_RemoteLog(); |
543 | } | 520 | } |
544 | #endif | ||
545 | 521 | ||
546 | logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER ); | 522 | logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER ); |
547 | 523 | ||
@@ -613,10 +589,10 @@ int syslogd_main(int argc, char **argv) | |||
613 | RemotePort = atoi(p + 1); | 589 | RemotePort = atoi(p + 1); |
614 | *p = '\0'; | 590 | *p = '\0'; |
615 | } | 591 | } |
616 | doRemoteLog = TRUE; | 592 | opts |= SYSLOG_OPT_remotelog; |
617 | break; | 593 | break; |
618 | case 'L': | 594 | case 'L': |
619 | local_logging = TRUE; | 595 | opts |= SYSLOG_OPT_locallog; |
620 | break; | 596 | break; |
621 | #endif | 597 | #endif |
622 | #ifdef CONFIG_FEATURE_IPC_SYSLOG | 598 | #ifdef CONFIG_FEATURE_IPC_SYSLOG |
@@ -627,22 +603,20 @@ int syslogd_main(int argc, char **argv) | |||
627 | shm_size = buf_size * 1024; | 603 | shm_size = buf_size * 1024; |
628 | } | 604 | } |
629 | } | 605 | } |
630 | circular_logging = TRUE; | 606 | opts |= SYSLOG_OPT_circularlog; |
631 | break; | 607 | break; |
632 | #endif | 608 | #endif |
633 | case 'S': | 609 | case 'S': |
634 | small = true; | 610 | opts |= SYSLOG_OPT_small; |
635 | break; | 611 | break; |
636 | default: | 612 | default: |
637 | bb_show_usage(); | 613 | bb_show_usage(); |
638 | } | 614 | } |
639 | } | 615 | } |
640 | 616 | ||
641 | #ifdef CONFIG_FEATURE_REMOTE_LOG | ||
642 | /* If they have not specified remote logging, then log locally */ | 617 | /* If they have not specified remote logging, then log locally */ |
643 | if (doRemoteLog == FALSE) | 618 | if (ENABLE_FEATURE_REMOTE_LOG && !(opts & SYSLOG_OPT_remotelog)) |
644 | local_logging = TRUE; | 619 | opts |= SYSLOG_OPT_locallog; |
645 | #endif | ||
646 | 620 | ||
647 | 621 | ||
648 | /* Store away localhost's name before the fork */ | 622 | /* Store away localhost's name before the fork */ |