libs: Do not rely on nftw for detecting the validity of plugin path
[babeltrace.git] / src / lib / plugin / plugin.c
index 47b49cf993caf2856a19531a6189f37a0cd94b72..1cef5123b071810d54ee1ea76882a1cfb3b963d9 100644 (file)
@@ -485,10 +485,28 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir(
        int nftw_flags = FTW_PHYS;
        int ret;
        enum bt_plugin_status status;
+       struct stat sb;
 
        BT_ASSERT(plugin_set);
        BT_ASSERT(path);
        BT_ASSERT(strlen(path) < PATH_MAX);
+
+       /*
+        * Make sure that path exists and is accessible.
+        * This is necessary since Cygwin implementation of nftw() is not POSIX
+        * compliant. Cygwin nftw() implementation does not fail on non-existent
+        * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
+        * nftw_append_all_from_dir is not treated as an error since we are
+        * traversing the tree for plugin discovery.
+        */
+       if (stat(path, &sb)) {
+               BT_LOGW_ERRNO("Cannot open directory",
+                       ": path=\"%s\", recurse=%d",
+                       path, recurse);
+               status = BT_PLUGIN_STATUS_ERROR;
+               goto end;
+       }
+
        pthread_mutex_lock(&append_all_from_dir_info.lock);
        append_all_from_dir_info.plugin_set = plugin_set;
        append_all_from_dir_info.recurse = recurse;
@@ -517,7 +535,7 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir(
        }
 
 end:
-       return ret;
+       return status;
 }
 
 enum bt_plugin_status bt_plugin_find_all_from_dir(const char *path,
This page took 0.02498 seconds and 4 git commands to generate.