Fix: load all possible path for sessiond conf file
authorDavid Goulet <dgoulet@efficios.com>
Wed, 14 May 2014 15:01:43 +0000 (11:01 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 14 May 2014 15:03:54 +0000 (11:03 -0400)
The session daemon now tries to load the system wide conf. file, user
local and finally the command line.

Fixes #709

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/main.c
src/common/config/config.c

index 3a8a1b27cf5e403389ba0b962ac775ec1040e158..0a2f3f48fa27e08ca7881a903ef44f4dd10fcd2a 100644 (file)
@@ -4258,6 +4258,9 @@ static int set_option(int opt, const char *arg, const char *optname)
                        ret = -ENOMEM;
                }
                break;
+       case 'f':
+               /* This is handled in set_options() thus silent break. */
+               break;
        default:
                /* Unknown option or other error.
                 * Error is printed by getopt, just return */
index 829a645bbb18820b2ad1237574a9fe229596b6cd..cdc044d6dc72fda892f9f2d3239140714ad61eb0 100644 (file)
@@ -191,55 +191,73 @@ int config_get_section_entries(const char *override_path, const char *section,
                config_entry_handler_cb handler, void *user_data)
 {
        int ret = 0;
+       char *path;
        FILE *config_file = NULL;
        struct handler_filter_args filter = { section, handler, user_data };
 
-       if (override_path) {
-               config_file = fopen(override_path, "r");
-               if (config_file) {
-                       DBG("Loaded daemon configuration file at %s",
-                               override_path);
-               } else {
-                       ERR("Failed to open daemon configuration file at %s",
-                               override_path);
-                       ret = -ENOENT;
-                       goto end;
-               }
-       } else {
-               char *path = utils_get_home_dir();
+       /* First, try system-wide conf. file. */
+       path = DEFAULT_DAEMON_SYSTEM_CONFIGPATH;
 
-               /* Try to open the user's daemon configuration file */
-               if (path) {
-                       ret = asprintf(&path, DEFAULT_DAEMON_HOME_CONFIGPATH, path);
-                       if (ret < 0) {
-                               goto end;
-                       }
+       config_file = fopen(path, "r");
+       if (config_file) {
+               DBG("Loading daemon conf file at %s", path);
+               /*
+                * Return value is not very important here since error or not, we
+                * continue and try the next possible conf. file.
+                */
+               (void) ini_parse_file(config_file,
+                               (ini_entry_handler) config_entry_handler_filter,
+                               (void *) &filter);
+               fclose(config_file);
+       }
 
-                       ret = 0;
-                       config_file = fopen(path, "r");
-                       if (config_file) {
-                               DBG("Loaded daemon configuration file at %s", path);
-                       }
+       /* Second is the user local configuration. */
+       path = utils_get_home_dir();
+       if (path) {
+               char fullpath[PATH_MAX];
 
-                       free(path);
+               ret = snprintf(fullpath, sizeof(fullpath),
+                               DEFAULT_DAEMON_HOME_CONFIGPATH, path);
+               if (ret < 0) {
+                       PERROR("snprintf user conf. path");
+                       goto error;
                }
 
-               /* Try to open the system daemon configuration file */
-               if (!config_file) {
-                       config_file = fopen(DEFAULT_DAEMON_HOME_CONFIGPATH, "r");
+               config_file = fopen(fullpath, "r");
+               if (config_file) {
+                       DBG("Loading daemon user conf file at %s", path);
+                       /*
+                        * Return value is not very important here since error or not, we
+                        * continue and try the next possible conf. file.
+                        */
+                       (void) ini_parse_file(config_file,
+                                       (ini_entry_handler) config_entry_handler_filter,
+                                       (void *) &filter);
+                       fclose(config_file);
                }
        }
 
-       if (!config_file) {
-               DBG("No daemon configuration file found.");
-               goto end;
+       /* Final path is the one that the user might have provided. */
+       if (override_path) {
+               config_file = fopen(override_path, "r");
+               if (config_file) {
+                       DBG("Loading daemon command line conf file at %s", override_path);
+                       (void) ini_parse_file(config_file,
+                                       (ini_entry_handler) config_entry_handler_filter,
+                                       (void *) &filter);
+                       fclose(config_file);
+               } else {
+                       ERR("Failed to open daemon configuration file at %s",
+                               override_path);
+                       ret = -ENOENT;
+                       goto error;
+               }
        }
 
-       ret = ini_parse_file(config_file,
-                       (ini_entry_handler) config_entry_handler_filter, (void *) &filter);
+       /* Everything went well. */
+       ret = 0;
 
-       fclose(config_file);
-end:
+error:
        return ret;
 }
 
This page took 0.031059 seconds and 5 git commands to generate.