aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-04-17 12:02:10 +0100
committerRon Yorston <rmy@pobox.com>2019-04-17 12:02:10 +0100
commite4bc2cb29c5465cbec2dec1ba3b325139007d03a (patch)
tree3556d0a31ca4f75807345aef3f8a377bebf725f7 /shell
parent9752b1d082e6bdb51f8fbec5e751087a687c0062 (diff)
parent1d37186fe2361f80c821e334cc61f41e2f4eeb72 (diff)
downloadbusybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.tar.gz
busybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.tar.bz2
busybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c79
-rw-r--r--shell/hush.c20
2 files changed, 79 insertions, 20 deletions
diff --git a/shell/ash.c b/shell/ash.c
index c4f0880c8..ad7b8f4dd 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -254,6 +254,7 @@
254#define BASH_SOURCE ENABLE_ASH_BASH_COMPAT 254#define BASH_SOURCE ENABLE_ASH_BASH_COMPAT
255#define BASH_PIPEFAIL ENABLE_ASH_BASH_COMPAT 255#define BASH_PIPEFAIL ENABLE_ASH_BASH_COMPAT
256#define BASH_HOSTNAME_VAR ENABLE_ASH_BASH_COMPAT 256#define BASH_HOSTNAME_VAR ENABLE_ASH_BASH_COMPAT
257#define BASH_EPOCH_VARS ENABLE_ASH_BASH_COMPAT
257#define BASH_SHLVL_VAR ENABLE_ASH_BASH_COMPAT 258#define BASH_SHLVL_VAR ENABLE_ASH_BASH_COMPAT
258#define BASH_XTRACEFD ENABLE_ASH_BASH_COMPAT 259#define BASH_XTRACEFD ENABLE_ASH_BASH_COMPAT
259#define BASH_READ_D ENABLE_ASH_BASH_COMPAT 260#define BASH_READ_D ENABLE_ASH_BASH_COMPAT
@@ -2194,6 +2195,10 @@ static void changepath(const char *) FAST_FUNC;
2194#if ENABLE_ASH_RANDOM_SUPPORT 2195#if ENABLE_ASH_RANDOM_SUPPORT
2195static void change_random(const char *) FAST_FUNC; 2196static void change_random(const char *) FAST_FUNC;
2196#endif 2197#endif
2198#if BASH_EPOCH_VARS
2199static void change_seconds(const char *) FAST_FUNC;
2200static void change_realtime(const char *) FAST_FUNC;
2201#endif
2197 2202
2198static const struct { 2203static const struct {
2199 int flags; 2204 int flags;
@@ -2220,6 +2225,10 @@ static const struct {
2220#if ENABLE_ASH_RANDOM_SUPPORT 2225#if ENABLE_ASH_RANDOM_SUPPORT
2221 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "RANDOM", change_random }, 2226 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "RANDOM", change_random },
2222#endif 2227#endif
2228#if BASH_EPOCH_VARS
2229 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "EPOCHSECONDS", change_seconds },
2230 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "EPOCHREALTIME", change_realtime },
2231#endif
2223#if ENABLE_LOCALE_SUPPORT 2232#if ENABLE_LOCALE_SUPPORT
2224 { VSTRFIXED|VTEXTFIXED|VUNSET, "LC_ALL" , change_lc_all }, 2233 { VSTRFIXED|VTEXTFIXED|VUNSET, "LC_ALL" , change_lc_all },
2225 { VSTRFIXED|VTEXTFIXED|VUNSET, "LC_CTYPE" , change_lc_ctype }, 2234 { VSTRFIXED|VTEXTFIXED|VUNSET, "LC_CTYPE" , change_lc_ctype },
@@ -2251,26 +2260,26 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var;
2251#define linenovar (G_var.linenovar ) 2260#define linenovar (G_var.linenovar )
2252#define vifs varinit[0] 2261#define vifs varinit[0]
2253#if ENABLE_ASH_MAIL 2262#if ENABLE_ASH_MAIL
2254# define vmail (&vifs)[1] 2263# define vmail varinit[1]
2255# define vmpath (&vmail)[1] 2264# define vmpath varinit[2]
2256# define vpath (&vmpath)[1] 2265#endif
2257#else 2266#define VAR_OFFSET1 (ENABLE_ASH_MAIL*2)
2258# define vpath (&vifs)[1] 2267#define vpath varinit[VAR_OFFSET1 + 1]
2259#endif 2268#define vps1 varinit[VAR_OFFSET1 + 2]
2260#define vps1 (&vpath)[1] 2269#define vps2 varinit[VAR_OFFSET1 + 3]
2261#define vps2 (&vps1)[1] 2270#define vps4 varinit[VAR_OFFSET1 + 4]
2262#define vps4 (&vps2)[1]
2263#if ENABLE_ASH_GETOPTS 2271#if ENABLE_ASH_GETOPTS
2264# define voptind (&vps4)[1] 2272# define voptind varinit[VAR_OFFSET1 + 5]
2265# define vlineno (&voptind)[1] 2273#endif
2266# if ENABLE_ASH_RANDOM_SUPPORT 2274#define VAR_OFFSET2 (VAR_OFFSET1 + ENABLE_ASH_GETOPTS)
2267# define vrandom (&vlineno)[1] 2275#define vlineno varinit[VAR_OFFSET2 + 5]
2268# endif 2276#if ENABLE_ASH_RANDOM_SUPPORT
2269#else 2277# define vrandom varinit[VAR_OFFSET2 + 6]
2270# define vlineno (&vps4)[1] 2278#endif
2271# if ENABLE_ASH_RANDOM_SUPPORT 2279#define VAR_OFFSET3 (VAR_OFFSET2 + ENABLE_ASH_RANDOM_SUPPORT)
2272# define vrandom (&vlineno)[1] 2280#if BASH_EPOCH_VARS
2273# endif 2281# define vepochs varinit[VAR_OFFSET3 + 6]
2282# define vepochr varinit[VAR_OFFSET3 + 7]
2274#endif 2283#endif
2275#define INIT_G_var() do { \ 2284#define INIT_G_var() do { \
2276 unsigned i; \ 2285 unsigned i; \
@@ -2409,7 +2418,7 @@ lookupvar(const char *name)
2409 2418
2410 v = *findvar(hashvar(name), name); 2419 v = *findvar(hashvar(name), name);
2411 if (v) { 2420 if (v) {
2412#if ENABLE_ASH_RANDOM_SUPPORT 2421#if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS
2413 /* 2422 /*
2414 * Dynamic variables are implemented roughly the same way they are 2423 * Dynamic variables are implemented roughly the same way they are
2415 * in bash. Namely, they're "special" so long as they aren't unset. 2424 * in bash. Namely, they're "special" so long as they aren't unset.
@@ -2562,6 +2571,10 @@ setvareq(char *s, int flags)
2562 } 2571 }
2563 2572
2564 flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET); 2573 flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET);
2574#if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS
2575 if (flags & VUNSET)
2576 flags &= ~VDYNAMIC;
2577#endif
2565 } else { 2578 } else {
2566 /* variable s is not found */ 2579 /* variable s is not found */
2567 if (flags & VNOSET) 2580 if (flags & VNOSET)
@@ -11950,6 +11963,32 @@ change_random(const char *value)
11950} 11963}
11951#endif 11964#endif
11952 11965
11966#if BASH_EPOCH_VARS
11967static void FAST_FUNC
11968change_epoch(struct var *vepoch, const char *fmt)
11969{
11970 struct timeval tv;
11971 char buffer[sizeof("%lu.nnnnnn") + sizeof(long)*3];
11972
11973 gettimeofday(&tv, NULL);
11974 sprintf(buffer, fmt, (unsigned long)tv.tv_sec, (unsigned)tv.tv_usec);
11975 setvar(vepoch->var_text, buffer, VNOFUNC);
11976 vepoch->flags &= ~VNOFUNC;
11977}
11978
11979static void FAST_FUNC
11980change_seconds(const char *value UNUSED_PARAM)
11981{
11982 change_epoch(&vepochs, "%lu");
11983}
11984
11985static void FAST_FUNC
11986change_realtime(const char *value UNUSED_PARAM)
11987{
11988 change_epoch(&vepochr, "%lu.%06u");
11989}
11990#endif
11991
11953#if ENABLE_ASH_GETOPTS 11992#if ENABLE_ASH_GETOPTS
11954static int 11993static int
11955getopts(char *optstr, char *optvar, char **optfirst) 11994getopts(char *optstr, char *optvar, char **optfirst)
diff --git a/shell/hush.c b/shell/hush.c
index fa9afa38e..d745148f4 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -379,6 +379,7 @@
379#define BASH_SUBSTR ENABLE_HUSH_BASH_COMPAT 379#define BASH_SUBSTR ENABLE_HUSH_BASH_COMPAT
380#define BASH_SOURCE ENABLE_HUSH_BASH_COMPAT 380#define BASH_SOURCE ENABLE_HUSH_BASH_COMPAT
381#define BASH_HOSTNAME_VAR ENABLE_HUSH_BASH_COMPAT 381#define BASH_HOSTNAME_VAR ENABLE_HUSH_BASH_COMPAT
382#define BASH_EPOCH_VARS ENABLE_HUSH_BASH_COMPAT
382#define BASH_TEST2 (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST) 383#define BASH_TEST2 (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
383#define BASH_READ_D ENABLE_HUSH_BASH_COMPAT 384#define BASH_READ_D ENABLE_HUSH_BASH_COMPAT
384 385
@@ -1011,6 +1012,9 @@ struct globals {
1011 int debug_indent; 1012 int debug_indent;
1012#endif 1013#endif
1013 struct sigaction sa; 1014 struct sigaction sa;
1015#if BASH_EPOCH_VARS
1016 char epoch_buf[sizeof("%lu.nnnnnn") + sizeof(long)*3];
1017#endif
1014#if ENABLE_FEATURE_EDITING 1018#if ENABLE_FEATURE_EDITING
1015 char user_input_buf[CONFIG_FEATURE_EDITING_MAX_LEN]; 1019 char user_input_buf[CONFIG_FEATURE_EDITING_MAX_LEN];
1016#endif 1020#endif
@@ -2228,6 +2232,22 @@ static const char* FAST_FUNC get_local_var_value(const char *name)
2228 if (strcmp(name, "RANDOM") == 0) 2232 if (strcmp(name, "RANDOM") == 0)
2229 return utoa(next_random(&G.random_gen)); 2233 return utoa(next_random(&G.random_gen));
2230#endif 2234#endif
2235#if BASH_EPOCH_VARS
2236 {
2237 const char *fmt = NULL;
2238 if (strcmp(name, "EPOCHSECONDS") == 0)
2239 fmt = "%lu";
2240 else if (strcmp(name, "EPOCHREALTIME") == 0)
2241 fmt = "%lu.%06u";
2242 if (fmt) {
2243 struct timeval tv;
2244 gettimeofday(&tv, NULL);
2245 sprintf(G.epoch_buf, fmt, (unsigned long)tv.tv_sec,
2246 (unsigned)tv.tv_usec);
2247 return G.epoch_buf;
2248 }
2249 }
2250#endif
2231 return NULL; 2251 return NULL;
2232} 2252}
2233 2253