diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 16:34:03 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 16:34:03 +0200 |
commit | 11f2e99c13b42675bb65cf2cfd3e3a98f95f2cee (patch) | |
tree | 3fc17fbedb484e69a6079da9550c2803bc1c31eb /shell/hush.c | |
parent | c52dc0e83699cd8378740ef8f32a063a9c24fa51 (diff) | |
download | busybox-w32-11f2e99c13b42675bb65cf2cfd3e3a98f95f2cee.tar.gz busybox-w32-11f2e99c13b42675bb65cf2cfd3e3a98f95f2cee.tar.bz2 busybox-w32-11f2e99c13b42675bb65cf2cfd3e3a98f95f2cee.zip |
hush: optional times builtin
function old new delta
builtin_times - 108 +108
bltins1 360 372 +12
static.times_tbl - 9 +9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/0 up/down: 129/0) Total: 129 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c index af3b95b86..b53d1dcfb 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -48,7 +48,7 @@ | |||
48 | * tilde expansion | 48 | * tilde expansion |
49 | * aliases | 49 | * aliases |
50 | * builtins mandated by standards we don't support: | 50 | * builtins mandated by standards we don't support: |
51 | * [un]alias, command, fc, getopts, times: | 51 | * [un]alias, command, fc, getopts: |
52 | * command -v CMD: print "/path/to/CMD" | 52 | * command -v CMD: print "/path/to/CMD" |
53 | * prints "CMD" for builtins | 53 | * prints "CMD" for builtins |
54 | * prints "alias ALIAS='EXPANSION'" for aliases | 54 | * prints "alias ALIAS='EXPANSION'" for aliases |
@@ -59,7 +59,6 @@ | |||
59 | * -p: use default $PATH | 59 | * -p: use default $PATH |
60 | * command BLTIN: disables special-ness (e.g. errors do not abort) | 60 | * command BLTIN: disables special-ness (e.g. errors do not abort) |
61 | * getopts: getopt() for shells | 61 | * getopts: getopt() for shells |
62 | * times: print getrusage(SELF/CHILDREN).ru_utime/ru_stime | ||
63 | * fc -l[nr] [BEG] [END]: list range of commands in history | 62 | * fc -l[nr] [BEG] [END]: list range of commands in history |
64 | * fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands | 63 | * fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands |
65 | * fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP | 64 | * fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP |
@@ -265,6 +264,11 @@ | |||
265 | //config: default y | 264 | //config: default y |
266 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | 265 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH |
267 | //config: | 266 | //config: |
267 | //config:config HUSH_TIMES | ||
268 | //config: bool "times builtin" | ||
269 | //config: default y | ||
270 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | ||
271 | //config: | ||
268 | //config:config HUSH_READ | 272 | //config:config HUSH_READ |
269 | //config: bool "read builtin" | 273 | //config: bool "read builtin" |
270 | //config: default y | 274 | //config: default y |
@@ -325,6 +329,7 @@ | |||
325 | #if ENABLE_HUSH_CASE | 329 | #if ENABLE_HUSH_CASE |
326 | # include <fnmatch.h> | 330 | # include <fnmatch.h> |
327 | #endif | 331 | #endif |
332 | #include <sys/times.h> | ||
328 | #include <sys/utsname.h> /* for setting $HOSTNAME */ | 333 | #include <sys/utsname.h> /* for setting $HOSTNAME */ |
329 | 334 | ||
330 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ | 335 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
@@ -1011,6 +1016,9 @@ static int builtin_trap(char **argv) FAST_FUNC; | |||
1011 | #if ENABLE_HUSH_TYPE | 1016 | #if ENABLE_HUSH_TYPE |
1012 | static int builtin_type(char **argv) FAST_FUNC; | 1017 | static int builtin_type(char **argv) FAST_FUNC; |
1013 | #endif | 1018 | #endif |
1019 | #if ENABLE_HUSH_TIMES | ||
1020 | static int builtin_times(char **argv) FAST_FUNC; | ||
1021 | #endif | ||
1014 | static int builtin_true(char **argv) FAST_FUNC; | 1022 | static int builtin_true(char **argv) FAST_FUNC; |
1015 | #if ENABLE_HUSH_UMASK | 1023 | #if ENABLE_HUSH_UMASK |
1016 | static int builtin_umask(char **argv) FAST_FUNC; | 1024 | static int builtin_umask(char **argv) FAST_FUNC; |
@@ -1105,6 +1113,9 @@ static const struct built_in_command bltins1[] = { | |||
1105 | #if BASH_SOURCE | 1113 | #if BASH_SOURCE |
1106 | BLTIN("source" , builtin_source , NULL), | 1114 | BLTIN("source" , builtin_source , NULL), |
1107 | #endif | 1115 | #endif |
1116 | #if ENABLE_HUSH_TIMES | ||
1117 | BLTIN("times" , builtin_times , NULL), | ||
1118 | #endif | ||
1108 | #if ENABLE_HUSH_TRAP | 1119 | #if ENABLE_HUSH_TRAP |
1109 | BLTIN("trap" , builtin_trap , "Trap signals"), | 1120 | BLTIN("trap" , builtin_trap , "Trap signals"), |
1110 | #endif | 1121 | #endif |
@@ -10407,6 +10418,41 @@ static int FAST_FUNC builtin_return(char **argv) | |||
10407 | } | 10418 | } |
10408 | #endif | 10419 | #endif |
10409 | 10420 | ||
10421 | #if ENABLE_HUSH_TIMES | ||
10422 | static int FAST_FUNC builtin_times(char **argv UNUSED_PARAM) | ||
10423 | { | ||
10424 | static const uint8_t times_tbl[] ALIGN1 = { | ||
10425 | ' ', offsetof(struct tms, tms_utime), | ||
10426 | '\n', offsetof(struct tms, tms_stime), | ||
10427 | ' ', offsetof(struct tms, tms_cutime), | ||
10428 | '\n', offsetof(struct tms, tms_cstime), | ||
10429 | 0 | ||
10430 | }; | ||
10431 | const uint8_t *p; | ||
10432 | unsigned clk_tck; | ||
10433 | struct tms buf; | ||
10434 | |||
10435 | clk_tck = bb_clk_tck(); | ||
10436 | |||
10437 | times(&buf); | ||
10438 | p = times_tbl; | ||
10439 | do { | ||
10440 | unsigned sec, frac; | ||
10441 | unsigned long t; | ||
10442 | t = *(clock_t *)(((char *) &buf) + p[1]); | ||
10443 | sec = t / clk_tck; | ||
10444 | frac = t % clk_tck; | ||
10445 | printf("%um%u.%03us%c", | ||
10446 | sec / 60, sec % 60, | ||
10447 | (frac * 1000) / clk_tck, | ||
10448 | p[0]); | ||
10449 | p += 2; | ||
10450 | } while (*p); | ||
10451 | |||
10452 | return EXIT_SUCCESS; | ||
10453 | } | ||
10454 | #endif | ||
10455 | |||
10410 | #if ENABLE_HUSH_MEMLEAK | 10456 | #if ENABLE_HUSH_MEMLEAK |
10411 | static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM) | 10457 | static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM) |
10412 | { | 10458 | { |