Skip to content

Commit b3b8d5d

Browse files
committed
bugfix: do not use find_my_exec(), because it is relying on PATH, which can be unavailable. More details: #39
1 parent 16dca32 commit b3b8d5d

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

Diff for: src/pg_probackup.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#include "utils/thread.h"
2121
#include <time.h>
2222

23-
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
24-
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
25-
const char *PROGRAM_FULL_PATH = NULL;
23+
const char *PROGRAM_NAME = NULL;
24+
const char *PROGRAM_FULL_PATH = NULL;
25+
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
26+
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2627

2728
typedef enum ProbackupSubcmd
2829
{
@@ -245,13 +246,7 @@ main(int argc, char *argv[])
245246
PROGRAM_NAME = get_progname(argv[0]);
246247
PROGRAM_FULL_PATH = palloc0(MAXPGPATH);
247248

248-
if (find_my_exec(argv[0],(char *) PROGRAM_FULL_PATH) < 0)
249-
{
250-
fprintf(stderr, _("%s: could not find own program executable\n"), PROGRAM_NAME);
251-
exit(1);
252-
}
253-
254-
set_pglocale_pgservice(argv[0], "pgscripts");
249+
//set_pglocale_pgservice(argv[0], "pgscripts");
255250

256251
#if PG_VERSION_NUM >= 110000
257252
/*
@@ -514,6 +509,15 @@ main(int argc, char *argv[])
514509
command = NULL;
515510
}
516511

512+
/* For archive-push and archive-get skip full path lookup */
513+
if ((backup_subcmd != ARCHIVE_GET_CMD &&
514+
backup_subcmd != ARCHIVE_PUSH_CMD) &&
515+
(find_my_exec(argv[0],(char *) PROGRAM_FULL_PATH) < 0))
516+
{
517+
PROGRAM_FULL_PATH = NULL;
518+
elog(WARNING, "%s: could not find a full path to executable", PROGRAM_NAME);
519+
}
520+
517521
/*
518522
* We have read pgdata path from command line or from configuration file.
519523
* Ensure that pgdata is an absolute path.

Diff for: src/pg_probackup.h

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434

3535
#include "datapagemap.h"
3636

37+
/* pgut client variables and full path */
38+
extern const char *PROGRAM_NAME;
39+
extern const char *PROGRAM_FULL_PATH;
40+
extern const char *PROGRAM_URL;
41+
extern const char *PROGRAM_EMAIL;
42+
3743
/* Directory/File names */
3844
#define DATABASE_DIR "database"
3945
#define BACKUPS_DIR "backups"

Diff for: src/restore.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,8 @@ create_recovery_conf(time_t backup_id,
882882

883883
fio_fprintf(fp, "restore_command = '%s archive-get -B %s --instance %s "
884884
"--wal-file-path %%p --wal-file-name %%f'\n",
885-
PROGRAM_FULL_PATH, backup_path, instance_name);
885+
PROGRAM_FULL_PATH ? PROGRAM_FULL_PATH : PROGRAM_NAME,
886+
backup_path, instance_name);
886887

887888
/*
888889
* We've already checked that only one of the four following mutually

Diff for: src/utils/pgut.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*-------------------------------------------------------------------------
99
*/
1010

11+
#include "pg_probackup.h"
1112
#include "postgres_fe.h"
1213

1314
#include "getopt_long.h"
@@ -22,8 +23,6 @@
2223
#include "file.h"
2324

2425

25-
const char *PROGRAM_NAME = "pg_probackup";
26-
2726
static char *password = NULL;
2827
bool prompt_password = true;
2928
bool force_password = false;

Diff for: src/utils/pgut.h

-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616

1717
typedef void (*pgut_atexit_callback)(bool fatal, void *userdata);
1818

19-
/*
20-
* pgut client variables and functions
21-
*/
22-
extern const char *PROGRAM_NAME;
23-
extern const char *PROGRAM_FULL_PATH;
24-
extern const char *PROGRAM_VERSION;
25-
extern const char *PROGRAM_URL;
26-
extern const char *PROGRAM_EMAIL;
27-
2819
extern void pgut_help(bool details);
2920

3021
/*

0 commit comments

Comments
 (0)