aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/hush.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 3028d795c..b80b6c742 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -86,6 +86,9 @@
86#endif 86#endif
87#include "math.h" 87#include "math.h"
88#include "match.h" 88#include "match.h"
89#if ENABLE_ASH_RANDOM_SUPPORT
90# include "random.h"
91#endif
89#ifndef PIPE_BUF 92#ifndef PIPE_BUF
90# define PIPE_BUF 4096 /* amount of buffering in a pipe */ 93# define PIPE_BUF 4096 /* amount of buffering in a pipe */
91#endif 94#endif
@@ -486,6 +489,9 @@ struct globals {
486 pid_t root_pid; 489 pid_t root_pid;
487 pid_t root_ppid; 490 pid_t root_ppid;
488 pid_t last_bg_pid; 491 pid_t last_bg_pid;
492#if ENABLE_HUSH_RANDOM_SUPPORT
493 random_t random_gen;
494#endif
489#if ENABLE_HUSH_JOB 495#if ENABLE_HUSH_JOB
490 int run_list_level; 496 int run_list_level;
491 int last_jobid; 497 int last_jobid;
@@ -1311,6 +1317,10 @@ static const char *get_local_var_value(const char *name)
1311 if (strcmp(name, "PPID") == 0) 1317 if (strcmp(name, "PPID") == 0)
1312 return utoa(G.root_ppid); 1318 return utoa(G.root_ppid);
1313 // bash compat: UID? EUID? 1319 // bash compat: UID? EUID?
1320#if ENABLE_HUSH_RANDOM_SUPPORT
1321 if (strcmp(name, "RANDOM") == 0)
1322 return utoa(next_random(&G.random_gen));
1323#endif
1314 return NULL; 1324 return NULL;
1315} 1325}
1316 1326
@@ -6595,6 +6605,9 @@ int hush_main(int argc, char **argv)
6595 if (!G.root_pid) { 6605 if (!G.root_pid) {
6596 G.root_pid = getpid(); 6606 G.root_pid = getpid();
6597 G.root_ppid = getppid(); 6607 G.root_ppid = getppid();
6608#if ENABLE_HUSH_RANDOM_SUPPORT
6609 INIT_RANDOM_T(&G.random_gen, G.root_pid, monotonic_us());
6610#endif
6598 } 6611 }
6599 G.global_argv = argv + optind; 6612 G.global_argv = argv + optind;
6600 G.global_argc = argc - optind; 6613 G.global_argc = argc - optind;
@@ -6683,6 +6696,9 @@ int hush_main(int argc, char **argv)
6683 G.root_pid = getpid(); 6696 G.root_pid = getpid();
6684 G.root_ppid = getppid(); 6697 G.root_ppid = getppid();
6685 } 6698 }
6699#if ENABLE_HUSH_RANDOM_SUPPORT
6700 INIT_RANDOM_T(&G.random_gen, G.root_pid, monotonic_us());
6701#endif
6686 6702
6687 /* If we are login shell... */ 6703 /* If we are login shell... */
6688 if (argv[0] && argv[0][0] == '-') { 6704 if (argv[0] && argv[0][0] == '-') {