1 /*-------------------------------------------------------------------------
4 * Convert a wait/waitpid(2) result code to a human-readable string
7 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 * src/common/wait_error.c
14 *-------------------------------------------------------------------------
20 #include "postgres_fe.h"
27 * Return a human-readable string explaining the reason a child process
28 * terminated. The argument is a return code returned by wait(2) or
29 * waitpid(2). The result is a translated, palloc'd or malloc'd string.
32 wait_result_to_str(int exitstatus)
36 if (WIFEXITED(exitstatus))
39 * Give more specific error message for some common exit codes that
40 * have a special meaning in shells.
42 switch (WEXITSTATUS(exitstatus))
45 snprintf(str, sizeof(str), _("command not executable"));
49 snprintf(str, sizeof(str), _("command not found"));
53 snprintf(str, sizeof(str),
54 _("child process exited with exit code %d"),
55 WEXITSTATUS(exitstatus));
58 else if (WIFSIGNALED(exitstatus))
60 snprintf(str, sizeof(str),
61 _("child process was terminated by exception 0x%X"),
62 WTERMSIG(exitstatus));
63 #elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
67 snprintf(str2, sizeof(str2), "%d: %s", WTERMSIG(exitstatus),
68 WTERMSIG(exitstatus) < NSIG ?
69 sys_siglist[WTERMSIG(exitstatus)] : "(unknown)");
70 snprintf(str, sizeof(str),
71 _("child process was terminated by signal %s"), str2);
74 snprintf(str, sizeof(str),
75 _("child process was terminated by signal %d"),
76 WTERMSIG(exitstatus));
79 snprintf(str, sizeof(str),
80 _("child process exited with unrecognized status %d"),