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 | |
| parent | c8f6c1d7750156b1d7daf0dc37aa2b60626fc0c1 (diff) | |
| download | busybox-w32-bb4e32befaf86f80a108d2b7a4b7c47ffcc64e9c.tar.gz busybox-w32-bb4e32befaf86f80a108d2b7a4b7c47ffcc64e9c.tar.bz2 busybox-w32-bb4e32befaf86f80a108d2b7a4b7c47ffcc64e9c.zip | |
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>
| -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) | |||
| 9988 | int hush_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 9988 | int hush_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 9989 | int hush_main(int argc, char **argv) | 9989 | int hush_main(int argc, char **argv) |
| 9990 | { | 9990 | { |
| 9991 | pid_t cached_getpid; | ||
| 9991 | enum { | 9992 | enum { |
| 9992 | OPT_login = (1 << 0), | 9993 | OPT_login = (1 << 0), |
| 9993 | }; | 9994 | }; |
| @@ -10016,6 +10017,10 @@ int hush_main(int argc, char **argv) | |||
| 10016 | G.argv0_for_re_execing = argv[0]; | 10017 | G.argv0_for_re_execing = argv[0]; |
| 10017 | #endif | 10018 | #endif |
| 10018 | 10019 | ||
| 10020 | cached_getpid = getpid(); /* for tcsetpgrp() during init */ | ||
| 10021 | G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */ | ||
| 10022 | G.root_ppid = getppid(); /* for $$PPID (NOMMU can override) */ | ||
| 10023 | |||
| 10019 | /* Deal with HUSH_VERSION */ | 10024 | /* Deal with HUSH_VERSION */ |
| 10020 | debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION"); | 10025 | debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION"); |
| 10021 | unsetenv("HUSH_VERSION"); /* in case it exists in initial env */ | 10026 | unsetenv("HUSH_VERSION"); /* in case it exists in initial env */ |
| @@ -10103,8 +10108,6 @@ int hush_main(int argc, char **argv) | |||
| 10103 | char *script = get_script_content(-argc - 1); | 10108 | char *script = get_script_content(-argc - 1); |
| 10104 | G.global_argv = argv; | 10109 | G.global_argv = argv; |
| 10105 | G.global_argc = string_array_len(argv); | 10110 | G.global_argc = string_array_len(argv); |
| 10106 | G.root_pid = getpid(); | ||
| 10107 | G.root_ppid = getppid(); | ||
| 10108 | //install_special_sighandlers(); - needed? | 10111 | //install_special_sighandlers(); - needed? |
| 10109 | parse_and_run_string(script); | 10112 | parse_and_run_string(script); |
| 10110 | goto final_return; | 10113 | goto final_return; |
| @@ -10232,11 +10235,6 @@ int hush_main(int argc, char **argv) | |||
| 10232 | G.global_argv = argv + (optind - 1); | 10235 | G.global_argv = argv + (optind - 1); |
| 10233 | G.global_argv[0] = argv[0]; | 10236 | G.global_argv[0] = argv[0]; |
| 10234 | 10237 | ||
| 10235 | if (!G.root_pid) { | ||
| 10236 | G.root_pid = getpid(); | ||
| 10237 | G.root_ppid = getppid(); | ||
| 10238 | } | ||
| 10239 | |||
| 10240 | /* If we are login shell... */ | 10238 | /* If we are login shell... */ |
| 10241 | if (flags & OPT_login) { | 10239 | if (flags & OPT_login) { |
| 10242 | const char *hp = NULL; | 10240 | const char *hp = NULL; |
| @@ -10406,7 +10404,7 @@ int hush_main(int argc, char **argv) | |||
| 10406 | * (bash, too, does this only if ctty is available) */ | 10404 | * (bash, too, does this only if ctty is available) */ |
| 10407 | bb_setpgrp(); /* is the same as setpgid(our_pid, our_pid); */ | 10405 | bb_setpgrp(); /* is the same as setpgid(our_pid, our_pid); */ |
| 10408 | /* Grab control of the terminal */ | 10406 | /* Grab control of the terminal */ |
| 10409 | tcsetpgrp(G_interactive_fd, getpid()); | 10407 | tcsetpgrp(G_interactive_fd, cached_getpid); |
| 10410 | } | 10408 | } |
| 10411 | enable_restore_tty_pgrp_on_exit(); | 10409 | enable_restore_tty_pgrp_on_exit(); |
| 10412 | 10410 | ||
