diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-17 12:28:44 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-17 12:28:44 +0000 |
commit | 16c2fea2803d64b84d196fc315132fd09112ff14 (patch) | |
tree | d66b6f43e8fd52c63a49d1b4fbb89852debe6eb1 | |
parent | 13436ea0dd2b70271d30bd6f682cc9cbe41b26c6 (diff) | |
download | busybox-w32-16c2fea2803d64b84d196fc315132fd09112ff14.tar.gz busybox-w32-16c2fea2803d64b84d196fc315132fd09112ff14.tar.bz2 busybox-w32-16c2fea2803d64b84d196fc315132fd09112ff14.zip |
hush: fix $$ handling
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/pid.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/pid.tests | 1 |
3 files changed, 7 insertions, 1 deletions
diff --git a/shell/hush.c b/shell/hush.c index 45448c5f3..e49e6e9b2 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -395,6 +395,7 @@ struct globals { | |||
395 | int run_list_level; | 395 | int run_list_level; |
396 | pid_t saved_task_pgrp; | 396 | pid_t saved_task_pgrp; |
397 | pid_t saved_tty_pgrp; | 397 | pid_t saved_tty_pgrp; |
398 | pid_t root_pid; | ||
398 | int last_jobid; | 399 | int last_jobid; |
399 | struct pipe *job_list; | 400 | struct pipe *job_list; |
400 | struct pipe *toplevel_list; | 401 | struct pipe *toplevel_list; |
@@ -441,6 +442,7 @@ enum { run_list_level = 0 }; | |||
441 | #define run_list_level (G.run_list_level ) | 442 | #define run_list_level (G.run_list_level ) |
442 | #define saved_task_pgrp (G.saved_task_pgrp ) | 443 | #define saved_task_pgrp (G.saved_task_pgrp ) |
443 | #define saved_tty_pgrp (G.saved_tty_pgrp ) | 444 | #define saved_tty_pgrp (G.saved_tty_pgrp ) |
445 | #define root_pid (G.root_pid ) | ||
444 | #define last_jobid (G.last_jobid ) | 446 | #define last_jobid (G.last_jobid ) |
445 | #define job_list (G.job_list ) | 447 | #define job_list (G.job_list ) |
446 | #define toplevel_list (G.toplevel_list ) | 448 | #define toplevel_list (G.toplevel_list ) |
@@ -2353,7 +2355,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
2353 | /* Highest bit in first_ch indicates that var is double-quoted */ | 2355 | /* Highest bit in first_ch indicates that var is double-quoted */ |
2354 | case '$': /* pid */ | 2356 | case '$': /* pid */ |
2355 | /* FIXME: (echo $$) should still print pid of main shell */ | 2357 | /* FIXME: (echo $$) should still print pid of main shell */ |
2356 | val = utoa(getpid()); /* rootpid? */ | 2358 | val = utoa(root_pid); |
2357 | break; | 2359 | break; |
2358 | case '!': /* bg pid */ | 2360 | case '!': /* bg pid */ |
2359 | val = last_bg_pid ? utoa(last_bg_pid) : (char*)""; | 2361 | val = last_bg_pid ? utoa(last_bg_pid) : (char*)""; |
@@ -3752,6 +3754,8 @@ int hush_main(int argc, char **argv) | |||
3752 | 3754 | ||
3753 | INIT_G(); | 3755 | INIT_G(); |
3754 | 3756 | ||
3757 | root_pid = getpid(); | ||
3758 | |||
3755 | /* Deal with HUSH_VERSION */ | 3759 | /* Deal with HUSH_VERSION */ |
3756 | shell_ver = const_shell_ver; /* copying struct here */ | 3760 | shell_ver = const_shell_ver; /* copying struct here */ |
3757 | top_var = &shell_ver; | 3761 | top_var = &shell_ver; |
diff --git a/shell/hush_test/hush-misc/pid.right b/shell/hush_test/hush-misc/pid.right new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/shell/hush_test/hush-misc/pid.right | |||
@@ -0,0 +1 @@ | |||
0 | |||
diff --git a/shell/hush_test/hush-misc/pid.tests b/shell/hush_test/hush-misc/pid.tests new file mode 100755 index 000000000..eaeaa717b --- /dev/null +++ b/shell/hush_test/hush-misc/pid.tests | |||
@@ -0,0 +1 @@ | |||
test `(echo $$)` = `echo $$`; echo $? | |||