From 5bcd8369af18008a93e35ecb8e71645cbab22cef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 3 May 2018 22:40:54 +0200 Subject: [PATCH] ignore sqlite setting errno --- src/kernel/db/sqlite.c | 16 +++++++++++++--- src/report.c | 22 +++++----------------- src/util/log.c | 8 ++++++++ src/util/log.h | 16 ++++++++++------ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/kernel/db/sqlite.c b/src/kernel/db/sqlite.c index 965363223..b3090cca0 100644 --- a/src/kernel/db/sqlite.c +++ b/src/kernel/db/sqlite.c @@ -26,7 +26,8 @@ order_data *db_driver_order_load(int id) { order_data * od = NULL; int err; - + + ERRNO_CHECK(); if (g_order_tx_size > 0) { g_order_tx_size = 0; err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL); @@ -45,10 +46,12 @@ order_data *db_driver_order_load(int id) assert(bytes > 0); text = sqlite3_column_text(g_stmt_select, 0); odata_create(&od, 1+(size_t)bytes, (const char *)text); + ERRNO_CHECK(); return od; } } while (err == SQLITE_ROW); assert(err == SQLITE_DONE); + ERRNO_CHECK(); return NULL; } @@ -58,7 +61,9 @@ int db_driver_order_save(order_data *od) sqlite3_int64 id; assert(od && od->_str); - + + ERRNO_CHECK(); + if (g_order_batchsize > 0) { if (g_order_tx_size == 0) { err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL); @@ -82,7 +87,7 @@ int db_driver_order_save(order_data *od) g_order_tx_size = 0; } } - + ERRNO_CHECK(); return (int)id; } @@ -91,6 +96,7 @@ void db_driver_open(void) int err; const char *dbname; + ERRNO_CHECK(); g_order_batchsize = config_get_int("game.dbbatch", 100); dbname = config_get("game.dbname"); if (!dbname) { @@ -108,16 +114,20 @@ void db_driver_open(void) assert(err == SQLITE_OK); err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL); assert(err == SQLITE_OK); + ERRNO_CHECK(); } void db_driver_close(void) { int err; + ERRNO_CHECK(); err = sqlite3_finalize(g_stmt_select); assert(err == SQLITE_OK); err = sqlite3_finalize(g_stmt_insert); assert(err == SQLITE_OK); err = sqlite3_close(g_db); assert(err == SQLITE_OK); + ERRNO_CHECK(); } + diff --git a/src/report.c b/src/report.c index c0b84f181..adea79257 100644 --- a/src/report.c +++ b/src/report.c @@ -96,7 +96,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include -#include #include #include #include @@ -111,17 +110,6 @@ extern int *storms; extern int weeks_per_month; extern int months_per_year; -static void check_errno(const char * file, int line) { - if (errno) { - char zText[64]; - sprintf(zText, "error %d during report at %s:%d", errno, file, line); - perror(zText); - errno = 0; - } -} - -#define CHECK_ERRNO() check_errno(__FILE__, __LINE__) - static char *gamedate_season(const struct locale *lang) { static char buf[256]; /* FIXME: static return value */ @@ -2195,7 +2183,7 @@ report_plaintext(const char *filename, report_context * ctx, } ch = 0; - CHECK_ERRNO(); + ERRNO_CHECK(); for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; a = a->next) { const item_type *itype = (const item_type *)a->data.v; @@ -2245,7 +2233,7 @@ report_plaintext(const char *filename, report_context * ctx, } } newline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); centre(out, LOC(f->locale, "nr_alliances"), false); newline(out); @@ -2253,7 +2241,7 @@ report_plaintext(const char *filename, report_context * ctx, rpline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); anyunits = 0; for (r = ctx->first; r != ctx->last; r = r->next) { @@ -2367,7 +2355,7 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); rpline(out); - CHECK_ERRNO(); + ERRNO_CHECK(); } if (!is_monsters(f)) { if (!anyunits) { @@ -2379,7 +2367,7 @@ report_plaintext(const char *filename, report_context * ctx, } } fstream_done(&strm); - CHECK_ERRNO(); + ERRNO_CHECK(); return 0; } diff --git a/src/util/log.c b/src/util/log.c index 51479cb4a..4b29332a8 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -24,6 +24,14 @@ without prior permission by the authors of Eressea. #include #include +void errno_check(const char * file, int line) { + if (errno) { + log_info("errno is %d (%s) at %s:%d", + errno, strerror(errno), file, line); + errno = 0; + } +} + #ifdef STDIO_CP static int stdio_codepage = STDIO_CP; #else diff --git a/src/util/log.h b/src/util/log.h index 06d150751..15872d6dc 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -28,13 +28,17 @@ extern "C" { int log_level(struct log_t *log, int flags); void log_close(void); - extern void log_fatal(const char *format, ...); - extern void log_error(const char *format, ...); - extern void log_warning(const char *format, ...); - extern void log_debug(const char *format, ...); - extern void log_info(const char *format, ...); - extern void log_printf(FILE * ios, const char *format, ...); + void log_fatal(const char *format, ...); + void log_error(const char *format, ...); + void log_warning(const char *format, ...); + void log_debug(const char *format, ...); + void log_info(const char *format, ...); + void log_printf(FILE * ios, const char *format, ...); + void errno_check(const char *file, int line); +#define ERRNO_CHECK() errno_check(__FILE__, __LINE__) + + #define LOG_CPERROR 0x01 #define LOG_CPWARNING 0x02 #define LOG_CPINFO 0x04