diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-08 17:27:17 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-08 17:27:17 +0000 |
commit | 92c0b8222eb50dd35c06e2f1265706b388762234 (patch) | |
tree | c94def6f5c4cfbbcc1a7a70d96e721eb433ed01f | |
parent | 0cacc80952a7a34f9cb8b384d6dd0b1522c37bae (diff) | |
download | busybox-w32-92c0b8222eb50dd35c06e2f1265706b388762234.tar.gz busybox-w32-92c0b8222eb50dd35c06e2f1265706b388762234.tar.bz2 busybox-w32-92c0b8222eb50dd35c06e2f1265706b388762234.zip |
tail: fix SEGV on "tail -N"
config system: clarify PREFER_APPLETS/SH_STANDALONE effects in help text
-rw-r--r-- | Config.in | 9 | ||||
-rw-r--r-- | coreutils/tail.c | 16 | ||||
-rw-r--r-- | shell/Config.in | 29 |
3 files changed, 37 insertions, 17 deletions
@@ -244,8 +244,13 @@ config FEATURE_PREFER_APPLETS | |||
244 | help | 244 | help |
245 | This is an experimental option which directs applets about to | 245 | This is an experimental option which directs applets about to |
246 | call 'exec' to try and find an applicable busybox applet before | 246 | call 'exec' to try and find an applicable busybox applet before |
247 | searching the PATH. This may affect shell, find -exec, xargs and | 247 | searching the PATH. This is typically done by exec'ing |
248 | similar programs. | 248 | /proc/self/exe. |
249 | This may affect shell, find -exec, xargs and similar applets. | ||
250 | They will use applets even if /bin/<applet> -> busybox link | ||
251 | is missing (or is not a link to busybox). However, this causes | ||
252 | problems in chroot jails without mounted /proc and with ps/top | ||
253 | (command name can be shown as 'exe' for applets started this way). | ||
249 | 254 | ||
250 | config BUSYBOX_EXEC_PATH | 255 | config BUSYBOX_EXEC_PATH |
251 | string "Path to BusyBox executable" | 256 | string "Path to BusyBox executable" |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 629ee2125..32df25914 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -79,7 +79,8 @@ int tail_main(int argc, char **argv) | |||
79 | unsigned sleep_period = 1; | 79 | unsigned sleep_period = 1; |
80 | bool from_top; | 80 | bool from_top; |
81 | int header_threshhold = 1; | 81 | int header_threshhold = 1; |
82 | const char *str_c, *str_n, *str_s; | 82 | const char *str_c, *str_n; |
83 | USE_FEATURE_FANCY_TAIL(const char *str_s;) | ||
83 | 84 | ||
84 | char *tailbuf; | 85 | char *tailbuf; |
85 | size_t tailbufsize; | 86 | size_t tailbufsize; |
@@ -96,13 +97,18 @@ int tail_main(int argc, char **argv) | |||
96 | if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') | 97 | if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') |
97 | && isdigit(argv[1][1]) | 98 | && isdigit(argv[1][1]) |
98 | ) { | 99 | ) { |
99 | argv[0] = (char*)"-n"; | 100 | /* replacing arg[0] with "-n" can segfault, so... */ |
100 | argv--; | 101 | argv[1] = xasprintf("-n%s", argv[1]); |
101 | argc++; | 102 | #if 0 /* If we ever decide to make tail NOFORK */ |
103 | char *s = alloca(strlen(argv[1]) + 3); | ||
104 | sprintf(s, "-n%s", argv[1]); | ||
105 | argv[1] = s; | ||
106 | #endif | ||
102 | } | 107 | } |
103 | #endif | 108 | #endif |
104 | 109 | ||
105 | opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), &str_c, &str_n, &str_s); | 110 | opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), |
111 | &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s)); | ||
106 | #define FOLLOW (opt & 0x1) | 112 | #define FOLLOW (opt & 0x1) |
107 | #define COUNT_BYTES (opt & 0x2) | 113 | #define COUNT_BYTES (opt & 0x2) |
108 | //if (opt & 0x1) // -f | 114 | //if (opt & 0x1) // -f |
diff --git a/shell/Config.in b/shell/Config.in index f3726e302..027993483 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -242,7 +242,7 @@ config FEATURE_SH_STANDALONE | |||
242 | default n | 242 | default n |
243 | depends on (MSH || LASH || HUSH || ASH) && FEATURE_PREFER_APPLETS | 243 | depends on (MSH || LASH || HUSH || ASH) && FEATURE_PREFER_APPLETS |
244 | help | 244 | help |
245 | This option causes the selected busybox shell to use busybox applets | 245 | This option causes busybox shells to use busybox applets |
246 | in preference to executables in the PATH whenever possible. For | 246 | in preference to executables in the PATH whenever possible. For |
247 | example, entering the command 'ifconfig' into the shell would cause | 247 | example, entering the command 'ifconfig' into the shell would cause |
248 | busybox to use the ifconfig busybox applet. Specifying the fully | 248 | busybox to use the ifconfig busybox applet. Specifying the fully |
@@ -251,14 +251,23 @@ config FEATURE_SH_STANDALONE | |||
251 | is generally used when creating a statically linked version of busybox | 251 | is generally used when creating a statically linked version of busybox |
252 | for use as a rescue shell, in the event that you screw up your system. | 252 | for use as a rescue shell, in the event that you screw up your system. |
253 | 253 | ||
254 | Note that this will *also* cause applets to take precedence | 254 | This is implemented by re-execing /proc/self/exe (typically) |
255 | over shell builtins of the same name. So turning this on will | 255 | with right parameters. Some selected applets ("NOFORK" applets) |
256 | eliminate any performance gained by turning on the builtin "echo" | 256 | can even be executed without creating new process. |
257 | and "test" commands in ash. | 257 | Instead, busybox will call <applet>_main() internally. |
258 | 258 | ||
259 | Note that when using this option, the shell will attempt to directly | 259 | However, this causes problems in chroot jails without mounted /proc |
260 | run '/bin/busybox'. If you do not have the busybox binary sitting in | 260 | and with ps/top (command name can be shown as 'exe' for applets |
261 | that exact location with that exact name, this option will not work at | 261 | started this way). |
262 | all. | 262 | # untrue? |
263 | # Note that this will *also* cause applets to take precedence | ||
264 | # over shell builtins of the same name. So turning this on will | ||
265 | # eliminate any performance gained by turning on the builtin "echo" | ||
266 | # and "test" commands in ash. | ||
267 | # untrue? | ||
268 | # Note that when using this option, the shell will attempt to directly | ||
269 | # run '/bin/busybox'. If you do not have the busybox binary sitting in | ||
270 | # that exact location with that exact name, this option will not work at | ||
271 | # all. | ||
263 | 272 | ||
264 | endmenu | 273 | endmenu |