Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ ifeq ($(VALGRIND),)
BINPATH = ./src/bin/pg_autoctl/pg_autoctl
PG_AUTOCTL = PG_AUTOCTL_DEBUG=1 ./src/bin/pg_autoctl/pg_autoctl
else
BINPATH = ./src/tools/pg_autoctl.valgrind
PG_AUTOCTL = PG_AUTOCTL_DEBUG=1 ./src/tools/pg_autoctl.valgrind
BINPATH = $(abspath $(PWD))/src/tools/pg_autoctl.valgrind
PG_AUTOCTL = PG_AUTOCTL_DEBUG=1 PG_AUTOCTL_DEBUG_BIN_PATH="$(BINPATH)" ./src/tools/pg_autoctl.valgrind
endif


Expand Down
10 changes: 8 additions & 2 deletions src/bin/pg_autoctl/cli_do_tmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ prepare_tmux_script(TmuxOptions *options, PQExpBuffer script)
* tmux_start_server starts a tmux session with the given script.
*/
bool
tmux_start_server(const char *scriptName)
tmux_start_server(const char *scriptName, const char *binpath)
{
char *args[8];
int argsIndex = 0;
Expand All @@ -869,6 +869,12 @@ tmux_start_server(const char *scriptName)
return false;
}

if (binpath && setenv("PG_AUTOCTL_DEBUG_BIN_PATH", binpath, 1) != 0)
{
log_error("Failed to set environment PG_AUTOCTL_DEBUG_BIN_PATH: %m");
return false;
}

if (!search_path_first("tmux", tmux, LOG_ERROR))
{
log_fatal("Failed to find program tmux in PATH");
Expand Down Expand Up @@ -1358,7 +1364,7 @@ cli_do_tmux_session(int argc, char **argv)
/*
* Start a tmux session from the script.
*/
if (!tmux_start_server(scriptName))
if (!tmux_start_server(scriptName, options.binpath))
{
success = false;
log_fatal("Failed to start the tmux session, see above for details");
Expand Down
2 changes: 1 addition & 1 deletion src/bin/pg_autoctl/cli_do_tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void tmux_pg_autoctl_create_postgres(PQExpBuffer script,
int candidatePriority,
bool skipHBA);

bool tmux_start_server(const char *scriptName);
bool tmux_start_server(const char *scriptName, const char *binpath);
bool pg_autoctl_getpid(const char *pgdata, pid_t *pid);

bool tmux_has_session(const char *tmux_path, const char *sessionName);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/pg_autoctl/cli_do_tmux_azure.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ tmux_azure_start_or_attach_session(AzureRegionResources *azRegion)
return false;
}

if (!tmux_start_server(scriptName))
if (!tmux_start_server(scriptName, NULL))
{
log_fatal("Failed to start the tmux session, see above for details");
destroyPQExpBuffer(script);
Expand Down
17 changes: 13 additions & 4 deletions src/bin/pg_autoctl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,22 @@ main(int argc, char **argv)
* hard-coded LOG_INFO as our log level. For now we won't see the log_debug
* output, but as a developer you could always change the LOG_INFO to
* LOG_DEBUG above and then see the message.
*
* When running pg_autoctl using valgrind we also want the subprocesses to
* be run with valgrind. However, valgrind modifies the argv variables to
* be the pg_autoctl binary, instead of the valgrind binary. So to make
* sure subprocesses are spawned using valgrind, we allow overriding To
* this program path detection using the PG_AUTOCTL_DEBUG_BIN_PATH
* environment variable.
*/
strlcpy(pg_autoctl_argv0, argv[0], MAXPGPATH);

if (!set_program_absolute_path(pg_autoctl_program, MAXPGPATH))
if (!get_env_copy("PG_AUTOCTL_DEBUG_BIN_PATH", pg_autoctl_program, MAXPGPATH))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
if (!set_program_absolute_path(pg_autoctl_program, MAXPGPATH))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
}
}

if (!commandline_run(&command, argc, argv))
Expand Down