diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-09 20:59:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-09 20:59:39 +0200 |
commit | 20b3d144e9449c2fa3858e8a4edd4397932dff97 (patch) | |
tree | 46982b0c2251c38438eba443b78679110c8192d2 | |
parent | 3ea2e82dc7b32703f5043c3b30b049905a0d07aa (diff) | |
download | busybox-w32-20b3d144e9449c2fa3858e8a4edd4397932dff97.tar.gz busybox-w32-20b3d144e9449c2fa3858e8a4edd4397932dff97.tar.bz2 busybox-w32-20b3d144e9449c2fa3858e8a4edd4397932dff97.zip |
hush: add support for $RANDOM. If on:
function old new delta
hush_main 983 1024 +41
get_local_var_value 72 104 +32
block_signals 155 161 +6
reset_traps_to_defaults 211 214 +3
builtin_wait 268 271 +3
pseudo_exec_argv 198 200 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 87/0) Total: 87 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 16 |
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] == '-') { |