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 /coreutils/tail.c | |
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
Diffstat (limited to 'coreutils/tail.c')
-rw-r--r-- | coreutils/tail.c | 16 |
1 files changed, 11 insertions, 5 deletions
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 |