Skip to content

Commit 664dd61

Browse files
committed
If create/drop database are going to call closeAllVfds(), they ought
to do it at the last moment before calling system() ... not at some randomly-chosen earlier point in the routine ...
1 parent b659ab0 commit 664dd61

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/backend/commands/dbcommands.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.56 2000/05/30 00:49:43 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.57 2000/06/02 04:04:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -55,6 +55,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
5555
char *loc;
5656
char locbuf[512];
5757
int4 user_id;
58+
int ret;
5859
bool use_super,
5960
use_createdb;
6061
Relation pg_database_rel;
@@ -90,12 +91,6 @@ createdb(const char *dbname, const char *dbpath, int encoding)
9091
"This may be due to a character that is not allowed or because the chosen "
9192
"path isn't permitted for databases", dbpath);
9293

93-
/*
94-
* close virtual file descriptors so the kernel has more available for
95-
* the system() calls
96-
*/
97-
closeAllVfds();
98-
9994
/*
10095
* Insert a new tuple into pg_database
10196
*/
@@ -133,21 +128,28 @@ createdb(const char *dbname, const char *dbpath, int encoding)
133128

134129
heap_close(pg_database_rel, NoLock);
135130

131+
/*
132+
* Close virtual file descriptors so the kernel has more available for
133+
* the mkdir() and system() calls below.
134+
*/
135+
closeAllVfds();
136+
136137
/* Copy the template database to the new location */
137138

138139
if (mkdir(loc, S_IRWXU) != 0)
139140
elog(ERROR, "CREATE DATABASE: unable to create database directory '%s': %s", loc, strerror(errno));
140141

141142
snprintf(buf, sizeof(buf), "cp %s%cbase%ctemplate1%c* '%s'",
142143
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, loc);
144+
ret = system(buf);
145+
/* Some versions of SunOS seem to return ECHILD after a system() call */
143146
#if defined(sun)
144-
if (system(buf) != 0 && errno != ECHILD)
147+
if (ret != 0 && errno != ECHILD)
145148
#else
146-
if (system(buf) != 0)
149+
if (ret != 0)
147150
#endif
148151
{
149-
int ret;
150-
152+
/* Failed, so try to clean up the created directory ... */
151153
snprintf(buf, sizeof(buf), "rm -rf '%s'", loc);
152154
ret = system(buf);
153155
#if defined(sun)
@@ -209,12 +211,6 @@ dropdb(const char *dbname)
209211
"This may be due to a character that is not allowed or because the chosen "
210212
"path isn't permitted for databases", path);
211213

212-
/*
213-
* close virtual file descriptors so the kernel has more available for
214-
* the system() calls
215-
*/
216-
closeAllVfds();
217-
218214
/*
219215
* Obtain exclusive lock on pg_database. We need this to ensure that
220216
* no new backend starts up in the target database while we are
@@ -277,6 +273,12 @@ dropdb(const char *dbname)
277273
*/
278274
DropBuffers(db_id);
279275

276+
/*
277+
* Close virtual file descriptors so the kernel has more available for
278+
* the system() call below.
279+
*/
280+
closeAllVfds();
281+
280282
/*
281283
* Remove the database's subdirectory and everything in it.
282284
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy