Fix: time of check time of use scenario
authorDavid Goulet <dgoulet@efficios.com>
Wed, 12 Mar 2014 18:43:45 +0000 (14:43 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 12 Mar 2014 18:43:45 +0000 (14:43 -0400)
Fixes coverity issue 1191753.

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

index c952e8ba29180b4164638802b486c22244b0dd95..088d5b55a1b7e7c926f9ee4c0e1444a41b94ac38 100644 (file)
@@ -2338,18 +2338,19 @@ int load_session_from_path(const char *path, const char *session_name,
        struct session_config_validation_ctx *validation_ctx, int override)
 {
        int ret, session_found = !session_name;
-       struct stat sb;
        DIR *directory = NULL;
 
        assert(path);
        assert(validation_ctx);
 
-       ret = stat(path, &sb);
-       if (ret) {
-               ret = -LTTNG_ERR_LOAD_SESSION_NOENT;
-               goto end;
+       directory = opendir(path);
+       if (!directory) {
+               if (errno != ENOTDIR) {
+                       ret = -LTTNG_ERR_LOAD_IO_FAIL;
+                       goto end;
+               }
        }
-       if (S_ISDIR(sb.st_mode)) {
+       if (directory) {
                struct dirent *entry;
                struct dirent *result;
                char *file_path = NULL;
@@ -2366,13 +2367,6 @@ int load_session_from_path(const char *path, const char *session_name,
                        goto end;
                }
 
-               directory = opendir(path);
-               if (!directory) {
-                       ret = -LTTNG_ERR_LOAD_IO_FAIL;
-                       free(entry);
-                       goto end;
-               }
-
                file_path = zmalloc(PATH_MAX);
                if (!file_path) {
                        ret = -LTTNG_ERR_NOMEM;
@@ -2385,6 +2379,7 @@ int load_session_from_path(const char *path, const char *session_name,
                        file_path[path_len++] = '/';
                }
 
+               ret = 0;
                /* Search for *.lttng files */
                while (!readdir_r(directory, entry, &result) && result) {
                        size_t file_name_len = strlen(result->d_name);
This page took 0.028073 seconds and 5 git commands to generate.