aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
committerRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
commita9271a8e97e6e7be5285330d5f19352decabf807 (patch)
treebf3c4464c369a15a46454792dac167505f74769f /coreutils
parentb0b7ab792bc1f45963f4b84b94faaf05054e1613 (diff)
parent9ec836c033fc6e55e80f3309b3e05acdf09bb297 (diff)
downloadbusybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.gz
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.bz2
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chgrp.c4
-rw-r--r--coreutils/date.c13
-rw-r--r--coreutils/ln.c25
-rw-r--r--coreutils/tee.c24
-rw-r--r--coreutils/test.c2
5 files changed, 51 insertions, 17 deletions
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c
index ae216aa3f..4da43c45e 100644
--- a/coreutils/chgrp.c
+++ b/coreutils/chgrp.c
@@ -21,15 +21,15 @@
21/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ 21/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
22 22
23//usage:#define chgrp_trivial_usage 23//usage:#define chgrp_trivial_usage
24//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..." 24//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..."
25//usage:#define chgrp_full_usage "\n\n" 25//usage:#define chgrp_full_usage "\n\n"
26//usage: "Change the group membership of each FILE to GROUP\n" 26//usage: "Change the group membership of each FILE to GROUP\n"
27//usage: "\n -R Recurse" 27//usage: "\n -R Recurse"
28//usage: "\n -h Affect symlinks instead of symlink targets" 28//usage: "\n -h Affect symlinks instead of symlink targets"
29//usage: IF_DESKTOP(
29//usage: "\n -L Traverse all symlinks to directories" 30//usage: "\n -L Traverse all symlinks to directories"
30//usage: "\n -H Traverse symlinks on command line only" 31//usage: "\n -H Traverse symlinks on command line only"
31//usage: "\n -P Don't traverse symlinks (default)" 32//usage: "\n -P Don't traverse symlinks (default)"
32//usage: IF_DESKTOP(
33//usage: "\n -c List changed files" 33//usage: "\n -c List changed files"
34//usage: "\n -v Verbose" 34//usage: "\n -v Verbose"
35//usage: "\n -f Hide errors" 35//usage: "\n -f Hide errors"
diff --git a/coreutils/date.c b/coreutils/date.c
index feb400430..b9b7fd2cb 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -33,10 +33,9 @@
33//config: Enable option (-I) to output an ISO-8601 compliant 33//config: Enable option (-I) to output an ISO-8601 compliant
34//config: date/time string. 34//config: date/time string.
35//config: 35//config:
36//config:# defaults to "no": stat's nanosecond field is a bit non-portable
37//config:config FEATURE_DATE_NANO 36//config:config FEATURE_DATE_NANO
38//config: bool "Support %[num]N nanosecond format specifier" 37//config: bool "Support %[num]N nanosecond format specifier"
39//config: default n # syscall(__NR_clock_gettime) 38//config: default n # stat's nanosecond field is a bit non-portable
40//config: depends on DATE 39//config: depends on DATE
41//config: select PLATFORM_LINUX 40//config: select PLATFORM_LINUX
42//config: help 41//config: help
@@ -272,13 +271,14 @@ int date_main(int argc UNUSED_PARAM, char **argv)
272#endif 271#endif
273 } else { 272 } else {
274#if ENABLE_FEATURE_DATE_NANO 273#if ENABLE_FEATURE_DATE_NANO
275 /* libc has incredibly messy way of doing this, 274 clock_gettime(CLOCK_REALTIME, &ts);
276 * typically requiring -lrt. We just skip all this mess */
277 syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
278#else 275#else
279 time(&ts.tv_sec); 276 time(&ts.tv_sec);
280#endif 277#endif
281 } 278 }
279#if !ENABLE_FEATURE_DATE_NANO
280 ts.tv_nsec = 0;
281#endif
282 localtime_r(&ts.tv_sec, &tm_time); 282 localtime_r(&ts.tv_sec, &tm_time);
283 283
284 /* If date string is given, update tm_time, and maybe set date */ 284 /* If date string is given, update tm_time, and maybe set date */
@@ -301,9 +301,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
301 if (date_str[0] != '@') 301 if (date_str[0] != '@')
302 tm_time.tm_isdst = -1; 302 tm_time.tm_isdst = -1;
303 ts.tv_sec = validate_tm_time(date_str, &tm_time); 303 ts.tv_sec = validate_tm_time(date_str, &tm_time);
304 ts.tv_nsec = 0;
304 305
305 /* if setting time, set it */ 306 /* if setting time, set it */
306 if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) { 307 if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
307 bb_simple_perror_msg("can't set date"); 308 bb_simple_perror_msg("can't set date");
308 } 309 }
309 } 310 }
diff --git a/coreutils/ln.c b/coreutils/ln.c
index ea2d10eab..5591e8335 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -41,7 +41,6 @@
41 41
42/* This is a NOEXEC applet. Be very careful! */ 42/* This is a NOEXEC applet. Be very careful! */
43 43
44
45#define LN_SYMLINK (1 << 0) 44#define LN_SYMLINK (1 << 0)
46#define LN_FORCE (1 << 1) 45#define LN_FORCE (1 << 1)
47#define LN_NODEREFERENCE (1 << 2) 46#define LN_NODEREFERENCE (1 << 2)
@@ -63,7 +62,22 @@ int ln_main(int argc, char **argv)
63 int (*link_func)(const char *, const char *); 62 int (*link_func)(const char *, const char *);
64 63
65 opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix); 64 opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
66 65/*
66 -s, --symbolic make symbolic links instead of hard links
67 -f, --force remove existing destination files
68 -n, --no-dereference treat LINK_NAME as a normal file if it is a symbolic link to a directory
69 -b like --backup but does not accept an argument
70 --backup[=CONTROL] make a backup of each existing destination file
71 -S, --suffix=SUFFIX override the usual backup suffix
72 -v, --verbose
73 -T, --no-target-directory
74 -d, -F, --directory allow the superuser to attempt to hard link directories
75 -i, --interactive prompt whether to remove destinations
76 -L, --logical dereference TARGETs that are symbolic links
77 -P, --physical make hard links directly to symbolic links
78 -r, --relative create symbolic links relative to link location
79 -t, --target-directory=DIRECTORY specify the DIRECTORY in which to create the links
80 */
67 last = argv[argc - 1]; 81 last = argv[argc - 1];
68 argv += optind; 82 argv += optind;
69 argc -= optind; 83 argc -= optind;
@@ -86,8 +100,11 @@ int ln_main(int argc, char **argv)
86 src = last; 100 src = last;
87 101
88 if (is_directory(src, 102 if (is_directory(src,
89 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE 103 /*followlinks:*/ !(opts & (LN_NODEREFERENCE|LN_LINKFILE))
90 ) 104 /* Why LN_LINKFILE does not follow links:
105 * -T/--no-target-directory implies -n/--no-dereference
106 */
107 )
91 ) { 108 ) {
92 if (opts & LN_LINKFILE) { 109 if (opts & LN_LINKFILE) {
93 bb_error_msg_and_die("'%s' is a directory", src); 110 bb_error_msg_and_die("'%s' is a directory", src);
diff --git a/coreutils/tee.c b/coreutils/tee.c
index fe5694331..e67296d43 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -39,6 +39,19 @@
39//usage: "$ cat /tmp/foo\n" 39//usage: "$ cat /tmp/foo\n"
40//usage: "Hello\n" 40//usage: "Hello\n"
41 41
42// Bare "tee" with no below options does not install SIGPIPE handler - just dies on it.
43// TODO:
44// --output-error[=MODE]
45// 'warn' diagnose errors writing to any output
46// 'warn-nopipe' diagnose errors writing to any output not a pipe
47// 'exit' exit on error writing to any output
48// 'exit-nopipe' exit on error writing to any output not a pipe
49// ^^^ all of these should set SIGPIPE to SIG_IGN.
50// Because "exit" mode should print error message and exit1(1) - not die on SIGPIPE.
51// "exit-nopipe" does not exit on EPIPE and does not set exitcode to 1 too.
52// -p diagnose errors writing to non pipes
53// ^^^^ this should set SIGPIPE to SIG_IGN. EPIPE is ignored (same as "warn-nopipe")
54
42#include "libbb.h" 55#include "libbb.h"
43#include "common_bufsiz.h" 56#include "common_bufsiz.h"
44 57
@@ -66,12 +79,12 @@ int tee_main(int argc, char **argv)
66 mode += (retval & 2); /* Since 'a' is the 2nd option... */ 79 mode += (retval & 2); /* Since 'a' is the 2nd option... */
67 80
68 if (retval & 1) { 81 if (retval & 1) {
69 signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */ 82 signal(SIGINT, SIG_IGN);
70 } 83 }
71 retval = EXIT_SUCCESS; 84 retval = EXIT_SUCCESS;
72 /* gnu tee ignores SIGPIPE in case one of the output files is a pipe 85 /* if (opt_p || opt_output_error)
73 * that doesn't consume all its input. Good idea... */ 86 signal(SIGPIPE, SIG_IGN);
74 signal(SIGPIPE, SIG_IGN); 87 */
75 88
76 /* Allocate an array of FILE *'s, with one extra for a sentinel. */ 89 /* Allocate an array of FILE *'s, with one extra for a sentinel. */
77 fp = files = xzalloc(sizeof(FILE *) * (argc + 2)); 90 fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@@ -79,6 +92,7 @@ int tee_main(int argc, char **argv)
79 92
80 files[0] = stdout; 93 files[0] = stdout;
81 goto GOT_NEW_FILE; 94 goto GOT_NEW_FILE;
95
82 do { 96 do {
83 *fp = stdout; 97 *fp = stdout;
84 if (NOT_LONE_DASH(*argv)) { 98 if (NOT_LONE_DASH(*argv)) {
@@ -102,6 +116,7 @@ int tee_main(int argc, char **argv)
102 fp = files; 116 fp = files;
103 do 117 do
104 fwrite(buf, 1, c, *fp); 118 fwrite(buf, 1, c, *fp);
119 /* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
105 while (*++fp); 120 while (*++fp);
106 } 121 }
107 if (c < 0) { /* Make sure read errors are signaled. */ 122 if (c < 0) { /* Make sure read errors are signaled. */
@@ -113,6 +128,7 @@ int tee_main(int argc, char **argv)
113 fp = files; 128 fp = files;
114 do 129 do
115 putc(c, *fp); 130 putc(c, *fp);
131 /* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
116 while (*++fp); 132 while (*++fp);
117 } 133 }
118#endif 134#endif
diff --git a/coreutils/test.c b/coreutils/test.c
index 868ffbecb..a08986130 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -411,7 +411,7 @@ extern struct test_statics *const test_ptr_to_statics;
411#define leaving (S.leaving ) 411#define leaving (S.leaving )
412 412
413#define INIT_S() do { \ 413#define INIT_S() do { \
414 (*(struct test_statics**)&test_ptr_to_statics) = xzalloc(sizeof(S)); \ 414 (*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \
415 barrier(); \ 415 barrier(); \
416} while (0) 416} while (0)
417#define DEINIT_S() do { \ 417#define DEINIT_S() do { \