Fossil SCM

Make sure config database state is consistent when returning from 'sqlite' command.

mistachkin 2017-05-28 20:33 trunk
Commit 97ff702f3db54eb98b8872052e93d9e04835daf2a2c4d363747f81cf1a2b6852
1 file changed +9
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
2020
** is a copy of the "shell.c" code from SQLite. This file contains logic
2121
** to initialize the code in shell.c.
2222
*/
2323
#include "config.h"
2424
#include "sqlcmd.h"
25
+#include <stdlib.h> /* atexit() */
2526
#if defined(FOSSIL_ENABLE_MINIZ)
2627
# define MINIZ_HEADER_FILE_ONLY
2728
# include "miniz.c"
2829
#else
2930
# include <zlib.h>
@@ -162,10 +163,17 @@
162163
sqlite3_exec(db, zSql, 0, 0, 0);
163164
sqlite3_free(zSql);
164165
}
165166
return SQLITE_OK;
166167
}
168
+
169
+/*
170
+** atexit() handler that cleans up global state modified by this module.
171
+*/
172
+static void sqlcmd_atexit(void) {
173
+ g.zConfigDbName = 0; /* prevent panic */
174
+}
167175
168176
/*
169177
** COMMAND: sqlite3
170178
**
171179
** Usage: %fossil sql ?OPTIONS?
@@ -226,10 +234,11 @@
226234
fossil_close(1, noRepository);
227235
sqlite3_shutdown();
228236
#ifndef _WIN32
229237
linenoiseSetMultiLine(1);
230238
#endif
239
+ atexit(sqlcmd_atexit);
231240
g.zConfigDbName = zConfigDb;
232241
sqlite3_shell(g.argc-1, g.argv+1);
233242
sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
234243
fossil_close(0, noRepository);
235244
}
236245
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
 
25 #if defined(FOSSIL_ENABLE_MINIZ)
26 # define MINIZ_HEADER_FILE_ONLY
27 # include "miniz.c"
28 #else
29 # include <zlib.h>
@@ -162,10 +163,17 @@
162 sqlite3_exec(db, zSql, 0, 0, 0);
163 sqlite3_free(zSql);
164 }
165 return SQLITE_OK;
166 }
 
 
 
 
 
 
 
167
168 /*
169 ** COMMAND: sqlite3
170 **
171 ** Usage: %fossil sql ?OPTIONS?
@@ -226,10 +234,11 @@
226 fossil_close(1, noRepository);
227 sqlite3_shutdown();
228 #ifndef _WIN32
229 linenoiseSetMultiLine(1);
230 #endif
 
231 g.zConfigDbName = zConfigDb;
232 sqlite3_shell(g.argc-1, g.argv+1);
233 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
234 fossil_close(0, noRepository);
235 }
236
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
25 #include <stdlib.h> /* atexit() */
26 #if defined(FOSSIL_ENABLE_MINIZ)
27 # define MINIZ_HEADER_FILE_ONLY
28 # include "miniz.c"
29 #else
30 # include <zlib.h>
@@ -162,10 +163,17 @@
163 sqlite3_exec(db, zSql, 0, 0, 0);
164 sqlite3_free(zSql);
165 }
166 return SQLITE_OK;
167 }
168
169 /*
170 ** atexit() handler that cleans up global state modified by this module.
171 */
172 static void sqlcmd_atexit(void) {
173 g.zConfigDbName = 0; /* prevent panic */
174 }
175
176 /*
177 ** COMMAND: sqlite3
178 **
179 ** Usage: %fossil sql ?OPTIONS?
@@ -226,10 +234,11 @@
234 fossil_close(1, noRepository);
235 sqlite3_shutdown();
236 #ifndef _WIN32
237 linenoiseSetMultiLine(1);
238 #endif
239 atexit(sqlcmd_atexit);
240 g.zConfigDbName = zConfigDb;
241 sqlite3_shell(g.argc-1, g.argv+1);
242 sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit);
243 fossil_close(0, noRepository);
244 }
245

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button