original) (raw)
PostgreSQL Source Code: src/common/exec.c File Reference (#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <signal.h>
#include <sys/stat.h>
#include <[sys/wait.h](wait%5F8h%5Fsource.html)>
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include "[common/string.h](string%5F8h%5Fsource.html)"
Go to the source code of this file.
Functions | |
---|---|
static int | normalize_exec_path (char *path) |
static char * | pg_realpath (const char *fname) |
int | validate_exec (const char *path) |
int | find_my_exec (const char *argv0, char *retpath) |
int | find_other_exec (const char *argv0, const char *target, const char *versionstr, char *retpath) |
char * | pipe_read_line (char *cmd) |
int | pclose_check (FILE *stream) |
void | set_pglocale_pgservice (const char *argv0, const char *app) |
◆ _DARWIN_BETTER_REALPATH
#define _DARWIN_BETTER_REALPATH
Definition at line 24 of file exec.c.
◆ log_error
◆ find_my_exec()
int find_my_exec | ( | const char * | argv0, |
---|---|---|---|
char * | retpath | ||
) |
Definition at line 160 of file exec.c.
161{
162 char *path;
163
164
165
166
169 {
172
174 _("invalid binary \"%s\": %m"), retpath);
175 return -1;
176 }
177
178#ifdef WIN32
179
182#endif
183
184
185
186
187
188 if ((path = getenv("PATH")) && *path)
189 {
190 char *startp = NULL,
191 *endp = NULL;
192
193 do
194 {
195 if (!startp)
196 startp = path;
197 else
198 startp = endp + 1;
199
201 if (!endp)
202 endp = startp + strlen(startp);
203
205
208
210 {
211 case 0:
213 case -1:
214 break;
215 case -2:
217 _("could not read binary \"%s\": %m"),
218 retpath);
219 break;
220 }
221 } while (*endp);
222 }
223
225 _("could not find a \"%s\" to execute"), argv0);
226 return -1;
227}
#define log_error(errcodefn,...)
int validate_exec(const char *path)
static int normalize_exec_path(char *path)
int errcode(int sqlerrcode)
void join_path_components(char *ret_path, const char *head, const char *tail)
char * first_path_var_separator(const char *pathlist)
void canonicalize_path(char *path)
char * first_dir_separator(const char *filename)
size_t strlcpy(char *dst, const char *src, size_t siz)
References _, argv0, canonicalize_path(), errcode(), first_dir_separator(), first_path_var_separator(), join_path_components(), log_error, MAXPGPATH, Min, normalize_exec_path(), strlcpy(), and validate_exec().
Referenced by ensureCleanShutdown(), find_other_exec(), find_other_exec_or_die(), get_exec_path(), getInstallationPaths(), getRestoreCommand(), InitStandaloneProcess(), main(), process_psqlrc(), set_pglocale_pgservice(), setup(), and setup_bin_paths().
◆ find_other_exec()
int find_other_exec | ( | const char * | argv0, |
---|---|---|---|
const char * | target, | ||
const char * | versionstr, | ||
char * | retpath | ||
) |
Definition at line 310 of file exec.c.
312{
314 char *line;
315
317 return -1;
318
319
322
323
325 "/%s%s", target, EXE);
326
328 return -1;
329
330 snprintf(cmd, sizeof(cmd), "\"%s\" -V", retpath);
331
333 return -1;
334
335 if (strcmp(line, versionstr) != 0)
336 {
338 return -2;
339 }
340
342 return 0;
343}
int find_my_exec(const char *argv0, char *retpath)
char * pipe_read_line(char *cmd)
void pfree(void *pointer)
char * last_dir_separator(const char *filename)
References argv0, canonicalize_path(), EXE, find_my_exec(), last_dir_separator(), MAXPGPATH, pfree(), pipe_read_line(), snprintf, and validate_exec().
Referenced by ensureCleanShutdown(), find_other_exec_or_die(), get_exec_path(), getInstallationPaths(), getRestoreCommand(), isolation_start_test(), main(), and setup_bin_paths().
◆ normalize_exec_path()
static int normalize_exec_path ( char * path) | static |
---|
◆ pclose_check()
int pclose_check | ( | FILE * | stream | ) |
---|
Definition at line 391 of file exec.c.
392{
393 int exitstatus;
394 char *reason;
395
396 exitstatus = pclose(stream);
397
398 if (exitstatus == 0)
399 return 0;
400
401 if (exitstatus == -1)
402 {
403
405 _("%s() failed: %m"), "pclose");
406 }
407 else
408 {
411 "%s", reason);
413 }
414 return exitstatus;
415}
char * wait_result_to_str(int exitstatus)
References _, errcode(), log_error, pfree(), and wait_result_to_str().
Referenced by pipe_read_line().
◆ pg_realpath()
static char * pg_realpath ( const char * fname) | static |
---|
Definition at line 282 of file exec.c.
283{
284 char *path;
285
286#ifndef WIN32
287 path = realpath(fname, NULL);
288#else
289
290
291
292
293
294
295
296
297 errno = 0;
298 path = _fullpath(NULL, fname, 0);
299#endif
300
301 return path;
302}
Referenced by normalize_exec_path().
◆ pipe_read_line()
char * pipe_read_line | ( | char * | cmd | ) |
---|
Definition at line 352 of file exec.c.
353{
354 FILE *pipe_cmd;
355 char *line;
356
357 fflush(NULL);
358
359 errno = 0;
360 if ((pipe_cmd = popen(cmd, "r")) == NULL)
361 {
363 _("could not execute command \"%s\": %m"), cmd);
364 return NULL;
365 }
366
367
368 errno = 0;
370
371 if (line == NULL)
372 {
373 if (ferror(pipe_cmd))
375 _("could not read from command \"%s\": %m"), cmd);
376 else
378 _("no data was returned by command \"%s\""), cmd);
379 }
380
382
383 return line;
384}
int pclose_check(FILE *stream)
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
References _, errcode(), errcode_for_file_access(), log_error, pclose_check(), and pg_get_line().
Referenced by check_exec(), find_other_exec(), and getRestoreCommand().
◆ set_pglocale_pgservice()
void set_pglocale_pgservice | ( | const char * | argv0, |
---|---|---|---|
const char * | app | ||
) |
Definition at line 429 of file exec.c.
430{
433
434
436 {
438
439
440
441
442
443
444
445
446
447
448 }
449
451 return;
452
453#ifdef ENABLE_NLS
455 bindtextdomain(app, path);
456 textdomain(app);
457
458 setenv("PGLOCALEDIR", path, 0);
459#endif
460
461 if (getenv("PGSYSCONFDIR") == NULL)
462 {
464
465 setenv("PGSYSCONFDIR", path, 0);
466 }
467}
#define PG_TEXTDOMAIN(domain)
char my_exec_path[MAXPGPATH]
void get_locale_path(const char *my_exec_path, char *ret_path)
void get_etc_path(const char *my_exec_path, char *ret_path)
References argv0, find_my_exec(), get_etc_path(), get_locale_path(), MAXPGPATH, my_exec_path, PG_TEXTDOMAIN, setenv, and setlocale.
Referenced by main(), and regression_main().
◆ validate_exec()
int validate_exec | ( | const char * | path | ) |
---|
Definition at line 88 of file exec.c.
89{
91 int is_r;
92 int is_x;
93
94#ifdef WIN32
95 char path_exe[MAXPGPATH + sizeof(".exe") - 1];
96
97
98 if (strlen(path) < strlen(".exe") ||
99 pg_strcasecmp(path + strlen(path) - strlen(".exe"), ".exe") != 0)
100 {
101 strlcpy(path_exe, path, sizeof(path_exe) - 4);
102 strcat(path_exe, ".exe");
103 path = path_exe;
104 }
105#endif
106
107
108
109
110
111
112
114 return -1;
115
117 {
118
119
120
121
122
123
124 errno = S_ISDIR(buf.st_mode) ? EISDIR : EPERM;
125 return -1;
126 }
127
128
129
130
131
132#ifndef WIN32
133 is_r = (access(path, R_OK) == 0);
134 is_x = (access(path, X_OK) == 0);
135
136#else
139 errno = EACCES;
140#endif
141 return is_x ? (is_r ? 0 : -2) : -1;
142}
int pg_strcasecmp(const char *s1, const char *s2)
References buf, MAXPGPATH, pg_strcasecmp(), S_IRUSR, S_ISDIR, S_ISREG, S_IXUSR, stat, and strlcpy().
Referenced by check_exec(), find_my_exec(), and find_other_exec().