bool LocalSlaveProcess::DecodeExitCode(int status) { if(WIFEXITED(status)) { exit_code = (byte)WEXITSTATUS(status); return true; } else if(WIFSIGNALED(status) || WIFSTOPPED(status)) { static const struct { const char *name; int code; } signal_map[] = { #define SIGDEF(s) { #s, s }, SIGDEF(SIGHUP) SIGDEF(SIGINT) SIGDEF(SIGQUIT) SIGDEF(SIGILL) SIGDEF(SIGABRT) SIGDEF(SIGFPE) SIGDEF(SIGKILL) SIGDEF(SIGSEGV) SIGDEF(SIGPIPE) SIGDEF(SIGALRM) SIGDEF(SIGPIPE) SIGDEF(SIGTERM) SIGDEF(SIGUSR1) SIGDEF(SIGUSR2) SIGDEF(SIGTRAP) SIGDEF(SIGURG) SIGDEF(SIGVTALRM) SIGDEF(SIGXCPU) SIGDEF(SIGXFSZ) SIGDEF(SIGIOT) SIGDEF(SIGIO) SIGDEF(SIGWINCH) #ifndef PLATFORM_BSD //SIGDEF(SIGCLD) SIGDEF(SIGPWR) #endif //SIGDEF(SIGSTKFLT) SIGDEF(SIGUNUSED) // not in Solaris, make conditional if needed #undef SIGDEF }; int sig = (WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status)); exit_code = (WIFSIGNALED(status) ? 1000 : 2000) + sig; exit_string << "\nProcess " << (WIFSIGNALED(status) ? "terminated" : "stopped") << " on signal " << sig; for(int i = 0; i < __countof(signal_map); i++) if(signal_map[i].code == sig) { exit_string << " (" << signal_map[i].name << ")"; break; } exit_string << "\n"; return true; } return false; }
#define SIGDEF_ERROR 2 /* Gauche installs a default signal handler that raises an error. */ #define SIGDEF_EXIT 3 /* Gauche installs a handler that calls Scm_Exit(). */ #define SIGDEF_INDIFFERENT 4 /* Gauche installs a handler that does nothing. */ #define SIGDEF(x, flag) { #x, x, flag } static struct sigdesc { const char *name; int num; int defaultHandle; } sigDesc[] = { #ifdef SIGHUP SIGDEF(SIGHUP, SIGDEF_EXIT), /* Hangup (POSIX) */ #endif SIGDEF(SIGINT, SIGDEF_ERROR), /* Interrupt (ANSI) */ #ifdef SIGQUIT SIGDEF(SIGQUIT, SIGDEF_EXIT), /* Quit (POSIX) */ #endif SIGDEF(SIGILL, SIGDEF_NOHANDLE), /* Illegal instruction (ANSI) */ #ifdef SIGTRAP SIGDEF(SIGTRAP, SIGDEF_ERROR), /* Trace trap */ #endif SIGDEF(SIGABRT, SIGDEF_NOHANDLE), /* Abort (ANSI) */ #ifdef SIGIOT SIGDEF(SIGIOT, SIGDEF_ERROR), /* IOT trap (4.2 BSD) */ #endif #ifdef SIGBUS SIGDEF(SIGBUS, SIGDEF_NOHANDLE), /* BUS error (4.2 BSD) */