aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-03-23 13:56:37 +0000
committerRon Yorston <rmy@pobox.com>2015-03-23 13:56:37 +0000
commit486a3907f353adeb7f3ced5357db1e604659b785 (patch)
tree5033870835b2b9d5b26ba1f4544943c47893b904
parent74ba8c760f3337218cddabaaa0acc4e1f5d6e6c5 (diff)
parent1850d5ec0e90fbfb598ed7ad8ff0a63b6e5692ce (diff)
downloadbusybox-w32-486a3907f353adeb7f3ced5357db1e604659b785.tar.gz
busybox-w32-486a3907f353adeb7f3ced5357db1e604659b785.tar.bz2
busybox-w32-486a3907f353adeb7f3ced5357db1e604659b785.zip
Merge branch 'busybox' into merge
-rw-r--r--coreutils/dd.c31
-rw-r--r--coreutils/truncate.c77
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/xatonum.c21
-rw-r--r--networking/ifupdown.c9
-rw-r--r--networking/zcip.c2
-rwxr-xr-xscripts/trylink12
-rw-r--r--shell/ash.c3
-rw-r--r--sysklogd/logread.c16
9 files changed, 129 insertions, 44 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index a01722040..589547e77 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -99,25 +99,6 @@ enum {
99 ofd = STDOUT_FILENO, 99 ofd = STDOUT_FILENO,
100}; 100};
101 101
102static const struct suffix_mult dd_suffixes[] = {
103 { "c", 1 },
104 { "w", 2 },
105 { "b", 512 },
106 { "kB", 1000 },
107 { "kD", 1000 },
108 { "k", 1024 },
109 { "K", 1024 }, /* compat with coreutils dd (it also accepts KB and KD, TODO?) */
110 { "MB", 1000000 },
111 { "MD", 1000000 },
112 { "M", 1024*1024 },
113 { "GB", 1000000000 },
114 { "GD", 1000000000 },
115 { "G", 1024*1024*1024 },
116 /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
117 /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
118 { "", 0 }
119};
120
121struct globals { 102struct globals {
122 off_t out_full, out_part, in_full, in_part; 103 off_t out_full, out_part, in_full, in_part;
123#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE 104#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
@@ -327,11 +308,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
327#if ENABLE_FEATURE_DD_IBS_OBS 308#if ENABLE_FEATURE_DD_IBS_OBS
328 if (what == OP_ibs) { 309 if (what == OP_ibs) {
329 /* Must fit into positive ssize_t */ 310 /* Must fit into positive ssize_t */
330 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 311 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
331 /*continue;*/ 312 /*continue;*/
332 } 313 }
333 if (what == OP_obs) { 314 if (what == OP_obs) {
334 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 315 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
335 /*continue;*/ 316 /*continue;*/
336 } 317 }
337 if (what == OP_conv) { 318 if (what == OP_conv) {
@@ -357,22 +338,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
357 } 338 }
358#endif 339#endif
359 if (what == OP_bs) { 340 if (what == OP_bs) {
360 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 341 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
361 obs = ibs; 342 obs = ibs;
362 /*continue;*/ 343 /*continue;*/
363 } 344 }
364 /* These can be large: */ 345 /* These can be large: */
365 if (what == OP_count) { 346 if (what == OP_count) {
366 G.flags |= FLAG_COUNT; 347 G.flags |= FLAG_COUNT;
367 count = XATOU_SFX(val, dd_suffixes); 348 count = XATOU_SFX(val, cwbkMG_suffixes);
368 /*continue;*/ 349 /*continue;*/
369 } 350 }
370 if (what == OP_seek) { 351 if (what == OP_seek) {
371 seek = XATOU_SFX(val, dd_suffixes); 352 seek = XATOU_SFX(val, cwbkMG_suffixes);
372 /*continue;*/ 353 /*continue;*/
373 } 354 }
374 if (what == OP_skip) { 355 if (what == OP_skip) {
375 skip = XATOU_SFX(val, dd_suffixes); 356 skip = XATOU_SFX(val, cwbkMG_suffixes);
376 /*continue;*/ 357 /*continue;*/
377 } 358 }
378 if (what == OP_if) { 359 if (what == OP_if) {
diff --git a/coreutils/truncate.c b/coreutils/truncate.c
new file mode 100644
index 000000000..0e36daba3
--- /dev/null
+++ b/coreutils/truncate.c
@@ -0,0 +1,77 @@
1/*
2 * Mini truncate implementation for busybox
3 *
4 * Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 */
8
9//config:config TRUNCATE
10//config: bool "truncate"
11//config: default y
12//config: help
13//config: truncate truncates files to a given size. If a file does
14//config: not exist, it is created unless told otherwise.
15
16//kbuild:lib-$(CONFIG_TRUNCATE) += truncate.o
17//applet:IF_TRUNCATE(APPLET_NOFORK(truncate, truncate, BB_DIR_USR_BIN, BB_SUID_DROP, truncate))
18
19//usage:#define truncate_trivial_usage
20//usage: "[-c] -s SIZE FILE..."
21//usage:#define truncate_full_usage "\n\n"
22//usage: "Truncate FILEs to the given size\n"
23//usage: "\n -c Do not create files"
24//usage: "\n -s SIZE Truncate to SIZE"
25//usage:
26//usage:#define truncate_example_usage
27//usage: "$ truncate -s 1G foo"
28
29#include "libbb.h"
30
31#if ENABLE_LFS
32# define XATOU_SFX xatoull_sfx
33#else
34# define XATOU_SFX xatoul_sfx
35#endif
36
37/* This is a NOFORK applet. Be very careful! */
38
39int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40int truncate_main(int argc UNUSED_PARAM, char **argv)
41{
42 unsigned opts;
43 int flags = O_RDWR;
44 int ret = EXIT_SUCCESS;
45 char *size_str;
46 off_t size;
47
48 enum {
49 OPT_NOCREATE = (1 << 0),
50 OPT_SIZE = (1 << 1),
51 };
52
53 opt_complementary = "s:-1";
54 opts = getopt32(argv, "cs:", &size_str);
55
56 if (!(opts & OPT_NOCREATE))
57 flags |= O_CREAT;
58
59 // TODO: coreutils 8.17 also support "m" (lowercase) suffix
60 // with truncate, but not with dd!
61 // We share kMG_suffixes[], so we can't make both tools
62 // compatible at once...
63 size = XATOU_SFX(size_str, kMG_suffixes);
64
65 argv += optind;
66 while (*argv) {
67 int fd = xopen(*argv, flags);
68 if (ftruncate(fd, size) == -1) {
69 bb_perror_msg("%s: ftruncate", *argv);
70 ret = EXIT_FAILURE;
71 }
72 xclose(fd);
73 ++argv;
74 }
75
76 return ret;
77}
diff --git a/include/libbb.h b/include/libbb.h
index 1733e9a0f..28ac779c3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -878,6 +878,8 @@ struct suffix_mult {
878}; 878};
879extern const struct suffix_mult bkm_suffixes[]; 879extern const struct suffix_mult bkm_suffixes[];
880#define km_suffixes (bkm_suffixes + 1) 880#define km_suffixes (bkm_suffixes + 1)
881extern const struct suffix_mult cwbkMG_suffixes[];
882#define kMG_suffixes (cwbkMG_suffixes + 3)
881 883
882#include "xatonum.h" 884#include "xatonum.h"
883/* Specialized: */ 885/* Specialized: */
diff --git a/libbb/xatonum.c b/libbb/xatonum.c
index 6f4e023bb..9dd5c3e7e 100644
--- a/libbb/xatonum.c
+++ b/libbb/xatonum.c
@@ -75,3 +75,24 @@ const struct suffix_mult bkm_suffixes[] = {
75 { "m", 1024*1024 }, 75 { "m", 1024*1024 },
76 { "", 0 } 76 { "", 0 }
77}; 77};
78
79const struct suffix_mult cwbkMG_suffixes[] = {
80 { "c", 1 },
81 { "w", 2 },
82 { "b", 512 },
83 { "kB", 1000 },
84 { "kD", 1000 },
85 { "k", 1024 },
86 { "KB", 1000 }, /* compat with coreutils dd */
87 { "KD", 1000 }, /* compat with coreutils dd */
88 { "K", 1024 }, /* compat with coreutils dd */
89 { "MB", 1000000 },
90 { "MD", 1000000 },
91 { "M", 1024*1024 },
92 { "GB", 1000000000 },
93 { "GD", 1000000000 },
94 { "G", 1024*1024*1024 },
95 /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
96 /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
97 { "", 0 }
98};
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index daabeec0c..606fc049f 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -1239,6 +1239,7 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv)
1239 char *pch; 1239 char *pch;
1240 bool okay = 0; 1240 bool okay = 0;
1241 int cmds_ret; 1241 int cmds_ret;
1242 bool curr_failure = 0;
1242 1243
1243 iface = xstrdup(target_list->data); 1244 iface = xstrdup(target_list->data);
1244 target_list = target_list->link; 1245 target_list = target_list->link;
@@ -1304,11 +1305,11 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv)
1304 /* Call the cmds function pointer, does either iface_up() or iface_down() */ 1305 /* Call the cmds function pointer, does either iface_up() or iface_down() */
1305 cmds_ret = cmds(currif); 1306 cmds_ret = cmds(currif);
1306 if (cmds_ret == -1) { 1307 if (cmds_ret == -1) {
1307 bb_error_msg("don't seem to have all the variables for %s/%s", 1308 bb_error_msg("don't have all variables for %s/%s",
1308 liface, currif->address_family->name); 1309 liface, currif->address_family->name);
1309 any_failures = 1; 1310 any_failures = curr_failure = 1;
1310 } else if (cmds_ret == 0) { 1311 } else if (cmds_ret == 0) {
1311 any_failures = 1; 1312 any_failures = curr_failure = 1;
1312 } 1313 }
1313 1314
1314 currif->iface = oldiface; 1315 currif->iface = oldiface;
@@ -1329,7 +1330,7 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv)
1329 llist_t *state_list = read_iface_state(); 1330 llist_t *state_list = read_iface_state();
1330 llist_t *iface_state = find_iface_state(state_list, iface); 1331 llist_t *iface_state = find_iface_state(state_list, iface);
1331 1332
1332 if (cmds == iface_up && !any_failures) { 1333 if (cmds == iface_up && !curr_failure) {
1333 char *newiface = xasprintf("%s=%s", iface, liface); 1334 char *newiface = xasprintf("%s=%s", iface, liface);
1334 if (!iface_state) { 1335 if (!iface_state) {
1335 llist_add_to_end(&state_list, newiface); 1336 llist_add_to_end(&state_list, newiface);
diff --git a/networking/zcip.c b/networking/zcip.c
index a3307c5c9..962ba2e60 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -521,7 +521,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
521 target_ip_conflict = 0; 521 target_ip_conflict = 0;
522 522
523 if (memcmp(&p.arp.arp_sha, &eth_addr, ETH_ALEN) != 0) { 523 if (memcmp(&p.arp.arp_sha, &eth_addr, ETH_ALEN) != 0) {
524 if (memcmp(p.arp.arp_spa, &ip.s_addr, sizeof(struct in_addr))) { 524 if (memcmp(p.arp.arp_spa, &ip.s_addr, sizeof(struct in_addr)) == 0) {
525 /* A probe or reply with source_ip == chosen ip */ 525 /* A probe or reply with source_ip == chosen ip */
526 source_ip_conflict = 1; 526 source_ip_conflict = 1;
527 } 527 }
diff --git a/scripts/trylink b/scripts/trylink
index 5da494fbb..48c487bcd 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -46,19 +46,19 @@ try() {
46} 46}
47 47
48check_cc() { 48check_cc() {
49 local tempname="/tmp/temp.$$.$RANDOM" 49 local tempname="$(mktemp)"
50 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :( 50 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
51 # "-xc": C language. "/dev/null" is an empty source file. 51 # "-xc": C language. "/dev/null" is an empty source file.
52 if $CC $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then 52 if $CC $CPPFLAGS $CFLAGS $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then
53 echo "$1"; 53 echo "$1";
54 else 54 else
55 echo "$2"; 55 echo "$2";
56 fi 56 fi
57 rm "$tempname".o 2>/dev/null 57 rm -f "$tempname" "$tempname".o
58} 58}
59 59
60check_libc_is_glibc() { 60check_libc_is_glibc() {
61 local tempname="/tmp/temp.$$.$RANDOM" 61 local tempname="$(mktemp)"
62 echo "\ 62 echo "\
63 #include <stdlib.h> 63 #include <stdlib.h>
64 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ 64 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
@@ -66,12 +66,12 @@ check_libc_is_glibc() {
66 syntax error here 66 syntax error here
67 #endif 67 #endif
68 " >"$tempname".c 68 " >"$tempname".c
69 if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then 69 if $CC $CPPFLAGS $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
70 echo "$2"; 70 echo "$2";
71 else 71 else
72 echo "$1"; 72 echo "$1";
73 fi 73 fi
74 rm "$tempname".c "$tempname".o 2>/dev/null 74 rm -f "$tempname" "$tempname".[co]
75} 75}
76 76
77EXE="$1" 77EXE="$1"
diff --git a/shell/ash.c b/shell/ash.c
index df7083370..8cc3f0872 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6108,7 +6108,6 @@ exptilde(char *startp, char *p, int flags)
6108 struct passwd *pw; 6108 struct passwd *pw;
6109 const char *home; 6109 const char *home;
6110 int quotes = flags & (EXP_FULL | EXP_CASE | EXP_REDIR); 6110 int quotes = flags & (EXP_FULL | EXP_CASE | EXP_REDIR);
6111 int startloc;
6112 6111
6113 name = p + 1; 6112 name = p + 1;
6114 6113
@@ -6140,9 +6139,7 @@ exptilde(char *startp, char *p, int flags)
6140 if (!home || !*home) 6139 if (!home || !*home)
6141 goto lose; 6140 goto lose;
6142 *p = c; 6141 *p = c;
6143 startloc = expdest - (char *)stackblock();
6144 strtodest(home, SQSYNTAX, quotes); 6142 strtodest(home, SQSYNTAX, quotes);
6145 recordregion(startloc, expdest - (char *)stackblock(), 0);
6146 return p; 6143 return p;
6147 lose: 6144 lose:
6148 *p = c; 6145 *p = c;
diff --git a/sysklogd/logread.c b/sysklogd/logread.c
index bea73d932..da4a4d4df 100644
--- a/sysklogd/logread.c
+++ b/sysklogd/logread.c
@@ -10,10 +10,11 @@
10 */ 10 */
11 11
12//usage:#define logread_trivial_usage 12//usage:#define logread_trivial_usage
13//usage: "[-f]" 13//usage: "[-fF]"
14//usage:#define logread_full_usage "\n\n" 14//usage:#define logread_full_usage "\n\n"
15//usage: "Show messages in syslogd's circular buffer\n" 15//usage: "Show messages in syslogd's circular buffer\n"
16//usage: "\n -f Output data as log grows" 16//usage: "\n -f Output data as log grows"
17//usage: "\n -F Same as -f, but dump buffer first"
17 18
18#include "libbb.h" 19#include "libbb.h"
19#include <sys/ipc.h> 20#include <sys/ipc.h>
@@ -83,7 +84,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
83 unsigned cur; 84 unsigned cur;
84 int log_semid; /* ipc semaphore id */ 85 int log_semid; /* ipc semaphore id */
85 int log_shmid; /* ipc shared memory id */ 86 int log_shmid; /* ipc shared memory id */
86 smallint follow = getopt32(argv, "f"); 87 int follow = getopt32(argv, "fF");
87 88
88 INIT_G(); 89 INIT_G();
89 90
@@ -106,7 +107,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
106 /* Max possible value for tail is shbuf->size - 1 */ 107 /* Max possible value for tail is shbuf->size - 1 */
107 cur = shbuf->tail; 108 cur = shbuf->tail;
108 109
109 /* Loop for logread -f, one pass if there was no -f */ 110 /* Loop for -f or -F, one pass otherwise */
110 do { 111 do {
111 unsigned shbuf_size; 112 unsigned shbuf_size;
112 unsigned shbuf_tail; 113 unsigned shbuf_tail;
@@ -129,7 +130,12 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
129 printf("cur:%u tail:%u size:%u\n", 130 printf("cur:%u tail:%u size:%u\n",
130 cur, shbuf_tail, shbuf_size); 131 cur, shbuf_tail, shbuf_size);
131 132
132 if (!follow) { 133 if (!(follow & 1)) { /* not -f */
134 /* if -F, "convert" it to -f, so that we dont
135 * dump the entire buffer on each iteration
136 */
137 follow >>= 1;
138
133 /* advance to oldest complete message */ 139 /* advance to oldest complete message */
134 /* find NUL */ 140 /* find NUL */
135 cur += strlen(shbuf_data + cur); 141 cur += strlen(shbuf_data + cur);
@@ -142,7 +148,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
142 cur++; 148 cur++;
143 if (cur >= shbuf_size) /* last byte in buffer? */ 149 if (cur >= shbuf_size) /* last byte in buffer? */
144 cur = 0; 150 cur = 0;
145 } else { /* logread -f */ 151 } else { /* -f */
146 if (cur == shbuf_tail) { 152 if (cur == shbuf_tail) {
147 sem_up(log_semid); 153 sem_up(log_semid);
148 fflush_all(); 154 fflush_all();