bc: fix exit codes for FEATURE_CLEAN_UP=y
$ echo 0/0 | ./busybox bc; echo $? bc: divide by zero 1 $ echo halt | ./busybox bc; echo $? 0 <------- was 1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
a133137174
commit
c7a7ce06b8
@ -741,6 +741,7 @@ typedef unsigned long (*BcProgramBuiltIn)(BcNum *);
|
|||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
IF_FEATURE_BC_SIGNALS(smallint ttyin;)
|
IF_FEATURE_BC_SIGNALS(smallint ttyin;)
|
||||||
|
IF_FEATURE_CLEAN_UP(smallint exiting;)
|
||||||
smallint eof;
|
smallint eof;
|
||||||
char sbgn;
|
char sbgn;
|
||||||
char send;
|
char send;
|
||||||
@ -776,6 +777,11 @@ struct globals {
|
|||||||
#else
|
#else
|
||||||
# define G_ttyin 0
|
# define G_ttyin 0
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
|
# define G_exiting G.exiting
|
||||||
|
#else
|
||||||
|
# define G_exiting 0
|
||||||
|
#endif
|
||||||
#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b'))
|
#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b'))
|
||||||
|
|
||||||
#if ENABLE_BC
|
#if ENABLE_BC
|
||||||
@ -921,13 +927,14 @@ static void fflush_and_check(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_FEATURE_CLEAN_UP
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
#define quit_or_return_for_exit() \
|
#define QUIT_OR_RETURN_TO_MAIN \
|
||||||
do { \
|
do { \
|
||||||
IF_FEATURE_BC_SIGNALS(G_ttyin = 0;) /* do not loop in main loop anymore */ \
|
IF_FEATURE_BC_SIGNALS(G_ttyin = 0;) /* do not loop in main loop anymore */ \
|
||||||
|
G_exiting = 1; \
|
||||||
return BC_STATUS_FAILURE; \
|
return BC_STATUS_FAILURE; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define quit_or_return_for_exit() quit()
|
#define QUIT_OR_RETURN_TO_MAIN quit()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void quit(void) NORETURN;
|
static void quit(void) NORETURN;
|
||||||
@ -4708,7 +4715,7 @@ static BcStatus bc_parse_stmt(BcParse *p)
|
|||||||
// "quit" is a compile-time command. For example,
|
// "quit" is a compile-time command. For example,
|
||||||
// "if (0 == 1) quit" terminates when parsing the statement,
|
// "if (0 == 1) quit" terminates when parsing the statement,
|
||||||
// not when it is executed
|
// not when it is executed
|
||||||
quit_or_return_for_exit();
|
QUIT_OR_RETURN_TO_MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BC_LEX_KEY_RETURN:
|
case BC_LEX_KEY_RETURN:
|
||||||
@ -6411,9 +6418,7 @@ static BcStatus bc_program_nquit(void)
|
|||||||
if (G.prog.stack.len < val)
|
if (G.prog.stack.len < val)
|
||||||
return bc_error_stack_has_too_few_elements();
|
return bc_error_stack_has_too_few_elements();
|
||||||
if (G.prog.stack.len == val) {
|
if (G.prog.stack.len == val) {
|
||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
QUIT_OR_RETURN_TO_MAIN;
|
||||||
return BC_STATUS_FAILURE;
|
|
||||||
quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bc_vec_npop(&G.prog.stack, val);
|
bc_vec_npop(&G.prog.stack, val);
|
||||||
@ -6627,7 +6632,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
|
|
||||||
case BC_INST_HALT:
|
case BC_INST_HALT:
|
||||||
{
|
{
|
||||||
quit_or_return_for_exit();
|
QUIT_OR_RETURN_TO_MAIN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6872,7 +6877,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
case BC_INST_QUIT:
|
case BC_INST_QUIT:
|
||||||
{
|
{
|
||||||
if (G.prog.stack.len <= 2)
|
if (G.prog.stack.len <= 2)
|
||||||
quit_or_return_for_exit();
|
QUIT_OR_RETURN_TO_MAIN;
|
||||||
bc_vec_npop(&G.prog.stack, 2);
|
bc_vec_npop(&G.prog.stack, 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -7489,6 +7494,8 @@ static BcStatus bc_vm_run(void)
|
|||||||
{
|
{
|
||||||
BcStatus st = bc_vm_exec();
|
BcStatus st = bc_vm_exec();
|
||||||
#if ENABLE_FEATURE_CLEAN_UP
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
|
if (G_exiting) // it was actually "halt" or "quit"
|
||||||
|
st = EXIT_SUCCESS;
|
||||||
bc_vm_free();
|
bc_vm_free();
|
||||||
# if ENABLE_FEATURE_EDITING
|
# if ENABLE_FEATURE_EDITING
|
||||||
free_line_input_t(G.line_input_state);
|
free_line_input_t(G.line_input_state);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user