From edccc982e515e63a080a75fb49fd08b946f62cc6 Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Tue, 13 Feb 2018 16:48:52 +0100
Subject: progress meter: add disabled code for a more stable ETA

Compiles to ~25 bytes if enabled.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 libbb/progress.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

(limited to 'libbb')

diff --git a/libbb/progress.c b/libbb/progress.c
index f1d980d68..23e974ce7 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -57,6 +57,9 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
 	p->last_update_sec = p->start_sec;
 	p->last_change_sec = p->start_sec;
 	p->last_size = 0;
+#if 0
+	p->last_eta = INT_MAX;
+#endif
 }
 
 /* File already had beg_size bytes.
@@ -192,6 +195,16 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
 		/* if 32bit, can overflow ^^^^^^^^^^, but this would only show bad ETA */
 		if (eta >= 1000*60*60)
 			eta = 1000*60*60 - 1;
+#if 0
+		/* To prevent annoying "back-and-forth" estimation jitter,
+		 * if new ETA is larger than the last just by a few seconds,
+		 * disregard it, and show last one. The end result is that
+		 * ETA usually only decreases, unless download slows down a lot.
+		 */
+		if ((unsigned)(eta - p->last_eta) < 10)
+			eta = p->last_eta;
+		p->last_eta = eta;
+#endif
 		secs = eta % 3600;
 		hours = eta / 3600;
 		fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60);
-- 
cgit v1.2.3-55-g6feb


From 2af5e3fac394a922bcf7752be25128879405a21a Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Wed, 21 Feb 2018 20:13:39 +0100
Subject: libbb: compile capability code only if FEATURE_SETPRIV_CAPABILITIES
 or RUN_INIT

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 include/libbb.h          | 5 ++---
 libbb/capability.c       | 3 ++-
 util-linux/switch_root.c | 6 ++++++
 3 files changed, 10 insertions(+), 4 deletions(-)

(limited to 'libbb')

diff --git a/include/libbb.h b/include/libbb.h
index c02621d94..f1ab1ca6f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1488,6 +1488,7 @@ extern void run_shell(const char *shell, int loginshell, const char **args) NORE
  */
 const char *get_shell_name(void) FAST_FUNC;
 
+#if ENABLE_FEATURE_SETPRIV_CAPABILITIES || ENABLE_RUN_INIT
 unsigned cap_name_to_number(const char *cap) FAST_FUNC;
 void printf_cap(const char *pfx, unsigned cap_no) FAST_FUNC;
 void drop_capability(int cap_ordinal) FAST_FUNC;
@@ -1499,9 +1500,7 @@ struct caps { \
 	struct __user_cap_data_struct data[2]; \
 }
 void getcaps(void *caps) FAST_FUNC;
-
-unsigned cap_name_to_number(const char *name) FAST_FUNC;
-void printf_cap(const char *pfx, unsigned cap_no) FAST_FUNC;
+#endif
 
 #if ENABLE_SELINUX
 extern void renew_current_security_context(void) FAST_FUNC;
diff --git a/libbb/capability.c b/libbb/capability.c
index f60062bfc..6587dcbf7 100644
--- a/libbb/capability.c
+++ b/libbb/capability.c
@@ -3,7 +3,8 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-//kbuild:lib-$(CONFIG_PLATFORM_LINUX) += capability.o
+//kbuild:lib-$(CONFIG_FEATURE_SETPRIV_CAPABILITIES) += capability.o
+//kbuild:lib-$(CONFIG_RUN_INIT) += capability.o
 
 #include <linux/capability.h>
 // #include <sys/capability.h>
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
index 2d1802b79..947dd0cdc 100644
--- a/util-linux/switch_root.c
+++ b/util-linux/switch_root.c
@@ -39,6 +39,12 @@
 #include <sys/mount.h>
 #if ENABLE_RUN_INIT
 # include <sys/prctl.h>
+# ifndef PR_CAPBSET_READ
+# define PR_CAPBSET_READ 23
+# endif
+# ifndef PR_CAPBSET_DROP
+# define PR_CAPBSET_DROP 24
+# endif
 # include <linux/capability.h>
 // #include <sys/capability.h>
 // This header is in libcap, but the functions are in libc.
-- 
cgit v1.2.3-55-g6feb


From 23286900da2f38de6b7f0c8318263eac4ce774d1 Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Sun, 25 Feb 2018 20:09:54 +0100
Subject: lineedit: allow window size tracking to be disabled

function                                             old     new   delta
lineedit_read_key                                    269     261      -8
win_changed                                           47       -     -47
read_line_input                                     3884    3821     -63
cmdedit_setwidth                                      63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181)           Total: -181 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 libbb/Config.src |  5 +++++
 libbb/lineedit.c | 18 ++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

(limited to 'libbb')

diff --git a/libbb/Config.src b/libbb/Config.src
index 3c1b064b6..fdf8bbb28 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -149,6 +149,11 @@ config FEATURE_EDITING_FANCY_PROMPT
 	Setting this option allows for prompts to use things like \w and
 	\$ and escape codes.
 
+config FEATURE_EDITING_WINCH
+	bool "Enable automatic tracking of window size changes"
+	default y
+	depends on FEATURE_EDITING
+
 config FEATURE_EDITING_ASK_TERMINAL
 	bool "Query cursor position from terminal"
 	default n
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 896bbc88c..678c4d29c 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -151,9 +151,11 @@ struct lineedit_statics {
 	unsigned num_matches;
 #endif
 
+#if ENABLE_FEATURE_EDITING_WINCH
 	unsigned SIGWINCH_saved;
 	volatile unsigned SIGWINCH_count;
 	volatile smallint ok_to_redraw;
+#endif
 
 #if ENABLE_FEATURE_EDITING_VI
 # define DELBUFSIZ 128
@@ -165,8 +167,10 @@ struct lineedit_statics {
 	smallint sent_ESC_br6n;
 #endif
 
+#if ENABLE_FEATURE_EDITING_WINCH
 	/* Largish struct, keeping it last results in smaller code */
 	struct sigaction SIGWINCH_handler;
+#endif
 };
 
 /* See lineedit_ptr_hack.c */
@@ -2030,6 +2034,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
 }
 #endif
 
+#if ENABLE_FEATURE_EDITING_WINCH
 static void cmdedit_setwidth(void)
 {
 	int new_y;
@@ -2054,6 +2059,7 @@ static void win_changed(int nsig UNUSED_PARAM)
 		S.SIGWINCH_count++;
 	}
 }
+#endif
 
 static int lineedit_read_key(char *read_key_buffer, int timeout)
 {
@@ -2072,9 +2078,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
 		 *
 		 * Note: read_key sets errno to 0 on success.
 		 */
-		S.ok_to_redraw = 1;
+		IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;)
 		ic = read_key(STDIN_FILENO, read_key_buffer, timeout);
-		S.ok_to_redraw = 0;
+		IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;)
 		if (errno) {
 #if ENABLE_UNICODE_SUPPORT
 			if (errno == EAGAIN && unicode_idx != 0)
@@ -2408,11 +2414,12 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
 	parse_and_put_prompt(prompt);
 	ask_terminal();
 
+#if ENABLE_FEATURE_EDITING_WINCH
 	/* Install window resize handler (NB: after *all* init is complete) */
 	S.SIGWINCH_handler.sa_handler = win_changed;
 	S.SIGWINCH_handler.sa_flags = SA_RESTART;
 	sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler);
-
+#endif
 	read_key_buffer[0] = 0;
 	while (1) {
 		/*
@@ -2424,6 +2431,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
 		 * in one place.
 		 */
 		int32_t ic, ic_raw;
+#if ENABLE_FEATURE_EDITING_WINCH
 		unsigned count;
 
 		count = S.SIGWINCH_count;
@@ -2431,7 +2439,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
 			S.SIGWINCH_saved = count;
 			cmdedit_setwidth();
 		}
-
+#endif
 		ic = ic_raw = lineedit_read_key(read_key_buffer, timeout);
 
 #if ENABLE_FEATURE_REVERSE_SEARCH
@@ -2868,8 +2876,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
 
 	/* restore initial_settings */
 	tcsetattr_stdin_TCSANOW(&initial_settings);
+#if ENABLE_FEATURE_EDITING_WINCH
 	/* restore SIGWINCH handler */
 	sigaction_set(SIGWINCH, &S.SIGWINCH_handler);
+#endif
 	fflush_all();
 
 	len = command_len;
-- 
cgit v1.2.3-55-g6feb


From cc222747ae7e264cbe9b1c8a9c253860275db8a9 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Thu, 23 Nov 2017 19:49:31 +0200
Subject: libbb: Use return value from is_prefixed_with()

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5 (-5)
Function                                     old     new   delta
skip_dev_pfx                                  30      25      -5
Total: Before=779966, After=779961, chg -0.00%

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 libbb/skip_whitespace.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

(limited to 'libbb')

diff --git a/libbb/skip_whitespace.c b/libbb/skip_whitespace.c
index 4df5d9e4d..37a24d3be 100644
--- a/libbb/skip_whitespace.c
+++ b/libbb/skip_whitespace.c
@@ -32,7 +32,6 @@ char* FAST_FUNC skip_non_whitespace(const char *s)
 
 char* FAST_FUNC skip_dev_pfx(const char *tty_name)
 {
-	if (is_prefixed_with(tty_name, "/dev/"))
-		tty_name += 5;
-	return (char*)tty_name;
+	char *unprefixed = is_prefixed_with(tty_name, "/dev/");
+	return unprefixed ? unprefixed : (char*)tty_name;
 }
-- 
cgit v1.2.3-55-g6feb