aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-05-09 15:23:38 +0100
committerRon Yorston <rmy@pobox.com>2012-05-09 15:23:38 +0100
commit7e572c27e15f5ca458dd02a745b20d1dbbc9f1f6 (patch)
tree2ff84ec9c7249a0a370da7cb187ac99ca5033863
parent4066aff5e481941585c5958460c39a1b1399ce88 (diff)
parentf1f8fcaad556ea2991e57bbb6132d80e86346e1e (diff)
downloadbusybox-w32-7e572c27e15f5ca458dd02a745b20d1dbbc9f1f6.tar.gz
busybox-w32-7e572c27e15f5ca458dd02a745b20d1dbbc9f1f6.tar.bz2
busybox-w32-7e572c27e15f5ca458dd02a745b20d1dbbc9f1f6.zip
Merge branch 'busybox' into merge
-rw-r--r--coreutils/ln.c28
-rw-r--r--coreutils/mkdir.c3
-rw-r--r--coreutils/mv.c19
-rw-r--r--coreutils/rmdir.c8
-rw-r--r--editors/sed.c33
-rw-r--r--libbb/kernel_version.c11
-rw-r--r--libbb/remove_file.c2
-rw-r--r--networking/udhcp/d6_dhcpc.c9
8 files changed, 78 insertions, 35 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 0eb3e6579..3b822e8c7 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -20,6 +20,8 @@
20//usage: "\n -n Don't dereference symlinks - treat like normal file" 20//usage: "\n -n Don't dereference symlinks - treat like normal file"
21//usage: "\n -b Make a backup of the target (if exists) before link operation" 21//usage: "\n -b Make a backup of the target (if exists) before link operation"
22//usage: "\n -S suf Use suffix instead of ~ when making backup files" 22//usage: "\n -S suf Use suffix instead of ~ when making backup files"
23//usage: "\n -T 2nd arg must be a DIR"
24//usage: "\n -v Verbose"
23//usage: 25//usage:
24//usage:#define ln_example_usage 26//usage:#define ln_example_usage
25//usage: "$ ln -s BusyBox /tmp/ls\n" 27//usage: "$ ln -s BusyBox /tmp/ls\n"
@@ -31,11 +33,13 @@
31/* This is a NOEXEC applet. Be very careful! */ 33/* This is a NOEXEC applet. Be very careful! */
32 34
33 35
34#define LN_SYMLINK 1 36#define LN_SYMLINK (1 << 0)
35#define LN_FORCE 2 37#define LN_FORCE (1 << 1)
36#define LN_NODEREFERENCE 4 38#define LN_NODEREFERENCE (1 << 2)
37#define LN_BACKUP 8 39#define LN_BACKUP (1 << 3)
38#define LN_SUFFIX 16 40#define LN_SUFFIX (1 << 4)
41#define LN_VERBOSE (1 << 5)
42#define LN_LINKFILE (1 << 6)
39 43
40int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 44int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
41int ln_main(int argc, char **argv) 45int ln_main(int argc, char **argv)
@@ -50,10 +54,15 @@ int ln_main(int argc, char **argv)
50 int (*link_func)(const char *, const char *); 54 int (*link_func)(const char *, const char *);
51 55
52 opt_complementary = "-1"; /* min one arg */ 56 opt_complementary = "-1"; /* min one arg */
53 opts = getopt32(argv, "sfnbS:", &suffix); 57 opts = getopt32(argv, "sfnbS:vT", &suffix);
54 58
55 last = argv[argc - 1]; 59 last = argv[argc - 1];
56 argv += optind; 60 argv += optind;
61 argc -= optind;
62
63 if ((opts & LN_LINKFILE) && argc > 2) {
64 bb_error_msg_and_die("-T accepts 2 args max");
65 }
57 66
58 if (!argv[1]) { 67 if (!argv[1]) {
59 /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */ 68 /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */
@@ -72,6 +81,9 @@ int ln_main(int argc, char **argv)
72 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE 81 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE
73 ) 82 )
74 ) { 83 ) {
84 if (opts & LN_LINKFILE) {
85 bb_error_msg_and_die("'%s' is a directory", src);
86 }
75 src_name = xstrdup(*argv); 87 src_name = xstrdup(*argv);
76 src = concat_path_file(src, bb_get_last_path_component_strip(src_name)); 88 src = concat_path_file(src, bb_get_last_path_component_strip(src_name));
77 free(src_name); 89 free(src_name);
@@ -112,6 +124,10 @@ int ln_main(int argc, char **argv)
112 link_func = symlink; 124 link_func = symlink;
113 } 125 }
114 126
127 if (opts & LN_VERBOSE) {
128 printf("'%s' -> '%s'\n", src, *argv);
129 }
130
115 if (link_func(*argv, src) != 0) { 131 if (link_func(*argv, src) != 0) {
116 bb_simple_perror_msg(src); 132 bb_simple_perror_msg(src);
117 status = EXIT_FAILURE; 133 status = EXIT_FAILURE;
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index b33b6bba3..4a8e43e43 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -48,6 +48,7 @@ static const char mkdir_longopts[] ALIGN1 =
48#if ENABLE_SELINUX 48#if ENABLE_SELINUX
49 "context\0" Required_argument "Z" 49 "context\0" Required_argument "Z"
50#endif 50#endif
51 "verbose\0" No_argument "v"
51 ; 52 ;
52#endif 53#endif
53 54
@@ -66,7 +67,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
66#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS 67#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
67 applet_long_options = mkdir_longopts; 68 applet_long_options = mkdir_longopts;
68#endif 69#endif
69 opt = getopt32(argv, "m:p" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); 70 opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
70 if (opt & 1) { 71 if (opt & 1) {
71 mode_t mmode = 0777; 72 mode_t mmode = 0777;
72 if (!bb_parse_mode(smode, &mmode)) { 73 if (!bb_parse_mode(smode, &mmode)) {
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 87f4cd5a5..f127dfabd 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -33,12 +33,13 @@ static const char mv_longopts[] ALIGN1 =
33 "interactive\0" No_argument "i" 33 "interactive\0" No_argument "i"
34 "force\0" No_argument "f" 34 "force\0" No_argument "f"
35 "no-clobber\0" No_argument "n" 35 "no-clobber\0" No_argument "n"
36 "verbose\0" No_argument "v"
36 ; 37 ;
37#endif 38#endif
38 39
39#define OPT_FILEUTILS_FORCE 1 40#define OPT_FORCE (1 << 0)
40#define OPT_FILEUTILS_INTERACTIVE 2 41#define OPT_INTERACTIVE (1 << 1)
41#define OPT_FILEUTILS_NOCLOBBER 4 42#define OPT_NOCLOBBER (1 << 2)
42 43
43int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 44int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44int mv_main(int argc, char **argv) 45int mv_main(int argc, char **argv)
@@ -56,9 +57,11 @@ int mv_main(int argc, char **argv)
56#endif 57#endif
57 /* Need at least two arguments. 58 /* Need at least two arguments.
58 * If more than one of -f, -i, -n is specified , only the final one 59 * If more than one of -f, -i, -n is specified , only the final one
59 * takes effect (it unsets previous options). */ 60 * takes effect (it unsets previous options).
61 * -v is accepted but ignored.
62 */
60 opt_complementary = "-2:f-in:i-fn:n-fi"; 63 opt_complementary = "-2:f-in:i-fn:n-fi";
61 flags = getopt32(argv, "fin"); 64 flags = getopt32(argv, "finv");
62 argc -= optind; 65 argc -= optind;
63 argv += optind; 66 argv += optind;
64 last = argv[argc - 1]; 67 last = argv[argc - 1];
@@ -84,11 +87,11 @@ int mv_main(int argc, char **argv)
84 87
85 DO_MOVE: 88 DO_MOVE:
86 if (dest_exists) { 89 if (dest_exists) {
87 if (flags & OPT_FILEUTILS_NOCLOBBER) 90 if (flags & OPT_NOCLOBBER)
88 goto RET_0; 91 goto RET_0;
89 if (!(flags & OPT_FILEUTILS_FORCE) 92 if (!(flags & OPT_FORCE)
90 && ((access(dest, W_OK) < 0 && isatty(0)) 93 && ((access(dest, W_OK) < 0 && isatty(0))
91 || (flags & OPT_FILEUTILS_INTERACTIVE)) 94 || (flags & OPT_INTERACTIVE))
92 ) { 95 ) {
93 if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) { 96 if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
94 goto RET_1; /* Ouch! fprintf failed! */ 97 goto RET_1; /* Ouch! fprintf failed! */
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index 2840d1cfa..cc2dea010 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -30,8 +30,9 @@
30/* This is a NOFORK applet. Be very careful! */ 30/* This is a NOFORK applet. Be very careful! */
31 31
32 32
33#define PARENTS 0x01 33#define PARENTS (1 << 0)
34#define IGNORE_NON_EMPTY 0x02 34//efine VERBOSE (1 << 1) //accepted but ignored
35#define IGNORE_NON_EMPTY (1 << 2)
35 36
36int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 37int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int rmdir_main(int argc UNUSED_PARAM, char **argv) 38int rmdir_main(int argc UNUSED_PARAM, char **argv)
@@ -43,13 +44,14 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
43#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS 44#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
44 static const char rmdir_longopts[] ALIGN1 = 45 static const char rmdir_longopts[] ALIGN1 =
45 "parents\0" No_argument "p" 46 "parents\0" No_argument "p"
47 "verbose\0" No_argument "v"
46 /* Debian etch: many packages fail to be purged or installed 48 /* Debian etch: many packages fail to be purged or installed
47 * because they desperately want this option: */ 49 * because they desperately want this option: */
48 "ignore-fail-on-non-empty\0" No_argument "\xff" 50 "ignore-fail-on-non-empty\0" No_argument "\xff"
49 ; 51 ;
50 applet_long_options = rmdir_longopts; 52 applet_long_options = rmdir_longopts;
51#endif 53#endif
52 flags = getopt32(argv, "p"); 54 flags = getopt32(argv, "pv");
53 argv += optind; 55 argv += optind;
54 56
55 if (!*argv) { 57 if (!*argv) {
diff --git a/editors/sed.c b/editors/sed.c
index 3ee8edc43..a2df93165 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -62,7 +62,8 @@
62//usage:#define sed_full_usage "\n\n" 62//usage:#define sed_full_usage "\n\n"
63//usage: " -e CMD Add CMD to sed commands to be executed" 63//usage: " -e CMD Add CMD to sed commands to be executed"
64//usage: "\n -f FILE Add FILE contents to sed commands to be executed" 64//usage: "\n -f FILE Add FILE contents to sed commands to be executed"
65//usage: "\n -i Edit files in-place (else sends result to stdout)" 65//usage: "\n -i[SFX] Edit files in-place (otherwise sends to stdout)"
66//usage: "\n Optionally backs files up, appending SFX"
66//usage: "\n -n Suppress automatic printing of pattern space" 67//usage: "\n -n Suppress automatic printing of pattern space"
67//usage: "\n -r Use extended regex syntax" 68//usage: "\n -r Use extended regex syntax"
68//usage: "\n" 69//usage: "\n"
@@ -1374,6 +1375,19 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1374{ 1375{
1375 unsigned opt; 1376 unsigned opt;
1376 llist_t *opt_e, *opt_f; 1377 llist_t *opt_e, *opt_f;
1378 char *opt_i;
1379
1380#if ENABLE_LONG_OPTS
1381 static const char sed_longopts[] ALIGN1 =
1382 /* name has_arg short */
1383 "in-place\0" Optional_argument "i"
1384 "regexp-extended\0" No_argument "r"
1385 "quiet\0" No_argument "n"
1386 "silent\0" No_argument "n"
1387 "expression\0" Required_argument "e"
1388 "file\0" Required_argument "f";
1389#endif
1390
1377 int status = EXIT_SUCCESS; 1391 int status = EXIT_SUCCESS;
1378 1392
1379 INIT_G(); 1393 INIT_G();
@@ -1382,17 +1396,21 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1382 if (ENABLE_FEATURE_CLEAN_UP) atexit(sed_free_and_close_stuff); 1396 if (ENABLE_FEATURE_CLEAN_UP) atexit(sed_free_and_close_stuff);
1383 1397
1384 /* Lie to autoconf when it starts asking stupid questions. */ 1398 /* Lie to autoconf when it starts asking stupid questions. */
1385 if (argv[1] && !strcmp(argv[1], "--version")) { 1399 if (argv[1] && strcmp(argv[1], "--version") == 0) {
1386 puts("This is not GNU sed version 4.0"); 1400 puts("This is not GNU sed version 4.0");
1387 return 0; 1401 return 0;
1388 } 1402 }
1389 1403
1390 /* do normal option parsing */ 1404 /* do normal option parsing */
1391 opt_e = opt_f = NULL; 1405 opt_e = opt_f = NULL;
1406 opt_i = NULL;
1392 opt_complementary = "e::f::" /* can occur multiple times */ 1407 opt_complementary = "e::f::" /* can occur multiple times */
1393 "nn"; /* count -n */ 1408 "nn"; /* count -n */
1409
1410 IF_LONG_OPTS(applet_long_options = sed_longopts);
1411
1394 /* -i must be first, to match OPT_in_place definition */ 1412 /* -i must be first, to match OPT_in_place definition */
1395 opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, 1413 opt = getopt32(argv, "i::rne:f:", &opt_i, &opt_e, &opt_f,
1396 &G.be_quiet); /* counter for -n */ 1414 &G.be_quiet); /* counter for -n */
1397 //argc -= optind; 1415 //argc -= optind;
1398 argv += optind; 1416 argv += optind;
@@ -1474,8 +1492,13 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1474 fclose(G.nonstdout); 1492 fclose(G.nonstdout);
1475 G.nonstdout = stdout; 1493 G.nonstdout = stdout;
1476 1494
1477 /* unlink(argv[i]); */ 1495 if (opt_i) {
1478 xrename(G.outname, argv[i]); 1496 char *backupname = xasprintf("%s%s", argv[i], opt_i);
1497 xrename(argv[i], backupname);
1498 free(backupname);
1499 }
1500 /* else unlink(argv[i]); - rename below does this */
1501 xrename(G.outname, argv[i]); //TODO: rollback backup on error?
1479 free(G.outname); 1502 free(G.outname);
1480 G.outname = NULL; 1503 G.outname = NULL;
1481 1504
diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c
index a168a1e4e..738ed022b 100644
--- a/libbb/kernel_version.c
+++ b/libbb/kernel_version.c
@@ -20,18 +20,15 @@
20int FAST_FUNC get_linux_version_code(void) 20int FAST_FUNC get_linux_version_code(void)
21{ 21{
22 struct utsname name; 22 struct utsname name;
23 char *s; 23 char *s, *t;
24 int i, r; 24 int i, r;
25 25
26 if (uname(&name) == -1) { 26 uname(&name); /* never fails */
27 bb_perror_msg("can't get system information");
28 return 0;
29 }
30
31 s = name.release; 27 s = name.release;
32 r = 0; 28 r = 0;
33 for (i = 0; i < 3; i++) { 29 for (i = 0; i < 3; i++) {
34 r = r * 256 + atoi(strtok(s, ".")); 30 t = strtok(s, ".");
31 r = r * 256 + (t ? atoi(t) : 0);
35 s = NULL; 32 s = NULL;
36 } 33 }
37 return r; 34 return r;
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index c6531a0b9..5b75f7f30 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -33,7 +33,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
33 int status = 0; 33 int status = 0;
34 34
35 if (!(flags & FILEUTILS_RECUR)) { 35 if (!(flags & FILEUTILS_RECUR)) {
36 bb_error_msg("%s: is a directory", path); 36 bb_error_msg("'%s' is a directory", path);
37 return -1; 37 return -1;
38 } 38 }
39 39
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index a792a9dca..7c9f52ae7 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -12,10 +12,11 @@
12 */ 12 */
13 13
14//config:config UDHCPC6 14//config:config UDHCPC6
15//config: bool "udhcp client for DHCPv6 (udhcpc6)" 15//config: bool "udhcp client for DHCPv6 (udhcpc6)"
16//config: default n # not yet ready 16//config: default n # not yet ready
17//config: help 17//config: depends on FEATURE_IPV6
18//config: udhcpc6 is a DHCPv6 client 18//config: help
19//config: udhcpc6 is a DHCPv6 client
19 20
20//applet:IF_UDHCPC6(APPLET(udhcpc6, BB_DIR_USR_BIN, BB_SUID_DROP)) 21//applet:IF_UDHCPC6(APPLET(udhcpc6, BB_DIR_USR_BIN, BB_SUID_DROP))
21 22