4f0058e38adacba3fda94753aede51935ed4da09
[openwrt.git] / package / busybox / patches / 922-shell.patch
1 --- a/shell/ash.c
2 +++ b/shell/ash.c
3 @@ -4515,6 +4515,7 @@ clear_traps(void)
4                         INT_ON;
5                 }
6         }
7 +       may_have_traps = 0;
8  }
9  
10  /* Lives far away from here, needed for forkchild */
11 --- /dev/null
12 +++ b/shell/ash_test/ash-signals/signal7.right
13 @@ -0,0 +1 @@
14 +Bug detected: 0
15 --- /dev/null
16 +++ b/shell/ash_test/ash-signals/signal7.tests
17 @@ -0,0 +1,18 @@
18 +bug() {
19 +       trap : exit
20 +       # Bug was causing sh to be run in subshell,
21 +       # as if this line is replaced with (sh -c ...; exit $?) &
22 +       # here:
23 +       sh -c 'echo REAL_CHILD=$$' &
24 +       echo PARENTS_IDEA_OF_CHILD=$!
25 +       wait  # make sure bkgd shell completes
26 +}
27 +
28 +bug | {
29 +while read varval; do
30 +       eval $varval
31 +done
32 +test x"$REAL_CHILD" != x"" \
33 +&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD"
34 +echo "Bug detected: $?"
35 +}
36 --- a/shell/hush.c
37 +++ b/shell/hush.c
38 @@ -3901,8 +3901,6 @@ static void insert_bg_job(struct pipe *p
39  
40         if (G_interactive_fd)
41                 printf("[%d] %d %s\n", job->jobid, job->cmds[0].pid, job->cmdtext);
42 -       /* Last command's pid goes to $! */
43 -       G.last_bg_pid = job->cmds[job->num_cmds - 1].pid;
44         G.last_jobid = job->jobid;
45  }
46  
47 @@ -4825,6 +4823,8 @@ static int run_list(struct pipe *pi)
48                                 if (G.run_list_level == 1)
49                                         insert_bg_job(pi);
50  #endif
51 +                               /* Last command's pid goes to $! */
52 +                               G.last_bg_pid = pi->cmds[pi->num_cmds - 1].pid;
53                                 G.last_exitcode = rcode = EXIT_SUCCESS;
54                                 debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n");
55                         } else {
56 --- /dev/null
57 +++ b/shell/hush_test/hush-trap/signal7.right
58 @@ -0,0 +1 @@
59 +Bug detected: 0
60 --- /dev/null
61 +++ b/shell/hush_test/hush-trap/signal7.tests
62 @@ -0,0 +1,18 @@
63 +bug() {
64 +       trap : exit
65 +       # Bug was causing sh to be run in subshell,
66 +       # as if this line is replaced with (sh -c ...; exit $?) &
67 +       # here:
68 +       sh -c 'echo REAL_CHILD=$$' &
69 +       echo PARENTS_IDEA_OF_CHILD=$!
70 +       wait  # make sure bkgd shell completes
71 +}
72 +
73 +bug | {
74 +while read varval; do
75 +       eval $varval
76 +done
77 +test x"$REAL_CHILD" != x"" \
78 +&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD"
79 +echo "Bug detected: $?"
80 +}
81 --- a/shell/shell_common.c
82 +++ b/shell/shell_common.c
83 @@ -428,9 +428,14 @@ shell_builtin_ulimit(char **argv)
84                                                 val <<= l->factor_shift;
85                                         }
86  //bb_error_msg("opt %c val_str:'%s' val:%lld", opt_char, val_str, (long long)val);
87 +                                       /* from man bash: "If neither -H nor -S
88 +                                        * is specified, both the soft and hard
89 +                                        * limits are set. */
90 +                                       if (!opts)
91 +                                               opts = OPT_hard + OPT_soft;
92                                         if (opts & OPT_hard)
93                                                 limit.rlim_max = val;
94 -                                       if ((opts & OPT_soft) || opts == 0)
95 +                                       if (opts & OPT_soft)
96                                                 limit.rlim_cur = val;
97  //bb_error_msg("setrlimit(%d, %lld, %lld)", l->cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max);
98                                         if (setrlimit(l->cmd, &limit) < 0) {