Fix: change session file loading order
authorDavid Goulet <dgoulet@efficios.com>
Wed, 16 Jul 2014 18:02:56 +0000 (14:02 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 16 Jul 2014 19:53:38 +0000 (15:53 -0400)
Libconfig now tries to load a session file from the user directory
followed by the system wide. A user session file should always
supersedes the system wide.

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

index b9c4021087bfbecd5af5aea619f162e92fc31d5a..8c926b53ed74ea90151d19bb8097c73cfda26b67 100644 (file)
@@ -2554,29 +2554,15 @@ int config_load_session(const char *path, const char *session_name,
                char *home_path;
                const char *sys_path;
 
-               /*
-                * Try system session configuration path. Ignore error here so we can
-                * continue loading the home sessions. The above call should print an
-                * error to inform the user.
-                */
-               if (autoload) {
-                       sys_path = DEFAULT_SESSION_SYSTEM_CONFIGPATH "/"
-                               DEFAULT_SESSION_CONFIG_AUTOLOAD;
-               } else {
-                       sys_path = DEFAULT_SESSION_HOME_CONFIGPATH;
-               }
-
-               ret = validate_path_creds(sys_path);
-               if (!ret && autoload) {
-                       (void) load_session_from_path(sys_path, session_name,
-                                       &validation_ctx, override);
-               }
-
                /* Try home path */
                home_path = utils_get_home_dir();
                if (home_path) {
                        char path[PATH_MAX];
 
+                       /*
+                        * Try user session configuration path. Ignore error here so we can
+                        * continue loading the system wide sessions.
+                        */
                        if (autoload) {
                                ret = snprintf(path, sizeof(path),
                                                DEFAULT_SESSION_HOME_CONFIGPATH "/"
@@ -2586,21 +2572,37 @@ int config_load_session(const char *path, const char *session_name,
                                                DEFAULT_SESSION_HOME_CONFIGPATH, home_path);
                        }
                        if (ret < 0) {
+                               PERROR("snprintf session home config path");
                                goto end;
                        }
 
                        ret = validate_path_creds(path);
-                       if (ret && autoload) {
-                               ret = 0;
-                               goto end;
+                       if (!ret && autoload) {
+                               ret = load_session_from_path(path, session_name,
+                                               &validation_ctx, override);
+                               if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) {
+                                       goto end;
+                               }
+                               /*
+                                * Continue even if the session was found since we have to try
+                                * the system wide sessions.
+                                */
                        }
+               }
 
-                       ret = load_session_from_path(path, session_name,
-                               &validation_ctx, override);
-                       if (!ret || (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT)) {
-                               /* Session found or an error occured */
-                               goto end;
-                       }
+               /* Try system wide configuration directory. */
+               if (autoload) {
+                       sys_path = DEFAULT_SESSION_SYSTEM_CONFIGPATH "/"
+                               DEFAULT_SESSION_CONFIG_AUTOLOAD;
+               } else {
+                       sys_path = DEFAULT_SESSION_HOME_CONFIGPATH;
+               }
+
+               ret = validate_path_creds(sys_path);
+               if (!ret && autoload) {
+                       ret = load_session_from_path(sys_path, session_name,
+                                       &validation_ctx, override);
+                       goto end;
                }
        } else {
                ret = access(path, F_OK);
This page took 0.027447 seconds and 4 git commands to generate.