aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-12-14 14:20:56 +0000
committerRon Yorston <rmy@pobox.com>2014-12-14 14:20:56 +0000
commit6d6d18d45c145899fce3a39553771cf0af671f30 (patch)
tree1936d18cbf61b9e0989464aad0a11c52cbeff7b7 /libbb
parent0c204dc07b718244c360e0b84df66ce0a012e14f (diff)
parentacb8be721768b54075a51d1859d390904a0f1f6c (diff)
downloadbusybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.tar.gz
busybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.tar.bz2
busybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.zip
Merge branch 'busybox' into merge
Conflicts: archival/libarchive/open_transformer.c libbb/lineedit.c miscutils/man.c
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Kbuild.src3
-rw-r--r--libbb/appletlib.c6
-rw-r--r--libbb/bbunit.c2
-rw-r--r--libbb/copyfd.c87
-rw-r--r--libbb/lineedit.c8
-rw-r--r--libbb/logenv.c24
-rw-r--r--libbb/sysconf.c2
7 files changed, 95 insertions, 37 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 1f2ed36d9..1be87b337 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -189,3 +189,6 @@ lib-$(CONFIG_PGREP) += xregcomp.o
189lib-$(CONFIG_PKILL) += xregcomp.o 189lib-$(CONFIG_PKILL) += xregcomp.o
190lib-$(CONFIG_DEVFSD) += xregcomp.o 190lib-$(CONFIG_DEVFSD) += xregcomp.o
191lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o 191lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o
192
193# Add the experimental logging functionality, only used by zcip
194lib-$(CONFIG_ZCIP) += logenv.o
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 2c85062b4..b74b6e724 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -746,7 +746,8 @@ static int busybox_main(char **argv)
746 /*bb_error_msg_and_die("applet not found"); - sucks in printf */ 746 /*bb_error_msg_and_die("applet not found"); - sucks in printf */
747 full_write2_str(applet_name); 747 full_write2_str(applet_name);
748 full_write2_str(": applet not found\n"); 748 full_write2_str(": applet not found\n");
749 xfunc_die(); 749 /* POSIX: "If a command is not found, the exit status shall be 127" */
750 exit(127);
750} 751}
751 752
752void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) 753void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
@@ -870,6 +871,7 @@ int main(int argc UNUSED_PARAM, char **argv)
870 /*bb_error_msg_and_die("applet not found"); - sucks in printf */ 871 /*bb_error_msg_and_die("applet not found"); - sucks in printf */
871 full_write2_str(applet_name); 872 full_write2_str(applet_name);
872 full_write2_str(": applet not found\n"); 873 full_write2_str(": applet not found\n");
873 xfunc_die(); 874 /* POSIX: "If a command is not found, the exit status shall be 127" */
875 exit(127);
874#endif 876#endif
875} 877}
diff --git a/libbb/bbunit.c b/libbb/bbunit.c
index 256014441..4c692d59f 100644
--- a/libbb/bbunit.c
+++ b/libbb/bbunit.c
@@ -77,7 +77,7 @@ int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
77#if WANT_TIMING 77#if WANT_TIMING
78 gettimeofday(&end, NULL); 78 gettimeofday(&end, NULL);
79 timeval_diff(&time_spent, &end, &begin); 79 timeval_diff(&time_spent, &end, &begin);
80 bb_error_msg("Elapsed time %u.%06u seconds" 80 bb_error_msg("Elapsed time %u.%06u seconds",
81 (int)time_spent.tv_sec, 81 (int)time_spent.tv_sec,
82 (int)time_spent.tv_usec); 82 (int)time_spent.tv_usec);
83#endif 83#endif
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index eda2747f9..7e3531903 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -8,6 +8,20 @@
8 */ 8 */
9 9
10#include "libbb.h" 10#include "libbb.h"
11#if ENABLE_FEATURE_USE_SENDFILE
12# include <sys/sendfile.h>
13#else
14# define sendfile(a,b,c,d) (-1)
15#endif
16
17/*
18 * We were using 0x7fff0000 as sendfile chunk size, but it
19 * was seen to cause largish delays when user tries to ^C a file copy.
20 * Let's use a saner size.
21 * Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB),
22 * or else "copy to eof" code will use neddlesly short reads.
23 */
24#define SENDFILE_BIGBUF (16*1024*1024)
11 25
12/* Used by NOFORK applets (e.g. cat) - must not use xmalloc. 26/* Used by NOFORK applets (e.g. cat) - must not use xmalloc.
13 * size < 0 means "ignore write errors", used by tar --to-command 27 * size < 0 means "ignore write errors", used by tar --to-command
@@ -18,12 +32,13 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
18 int status = -1; 32 int status = -1;
19 off_t total = 0; 33 off_t total = 0;
20 bool continue_on_write_error = 0; 34 bool continue_on_write_error = 0;
21#if CONFIG_FEATURE_COPYBUF_KB <= 4 35 ssize_t sendfile_sz;
36#if CONFIG_FEATURE_COPYBUF_KB > 4
37 char *buffer = buffer; /* for compiler */
38 int buffer_size = 0;
39#else
22 char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024]; 40 char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
23 enum { buffer_size = sizeof(buffer) }; 41 enum { buffer_size = sizeof(buffer) };
24#else
25 char *buffer;
26 int buffer_size;
27#endif 42#endif
28 43
29 if (size < 0) { 44 if (size < 0) {
@@ -31,46 +46,58 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
31 continue_on_write_error = 1; 46 continue_on_write_error = 1;
32 } 47 }
33 48
34#if CONFIG_FEATURE_COPYBUF_KB > 4
35 if (size > 0 && size <= 4 * 1024)
36 goto use_small_buf;
37 /* We want page-aligned buffer, just in case kernel is clever
38 * and can do page-aligned io more efficiently */
39 buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
40 PROT_READ | PROT_WRITE,
41 MAP_PRIVATE | MAP_ANON,
42 /* ignored: */ -1, 0);
43 buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
44 if (buffer == MAP_FAILED) {
45 use_small_buf:
46 buffer = alloca(4 * 1024);
47 buffer_size = 4 * 1024;
48 }
49#endif
50
51 if (src_fd < 0) 49 if (src_fd < 0)
52 goto out; 50 goto out;
53 51
52 sendfile_sz = !ENABLE_FEATURE_USE_SENDFILE
53 ? 0
54 : SENDFILE_BIGBUF;
54 if (!size) { 55 if (!size) {
55 size = buffer_size; 56 size = SENDFILE_BIGBUF;
56 status = 1; /* copy until eof */ 57 status = 1; /* copy until eof */
57 } 58 }
58 59
59 while (1) { 60 while (1) {
60 ssize_t rd; 61 ssize_t rd;
61 62
62 rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size); 63 if (sendfile_sz) {
63 64 rd = sendfile(dst_fd, src_fd, NULL,
64 if (!rd) { /* eof - all done */ 65 size > sendfile_sz ? sendfile_sz : size);
65 status = 0; 66 if (rd >= 0)
66 break; 67 goto read_ok;
68 sendfile_sz = 0; /* do not try sendfile anymore */
69 }
70#if CONFIG_FEATURE_COPYBUF_KB > 4
71 if (buffer_size == 0) {
72 if (size > 0 && size <= 4 * 1024)
73 goto use_small_buf;
74 /* We want page-aligned buffer, just in case kernel is clever
75 * and can do page-aligned io more efficiently */
76 buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
77 PROT_READ | PROT_WRITE,
78 MAP_PRIVATE | MAP_ANON,
79 /* ignored: */ -1, 0);
80 buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
81 if (buffer == MAP_FAILED) {
82 use_small_buf:
83 buffer = alloca(4 * 1024);
84 buffer_size = 4 * 1024;
85 }
67 } 86 }
87#endif
88 rd = safe_read(src_fd, buffer,
89 size > buffer_size ? buffer_size : size);
68 if (rd < 0) { 90 if (rd < 0) {
69 bb_perror_msg(bb_msg_read_error); 91 bb_perror_msg(bb_msg_read_error);
70 break; 92 break;
71 } 93 }
94 read_ok:
95 if (!rd) { /* eof - all done */
96 status = 0;
97 break;
98 }
72 /* dst_fd == -1 is a fake, else... */ 99 /* dst_fd == -1 is a fake, else... */
73 if (dst_fd >= 0) { 100 if (dst_fd >= 0 && !sendfile_sz) {
74 ssize_t wr = full_write(dst_fd, buffer, rd); 101 ssize_t wr = full_write(dst_fd, buffer, rd);
75 if (wr < rd) { 102 if (wr < rd) {
76 if (!continue_on_write_error) { 103 if (!continue_on_write_error) {
@@ -92,10 +119,8 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
92 } 119 }
93 out: 120 out:
94 121
95#if CONFIG_FEATURE_COPYBUF_KB > 4 122 if (buffer_size > 4 * 1024)
96 if (buffer_size != 4 * 1024)
97 munmap(buffer, buffer_size); 123 munmap(buffer, buffer_size);
98#endif
99 return status ? -1 : total; 124 return status ? -1 : total;
100} 125}
101 126
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 1f5653cb5..3d96a8e9f 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2316,10 +2316,14 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2316 if (!isatty(0) || !isatty(1)) { 2316 if (!isatty(0) || !isatty(1)) {
2317#else 2317#else
2318 if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 2318 if (tcgetattr(STDIN_FILENO, &initial_settings) < 0
2319 || !(initial_settings.c_lflag & ECHO) 2319 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON
2320 ) { 2320 ) {
2321#endif 2321#endif
2322 /* Happens when e.g. stty -echo was run before */ 2322 /* Happens when e.g. stty -echo was run before.
2323 * But if ICANON is not set, we don't come here.
2324 * (example: interactive python ^Z-backgrounded,
2325 * tty is still in "raw mode").
2326 */
2323 parse_and_put_prompt(prompt); 2327 parse_and_put_prompt(prompt);
2324 /* fflush_all(); - done by parse_and_put_prompt */ 2328 /* fflush_all(); - done by parse_and_put_prompt */
2325 if (fgets(command, maxsize, stdin) == NULL) 2329 if (fgets(command, maxsize, stdin) == NULL)
diff --git a/libbb/logenv.c b/libbb/logenv.c
new file mode 100644
index 000000000..66c60bd4e
--- /dev/null
+++ b/libbb/logenv.c
@@ -0,0 +1,24 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 2014 by Fugro Intersite B.V. <m.stam@fugro.nl>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9#include "libbb.h"
10
11void FAST_FUNC bb_logenv_override(void)
12{
13 const char* mode = getenv("LOGGING");
14
15 if (!mode)
16 return;
17
18 if (strcmp(mode, "none") == 0)
19 logmode = LOGMODE_NONE;
20#if ENABLE_FEATURE_SYSLOG
21 else if (strcmp(mode, "syslog") == 0)
22 logmode = LOGMODE_SYSLOG;
23#endif
24}
diff --git a/libbb/sysconf.c b/libbb/sysconf.c
index 031901980..cfad9cdc0 100644
--- a/libbb/sysconf.c
+++ b/libbb/sysconf.c
@@ -8,7 +8,7 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11#if !defined(ARG_MAX) && defined(_SC_ARG_MAX) 11#if !defined(bb_arg_max)
12unsigned FAST_FUNC bb_arg_max(void) 12unsigned FAST_FUNC bb_arg_max(void)
13{ 13{
14 return sysconf(_SC_ARG_MAX); 14 return sysconf(_SC_ARG_MAX);