|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * 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 $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -55,6 +55,7 @@ createdb(const char *dbname, const char *dbpath, int encoding) |
55 | 55 | char*loc; |
56 | 56 | charlocbuf[512]; |
57 | 57 | int4user_id; |
| 58 | +intret; |
58 | 59 | booluse_super, |
59 | 60 | use_createdb; |
60 | 61 | Relationpg_database_rel; |
@@ -90,12 +91,6 @@ createdb(const char *dbname, const char *dbpath, int encoding) |
90 | 91 | "This may be due to a character that is not allowed or because the chosen " |
91 | 92 | "path isn't permitted for databases",dbpath); |
92 | 93 |
|
93 | | -/* |
94 | | - * close virtual file descriptors so the kernel has more available for |
95 | | - * the system() calls |
96 | | - */ |
97 | | -closeAllVfds(); |
98 | | - |
99 | 94 | /* |
100 | 95 | * Insert a new tuple into pg_database |
101 | 96 | */ |
@@ -133,21 +128,28 @@ createdb(const char *dbname, const char *dbpath, int encoding) |
133 | 128 |
|
134 | 129 | heap_close(pg_database_rel,NoLock); |
135 | 130 |
|
| 131 | +/* |
| 132 | + * Close virtual file descriptors so the kernel has more available for |
| 133 | + * the mkdir() and system() calls below. |
| 134 | + */ |
| 135 | +closeAllVfds(); |
| 136 | + |
136 | 137 | /* Copy the template database to the new location */ |
137 | 138 |
|
138 | 139 | if (mkdir(loc,S_IRWXU)!=0) |
139 | 140 | elog(ERROR,"CREATE DATABASE: unable to create database directory '%s': %s",loc,strerror(errno)); |
140 | 141 |
|
141 | 142 | snprintf(buf,sizeof(buf),"cp %s%cbase%ctemplate1%c* '%s'", |
142 | 143 | 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 */ |
143 | 146 | #if defined(sun) |
144 | | -if (system(buf)!=0&&errno!=ECHILD) |
| 147 | +if (ret!=0&&errno!=ECHILD) |
145 | 148 | #else |
146 | | -if (system(buf)!=0) |
| 149 | +if (ret!=0) |
147 | 150 | #endif |
148 | 151 | { |
149 | | -intret; |
150 | | - |
| 152 | +/* Failed, so try to clean up the created directory ... */ |
151 | 153 | snprintf(buf,sizeof(buf),"rm -rf '%s'",loc); |
152 | 154 | ret=system(buf); |
153 | 155 | #if defined(sun) |
@@ -209,12 +211,6 @@ dropdb(const char *dbname) |
209 | 211 | "This may be due to a character that is not allowed or because the chosen " |
210 | 212 | "path isn't permitted for databases",path); |
211 | 213 |
|
212 | | -/* |
213 | | - * close virtual file descriptors so the kernel has more available for |
214 | | - * the system() calls |
215 | | - */ |
216 | | -closeAllVfds(); |
217 | | - |
218 | 214 | /* |
219 | 215 | * Obtain exclusive lock on pg_database. We need this to ensure that |
220 | 216 | * no new backend starts up in the target database while we are |
@@ -277,6 +273,12 @@ dropdb(const char *dbname) |
277 | 273 | */ |
278 | 274 | DropBuffers(db_id); |
279 | 275 |
|
| 276 | +/* |
| 277 | + * Close virtual file descriptors so the kernel has more available for |
| 278 | + * the system() call below. |
| 279 | + */ |
| 280 | +closeAllVfds(); |
| 281 | + |
280 | 282 | /* |
281 | 283 | * Remove the database's subdirectory and everything in it. |
282 | 284 | */ |
|