Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit871293f

Browse files
committed
vacuumdb: Check result status of PQsendQuery
Noticed by Coverity
1 parent4babae1 commit871293f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

‎src/bin/scripts/vacuumdb.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
484484
else
485485
free_slot=slots;
486486

487+
/*
488+
* Execute the vacuum. If not in parallel mode, this terminates the
489+
* program in case of an error. (The parallel case handles query
490+
* errors in GetQueryResult through GetIdleSlot.)
491+
*/
487492
run_vacuum_command(free_slot->connection,sql.data,
488493
echo,dbname,tabname,progname,parallel);
489494

@@ -661,21 +666,27 @@ prepare_vacuum_command(PQExpBuffer sql, PGconn *conn, vacuumingOptions *vacopts,
661666
/*
662667
* Execute a vacuum/analyze command to the server.
663668
*
664-
* Result status is checked only if 'async' is false.
669+
* Any errors during command execution are reported to stderr. If async is
670+
* false, this function exits the program after reporting the error.
665671
*/
666672
staticvoid
667673
run_vacuum_command(PGconn*conn,constchar*sql,boolecho,
668674
constchar*dbname,constchar*table,
669675
constchar*progname,boolasync)
670676
{
677+
boolstatus;
678+
671679
if (async)
672680
{
673681
if (echo)
674682
printf("%s\n",sql);
675683

676-
PQsendQuery(conn,sql);
684+
status=PQsendQuery(conn,sql)==1;
677685
}
678-
elseif (!executeMaintenanceCommand(conn,sql,echo))
686+
else
687+
status=executeMaintenanceCommand(conn,sql,echo);
688+
689+
if (!status)
679690
{
680691
if (table)
681692
fprintf(stderr,
@@ -684,8 +695,12 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo,
684695
else
685696
fprintf(stderr,_("%s: vacuuming of database \"%s\" failed: %s"),
686697
progname,dbname,PQerrorMessage(conn));
687-
PQfinish(conn);
688-
exit(1);
698+
699+
if (!async)
700+
{
701+
PQfinish(conn);
702+
exit(1);
703+
}
689704
}
690705
}
691706

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp