diff options
-rw-r--r-- | coreutils/Kbuild | 1 | ||||
-rw-r--r-- | coreutils/chown.c | 1 | ||||
-rw-r--r-- | coreutils/printf.c | 18 | ||||
-rw-r--r-- | include/applets.h | 2 | ||||
-rw-r--r-- | include/libbb.h | 9 | ||||
-rw-r--r-- | miscutils/last.c | 3 | ||||
-rw-r--r-- | miscutils/last_fancy.c | 3 | ||||
-rw-r--r-- | shell/Config.in | 7 | ||||
-rw-r--r-- | shell/ash.c | 14 |
9 files changed, 45 insertions, 13 deletions
diff --git a/coreutils/Kbuild b/coreutils/Kbuild index cb4543912..a5a2d4c26 100644 --- a/coreutils/Kbuild +++ b/coreutils/Kbuild | |||
@@ -54,6 +54,7 @@ lib-$(CONFIG_NOHUP) += nohup.o | |||
54 | lib-$(CONFIG_OD) += od.o | 54 | lib-$(CONFIG_OD) += od.o |
55 | lib-$(CONFIG_PRINTENV) += printenv.o | 55 | lib-$(CONFIG_PRINTENV) += printenv.o |
56 | lib-$(CONFIG_PRINTF) += printf.o | 56 | lib-$(CONFIG_PRINTF) += printf.o |
57 | lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o | ||
57 | lib-$(CONFIG_PWD) += pwd.o | 58 | lib-$(CONFIG_PWD) += pwd.o |
58 | lib-$(CONFIG_READLINK) += readlink.o | 59 | lib-$(CONFIG_READLINK) += readlink.o |
59 | lib-$(CONFIG_REALPATH) += realpath.o | 60 | lib-$(CONFIG_REALPATH) += realpath.o |
diff --git a/coreutils/chown.c b/coreutils/chown.c index eaaefaf29..78377e6a0 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -61,7 +61,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, | |||
61 | return FALSE; | 61 | return FALSE; |
62 | } | 62 | } |
63 | 63 | ||
64 | int chown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
65 | int chown_main(int argc ATTRIBUTE_UNUSED, char **argv) | 64 | int chown_main(int argc ATTRIBUTE_UNUSED, char **argv) |
66 | { | 65 | { |
67 | int retval = EXIT_SUCCESS; | 66 | int retval = EXIT_SUCCESS; |
diff --git a/coreutils/printf.c b/coreutils/printf.c index ebe961564..b7752369c 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -193,6 +193,7 @@ static char **print_formatted(char *f, char **argv) | |||
193 | unsigned direc_length; /* Length of % directive. */ | 193 | unsigned direc_length; /* Length of % directive. */ |
194 | int field_width; /* Arg to first '*', or -1 if none. */ | 194 | int field_width; /* Arg to first '*', or -1 if none. */ |
195 | int precision; /* Arg to second '*', or -1 if none. */ | 195 | int precision; /* Arg to second '*', or -1 if none. */ |
196 | char **saved_argv = argv; | ||
196 | 197 | ||
197 | for (; *f; ++f) { | 198 | for (; *f; ++f) { |
198 | switch (*f) { | 199 | switch (*f) { |
@@ -264,8 +265,9 @@ static char **print_formatted(char *f, char **argv) | |||
264 | precision, ""); | 265 | precision, ""); |
265 | break; | 266 | break; |
266 | case '\\': | 267 | case '\\': |
267 | if (*++f == 'c') | 268 | if (*++f == 'c') { |
268 | exit(EXIT_SUCCESS); | 269 | return saved_argv; /* causes main() to exit */ |
270 | } | ||
269 | bb_putchar(bb_process_escape_sequence((const char **)&f)); | 271 | bb_putchar(bb_process_escape_sequence((const char **)&f)); |
270 | f--; | 272 | f--; |
271 | break; | 273 | break; |
@@ -277,12 +279,22 @@ static char **print_formatted(char *f, char **argv) | |||
277 | return argv; | 279 | return argv; |
278 | } | 280 | } |
279 | 281 | ||
280 | int printf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
281 | int printf_main(int argc ATTRIBUTE_UNUSED, char **argv) | 282 | int printf_main(int argc ATTRIBUTE_UNUSED, char **argv) |
282 | { | 283 | { |
283 | char *format; | 284 | char *format; |
284 | char **argv2; | 285 | char **argv2; |
285 | 286 | ||
287 | /* We must check that stdout is not closed. | ||
288 | * The reason for this is highly non-obvious. printf_main is used from shell. | ||
289 | * Shell must correctly handle 'printf "%s" foo' | ||
290 | * if stdout is closed. With stdio, output gets shoveled into | ||
291 | * stdout buffer, and even fflush cannot clear it out. It seems that | ||
292 | * even if libc receives EBADF on write attempts, it feels determined | ||
293 | * to output data no matter what. So it will try later, | ||
294 | * and possibly will clobber future output. Not good. */ | ||
295 | if (dup2(1, 1) != 1) | ||
296 | return -1; | ||
297 | |||
286 | /* bash builtin errors out on "printf '-%s-\n' foo", | 298 | /* bash builtin errors out on "printf '-%s-\n' foo", |
287 | * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". | 299 | * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". |
288 | * We will mimic coreutils. */ | 300 | * We will mimic coreutils. */ |
diff --git a/include/applets.h b/include/applets.h index 17113dfe7..e7fc3c03c 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -275,7 +275,7 @@ USE_PIVOT_ROOT(APPLET(pivot_root, _BB_DIR_SBIN, _BB_SUID_NEVER)) | |||
275 | USE_PKILL(APPLET_ODDNAME(pkill, pgrep, _BB_DIR_USR_BIN, _BB_SUID_NEVER, pkill)) | 275 | USE_PKILL(APPLET_ODDNAME(pkill, pgrep, _BB_DIR_USR_BIN, _BB_SUID_NEVER, pkill)) |
276 | USE_HALT(APPLET_ODDNAME(poweroff, halt, _BB_DIR_SBIN, _BB_SUID_NEVER, poweroff)) | 276 | USE_HALT(APPLET_ODDNAME(poweroff, halt, _BB_DIR_SBIN, _BB_SUID_NEVER, poweroff)) |
277 | USE_PRINTENV(APPLET(printenv, _BB_DIR_BIN, _BB_SUID_NEVER)) | 277 | USE_PRINTENV(APPLET(printenv, _BB_DIR_BIN, _BB_SUID_NEVER)) |
278 | USE_PRINTF(APPLET(printf, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 278 | USE_PRINTF(APPLET_NOFORK(printf, printf, _BB_DIR_USR_BIN, _BB_SUID_NEVER, printf)) |
279 | USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER)) | 279 | USE_PS(APPLET(ps, _BB_DIR_BIN, _BB_SUID_NEVER)) |
280 | USE_PSCAN(APPLET(pscan, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 280 | USE_PSCAN(APPLET(pscan, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
281 | USE_PWD(APPLET_NOFORK(pwd, pwd, _BB_DIR_BIN, _BB_SUID_NEVER, pwd)) | 281 | USE_PWD(APPLET_NOFORK(pwd, pwd, _BB_DIR_BIN, _BB_SUID_NEVER, pwd)) |
diff --git a/include/libbb.h b/include/libbb.h index 947f28d79..c79cd8b20 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -878,13 +878,16 @@ extern void bb_verror_msg(const char *s, va_list p, const char *strerr); | |||
878 | #endif | 878 | #endif |
879 | 879 | ||
880 | 880 | ||
881 | /* applets which are useful from another applets */ | 881 | /* Applets which are useful from another applets */ |
882 | int bb_cat(char** argv); | 882 | int bb_cat(char** argv); |
883 | /* If shell needs them, these three "exist" even if not enabled as applets */ | 883 | /* If shell needs them, they exist even if not enabled as applets */ |
884 | int echo_main(int argc, char** argv) USE_ECHO(MAIN_EXTERNALLY_VISIBLE); | 884 | int echo_main(int argc, char** argv) USE_ECHO(MAIN_EXTERNALLY_VISIBLE); |
885 | int printf_main(int argc, char **argv) USE_PRINTF(MAIN_EXTERNALLY_VISIBLE); | ||
885 | int test_main(int argc, char **argv) USE_TEST(MAIN_EXTERNALLY_VISIBLE); | 886 | int test_main(int argc, char **argv) USE_TEST(MAIN_EXTERNALLY_VISIBLE); |
886 | int kill_main(int argc, char **argv) USE_KILL(MAIN_EXTERNALLY_VISIBLE); | 887 | int kill_main(int argc, char **argv) USE_KILL(MAIN_EXTERNALLY_VISIBLE); |
887 | int chown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 888 | /* Similar, but used by chgrp, not shell */ |
889 | int chown_main(int argc, char **argv) USE_CHOWN(MAIN_EXTERNALLY_VISIBLE); | ||
890 | /* Don't need USE_xxx() guard for these */ | ||
888 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 891 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
889 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 892 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
890 | int bbunpack(char **argv, | 893 | int bbunpack(char **argv, |
diff --git a/miscutils/last.c b/miscutils/last.c index a8800bfe6..612f50488 100644 --- a/miscutils/last.c +++ b/miscutils/last.c | |||
@@ -10,6 +10,9 @@ | |||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include <utmp.h> | 11 | #include <utmp.h> |
12 | 12 | ||
13 | /* NB: ut_name and ut_user are the same field, use only one name (ut_user) | ||
14 | * to reduce confusion */ | ||
15 | |||
13 | #ifndef SHUTDOWN_TIME | 16 | #ifndef SHUTDOWN_TIME |
14 | # define SHUTDOWN_TIME 254 | 17 | # define SHUTDOWN_TIME 254 |
15 | #endif | 18 | #endif |
diff --git a/miscutils/last_fancy.c b/miscutils/last_fancy.c index 0dba9dca7..2b7fee6e5 100644 --- a/miscutils/last_fancy.c +++ b/miscutils/last_fancy.c | |||
@@ -10,6 +10,9 @@ | |||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include <utmp.h> | 11 | #include <utmp.h> |
12 | 12 | ||
13 | /* NB: ut_name and ut_user are the same field, use only one name (ut_user) | ||
14 | * to reduce confusion */ | ||
15 | |||
13 | #ifndef SHUTDOWN_TIME | 16 | #ifndef SHUTDOWN_TIME |
14 | # define SHUTDOWN_TIME 254 | 17 | # define SHUTDOWN_TIME 254 |
15 | #endif | 18 | #endif |
diff --git a/shell/Config.in b/shell/Config.in index 94ffa09f8..a6701622c 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -114,6 +114,13 @@ config ASH_BUILTIN_ECHO | |||
114 | help | 114 | help |
115 | Enable support for echo, builtin to ash. | 115 | Enable support for echo, builtin to ash. |
116 | 116 | ||
117 | config ASH_BUILTIN_PRINTF | ||
118 | bool "Builtin version of 'printf'" | ||
119 | default y | ||
120 | depends on ASH | ||
121 | help | ||
122 | Enable support for printf, builtin to ash. | ||
123 | |||
117 | config ASH_BUILTIN_TEST | 124 | config ASH_BUILTIN_TEST |
118 | bool "Builtin version of 'test'" | 125 | bool "Builtin version of 'test'" |
119 | default y | 126 | default y |
diff --git a/shell/ash.c b/shell/ash.c index 20b93f326..31beb8671 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -8488,17 +8488,18 @@ static int ulimitcmd(int, char **); | |||
8488 | * Apart from the above, [[ expr ]] should work as [ expr ] | 8488 | * Apart from the above, [[ expr ]] should work as [ expr ] |
8489 | */ | 8489 | */ |
8490 | 8490 | ||
8491 | #define testcmd test_main | 8491 | #define echocmd echo_main |
8492 | #define echocmd echo_main | 8492 | #define printfcmd printf_main |
8493 | #define testcmd test_main | ||
8493 | 8494 | ||
8494 | /* Keep these in proper order since it is searched via bsearch() */ | 8495 | /* Keep these in proper order since it is searched via bsearch() */ |
8495 | static const struct builtincmd builtintab[] = { | 8496 | static const struct builtincmd builtintab[] = { |
8496 | { BUILTIN_SPEC_REG ".", dotcmd }, | 8497 | { BUILTIN_SPEC_REG ".", dotcmd }, |
8497 | { BUILTIN_SPEC_REG ":", truecmd }, | 8498 | { BUILTIN_SPEC_REG ":", truecmd }, |
8498 | #if ENABLE_ASH_BUILTIN_TEST | 8499 | #if ENABLE_ASH_BUILTIN_TEST |
8499 | { BUILTIN_REGULAR "[", testcmd }, | 8500 | { BUILTIN_REGULAR "[", testcmd }, |
8500 | #if ENABLE_ASH_BASH_COMPAT | 8501 | #if ENABLE_ASH_BASH_COMPAT |
8501 | { BUILTIN_REGULAR "[[", testcmd }, | 8502 | { BUILTIN_REGULAR "[[", testcmd }, |
8502 | #endif | 8503 | #endif |
8503 | #endif | 8504 | #endif |
8504 | #if ENABLE_ASH_ALIAS | 8505 | #if ENABLE_ASH_ALIAS |
@@ -8540,6 +8541,9 @@ static const struct builtincmd builtintab[] = { | |||
8540 | { BUILTIN_NOSPEC "let", letcmd }, | 8541 | { BUILTIN_NOSPEC "let", letcmd }, |
8541 | #endif | 8542 | #endif |
8542 | { BUILTIN_ASSIGN "local", localcmd }, | 8543 | { BUILTIN_ASSIGN "local", localcmd }, |
8544 | #if ENABLE_ASH_BUILTIN_PRINTF | ||
8545 | { BUILTIN_REGULAR "printf", printfcmd }, | ||
8546 | #endif | ||
8543 | { BUILTIN_NOSPEC "pwd", pwdcmd }, | 8547 | { BUILTIN_NOSPEC "pwd", pwdcmd }, |
8544 | { BUILTIN_REGULAR "read", readcmd }, | 8548 | { BUILTIN_REGULAR "read", readcmd }, |
8545 | { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd }, | 8549 | { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd }, |
@@ -8548,7 +8552,7 @@ static const struct builtincmd builtintab[] = { | |||
8548 | { BUILTIN_SPEC_REG "shift", shiftcmd }, | 8552 | { BUILTIN_SPEC_REG "shift", shiftcmd }, |
8549 | { BUILTIN_SPEC_REG "source", dotcmd }, | 8553 | { BUILTIN_SPEC_REG "source", dotcmd }, |
8550 | #if ENABLE_ASH_BUILTIN_TEST | 8554 | #if ENABLE_ASH_BUILTIN_TEST |
8551 | { BUILTIN_REGULAR "test", testcmd }, | 8555 | { BUILTIN_REGULAR "test", testcmd }, |
8552 | #endif | 8556 | #endif |
8553 | { BUILTIN_SPEC_REG "times", timescmd }, | 8557 | { BUILTIN_SPEC_REG "times", timescmd }, |
8554 | { BUILTIN_SPEC_REG "trap", trapcmd }, | 8558 | { BUILTIN_SPEC_REG "trap", trapcmd }, |