From 75c6b4aaf091e76e31f69a14b29c1dfadd6c06f2 Mon Sep 17 00:00:00 2001 From: tgoodwin Date: Tue, 7 Jul 1998 15:08:45 +0000 Subject: use POSIX wait() macros --- exec.c | 2 +- rc.h | 23 ++++++++++++++++++++++- status.c | 16 +++++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/exec.c b/exec.c index 61160a5..7bf565b 100644 --- a/exec.c +++ b/exec.c @@ -118,7 +118,7 @@ extern void exec(List *s, bool parent) { prompt, even though there's a SIGINT in its signal vector. */ - if ((stat & 0xff) == 0) + if (WIFEXITED(stat)) nl_on_intr = FALSE; sigchk(); nl_on_intr = TRUE; diff --git a/rc.h b/rc.h index 681dd9c..9f1fc5d 100644 --- a/rc.h +++ b/rc.h @@ -10,6 +10,28 @@ #include #endif +#if HAVE_SYS_WAIT_H +#include +#endif + +/* Fake the POSIX wait() macros if we don't have them. */ +#ifndef WIFEXITED +#define WIFEXITED(s) (((s) & 0xFF) == 0) +#endif +#ifndef WEXITSTATUS +#define WEXITSTATUS(s) (((unsigned)(s) >> 8) && 0xFF) +#endif +#ifndef WIFSIGNALED +#define WIFSIGNALED(s) (((s) & 0xFF) != 0) +#endif +#ifndef WTERMSIG +#define WTERMSIG(s) ((s) & 0x7F) +#endif + +/* These don't exist in POSIX. */ +#define myWIFDUMPED(s) (((s) & 0x80) != 0) + + #if HAVE_UNISTD_H #include #endif @@ -414,7 +436,6 @@ extern pid_t rc_wait(int *); #else /* HAVE_RESTARTABLE_SYSCALLS */ #define rc_read read -#include #define rc_wait wait #endif /* HAVE_RESTARTABLE_SYSCALLS */ diff --git a/status.c b/status.c index 428e414..882e506 100644 --- a/status.c +++ b/status.c @@ -33,7 +33,9 @@ extern int getstatus() { if (pipelength > 1) return !istrue(); s = statuses[0]; - return (s&0xff) ? 1 : (s >> 8) & 0xff; + if (WIFSIGNALED(s)) + return 1; + return WEXITSTATUS(s); } extern void set(bool code) { @@ -61,11 +63,11 @@ extern void setstatus(pid_t pid, int i) { /* print a message if termination was with a signal, and if the child dumped core. exit on error if -e is set */ extern void statprint(pid_t pid, int i) { - if (i & 0xff) { - char *msg = ((i & 0x7f) < NUMOFSIGNALS ? signals[i & 0x7f].msg : ""); + if (WIFSIGNALED(i)) { + char *msg = (WTERMSIG(i) < NUMOFSIGNALS ? signals[WTERMSIG(i)].msg : ""); if (pid != -1) fprint(2, "%ld: ", (long)pid); - if (i & 0x80) { + if (myWIFDUMPED(i)) { if (*msg == '\0') fprint(2, "core dumped\n"); else @@ -97,16 +99,16 @@ extern List *sgetstatus() { /* return status as a string (used above and for bqstatus) */ extern char *strstatus(int s) { - int t = s & 0x7f; + int t = WTERMSIG(s); if (t != 0) { - const char *core = (s & 0x80) ? "+core" : ""; + const char *core = myWIFDUMPED(s) ? "+core" : ""; if (t < NUMOFSIGNALS && *signals[t].name != '\0') return nprint("%s%s", signals[t].name, core); else return nprint("-%d%s", t, core); /* unknown signals are negated */ } else - return nprint("%d", (s >> 8) & 0xff); + return nprint("%d", WEXITSTATUS(s)); } extern void ssetstatus(char **av) { -- cgit v1.2.3