aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2019-05-13 22:21:12 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2019-05-13 22:21:12 +0200
commitd7389cb230822b34805f7ab63dd55ab33179e813 (patch)
tree1d3e4e64eefc1be7608387d1f3b424551d143978
parentfcd77d211f180bac0eda27b280213a56e4a08b2c (diff)
downloadembedlog-d7389cb230822b34805f7ab63dd55ab33179e813.tar.gz
embedlog-d7389cb230822b34805f7ab63dd55ab33179e813.tar.bz2
embedlog-d7389cb230822b34805f7ab63dd55ab33179e813.zip
src/el-options: use static value of 0x7fff for EL_OUT_ALL
EL_OUT_ALL now performs purely abstract role and is not used to check for valid errors - there is new ALL_OUTS define for that in el-private.h. This change is needed so ABI does not change when we add new output. * include/embedlog.h change EL_OUT_ALL value from dynamically calculated mask to static 0x7fff. Previously it was mask of all implemented outputs, now its role is pure abstract. * src/el-options.c when abstract EL_OUT_ALL value is passed to EL_OUT option, program will treat it as if VALID_OUTS was passed. EINVAL is returned now based on new ALL_OUTS define instead of EL_OUT_ALL. * src/el-private.h this is where ALL_OUTS is defined * tst/test-el-options.c update tests for the change Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--include/embedlog.h2
-rw-r--r--src/el-options.c3
-rw-r--r--src/el-private.h15
-rw-r--r--tst/test-el-options.c19
4 files changed, 35 insertions, 4 deletions
diff --git a/include/embedlog.h b/include/embedlog.h
index 671e8f1..524956a 100644
--- a/include/embedlog.h
+++ b/include/embedlog.h
@@ -79,7 +79,7 @@ enum el_output
EL_OUT_NET = 0x0010,
EL_OUT_TTY = 0x0020,
EL_OUT_CUSTOM = 0x0040,
- EL_OUT_ALL = 0x007f
+ EL_OUT_ALL = 0x7fff
};
enum el_level
diff --git a/src/el-options.c b/src/el-options.c
index 5114171..55055b0 100644
--- a/src/el-options.c
+++ b/src/el-options.c
@@ -165,7 +165,8 @@ static int el_vooption
case EL_OUT:
value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~EL_OUT_ALL) == 0x00);
+ value_int = value_int == EL_OUT_ALL ? VALID_OUTS : value_int;
+ VALID(EINVAL, (value_int & ~ALL_OUTS) == 0x00);
VALID(ENODEV, (value_int & ~VALID_OUTS) == 0x00);
options->outputs = value_int;
return 0;
diff --git a/src/el-private.h b/src/el-private.h
index c36ecbe..4215f40 100644
--- a/src/el-private.h
+++ b/src/el-private.h
@@ -278,6 +278,21 @@ extern struct el_options g_options;
/* ==========================================================================
+ ALL_OUTS is a mask of all implemented outputs. This is mask for *all*
+ implemented outputs - it doesn't matter if it's enabled during
+ compilation or not. This is used to return EINVAL value when user
+ provides any output that is not on that list (if specified output is on
+ that list but was not compiled, it will return ENODEV and it's done in
+ another check). This is basically an bitwise OR of all fields in enum
+ el_output
+ ========================================================================== */
+
+
+#define ALL_OUTS (EL_OUT_STDERR | EL_OUT_STDOUT | EL_OUT_SYSLOG | \
+ EL_OUT_FILE | EL_OUT_NET | EL_OUT_TTY | EL_OUT_CUSTOM)
+
+
+/* ==========================================================================
____ __ _
/ __/__ __ ____ _____ / /_ (_)____ ____ _____
/ /_ / / / // __ \ / ___// __// // __ \ / __ \ / ___/
diff --git a/tst/test-el-options.c b/tst/test-el-options.c
index 6ac0a85..0db6b6a 100644
--- a/tst/test-el-options.c
+++ b/tst/test-el-options.c
@@ -196,13 +196,21 @@ static void options_file_sync_level_set(void)
static void options_output(void)
{
int i;
+ int valid_outs = ALL_OUTS;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != EL_OUT_ALL; ++i)
+ for (i = 0; i != ALL_OUTS + 100; ++i)
{
int ok = 1;
+ if (i > ALL_OUTS)
+ {
+ mt_ferr(el_option(EL_OUT, i), EINVAL);
+ continue;
+ }
+
#ifndef ENABLE_OUT_STDERR
+ valid_outs &= ~EL_OUT_STDERR;
if (i & EL_OUT_STDERR)
{
ok = 0;
@@ -210,6 +218,7 @@ static void options_output(void)
#endif
#ifndef ENABLE_OUT_STDERR
+ valid_outs &= ~EL_OUT_STDOUT;
if (i & EL_OUT_STDOUT)
{
ok = 0;
@@ -218,6 +227,7 @@ static void options_output(void)
#ifndef ENABLE_OUT_SYSLOG
+ valid_outs &= ~EL_OUT_SYSLOG;
if (i & EL_OUT_SYSLOG)
{
ok = 0;
@@ -225,6 +235,7 @@ static void options_output(void)
#endif
#ifndef ENABLE_OUT_FILE
+ valid_outs &= ~EL_OUT_FILE;
if (i & EL_OUT_FILE)
{
ok = 0;
@@ -232,6 +243,7 @@ static void options_output(void)
#endif
#ifndef ENABLE_OUT_NET
+ valid_outs &= ~EL_OUT_NET;
if (i & EL_OUT_NET)
{
ok = 0;
@@ -239,6 +251,7 @@ static void options_output(void)
#endif
#ifndef ENABLE_OUT_TTY
+ valid_outs &= ~EL_OUT_TTY;
if (i & EL_OUT_TTY)
{
ok = 0;
@@ -246,6 +259,7 @@ static void options_output(void)
#endif
#ifndef ENABLE_OUT_CUSTOM
+ valid_outs &= ~EL_OUT_CUSTOM;
if (i & EL_OUT_CUSTOM)
{
ok = 0;
@@ -261,7 +275,8 @@ static void options_output(void)
mt_ferr(el_option(EL_OUT, i), ENODEV);
}
- mt_ferr(el_option(EL_OUT, EL_OUT_ALL + 7), EINVAL);
+ mt_fok(el_option(EL_OUT, EL_OUT_ALL));
+ mt_fail(g_options.outputs == valid_outs);
}