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>
This commit is contained in:
parent
3ea2e82dc7
commit
20b3d144e9
16
shell/hush.c
16
shell/hush.c
@ -86,6 +86,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
|
#if ENABLE_ASH_RANDOM_SUPPORT
|
||||||
|
# include "random.h"
|
||||||
|
#endif
|
||||||
#ifndef PIPE_BUF
|
#ifndef PIPE_BUF
|
||||||
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
||||||
#endif
|
#endif
|
||||||
@ -486,6 +489,9 @@ struct globals {
|
|||||||
pid_t root_pid;
|
pid_t root_pid;
|
||||||
pid_t root_ppid;
|
pid_t root_ppid;
|
||||||
pid_t last_bg_pid;
|
pid_t last_bg_pid;
|
||||||
|
#if ENABLE_HUSH_RANDOM_SUPPORT
|
||||||
|
random_t random_gen;
|
||||||
|
#endif
|
||||||
#if ENABLE_HUSH_JOB
|
#if ENABLE_HUSH_JOB
|
||||||
int run_list_level;
|
int run_list_level;
|
||||||
int last_jobid;
|
int last_jobid;
|
||||||
@ -1311,6 +1317,10 @@ static const char *get_local_var_value(const char *name)
|
|||||||
if (strcmp(name, "PPID") == 0)
|
if (strcmp(name, "PPID") == 0)
|
||||||
return utoa(G.root_ppid);
|
return utoa(G.root_ppid);
|
||||||
// bash compat: UID? EUID?
|
// bash compat: UID? EUID?
|
||||||
|
#if ENABLE_HUSH_RANDOM_SUPPORT
|
||||||
|
if (strcmp(name, "RANDOM") == 0)
|
||||||
|
return utoa(next_random(&G.random_gen));
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6595,6 +6605,9 @@ int hush_main(int argc, char **argv)
|
|||||||
if (!G.root_pid) {
|
if (!G.root_pid) {
|
||||||
G.root_pid = getpid();
|
G.root_pid = getpid();
|
||||||
G.root_ppid = getppid();
|
G.root_ppid = getppid();
|
||||||
|
#if ENABLE_HUSH_RANDOM_SUPPORT
|
||||||
|
INIT_RANDOM_T(&G.random_gen, G.root_pid, monotonic_us());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
G.global_argv = argv + optind;
|
G.global_argv = argv + optind;
|
||||||
G.global_argc = argc - optind;
|
G.global_argc = argc - optind;
|
||||||
@ -6683,6 +6696,9 @@ int hush_main(int argc, char **argv)
|
|||||||
G.root_pid = getpid();
|
G.root_pid = getpid();
|
||||||
G.root_ppid = getppid();
|
G.root_ppid = getppid();
|
||||||
}
|
}
|
||||||
|
#if ENABLE_HUSH_RANDOM_SUPPORT
|
||||||
|
INIT_RANDOM_T(&G.random_gen, G.root_pid, monotonic_us());
|
||||||
|
#endif
|
||||||
|
|
||||||
/* If we are login shell... */
|
/* If we are login shell... */
|
||||||
if (argv[0] && argv[0][0] == '-') {
|
if (argv[0] && argv[0][0] == '-') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user