Fix: Handle empty daemon configuration file lines
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 23 Nov 2014 16:30:33 +0000 (11:30 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 23 Nov 2014 16:40:34 +0000 (11:40 -0500)
Empty daemon configuration file lines such as
my_option=

will cause set_option to be called with an arg value of length 0
which should display a warning.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c

index 726c650c089eeedbd12cebd78950669aa914c62b..3e04f963329e6603c859164f1ee4ff4207a8e118 100644 (file)
@@ -4262,6 +4262,17 @@ static int set_option(int opt, const char *arg, const char *optname)
 {
        int ret = 0;
 
+       if (arg && arg[0] == '\0') {
+               /*
+                * This only happens if the value is read from daemon config
+                * file. This means the option requires an argument and the
+                * configuration file contains a line such as:
+                * my_option =
+                */
+               ret = -EINVAL;
+               goto end;
+       }
+
        switch (opt) {
        case 0:
                fprintf(stderr, "option %s", optname);
@@ -4453,6 +4464,22 @@ static int set_option(int opt, const char *arg, const char *optname)
                ret = -1;
        }
 
+       if (ret == -EINVAL) {
+               const char *opt_name = "unknown";
+               int i;
+
+               for (i = 0; i < sizeof(long_options) / sizeof(struct option);
+                       i++) {
+                       if (opt == long_options[i].val) {
+                               opt_name = long_options[i].name;
+                               break;
+                       }
+               }
+
+               WARN("Invalid argument provided for option \"%s\", using default value.",
+                       opt_name);
+       }
+end:
        return ret;
 }
 
This page took 0.027562 seconds and 4 git commands to generate.