20 static void check_exec(
const char *dir,
const char *program,
bool check_version);
23 static int win32_check_directory_write_permissions(
void);
45 if ((
output = popen(cmd,
"r")) == NULL ||
46 fgets(cmd_output,
sizeof(cmd_output),
output) == NULL)
47 pg_fatal(
"could not get pg_ctl version data using %s: %m", cmd);
51 pg_fatal(
"could not get pg_ctl version data using %s: %s",
54 if (sscanf(cmd_output,
"%*s %*s %d.%d", &v1, &v2) < 1)
55 pg_fatal(
"could not get pg_ctl version output from %s", cmd);
60 cluster->bin_version = v1 * 10000 + v2 * 100;
65 cluster->bin_version = v1 * 10000;
85 exec_prog(
const char *log_filename,
const char *opt_log_file,
86 bool report_error,
bool exit_on_error,
const char *
fmt,...)
92 #define MAXCMDLEN (2 * MAXPGPATH)
98 static DWORD mainThreadId = 0;
101 if (mainThreadId == 0)
102 mainThreadId = GetCurrentThreadId();
131 if (mainThreadId != GetCurrentThreadId())
134 result = system(cmd);
151 for (iter = 0; iter < 4 && log == NULL; iter++)
164 if (mainThreadId == GetCurrentThreadId())
167 fprintf(log,
"command: %s\n", cmd);
170 if (mainThreadId != GetCurrentThreadId())
182 if (mainThreadId == GetCurrentThreadId())
186 result = system(cmd);
189 if (result != 0 && report_error)
198 "Consult the last few lines of \"%s\" or \"%s\" for\n"
199 "the probable cause of the failure.",
203 "Consult the last few lines of \"%s\" for\n"
204 "the probable cause of the failure.",
217 if ((log = fopen(
log_file,
"a")) == NULL)
240 if ((
fd = open(path, O_RDONLY, 0)) < 0)
243 if (errno != ENOENT && errno != ENOTDIR)
244 pg_fatal(
"could not open file \"%s\" for reading: %m", path);
266 if (
access(
".", R_OK | W_OK | X_OK) != 0)
268 if (win32_check_directory_write_permissions() != 0)
270 pg_fatal(
"You must have read and write access in the current directory.");
288 win32_check_directory_write_permissions(
void)
322 if (
stat(subDirName, &statBuf) != 0)
429 check_exec(
const char *dir,
const char *program,
bool check_version)
434 char versionstr[128];
436 snprintf(path,
sizeof(path),
"%s/%s", dir, program);
439 pg_fatal(
"check for \"%s\" failed: %m", path);
441 snprintf(cmd,
sizeof(cmd),
"\"%s\" -V", path);
444 pg_fatal(
"check for \"%s\" failed: cannot execute",
451 snprintf(versionstr,
sizeof(versionstr),
"%s (PostgreSQL) " PG_VERSION, program);
453 if (strcmp(line, versionstr) != 0)
454 pg_fatal(
"check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"",
455 path, line, versionstr);
bool exec_prog(const char *log_filename, const char *opt_log_file, bool report_error, bool exit_on_error, const char *fmt,...)
static void check_exec(const char *dir, const char *program, bool check_version)
bool pid_lock_file_exists(const char *datadir)
static void check_single_dir(const char *pg_data, const char *subdir)
static void check_bin_dir(ClusterInfo *cluster, bool check_versions)
static void check_data_dir(ClusterInfo *cluster)
void verify_directories(void)
static void get_bin_version(ClusterInfo *cluster)
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
char * pipe_read_line(char *cmd)
int validate_exec(const char *path)
static void const char * fmt
static void const char fflush(stdout)
#define GLOBALS_DUMP_FILE
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
#define GET_MAJOR_VERSION(v)
uint32 get_major_server_version(ClusterInfo *cluster)
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2
static int fd(const char *x, int i)
void pg_usleep(long microsec)
int pg_strip_crlf(char *str)
char * wait_result_to_str(int exitstatus)