aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-11-24 22:40:55 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-11-25 01:19:41 +0100
commitbf704e506ffb2eef10882f55f404fb901b8a3e25 (patch)
treed36a41373faa535d22f2ed679ed2fb23f6d2faa8
parenta6bf86f7e006f05c586f7c75582403a67b3b4316 (diff)
downloadembedlog-bf704e506ffb2eef10882f55f404fb901b8a3e25.tar.gz
embedlog-bf704e506ffb2eef10882f55f404fb901b8a3e25.tar.bz2
embedlog-bf704e506ffb2eef10882f55f404fb901b8a3e25.zip
options: fix g_options altered after el_ocleanup
calling el_ocleanup() changed outputs in global g_options object, rendering all el_print function family to stop printing after any el_ocleanup() call.
-rw-r--r--src/el-options.c2
-rw-r--r--tst/test-el-options.c63
2 files changed, 64 insertions, 1 deletions
diff --git a/src/el-options.c b/src/el-options.c
index 1d83646..dcef59e 100644
--- a/src/el-options.c
+++ b/src/el-options.c
@@ -437,7 +437,7 @@ int el_ocleanup
{
VALID(EINVAL, options);
- g_options.outputs = 0;
+ options->outputs = 0;
#if ENABLE_OUT_FILE
el_file_cleanup(options);
#endif
diff --git a/tst/test-el-options.c b/tst/test-el-options.c
index 153e699..a5e74fb 100644
--- a/tst/test-el-options.c
+++ b/tst/test-el-options.c
@@ -470,6 +470,68 @@ static void options_einval(void)
/* ==========================================================================
+ ========================================================================== */
+
+
+static void options_global_options_after_options_cleanup(void)
+{
+ struct el_options default_options; /* expected default options */
+ struct el_options options; /* custom options to init */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ memset(&default_options, 0, sizeof(default_options));
+#if ENABLE_OUT_STDERR
+ default_options.outputs = EL_OUT_STDERR;
+#else
+ default_options.outputs = 0;
+#endif
+ default_options.level = EL_INFO;
+ default_options.file_sync_level = EL_FATAL;
+ default_options.level_current_msg = EL_DBG;
+ default_options.colors = 0;
+ default_options.timestamp = EL_TS_OFF;
+ default_options.timestamp_timer = EL_TS_TM_TIME;
+ default_options.timestamp_fractions = EL_TS_FRACT_OFF;
+ default_options.print_log_level = 1;
+ default_options.print_newline = 1;
+ default_options.custom_puts = NULL;
+ default_options.serial_fd = -1;
+
+ default_options.finfo = 0;
+ default_options.frotate_number = 0;
+ default_options.fcurrent_rotate = 0;
+ default_options.frotate_size = 0;
+ default_options.fpos = 0;
+ default_options.file = NULL;
+ default_options.file_sync_every = 32768;
+ default_options.fname = NULL;
+
+
+ el_init();
+ el_oinit(&options);
+ el_option(EL_OUT, EL_OUT_STDERR);
+ el_ooption(&options, EL_OUT, EL_OUT_STDERR);
+ mt_fail(memcmp(&g_options, &default_options, sizeof(default_options)) == 0);
+#if ENABLE_OUT_STDERR
+ mt_fail(g_options.outputs == EL_OUT_STDERR);
+ mt_fail(options.outputs == EL_OUT_STDERR);
+#else
+ mt_fail(g_options.outputs == 0);
+ mt_fail(options.outputs == 0);
+#endif
+
+ el_ocleanup(&options);
+
+ /* global options should not be altered when el_ocleanup is called
+ */
+
+ mt_fail(memcmp(&g_options, &default_options, sizeof(default_options)) == 0);
+ mt_fail(options.outputs == 0);
+}
+
+
+/* ==========================================================================
__ __
/ /_ ___ _____ / /_ ____ _ _____ ____ __ __ ____
/ __// _ \ / ___// __/ / __ `// ___// __ \ / / / // __ \
@@ -499,4 +561,5 @@ void el_options_test_group(void)
mt_run(options_ooption_test);
mt_run(options_einval);
mt_run(options_prefix);
+ mt_run(options_global_options_after_options_cleanup);
}