diff options
author | Shawn Landden <shawnlandden@tutanota.com> | 2022-08-27 19:56:21 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-08-27 19:56:21 +0200 |
commit | 58598eb7093561d914a6254697e137b815f1fdfc (patch) | |
tree | a1e15b99eb2deaebefa01a504498494a95c80f32 | |
parent | d432049f288c9acdc4a7caa729c68ceba3c5dca1 (diff) | |
download | busybox-w32-58598eb7093561d914a6254697e137b815f1fdfc.tar.gz busybox-w32-58598eb7093561d914a6254697e137b815f1fdfc.tar.bz2 busybox-w32-58598eb7093561d914a6254697e137b815f1fdfc.zip |
ash: optional sleep builtin
function old new delta
sleepcmd - 10 +10
builtintab 352 360 +8
.rodata 105264 105271 +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 25/0) Total: 25 bytes
Signed-off-by: Shawn Landden <shawnlandden@tutanota.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/sleep.c | 1 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/duration.c | 6 | ||||
-rw-r--r-- | shell/ash.c | 11 |
4 files changed, 19 insertions, 0 deletions
diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 2658e84df..442841210 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c | |||
@@ -37,6 +37,7 @@ | |||
37 | //applet:IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) | 37 | //applet:IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) |
38 | 38 | ||
39 | //kbuild:lib-$(CONFIG_SLEEP) += sleep.o | 39 | //kbuild:lib-$(CONFIG_SLEEP) += sleep.o |
40 | //kbuild:lib-$(CONFIG_ASH_SLEEP) += sleep.o | ||
40 | 41 | ||
41 | /* BB_AUDIT SUSv3 compliant */ | 42 | /* BB_AUDIT SUSv3 compliant */ |
42 | /* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */ | 43 | /* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */ |
diff --git a/include/libbb.h b/include/libbb.h index abbc9ac59..19ed9ec09 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1510,6 +1510,7 @@ int ash_main(int argc, char** argv) IF_SHELL_ASH(MAIN_EXTERNALLY_VISIBLE); | |||
1510 | int hush_main(int argc, char** argv) IF_SHELL_HUSH(MAIN_EXTERNALLY_VISIBLE); | 1510 | int hush_main(int argc, char** argv) IF_SHELL_HUSH(MAIN_EXTERNALLY_VISIBLE); |
1511 | /* If shell needs them, they exist even if not enabled as applets */ | 1511 | /* If shell needs them, they exist even if not enabled as applets */ |
1512 | int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE); | 1512 | int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE); |
1513 | int sleep_main(int argc, char **argv) IF_SLEEP(MAIN_EXTERNALLY_VISIBLE); | ||
1513 | int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE); | 1514 | int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE); |
1514 | int test_main(int argc, char **argv) | 1515 | int test_main(int argc, char **argv) |
1515 | #if ENABLE_TEST || ENABLE_TEST1 || ENABLE_TEST2 | 1516 | #if ENABLE_TEST || ENABLE_TEST1 || ENABLE_TEST2 |
diff --git a/libbb/duration.c b/libbb/duration.c index a6a29ddae..793d02f42 100644 --- a/libbb/duration.c +++ b/libbb/duration.c | |||
@@ -76,6 +76,12 @@ void FAST_FUNC sleep_for_duration(duration_t duration) | |||
76 | ts.tv_sec = duration; | 76 | ts.tv_sec = duration; |
77 | ts.tv_nsec = (duration - ts.tv_sec) * 1000000000; | 77 | ts.tv_nsec = (duration - ts.tv_sec) * 1000000000; |
78 | } | 78 | } |
79 | /* NB: if ENABLE_ASH_SLEEP, we end up here if "sleep N" | ||
80 | * is run in ash. ^C will still work, because ash's signal handler | ||
81 | * does not return (it longjumps), the below loop | ||
82 | * will not continue looping. | ||
83 | * (This wouldn't work in hush) | ||
84 | */ | ||
79 | do { | 85 | do { |
80 | errno = 0; | 86 | errno = 0; |
81 | nanosleep(&ts, &ts); | 87 | nanosleep(&ts, &ts); |
diff --git a/shell/ash.c b/shell/ash.c index 55c1034f5..326f8b2a9 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -134,6 +134,11 @@ | |||
134 | //config: default y | 134 | //config: default y |
135 | //config: depends on SHELL_ASH | 135 | //config: depends on SHELL_ASH |
136 | //config: | 136 | //config: |
137 | //config:config ASH_SLEEP | ||
138 | //config: bool "sleep builtin" | ||
139 | //config: default y | ||
140 | //config: depends on SHELL_ASH | ||
141 | //config: | ||
137 | //config:config ASH_HELP | 142 | //config:config ASH_HELP |
138 | //config: bool "help builtin" | 143 | //config: bool "help builtin" |
139 | //config: default y | 144 | //config: default y |
@@ -10155,6 +10160,9 @@ static int FAST_FUNC printfcmd(int argc, char **argv) { return printf_main(argc, | |||
10155 | #if ENABLE_ASH_TEST || BASH_TEST2 | 10160 | #if ENABLE_ASH_TEST || BASH_TEST2 |
10156 | static int FAST_FUNC testcmd(int argc, char **argv) { return test_main(argc, argv); } | 10161 | static int FAST_FUNC testcmd(int argc, char **argv) { return test_main(argc, argv); } |
10157 | #endif | 10162 | #endif |
10163 | #if ENABLE_ASH_SLEEP | ||
10164 | static int FAST_FUNC sleepcmd(int argc, char **argv) { return sleep_main(argc, argv); } | ||
10165 | #endif | ||
10158 | 10166 | ||
10159 | /* Keep these in proper order since it is searched via bsearch() */ | 10167 | /* Keep these in proper order since it is searched via bsearch() */ |
10160 | static const struct builtincmd builtintab[] = { | 10168 | static const struct builtincmd builtintab[] = { |
@@ -10217,6 +10225,9 @@ static const struct builtincmd builtintab[] = { | |||
10217 | { BUILTIN_SPEC_REG "return" , returncmd }, | 10225 | { BUILTIN_SPEC_REG "return" , returncmd }, |
10218 | { BUILTIN_SPEC_REG "set" , setcmd }, | 10226 | { BUILTIN_SPEC_REG "set" , setcmd }, |
10219 | { BUILTIN_SPEC_REG "shift" , shiftcmd }, | 10227 | { BUILTIN_SPEC_REG "shift" , shiftcmd }, |
10228 | #if ENABLE_ASH_SLEEP | ||
10229 | { BUILTIN_REGULAR "sleep" , sleepcmd }, | ||
10230 | #endif | ||
10220 | #if BASH_SOURCE | 10231 | #if BASH_SOURCE |
10221 | { BUILTIN_SPEC_REG "source" , dotcmd }, | 10232 | { BUILTIN_SPEC_REG "source" , dotcmd }, |
10222 | #endif | 10233 | #endif |