1 /*-------------------------------------------------------------------------
4 * Convert a wait/waitpid(2) result code to a human-readable string
7 * Portions Copyright (c) 1996-2017, 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"
29 * Return a human-readable string explaining the reason a child process
30 * terminated. The argument is a return code returned by wait(2) or
31 * waitpid(2). The result is a translated, palloc'd or malloc'd string.
34 wait_result_to_str(int exitstatus)
38 if (WIFEXITED(exitstatus))
41 * Give more specific error message for some common exit codes that
42 * have a special meaning in shells.
44 switch (WEXITSTATUS(exitstatus))
47 snprintf(str, sizeof(str), _("command not executable"));
51 snprintf(str, sizeof(str), _("command not found"));
55 snprintf(str, sizeof(str),
56 _("child process exited with exit code %d"),
57 WEXITSTATUS(exitstatus));
60 else if (WIFSIGNALED(exitstatus))
62 snprintf(str, sizeof(str),
63 _("child process was terminated by exception 0x%X"),
64 WTERMSIG(exitstatus));
65 #elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
69 snprintf(str2, sizeof(str2), "%d: %s", WTERMSIG(exitstatus),
70 WTERMSIG(exitstatus) < NSIG ?
71 sys_siglist[WTERMSIG(exitstatus)] : "(unknown)");
72 snprintf(str, sizeof(str),
73 _("child process was terminated by signal %s"), str2);
76 snprintf(str, sizeof(str),
77 _("child process was terminated by signal %d"),
78 WTERMSIG(exitstatus));
81 snprintf(str, sizeof(str),
82 _("child process exited with unrecognized status %d"),