diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-20 16:36:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-20 16:36:00 +0100 |
commit | bb4e32befaf86f80a108d2b7a4b7c47ffcc64e9c (patch) | |
tree | c4d95c1e49de3b1df631250ecfd29c62411d1f8a /shell | |
parent | c8f6c1d7750156b1d7daf0dc37aa2b60626fc0c1 (diff) | |
download | busybox-bb4e32befaf86f80a108d2b7a4b7c47ffcc64e9c.tar.gz |
hush: remove one redundant getpid() on every startup
function old new delta
hush_main 1151 1147 -4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3ccc18146..f29c985ad 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -9988,6 +9988,7 @@ static int set_mode(int state, char mode, const char *o_opt) int hush_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int hush_main(int argc, char **argv) { + pid_t cached_getpid; enum { OPT_login = (1 << 0), }; @@ -10016,6 +10017,10 @@ int hush_main(int argc, char **argv) G.argv0_for_re_execing = argv[0]; #endif + cached_getpid = getpid(); /* for tcsetpgrp() during init */ + G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */ + G.root_ppid = getppid(); /* for $$PPID (NOMMU can override) */ + /* Deal with HUSH_VERSION */ debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION"); unsetenv("HUSH_VERSION"); /* in case it exists in initial env */ @@ -10103,8 +10108,6 @@ int hush_main(int argc, char **argv) char *script = get_script_content(-argc - 1); G.global_argv = argv; G.global_argc = string_array_len(argv); - G.root_pid = getpid(); - G.root_ppid = getppid(); //install_special_sighandlers(); - needed? parse_and_run_string(script); goto final_return; @@ -10232,11 +10235,6 @@ int hush_main(int argc, char **argv) G.global_argv = argv + (optind - 1); G.global_argv[0] = argv[0]; - if (!G.root_pid) { - G.root_pid = getpid(); - G.root_ppid = getppid(); - } - /* If we are login shell... */ if (flags & OPT_login) { const char *hp = NULL; @@ -10406,7 +10404,7 @@ int hush_main(int argc, char **argv) * (bash, too, does this only if ctty is available) */ bb_setpgrp(); /* is the same as setpgid(our_pid, our_pid); */ /* Grab control of the terminal */ - tcsetpgrp(G_interactive_fd, getpid()); + tcsetpgrp(G_interactive_fd, cached_getpid); } enable_restore_tty_pgrp_on_exit(); |