Skip to content

Commit

Permalink
signal: propagate signal num to exit() properly [#537]
Browse files Browse the repository at this point in the history
And print in by dosemu wrapper script.
  • Loading branch information
stsp committed Nov 19, 2017
1 parent 082c8ab commit 921f66c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/arch/linux/async/signal.c
Expand Up @@ -437,7 +437,7 @@ void deinit_handler(struct sigcontext *scp, unsigned long *uc_flags)
static void leavedos_call(void *arg)
{
int *sig = arg;
leavedos(*sig);
_leavedos_sig(*sig);
}

int sigchld_register_handler(pid_t pid, void (*handler)(void))
Expand Down Expand Up @@ -501,7 +501,7 @@ int sigalrm_register_handler(void (*handler)(void))
void leavedos_from_sig(int sig)
{
/* anything more sophisticated? */
leavedos_main(sig);
__leavedos_main(0, sig);
}

static void leavedos_sig(int sig)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/linux/async/sigsegv.c
Expand Up @@ -187,7 +187,7 @@ static int dosemu_fault1(int signal, struct sigcontext *scp)
if (in_vm86)
show_regs();
fatalerr = 4;
leavedos_main(fatalerr); /* shouldn't return */
__leavedos_main(0, signal); /* shouldn't return */
return 0;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/bindist/dosemu
Expand Up @@ -168,4 +168,9 @@ if [ -n "$STALE" ]; then
stty sane
fi

if [ $EC -gt 128 ]; then
SIG=`expr $EC - 128`
echo "Terminated with signal $SIG"
fi

exit $EC
8 changes: 4 additions & 4 deletions src/emu.c
Expand Up @@ -440,7 +440,7 @@ static void leavedos_thr(void *arg)
}

/* "graceful" shutdown */
void __leavedos(int sig, const char *s, int num)
void __leavedos(int code, int sig, const char *s, int num)
{
int tmp;
dbug_printf("leavedos(%s:%i|%i) called - shutting down\n", s, num, sig);
Expand Down Expand Up @@ -482,10 +482,10 @@ void __leavedos(int sig, const char *s, int num)
/* vc switch may require vm86() so call it while waiting for thread */
coopth_join(ld_tid, vm86_helper);

leavedos_main(sig);
__leavedos_main(code, sig);
}

void leavedos_main(int sig)
void __leavedos_main(int code, int sig)
{
int i;

Expand Down Expand Up @@ -567,7 +567,7 @@ void leavedos_main(int sig)
flush_log();

/* We don't need to use _exit() here; this is the graceful exit path. */
exit(sig);
exit(sig ? sig + 128 : code);
}

void leavedos_from_thread(int code)
Expand Down
8 changes: 5 additions & 3 deletions src/include/emu.h
Expand Up @@ -377,8 +377,9 @@ extern int mfs_inte6(void);
extern int mfs_helper(struct vm86_regs *regs);
extern void pkt_helper(void);
extern short pop_word(struct vm86_regs *);
extern void __leavedos(int sig, const char *s, int num);
#define leavedos(n) __leavedos(n, __func__, __LINE__)
extern void __leavedos(int code, int sig, const char *s, int num);
#define leavedos(n) __leavedos(n, 0, __func__, __LINE__)
#define _leavedos_sig(s) __leavedos(0, s, __func__, __LINE__)
#define leavedos_once(n) { \
static int __left; \
if (!__left) { \
Expand All @@ -388,7 +389,8 @@ extern void __leavedos(int sig, const char *s, int num);
}
extern void leavedos_from_sig(int sig);
extern void leavedos_from_thread(int code);
extern void leavedos_main(int sig);
#define leavedos_main(n) __leavedos_main(n, 0)
extern void __leavedos_main(int code, int sig);
extern void check_leavedos(void);
extern void add_to_io_select_new(int, void(*)(void *), void *,
const char *name);
Expand Down

0 comments on commit 921f66c

Please sign in to comment.