1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

psql: set SHELL_ERROR and SHELL_EXIT_CODE in more places.

Make the \g, \o, \w, and \copy commands set these variables
when closing a pipe.  We missed doing this in commit b0d8f2d98,
but it seems like a good idea.

There are some remaining places in psql that intentionally don't
update these variables after running a child program:
	* pager invocations
	* backtick evaluation within a prompt
	* \e (edit query buffer)

Corey Huinker and Tom Lane

Discussion: https://postgr.es/m/CADkLM=eSKwRGF-rnRqhtBORRtL49QsjcVUCa-kLxKTqxypsakw@mail.gmail.com
This commit is contained in:
Tom Lane
2023-04-06 17:33:38 -04:00
parent 029dea882a
commit 31ae2aa9d2
6 changed files with 44 additions and 27 deletions

View File

@ -2734,6 +2734,7 @@ exec_command_write(PsqlScanState scan_state, bool active_branch,
pg_log_error("%s: %s", fname, wait_result_to_str(result));
status = PSQL_CMD_ERROR;
}
SetShellResultVariables(result);
}
else
{
@ -5119,20 +5120,7 @@ do_shell(const char *command)
else
result = system(command);
if (result == 0)
{
SetVariable(pset.vars, "SHELL_EXIT_CODE", "0");
SetVariable(pset.vars, "SHELL_ERROR", "false");
}
else
{
int exit_code = wait_result_to_exit_code(result);
char buf[32];
snprintf(buf, sizeof(buf), "%d", exit_code);
SetVariable(pset.vars, "SHELL_EXIT_CODE", buf);
SetVariable(pset.vars, "SHELL_ERROR", "true");
}
SetShellResultVariables(result);
if (result == 127 || result == -1)
{