PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
wait_error.c File Reference
#include "postgres.h"
#include <signal.h>
#include <sys/wait.h>
Include dependency graph for wait_error.c:

Go to the source code of this file.

Functions

char * wait_result_to_str (int exitstatus)
 

Function Documentation

char* wait_result_to_str ( int  exitstatus)

Definition at line 32 of file wait_error.c.

References _, pstrdup(), snprintf(), WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.

Referenced by ClosePipeToProgram(), do_copy(), ExecuteRecoveryCommand(), pclose_check(), and RestoreArchivedFile().

33 {
34  char str[512];
35 
36  if (WIFEXITED(exitstatus))
37  {
38  /*
39  * Give more specific error message for some common exit codes that
40  * have a special meaning in shells.
41  */
42  switch (WEXITSTATUS(exitstatus))
43  {
44  case 126:
45  snprintf(str, sizeof(str), _("command not executable"));
46  break;
47 
48  case 127:
49  snprintf(str, sizeof(str), _("command not found"));
50  break;
51 
52  default:
53  snprintf(str, sizeof(str),
54  _("child process exited with exit code %d"),
55  WEXITSTATUS(exitstatus));
56  }
57  }
58  else if (WIFSIGNALED(exitstatus))
59 #if defined(WIN32)
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
64  {
65  char str2[256];
66 
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);
72  }
73 #else
74  snprintf(str, sizeof(str),
75  _("child process was terminated by signal %d"),
76  WTERMSIG(exitstatus));
77 #endif
78  else
79  snprintf(str, sizeof(str),
80  _("child process exited with unrecognized status %d"),
81  exitstatus);
82 
83  return pstrdup(str);
84 }
char * pstrdup(const char *in)
Definition: mcxt.c:1076
#define WIFEXITED(w)
Definition: win32.h:172
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define WIFSIGNALED(w)
Definition: win32.h:173
#define WEXITSTATUS(w)
Definition: win32.h:174
#define WTERMSIG(w)
Definition: win32.h:175
#define _(x)
Definition: elog.c:84