2 * UCW Library -- Formatting of Process Exit Status
4 * (c) 2004--2012 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/process.h>
12 #include <ucw/signames.h>
19 format_exit_status(char *msg, int stat)
22 sprintf(msg, "failed to fork (err=%d)", errno);
23 else if (WIFEXITED(stat) && WEXITSTATUS(stat) < 256)
25 if (WEXITSTATUS(stat))
26 sprintf(msg, "died with exit code %d", WEXITSTATUS(stat));
33 else if (WIFSIGNALED(stat))
35 int sig = WTERMSIG(stat);
36 const char *sn = sig_number_to_name(sig);
37 sprintf(msg, "died on signal %d (%s)", sig, (sn ? : "unknown"));
40 sprintf(msg, "died with status %x", stat);