diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-09 15:40:49 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-09 15:40:49 +0200 |
commit | dea478855f8de7fe0974f5cbb5fa3f5968c46302 (patch) | |
tree | 512e659a6922af8cb7c2e303d93387f0019b04ea | |
parent | 3f11f35124f3b2deca1a403520260f290b6f8901 (diff) | |
download | busybox-w32-dea478855f8de7fe0974f5cbb5fa3f5968c46302.tar.gz busybox-w32-dea478855f8de7fe0974f5cbb5fa3f5968c46302.tar.bz2 busybox-w32-dea478855f8de7fe0974f5cbb5fa3f5968c46302.zip |
hush: support $PPID
function old new delta
get_local_var_value 33 72 +39
hush_main 951 983 +32
block_signals 152 155 +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 74/0) Total: 74 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c index ec38023ff..3028d795c 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -484,6 +484,7 @@ struct globals { | |||
484 | line_input_t *line_input_state; | 484 | line_input_t *line_input_state; |
485 | #endif | 485 | #endif |
486 | pid_t root_pid; | 486 | pid_t root_pid; |
487 | pid_t root_ppid; | ||
487 | pid_t last_bg_pid; | 488 | pid_t last_bg_pid; |
488 | #if ENABLE_HUSH_JOB | 489 | #if ENABLE_HUSH_JOB |
489 | int run_list_level; | 490 | int run_list_level; |
@@ -1307,6 +1308,9 @@ static const char *get_local_var_value(const char *name) | |||
1307 | struct variable **pp = get_ptr_to_local_var(name); | 1308 | struct variable **pp = get_ptr_to_local_var(name); |
1308 | if (pp) | 1309 | if (pp) |
1309 | return strchr((*pp)->varstr, '=') + 1; | 1310 | return strchr((*pp)->varstr, '=') + 1; |
1311 | if (strcmp(name, "PPID") == 0) | ||
1312 | return utoa(G.root_ppid); | ||
1313 | // bash compat: UID? EUID? | ||
1310 | return NULL; | 1314 | return NULL; |
1311 | } | 1315 | } |
1312 | 1316 | ||
@@ -2687,8 +2691,9 @@ static void re_execute_shell(char ***to_free, const char *s, | |||
2687 | if (pp) while (*pp++) | 2691 | if (pp) while (*pp++) |
2688 | cnt++; | 2692 | cnt++; |
2689 | 2693 | ||
2690 | sprintf(param_buf, "-$%x:%x:%x:%x" IF_HUSH_LOOPS(":%x") | 2694 | sprintf(param_buf, "-$%x:%x:%x:%x:%x" IF_HUSH_LOOPS(":%x") |
2691 | , (unsigned) G.root_pid | 2695 | , (unsigned) G.root_pid |
2696 | , (unsigned) G.root_ppid | ||
2692 | , (unsigned) G.last_bg_pid | 2697 | , (unsigned) G.last_bg_pid |
2693 | , (unsigned) G.last_exitcode | 2698 | , (unsigned) G.last_exitcode |
2694 | , cnt | 2699 | , cnt |
@@ -6510,7 +6515,7 @@ int hush_main(int argc, char **argv) | |||
6510 | * MACHTYPE=i386-pc-linux-gnu | 6515 | * MACHTYPE=i386-pc-linux-gnu |
6511 | * OSTYPE=linux-gnu | 6516 | * OSTYPE=linux-gnu |
6512 | * HOSTNAME=<xxxxxxxxxx> | 6517 | * HOSTNAME=<xxxxxxxxxx> |
6513 | * PPID=<NNNNN> | 6518 | * PPID=<NNNNN> - we also do it elsewhere |
6514 | * EUID=<NNNNN> | 6519 | * EUID=<NNNNN> |
6515 | * UID=<NNNNN> | 6520 | * UID=<NNNNN> |
6516 | * GROUPS=() | 6521 | * GROUPS=() |
@@ -6587,8 +6592,10 @@ int hush_main(int argc, char **argv) | |||
6587 | * Note: this form never happens: | 6592 | * Note: this form never happens: |
6588 | * sh ... -c 'builtin' [BARGV...] "" | 6593 | * sh ... -c 'builtin' [BARGV...] "" |
6589 | */ | 6594 | */ |
6590 | if (!G.root_pid) | 6595 | if (!G.root_pid) { |
6591 | G.root_pid = getpid(); | 6596 | G.root_pid = getpid(); |
6597 | G.root_ppid = getppid(); | ||
6598 | } | ||
6592 | G.global_argv = argv + optind; | 6599 | G.global_argv = argv + optind; |
6593 | G.global_argc = argc - optind; | 6600 | G.global_argc = argc - optind; |
6594 | if (builtin_argc) { | 6601 | if (builtin_argc) { |
@@ -6630,6 +6637,8 @@ int hush_main(int argc, char **argv) | |||
6630 | case '$': | 6637 | case '$': |
6631 | G.root_pid = bb_strtou(optarg, &optarg, 16); | 6638 | G.root_pid = bb_strtou(optarg, &optarg, 16); |
6632 | optarg++; | 6639 | optarg++; |
6640 | G.root_ppid = bb_strtou(optarg, &optarg, 16); | ||
6641 | optarg++; | ||
6633 | G.last_bg_pid = bb_strtou(optarg, &optarg, 16); | 6642 | G.last_bg_pid = bb_strtou(optarg, &optarg, 16); |
6634 | optarg++; | 6643 | optarg++; |
6635 | G.last_exitcode = bb_strtou(optarg, &optarg, 16); | 6644 | G.last_exitcode = bb_strtou(optarg, &optarg, 16); |
@@ -6670,8 +6679,10 @@ int hush_main(int argc, char **argv) | |||
6670 | } | 6679 | } |
6671 | } /* option parsing loop */ | 6680 | } /* option parsing loop */ |
6672 | 6681 | ||
6673 | if (!G.root_pid) | 6682 | if (!G.root_pid) { |
6674 | G.root_pid = getpid(); | 6683 | G.root_pid = getpid(); |
6684 | G.root_ppid = getppid(); | ||
6685 | } | ||
6675 | 6686 | ||
6676 | /* If we are login shell... */ | 6687 | /* If we are login shell... */ |
6677 | if (argv[0] && argv[0][0] == '-') { | 6688 | if (argv[0] && argv[0][0] == '-') { |