From 121f0a7775dc6df72896104cd8357ad3cd3323b6 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 19 Dec 2009 03:57:22 +0000 Subject: Improve message telling how process died git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1063 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libsystem.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/libsystem.c b/lib/libsystem.c index 64ebc46a..1f697c7d 100644 --- a/lib/libsystem.c +++ b/lib/libsystem.c @@ -184,14 +184,103 @@ spawnProcessor(const char * const progName, } + +static const char * +signalName(unsigned int const signalClass) { + + if (signalClass <= SIGSYS) { + switch (signalClass) { + case SIGHUP: + return "SIGHUP"; + case SIGINT: + return "SIGINT"; + case SIGQUIT: + return "SIGQUIT"; + case SIGILL: + return "SIGILL"; + case SIGTRAP: + return "SIGTRAP"; + case SIGABRT: + return "SIGABRT"; + case SIGBUS: + return "SIGBUS"; + case SIGFPE: + return "SIGFPE"; + case SIGKILL: + return "SIGKILL"; + case SIGUSR1: + return "SIGUSR1"; + case SIGSEGV: + return "SIGSEGV"; + case SIGUSR2: + return "SIGUSR2"; + case SIGPIPE: + return "SIGPIPE"; + case SIGALRM: + return "SIGALRM"; + case SIGTERM: + return "SIGTERM"; + case SIGCHLD: + return "SIGCHLD"; + case SIGCONT: + return "SIGCONT"; + case SIGSTOP: + return "SIGSTOP"; + case SIGTSTP: + return "SIGTSTP"; + case SIGTTIN: + return "SIGTTIN"; + case SIGTTOU: + return "SIGTTOU"; + case SIGURG: + return "SIGURG"; + case SIGXCPU: + return "SIGXCPU"; + case SIGXFSZ: + return "SIGXFSZ"; + case SIGVTALRM: + return "SIGVTALRM"; + case SIGPROF: + return "SIGPROF"; + case SIGWINCH: + return "SIGWINCH"; + case SIGIO: + return "SIGIO"; + case SIGPWR: + return "SIGPWR"; + case SIGSYS: + return "SIGSYS"; + default: + return "???"; + } + } else if ((int)signalClass >= SIGRTMIN && (int)signalClass <= SIGRTMAX) + return "SIGRTxxx"; + else + return "???"; +} + + + static void cleanupProcessorProcess(pid_t const processorPid) { - int status; - waitpid(processorPid, &status, 0); - if (status != 0) - pm_message("Shell process ended abnormally. " - "completion code = %d", status); + int terminationStatus; + waitpid(processorPid, &terminationStatus, 0); + + if (WIFEXITED(terminationStatus)) { + int const exitStatus = WEXITSTATUS(terminationStatus); + + if (exitStatus != 0) + pm_message("Shell process exited with abnormal exist status %u. ", + exitStatus); + } else if (WIFSIGNALED(terminationStatus)) { + pm_message("Shell process was killed by a Class %u (%s) signal.", + WTERMSIG(terminationStatus), + signalName(WTERMSIG(terminationStatus))); + } else { + pm_message("Shell process died, but its termination status " + "0x%x doesn't make sense", terminationStatus); + } } -- cgit 1.4.1