Thread: Solaris - psql returns 0 instead of 1 for file not found.
Hi all,
I've found the when psql is used with the -f flag and the specified file doesn't exist the rc value is 0.
$ uname -a
SunOS bld 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-V440
$ psql -V
psql (PostgreSQL) 8.0.2
$ ls foo
foo: No such file or directory
$ psql -f foo
foo: No such file or directory
$ echo $?
0
However, in the man page for psql it says:
EXIT STATUS
psql returns 0 to the shell if it finished normally, 1 if a
fatal error of its own (out of memory, file not found)
occurs, ...
I'm assuming this is the same with other platforms, but I only use PostgreSQL on Solaris.
Has this been fix in 8.0.3?
Cheers,
Andrew
I have applied the following patch to 8.1beta and 8.0.X to return the proper failure value for a psql -f filename open failure. The bug was that process_file() was returning false for failure, while the call site expected MainLoop() return values, meaning false/0 was success. --------------------------------------------------------------------------- Clark, Andrew wrote: > Hi all, > > I've found the when psql is used with the -f flag and the specified file > doesn't exist the rc value is 0. > > $ uname -a > SunOS bld 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-V440 > > $ psql -V > psql (PostgreSQL) 8.0.2 > > $ ls foo > foo: No such file or directory > > $ psql -f foo > foo: No such file or directory > > $ echo $? > 0 > > However, in the man page for psql it says: > > EXIT STATUS > psql returns 0 to the shell if it finished normally, 1 if a > fatal error of its own (out of memory, file not found) > occurs, ... > > I'm assuming this is the same with other platforms, but I only use > PostgreSQL on Solaris. > > Has this been fix in 8.0.3? > > Cheers, > Andrew -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 Index: src/bin/psql/command.c =================================================================== RCS file: /cvsroot/pgsql/src/bin/psql/command.c,v retrieving revision 1.152 diff -c -c -r1.152 command.c *** src/bin/psql/command.c 14 Aug 2005 18:49:30 -0000 1.152 --- src/bin/psql/command.c 20 Sep 2005 18:43:41 -0000 *************** *** 1314,1320 **** * process_file * * Read commands from filename and then them to the main processing loop ! * Handler for \i, but can be used for other things as well. */ int process_file(char *filename) --- 1314,1321 ---- * process_file * * Read commands from filename and then them to the main processing loop ! * Handler for \i, but can be used for other things as well. Returns ! * MainLoop() error code. */ int process_file(char *filename) *************** *** 1324,1330 **** char *oldfilename; if (!filename) ! return false; canonicalize_path(filename); fd = fopen(filename, PG_BINARY_R); --- 1325,1331 ---- char *oldfilename; if (!filename) ! return EXIT_FAILURE; canonicalize_path(filename); fd = fopen(filename, PG_BINARY_R); *************** *** 1332,1338 **** if (!fd) { psql_error("%s: %s\n", filename, strerror(errno)); ! return false; } oldfilename = pset.inputfile; --- 1333,1339 ---- if (!fd) { psql_error("%s: %s\n", filename, strerror(errno)); ! return EXIT_FAILURE; } oldfilename = pset.inputfile; Index: src/bin/psql/startup.c =================================================================== RCS file: /cvsroot/pgsql/src/bin/psql/startup.c,v retrieving revision 1.122 diff -c -c -r1.122 startup.c *** src/bin/psql/startup.c 5 Sep 2005 18:05:13 -0000 1.122 --- src/bin/psql/startup.c 20 Sep 2005 18:43:41 -0000 *************** *** 690,698 **** sprintf(psqlrc, "%s-%s", filename, PG_VERSION); if (access(psqlrc, R_OK) == 0) ! process_file(psqlrc); else if (access(filename, R_OK) == 0) ! process_file(filename); free(psqlrc); } --- 690,698 ---- sprintf(psqlrc, "%s-%s", filename, PG_VERSION); if (access(psqlrc, R_OK) == 0) ! (void)process_file(psqlrc); else if (access(filename, R_OK) == 0) ! (void)process_file(filename); free(psqlrc); }
On Monday 19 September 2005 14:01, Clark, Andrew wrote: > Hi all, > > I've found the when psql is used with the -f flag and the specified file > doesn't exist the rc value is 0. > > $ uname -a > SunOS bld 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-V440 > > $ psql -V > psql (PostgreSQL) 8.0.2 > > $ ls foo > foo: No such file or directory > > $ psql -f foo > foo: No such file or directory > > $ echo $? > 0 > > However, in the man page for psql it says: > > EXIT STATUS > psql returns 0 to the shell if it finished normally, 1 if a > fatal error of its own (out of memory, file not found) > occurs, ... > > I'm assuming this is the same with other platforms, but I only use > PostgreSQL on Solaris. > > Has this been fix in 8.0.3? > Redirecting to -bugs since I've confirmed this behavior on Slackware Linux 10 with psql version 8.1beta1 and there does seem to be something wrong with the above situation (perhaps the man page needs to be reworded?) -- Robert Treat Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
A patch has been applied and this will be fixed in 8.0.4 and 8.1beta3. --------------------------------------------------------------------------- Robert Treat wrote: > On Monday 19 September 2005 14:01, Clark, Andrew wrote: > > Hi all, > > > > I've found the when psql is used with the -f flag and the specified file > > doesn't exist the rc value is 0. > > > > $ uname -a > > SunOS bld 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Fire-V440 > > > > $ psql -V > > psql (PostgreSQL) 8.0.2 > > > > $ ls foo > > foo: No such file or directory > > > > $ psql -f foo > > foo: No such file or directory > > > > $ echo $? > > 0 > > > > However, in the man page for psql it says: > > > > EXIT STATUS > > psql returns 0 to the shell if it finished normally, 1 if a > > fatal error of its own (out of memory, file not found) > > occurs, ... > > > > I'm assuming this is the same with other platforms, but I only use > > PostgreSQL on Solaris. > > > > Has this been fix in 8.0.3? > > > > Redirecting to -bugs since I've confirmed this behavior on Slackware Linux 10 > with psql version 8.1beta1 and there does seem to be something wrong with the > above situation (perhaps the man page needs to be reworded?) > > -- > Robert Treat > Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073