PostgreSQL Source Code  git master
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)
 
bool wait_result_is_signal (int exit_status, int signum)
 
bool wait_result_is_any_signal (int exit_status, bool include_command_not_found)
 

Function Documentation

◆ wait_result_is_any_signal()

bool wait_result_is_any_signal ( int  exit_status,
bool  include_command_not_found 
)

Definition at line 111 of file wait_error.c.

References WEXITSTATUS, WIFEXITED, and WIFSIGNALED.

Referenced by ExecuteRecoveryCommand(), pgarch_archiveXlog(), and RestoreArchivedFile().

112 {
113  if (WIFSIGNALED(exit_status))
114  return true;
115  if (WIFEXITED(exit_status) &&
116  WEXITSTATUS(exit_status) > (include_command_not_found ? 125 : 128))
117  return true;
118  return false;
119 }
#define WIFEXITED(w)
Definition: win32_port.h:138
#define WIFSIGNALED(w)
Definition: win32_port.h:139
#define WEXITSTATUS(w)
Definition: win32_port.h:140

◆ wait_result_is_signal()

bool wait_result_is_signal ( int  exit_status,
int  signum 
)

Definition at line 92 of file wait_error.c.

References WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.

Referenced by ClosePipeToProgram(), and RestoreArchivedFile().

93 {
94  if (WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum)
95  return true;
96  if (WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == 128 + signum)
97  return true;
98  return false;
99 }
#define WTERMSIG(w)
Definition: win32_port.h:141
#define WIFEXITED(w)
Definition: win32_port.h:138
#define WIFSIGNALED(w)
Definition: win32_port.h:139
#define WEXITSTATUS(w)
Definition: win32_port.h:140

◆ wait_result_to_str()

char* wait_result_to_str ( int  exitstatus)

Definition at line 32 of file wait_error.c.

References _, pg_strsignal(), pstrdup(), snprintf, generate_unaccent_rules::str, WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.

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

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  {
60 #if defined(WIN32)
61  snprintf(str, sizeof(str),
62  _("child process was terminated by exception 0x%X"),
63  WTERMSIG(exitstatus));
64 #else
65  snprintf(str, sizeof(str),
66  _("child process was terminated by signal %d: %s"),
67  WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus)));
68 #endif
69  }
70  else
71  snprintf(str, sizeof(str),
72  _("child process exited with unrecognized status %d"),
73  exitstatus);
74 
75  return pstrdup(str);
76 }
#define WTERMSIG(w)
Definition: win32_port.h:141
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define WIFEXITED(w)
Definition: win32_port.h:138
const char * pg_strsignal(int signum)
Definition: pgstrsignal.c:42
#define WIFSIGNALED(w)
Definition: win32_port.h:139
#define snprintf
Definition: port.h:192
#define _(x)
Definition: elog.c:87
#define WEXITSTATUS(w)
Definition: win32_port.h:140