aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/ash.c16
-rw-r--r--shell/hush.c50
2 files changed, 57 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c
index fd1772351..5c03f1fdc 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13351,21 +13351,23 @@ static const unsigned char timescmd_str[] ALIGN1 = {
13351static int FAST_FUNC 13351static int FAST_FUNC
13352timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 13352timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
13353{ 13353{
13354 unsigned long clk_tck, s, t; 13354 unsigned clk_tck;
13355 const unsigned char *p; 13355 const unsigned char *p;
13356 struct tms buf; 13356 struct tms buf;
13357 13357
13358 clk_tck = bb_clk_tck(); 13358 clk_tck = bb_clk_tck();
13359 times(&buf);
13360 13359
13360 times(&buf);
13361 p = timescmd_str; 13361 p = timescmd_str;
13362 do { 13362 do {
13363 unsigned sec, frac;
13364 unsigned long t;
13363 t = *(clock_t *)(((char *) &buf) + p[1]); 13365 t = *(clock_t *)(((char *) &buf) + p[1]);
13364 s = t / clk_tck; 13366 sec = t / clk_tck;
13365 t = t % clk_tck; 13367 frac = t % clk_tck;
13366 out1fmt("%lum%lu.%03lus%c", 13368 out1fmt("%um%u.%03us%c",
13367 s / 60, s % 60, 13369 sec / 60, sec % 60,
13368 (t * 1000) / clk_tck, 13370 (frac * 1000) / clk_tck,
13369 p[0]); 13371 p[0]);
13370 p += 2; 13372 p += 2;
13371 } while (*p); 13373 } while (*p);
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
1012static int builtin_type(char **argv) FAST_FUNC; 1017static int builtin_type(char **argv) FAST_FUNC;
1013#endif 1018#endif
1019#if ENABLE_HUSH_TIMES
1020static int builtin_times(char **argv) FAST_FUNC;
1021#endif
1014static int builtin_true(char **argv) FAST_FUNC; 1022static int builtin_true(char **argv) FAST_FUNC;
1015#if ENABLE_HUSH_UMASK 1023#if ENABLE_HUSH_UMASK
1016static int builtin_umask(char **argv) FAST_FUNC; 1024static 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
10422static 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
10411static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM) 10457static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
10412{ 10458{