Re: Add SHELL_EXIT_CODE to psql - Mailing list pgsql-hackers

From Maxim Orlov
Subject Re: Add SHELL_EXIT_CODE to psql
Date
Msg-id CACG=ezYNoeAbSHbLDuEHH7SkKnnF0AF4N5kGda8=G9QRBvfL0A@mail.gmail.com
Whole thread Raw
In response to Re: Add SHELL_EXIT_CODE to psql  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: Add SHELL_EXIT_CODE to psql  (Corey Huinker <corey.huinker@gmail.com>)
List pgsql-hackers
Hi!

The patch is implementing what is declared to do. Shell return code is now accessible is psql var.
Overall code is in a good condition. Applies with no errors on master.
Unfortunately, regression tests are failing on the macOS due to the different shell output.

@@ -1308,13 +1308,13 @@
 deallocate q;
 -- test SHELL_EXIT_CODE
 \! nosuchcommand
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \echo :SHELL_EXIT_CODE
 127
 \set nosuchvar `nosuchcommand`
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \! nosuchcommand
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \echo :SHELL_EXIT_CODE
 127

Since we do not want to test shell output in these cases, but only return code,
what about using this kind of commands?
postgres=# \! true > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
0
postgres=# \! false > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
1
postgres=# \! nosuchcommand > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
127

It is better to use spaces around "=".
+               if (WIFEXITED(exit_code))
+                       exit_code=WEXITSTATUS(exit_code);
+               else if(WIFSIGNALED(exit_code))
+                       exit_code=WTERMSIG(exit_code);
+               else if(WIFSTOPPED(exit_code))
+                       exit_code=WSTOPSIG(exit_code);

--
Best regards,
Maxim Orlov.

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Add BufFileRead variants with short read and EOF detection
Next
From: Michail Nikolaev
Date:
Subject: Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION