#endif
smallint fake_mode;
/* These four support $?, $#, and $1 */
- smalluint last_return_code;
+ smalluint last_exitcode;
/* are global_argv and global_argv[1..n] malloced? (note: not [0]) */
smalluint global_args_malloced;
/* how many non-NULL argv's we have. NB: $# + 1 */
if (G.traps[sig][0]) {
/* We have user-defined handler */
char *argv[] = { NULL, xstrdup(G.traps[sig]), NULL };
- save_rcode = G.last_return_code;
+ save_rcode = G.last_exitcode;
builtin_eval(argv);
free(argv[1]);
- G.last_return_code = save_rcode;
+ G.last_exitcode = save_rcode;
} /* else: "" trap, ignoring signal */
continue;
}
val = G.last_bg_pid ? utoa(G.last_bg_pid) : (char*)"";
break;
case '?': /* exitcode */
- val = utoa(G.last_return_code);
+ val = utoa(G.last_exitcode);
break;
case '#': /* argc */
if (arg[1] != SPECIAL_VAR_SYMBOL)
sprintf(param_buf, "-$%x:%x:%x" USE_HUSH_LOOPS(":%x")
, (unsigned) G.root_pid
, (unsigned) G.last_bg_pid
- , (unsigned) G.last_return_code
+ , (unsigned) G.last_exitcode
USE_HUSH_LOOPS(, G.depth_of_loop)
);
/* 1:hush 2:-$<pid>:<pid>:<exitcode>:<depth> <vars...>
last_rword = RES_XXXX;
#endif
last_followup = PIPE_SEQ;
- rcode = G.last_return_code;
+ rcode = G.last_exitcode;
/* Go through list of pipes, (maybe) executing them. */
for (; pi; pi = USE_HUSH_LOOPS(rword == RES_DONE ? loop_top : ) pi->next) {
if (cond_code) {
if (rword == RES_THEN) {
/* if false; then ... fi has exitcode 0! */
- G.last_return_code = rcode = EXIT_SUCCESS;
+ G.last_exitcode = rcode = EXIT_SUCCESS;
/* "if <false> THEN cmd": skip cmd */
continue;
}
if (pi->next->res_word == RES_IN) {
/* if no variable values after "in" we skip "for" */
if (!pi->next->cmds[0].argv) {
- G.last_return_code = rcode = EXIT_SUCCESS;
+ G.last_exitcode = rcode = EXIT_SUCCESS;
debug_printf_exec(": null FOR: exitcode EXIT_SUCCESS\n");
break;
}
if (r != -1) {
/* We only ran a builtin: rcode is already known
* and we don't need to wait for anything. */
- G.last_return_code = rcode;
+ G.last_exitcode = rcode;
debug_printf_exec(": builtin exitcode %d\n", rcode);
check_and_run_traps(0);
#if ENABLE_HUSH_LOOPS
if (G.run_list_level == 1)
insert_bg_job(pi);
#endif
- G.last_return_code = rcode = EXIT_SUCCESS;
+ G.last_exitcode = rcode = EXIT_SUCCESS;
debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n");
} else {
#if ENABLE_HUSH_JOB
debug_printf_exec(": checkjobs exitcode %d\n", rcode);
check_and_run_traps(0);
}
- G.last_return_code = rcode;
+ G.last_exitcode = rcode;
}
}
if (rword == RES_WHILE) {
if (rcode) {
/* "while false; do...done" - exitcode 0 */
- G.last_return_code = rcode = EXIT_SUCCESS;
+ G.last_exitcode = rcode = EXIT_SUCCESS;
debug_printf_exec(": while expr is false: breaking (exitcode:EXIT_SUCCESS)\n");
goto check_jobs_and_break;
}
#if BB_MMU
reset_traps_to_defaults();
parse_and_run_string(s);
- _exit(G.last_return_code);
+ _exit(G.last_exitcode);
#else
/* We re-execute after vfork on NOMMU. This makes this script safe:
* yes "0123456789012345678901234567890" | dd bs=32 count=64k >BIG
INIT_G();
if (EXIT_SUCCESS) /* if EXIT_SUCCESS == 0, is already done */
- G.last_return_code = EXIT_SUCCESS;
+ G.last_exitcode = EXIT_SUCCESS;
#if !BB_MMU
G.argv0_for_re_execing = argv[0];
#endif
optarg++;
G.last_bg_pid = bb_strtou(optarg, &optarg, 16);
optarg++;
- G.last_return_code = bb_strtou(optarg, &optarg, 16);
+ G.last_exitcode = bb_strtou(optarg, &optarg, 16);
# if ENABLE_HUSH_LOOPS
optarg++;
G.depth_of_loop = bb_strtou(optarg, &optarg, 16);
free(tmp);
}
#endif
- hush_exit(G.last_return_code);
+ hush_exit(G.last_exitcode);
}
*/
parse_and_run_string(str);
free(str);
- rcode = G.last_return_code;
+ rcode = G.last_exitcode;
}
return rcode;
}
// TODO: warn if we have background jobs: "There are stopped jobs"
// On second consecutive 'exit', exit anyway.
if (*++argv == NULL)
- hush_exit(G.last_return_code);
+ hush_exit(G.last_exitcode);
/* mimic bash: exit 123abc == exit 255 + error msg */
xfunc_error_retval = 255;
/* bash: exit -2 == exit 254, no error msg */
* set G.global_argv=argv+1, recurse, and restore. */
parse_and_run_file(input);
fclose(input);
- return G.last_return_code;
+ return G.last_exitcode;
}
static int builtin_umask(char **argv)