*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.56 2000/05/30 00:49:43 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.57 2000/06/02 04:04:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char *loc;
char locbuf[512];
int4 user_id;
+ int ret;
bool use_super,
use_createdb;
Relation pg_database_rel;
"path isn't permitted for databases", dbpath);
/*
- * close virtual file descriptors so the kernel has more available for
- * the system() calls
- */
- closeAllVfds();
-
- /*
* Insert a new tuple into pg_database
*/
pg_database_rel = heap_openr(DatabaseRelationName, AccessExclusiveLock);
heap_close(pg_database_rel, NoLock);
+ /*
+ * Close virtual file descriptors so the kernel has more available for
+ * the mkdir() and system() calls below.
+ */
+ closeAllVfds();
+
/* Copy the template database to the new location */
if (mkdir(loc, S_IRWXU) != 0)
snprintf(buf, sizeof(buf), "cp %s%cbase%ctemplate1%c* '%s'",
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, loc);
+ ret = system(buf);
+ /* Some versions of SunOS seem to return ECHILD after a system() call */
#if defined(sun)
- if (system(buf) != 0 && errno != ECHILD)
+ if (ret != 0 && errno != ECHILD)
#else
- if (system(buf) != 0)
+ if (ret != 0)
#endif
{
- int ret;
-
+ /* Failed, so try to clean up the created directory ... */
snprintf(buf, sizeof(buf), "rm -rf '%s'", loc);
ret = system(buf);
#if defined(sun)
"path isn't permitted for databases", path);
/*
- * close virtual file descriptors so the kernel has more available for
- * the system() calls
- */
- closeAllVfds();
-
- /*
* Obtain exclusive lock on pg_database. We need this to ensure that
* no new backend starts up in the target database while we are
* deleting it. (Actually, a new backend might still manage to start
DropBuffers(db_id);
/*
+ * Close virtual file descriptors so the kernel has more available for
+ * the system() call below.
+ */
+ closeAllVfds();
+
+ /*
* Remove the database's subdirectory and everything in it.
*/
snprintf(buf, sizeof(buf), "rm -rf '%s'", path);