]> granicus.if.org Git - postgresql/blob - src/common/wait_error.c
Remove vestigial resolveUnknown arguments from transformSortClause etc.
[postgresql] / src / common / wait_error.c
1 /*-------------------------------------------------------------------------
2  *
3  * wait_error.c
4  *              Convert a wait/waitpid(2) result code to a human-readable string
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  *        src/common/wait_error.c
13  *
14  *-------------------------------------------------------------------------
15  */
16
17 #ifndef FRONTEND
18 #include "postgres.h"
19 #else
20 #include "postgres_fe.h"
21 #endif
22
23 #include <signal.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/wait.h>
27
28 /*
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.
32  */
33 char *
34 wait_result_to_str(int exitstatus)
35 {
36         char            str[512];
37
38         if (WIFEXITED(exitstatus))
39         {
40                 /*
41                  * Give more specific error message for some common exit codes that
42                  * have a special meaning in shells.
43                  */
44                 switch (WEXITSTATUS(exitstatus))
45                 {
46                         case 126:
47                                 snprintf(str, sizeof(str), _("command not executable"));
48                                 break;
49
50                         case 127:
51                                 snprintf(str, sizeof(str), _("command not found"));
52                                 break;
53
54                         default:
55                                 snprintf(str, sizeof(str),
56                                                  _("child process exited with exit code %d"),
57                                                  WEXITSTATUS(exitstatus));
58                 }
59         }
60         else if (WIFSIGNALED(exitstatus))
61 #if defined(WIN32)
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
66         {
67                 char            str2[256];
68
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);
74         }
75 #else
76                 snprintf(str, sizeof(str),
77                                  _("child process was terminated by signal %d"),
78                                  WTERMSIG(exitstatus));
79 #endif
80         else
81                 snprintf(str, sizeof(str),
82                                  _("child process exited with unrecognized status %d"),
83                                  exitstatus);
84
85         return pstrdup(str);
86 }