Fossil SCM
Make sure config database state is consistent when returning from 'sqlite' command.
Commit
97ff702f3db54eb98b8872052e93d9e04835daf2a2c4d363747f81cf1a2b6852
Parent
fa6b22c674c7112…
1 file changed
+9
+9
| --- src/sqlcmd.c | ||
| +++ src/sqlcmd.c | ||
| @@ -20,10 +20,11 @@ | ||
| 20 | 20 | ** is a copy of the "shell.c" code from SQLite. This file contains logic |
| 21 | 21 | ** to initialize the code in shell.c. |
| 22 | 22 | */ |
| 23 | 23 | #include "config.h" |
| 24 | 24 | #include "sqlcmd.h" |
| 25 | +#include <stdlib.h> /* atexit() */ | |
| 25 | 26 | #if defined(FOSSIL_ENABLE_MINIZ) |
| 26 | 27 | # define MINIZ_HEADER_FILE_ONLY |
| 27 | 28 | # include "miniz.c" |
| 28 | 29 | #else |
| 29 | 30 | # include <zlib.h> |
| @@ -162,10 +163,17 @@ | ||
| 162 | 163 | sqlite3_exec(db, zSql, 0, 0, 0); |
| 163 | 164 | sqlite3_free(zSql); |
| 164 | 165 | } |
| 165 | 166 | return SQLITE_OK; |
| 166 | 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 | +} | |
| 167 | 175 | |
| 168 | 176 | /* |
| 169 | 177 | ** COMMAND: sqlite3 |
| 170 | 178 | ** |
| 171 | 179 | ** Usage: %fossil sql ?OPTIONS? |
| @@ -226,10 +234,11 @@ | ||
| 226 | 234 | fossil_close(1, noRepository); |
| 227 | 235 | sqlite3_shutdown(); |
| 228 | 236 | #ifndef _WIN32 |
| 229 | 237 | linenoiseSetMultiLine(1); |
| 230 | 238 | #endif |
| 239 | + atexit(sqlcmd_atexit); | |
| 231 | 240 | g.zConfigDbName = zConfigDb; |
| 232 | 241 | sqlite3_shell(g.argc-1, g.argv+1); |
| 233 | 242 | sqlite3_cancel_auto_extension((void(*)(void))sqlcmd_autoinit); |
| 234 | 243 | fossil_close(0, noRepository); |
| 235 | 244 | } |
| 236 | 245 |
| --- 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 |