When looking up nvme subsystems for individual controllers we should
be using 'stat()' instead of 'opendir()'; this is less heavy-handed
and provides better error checking.
Signed-off-by: Hannes Reinecke <hare@suse.de>
#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <arpa/inet.h>
#include <netdb.h>
{
struct dirent **subsys;
char *subsys_name = NULL;
- DIR *d;
int ret, i;
char path[PATH_MAX];
if (ret < 0)
return NULL;
for (i = 0; i < ret; i++) {
+ struct stat st;
+
sprintf(path, "%s/%s/%s", nvme_subsys_sysfs_dir,
subsys[i]->d_name, c->name);
- d = opendir(path);
- if (!d)
+ nvme_msg(LOG_DEBUG, "lookup subsystem %s\n", path);
+ if (stat(path, &st) < 0)
continue;
subsys_name = strdup(subsys[i]->d_name);
- closedir(d);
break;
}
nvme_free_dirents(subsys, i);