aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 17:27:17 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-05-08 17:27:17 +0000
commit92ce299856803ce2a2e59c4bfd2cc9edce90d3f7 (patch)
treec94def6f5c4cfbbcc1a7a70d96e721eb433ed01f
parentfc24e2de044defa5e26e99a125dc2b361cab184a (diff)
downloadbusybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.tar.gz
busybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.tar.bz2
busybox-w32-92ce299856803ce2a2e59c4bfd2cc9edce90d3f7.zip
tail: fix SEGV on "tail -N"
config system: clarify PREFER_APPLETS/SH_STANDALONE effects in help text git-svn-id: svn://busybox.net/trunk/busybox@18585 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--Config.in9
-rw-r--r--coreutils/tail.c16
-rw-r--r--shell/Config.in29
3 files changed, 37 insertions, 17 deletions
diff --git a/Config.in b/Config.in
index 94ed109cb..a04e11b5c 100644
--- a/Config.in
+++ b/Config.in
@@ -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
250config BUSYBOX_EXEC_PATH 255config 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
264endmenu 273endmenu