aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Config.src10
-rw-r--r--libbb/appletlib.c10
-rw-r--r--libbb/kernel_version.c8
-rw-r--r--libbb/lineedit.c4
-rw-r--r--libbb/procps.c8
-rw-r--r--libbb/progress.c20
-rw-r--r--libbb/systemd_support.c62
-rw-r--r--libbb/xfuncs.c6
8 files changed, 37 insertions, 91 deletions
diff --git a/libbb/Config.src b/libbb/Config.src
index 19021fed1..6ba256290 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -16,7 +16,7 @@ config PASSWORD_MINLEN
16 16
17config MD5_SMALL 17config MD5_SMALL
18 int "MD5: Trade bytes for speed (0:fast, 3:slow)" 18 int "MD5: Trade bytes for speed (0:fast, 3:slow)"
19 default 1 19 default 1 # all "fast or small" options default to small
20 range 0 3 20 range 0 3
21 help 21 help
22 Trade binary size versus speed for the md5sum algorithm. 22 Trade binary size versus speed for the md5sum algorithm.
@@ -30,7 +30,7 @@ config MD5_SMALL
30 30
31config SHA3_SMALL 31config SHA3_SMALL
32 int "SHA3: Trade bytes for speed (0:fast, 1:slow)" 32 int "SHA3: Trade bytes for speed (0:fast, 1:slow)"
33 default 1 33 default 1 # all "fast or small" options default to small
34 range 0 1 34 range 0 1
35 help 35 help
36 Trade binary size versus speed for the sha3sum algorithm. 36 Trade binary size versus speed for the sha3sum algorithm.
@@ -40,7 +40,7 @@ config SHA3_SMALL
40 40
41config FEATURE_FAST_TOP 41config FEATURE_FAST_TOP
42 bool "Faster /proc scanning code (+100 bytes)" 42 bool "Faster /proc scanning code (+100 bytes)"
43 default y 43 default n # all "fast or small" options default to small
44 help 44 help
45 This option makes top (and ps) ~20% faster (or 20% less CPU hungry), 45 This option makes top (and ps) ~20% faster (or 20% less CPU hungry),
46 but code size is slightly bigger. 46 but code size is slightly bigger.
@@ -114,7 +114,7 @@ config FEATURE_EDITING_SAVE_ON_EXIT
114config FEATURE_REVERSE_SEARCH 114config FEATURE_REVERSE_SEARCH
115 bool "Reverse history search" 115 bool "Reverse history search"
116 default y 116 default y
117 depends on FEATURE_EDITING_SAVEHISTORY 117 depends on FEATURE_EDITING
118 help 118 help
119 Enable readline-like Ctrl-R combination for reverse history search. 119 Enable readline-like Ctrl-R combination for reverse history search.
120 Increases code by about 0.5k. 120 Increases code by about 0.5k.
@@ -208,7 +208,7 @@ config FEATURE_SKIP_ROOTFS
208 208
209config MONOTONIC_SYSCALL 209config MONOTONIC_SYSCALL
210 bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" 210 bool "Use clock_gettime(CLOCK_MONOTONIC) syscall"
211 default n 211 default y
212 select PLATFORM_LINUX 212 select PLATFORM_LINUX
213 help 213 help
214 Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring 214 Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 7da7cad1c..1d6a4b274 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -628,7 +628,7 @@ static int busybox_main(char **argv)
628 output_width = 80; 628 output_width = 80;
629 if (ENABLE_FEATURE_AUTOWIDTH) { 629 if (ENABLE_FEATURE_AUTOWIDTH) {
630 /* Obtain the terminal width */ 630 /* Obtain the terminal width */
631 get_terminal_width_height(0, &output_width, NULL); 631 output_width = get_terminal_width(2);
632 } 632 }
633 633
634 dup2(1, 2); 634 dup2(1, 2);
@@ -659,10 +659,10 @@ static int busybox_main(char **argv)
659 ) 659 )
660 IF_FEATURE_SH_STANDALONE( 660 IF_FEATURE_SH_STANDALONE(
661 "\tBusyBox is a multi-call binary that combines many common Unix\n" 661 "\tBusyBox is a multi-call binary that combines many common Unix\n"
662 "\tutilities into a single executable. The shell in this version\n" 662 "\tutilities into a single executable. The shell in this build\n"
663 "\thas been configured to prefer built-in utilities to external\n" 663 "\tis configured to run built-in utilities without $PATH search.\n"
664 "\tbinaries. This avoids having to install a link to busybox for\n" 664 "\tYou don't need to install a link to busybox for each utility.\n"
665 "\teach function to be invoked.\n" 665 "\tTo run external program, use full path (/sbin/ip instead of ip).\n"
666 ) 666 )
667 "\n" 667 "\n"
668#if ENABLE_GLOBBING 668#if ENABLE_GLOBBING
diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c
index 738ed022b..9b6c62299 100644
--- a/libbb/kernel_version.c
+++ b/libbb/kernel_version.c
@@ -20,16 +20,16 @@
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, *t; 23 char *t;
24 int i, r; 24 int i, r;
25 25
26 uname(&name); /* never fails */ 26 uname(&name); /* never fails */
27 s = name.release; 27 t = name.release;
28 r = 0; 28 r = 0;
29 for (i = 0; i < 3; i++) { 29 for (i = 0; i < 3; i++) {
30 t = strtok(s, "."); 30 t = strtok(t, ".");
31 r = r * 256 + (t ? atoi(t) : 0); 31 r = r * 256 + (t ? atoi(t) : 0);
32 s = NULL; 32 t = NULL;
33 } 33 }
34 return r; 34 return r;
35} 35}
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 5cb40a508..04361b509 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -829,10 +829,12 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
829 if (type == FIND_EXE_ONLY) { 829 if (type == FIND_EXE_ONLY) {
830 const char *p = applet_names; 830 const char *p = applet_names;
831 831
832 for (i=0; i < NUM_APPLETS; i++) { 832 i = 0;
833 while (i < NUM_APPLETS) {
833 if (strncmp(pfind, p, pf_len) == 0) 834 if (strncmp(pfind, p, pf_len) == 0)
834 add_match(xstrdup(p)); 835 add_match(xstrdup(p));
835 p += strlen(p) + 1; 836 p += strlen(p) + 1;
837 i++;
836 } 838 }
837 } 839 }
838#endif 840#endif
diff --git a/libbb/procps.c b/libbb/procps.c
index 5a4ea59d0..452b50b82 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -589,12 +589,14 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
589 buf[sz] = ' '; 589 buf[sz] = ' ';
590 sz--; 590 sz--;
591 } 591 }
592 if (base[0] == '-') /* "-sh" (login shell)? */
593 base++;
592 594
593 /* If comm differs from argv0, prepend "{comm} ". 595 /* If comm differs from argv0, prepend "{comm} ".
594 * It allows to see thread names set by prctl(PR_SET_NAME). 596 * It allows to see thread names set by prctl(PR_SET_NAME).
595 */ 597 */
596 if (base[0] == '-') /* "-sh" (login shell)? */ 598 if (!comm)
597 base++; 599 return;
598 comm_len = strlen(comm); 600 comm_len = strlen(comm);
599 /* Why compare up to comm_len, not COMM_LEN-1? 601 /* Why compare up to comm_len, not COMM_LEN-1?
600 * Well, some processes rewrite argv, and use _spaces_ there 602 * Well, some processes rewrite argv, and use _spaces_ there
@@ -613,7 +615,7 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
613 buf[col - 1] = '\0'; 615 buf[col - 1] = '\0';
614 } 616 }
615 } else { 617 } else {
616 snprintf(buf, col, "[%s]", comm); 618 snprintf(buf, col, "[%s]", comm ? comm : "?");
617 } 619 }
618} 620}
619 621
diff --git a/libbb/progress.c b/libbb/progress.c
index 372feb0c2..3c2f01667 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -45,13 +45,6 @@ enum {
45 STALLTIME = 5 45 STALLTIME = 5
46}; 46};
47 47
48static unsigned int get_tty2_width(void)
49{
50 unsigned width;
51 get_terminal_width_height(2, &width, NULL);
52 return width;
53}
54
55void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) 48void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
56{ 49{
57#if ENABLE_UNICODE_SUPPORT 50#if ENABLE_UNICODE_SUPPORT
@@ -80,7 +73,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
80{ 73{
81 uoff_t beg_and_transferred; 74 uoff_t beg_and_transferred;
82 unsigned since_last_update, elapsed; 75 unsigned since_last_update, elapsed;
83 int barlength; 76 int notty;
84 int kiloscale; 77 int kiloscale;
85 78
86 //transferred = 1234; /* use for stall detection testing */ 79 //transferred = 1234; /* use for stall detection testing */
@@ -137,18 +130,21 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
137 } 130 }
138 } 131 }
139 132
133 notty = !isatty(STDERR_FILENO);
134
140 if (ENABLE_UNICODE_SUPPORT) 135 if (ENABLE_UNICODE_SUPPORT)
141 fprintf(stderr, "\r%s", p->curfile); 136 fprintf(stderr, "\r%s" + notty, p->curfile);
142 else 137 else
143 fprintf(stderr, "\r%-20.20s", p->curfile); 138 fprintf(stderr, "\r%-20.20s" + notty, p->curfile);
144 139
145 beg_and_transferred = beg_size + transferred; 140 beg_and_transferred = beg_size + transferred;
146 141
147 if (totalsize != 0) { 142 if (totalsize != 0) {
143 int barlength;
148 unsigned ratio = 100 * beg_and_transferred / totalsize; 144 unsigned ratio = 100 * beg_and_transferred / totalsize;
149 fprintf(stderr, "%4u%%", ratio); 145 fprintf(stderr, "%4u%%", ratio);
150 146
151 barlength = get_tty2_width() - 49; 147 barlength = get_terminal_width(2) - 49;
152 if (barlength > 0) { 148 if (barlength > 0) {
153 /* god bless gcc for variable arrays :) */ 149 /* god bless gcc for variable arrays :) */
154 char buf[barlength + 1]; 150 char buf[barlength + 1];
@@ -204,4 +200,6 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
204 hours = eta / 3600; 200 hours = eta / 3600;
205 fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60); 201 fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60);
206 } 202 }
203 if (notty)
204 fputc('\n', stderr);
207} 205}
diff --git a/libbb/systemd_support.c b/libbb/systemd_support.c
deleted file mode 100644
index 542a3efff..000000000
--- a/libbb/systemd_support.c
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright (C) 2011 Davide Cavalca <davide@geexbox.org>
3 *
4 * Based on http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c
5 * Copyright 2010 Lennart Poettering
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction,
10 * including without limitation the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27#include "libbb.h"
28
29//config:config FEATURE_SYSTEMD
30//config: bool "Enable systemd support"
31//config: default y
32//config: help
33//config: If you plan to use busybox daemons on a system where daemons
34//config: are controlled by systemd, enable this option.
35//config: If you don't use systemd, it is still safe to enable it,
36//config: but the downside is increased code size.
37
38//kbuild:lib-$(CONFIG_FEATURE_SYSTEMD) += systemd_support.o
39
40int sd_listen_fds(void)
41{
42 const char *e;
43 int n;
44 int fd;
45
46 e = getenv("LISTEN_PID");
47 if (!e)
48 return 0;
49 n = xatoi_positive(e);
50 /* Is this for us? */
51 if (getpid() != (pid_t) n)
52 return 0;
53
54 e = getenv("LISTEN_FDS");
55 if (!e)
56 return 0;
57 n = xatoi_positive(e);
58 for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++)
59 close_on_exec_on(fd);
60
61 return n;
62}
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 0c9969640..206edb4a0 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -270,6 +270,12 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh
270 *width = wh_helper(win.ws_col, 80, "COLUMNS", &err); 270 *width = wh_helper(win.ws_col, 80, "COLUMNS", &err);
271 return err; 271 return err;
272} 272}
273int FAST_FUNC get_terminal_width(int fd)
274{
275 unsigned width;
276 get_terminal_width_height(fd, &width, NULL);
277 return width;
278}
273 279
274int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) 280int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp)
275{ 281{