From 791b222dd55d3aa0e8b09be1be571e4829465dd6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Oct 2023 13:56:32 +0200 Subject: sleep: fix "sleep -- ARGS" function old new delta sleep_main 116 119 +3 printf_main 860 837 -23 single_argv 50 25 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48) Total: -45 bytes Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 10 +++++----- coreutils/sleep.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'coreutils') diff --git a/coreutils/printf.c b/coreutils/printf.c index 7763d7c46..4edcfa9b5 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -425,9 +425,9 @@ int printf_main(int argc UNUSED_PARAM, char **argv) /* bash builtin errors out on "printf '-%s-\n' foo", * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". * We will mimic coreutils. */ - if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2]) - argv++; - if (!argv[1]) { + argv = skip_dash_dash(argv); + + if (!argv[0]) { if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF) && applet_name[0] != 'p' ) { @@ -437,8 +437,8 @@ int printf_main(int argc UNUSED_PARAM, char **argv) bb_show_usage(); } - format = argv[1]; - argv2 = argv + 2; + format = argv[0]; + argv2 = argv + 1; conv_err = 0; do { diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 6edff59cc..fa74f1fd4 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -71,8 +71,8 @@ int sleep_main(int argc UNUSED_PARAM, char **argv) * + we can't use bb_show_usage * + applet_name can be the name of the shell */ - ++argv; - if (!*argv) { + argv = skip_dash_dash(argv); + if (!argv[0]) { /* Without this, bare "sleep" in ash shows _ash_ --help */ /* (ash can be the "sh" applet as well, so check 2nd char) */ if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') { -- cgit v1.2.3-55-g6feb From 6d22c9abc29d43e919e819ff004fcd84a90de60b Mon Sep 17 00:00:00 2001 From: Nero Date: Sat, 23 Sep 2023 11:50:04 +0000 Subject: install: Fix chown resetting suid/sgid bits from chmod Since Linux 2.2.13, chown(2) resets the suid/gid bits for all users. This patch changes the ordering so that chmod gets called after chown. This behavior follows GNU coreutils. Signed-off-by: Nero Signed-off-by: Denys Vlasenko --- coreutils/install.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'coreutils') diff --git a/coreutils/install.c b/coreutils/install.c index c0f1c538a..00f8be87e 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -244,6 +244,15 @@ int install_main(int argc, char **argv) } } + /* Set the user and group id */ + /* (must be before chmod, or else chown may clear suid/gid bits) */ + if ((opts & (OPT_OWNER|OPT_GROUP)) + && lchown(dest, uid, gid) == -1 + ) { + bb_perror_msg("can't change %s of %s", "ownership", dest); + ret = EXIT_FAILURE; + } + /* Set the file mode (always, not only with -m). * GNU coreutils 6.10 is not affected by umask. */ if (chmod(dest, mode) == -1) { @@ -254,13 +263,6 @@ int install_main(int argc, char **argv) if (use_default_selinux_context) setdefaultfilecon(dest); #endif - /* Set the user and group id */ - if ((opts & (OPT_OWNER|OPT_GROUP)) - && lchown(dest, uid, gid) == -1 - ) { - bb_perror_msg("can't change %s of %s", "ownership", dest); - ret = EXIT_FAILURE; - } next: if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest); -- cgit v1.2.3-55-g6feb From d17c0a348fc10897d86e0e96aa98be5ac88d6fdd Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Fri, 3 Nov 2023 21:14:00 +0100 Subject: sleep: Update doc 4c20d9f2b removed FEATURE_FLOAT_SLEEP option, thus since then there are only two variants. Fixes: 4c20d9f2b ("extend fractional duration support to "top -d N.N" and "timeout"") Signed-off-by: Petr Vorel Signed-off-by: Denys Vlasenko --- coreutils/sleep.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'coreutils') diff --git a/coreutils/sleep.c b/coreutils/sleep.c index fa74f1fd4..6fd00f9f1 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -17,14 +17,15 @@ //config: default y //config: help //config: sleep is used to pause for a specified number of seconds. -//config: It comes in 3 versions: +//config: It comes in 2 versions: //config: - small: takes one integer parameter -//config: - fancy: takes multiple integer arguments with suffixes: -//config: sleep 1d 2h 3m 15s -//config: - fancy with fractional numbers: -//config: sleep 2.3s 4.5h sleeps for 16202.3 seconds -//config: Last one is "the most compatible" with coreutils sleep, -//config: but it adds around 1k of code. +//config: - fancy: +//config: * takes multiple integer arguments with suffixes: +//config: sleep 1d 2h 3m 15s +//config: * allows fractional numbers: +//config: sleep 2.3s 4.5h sleeps for 16202.3 seconds +//config: fancy is more compatible with coreutils sleep, but it adds around +//config: 1k of code. //config: //config:config FEATURE_FANCY_SLEEP //config: bool "Enable multiple arguments and s/m/h/d suffixes" -- cgit v1.2.3-55-g6feb