summaryrefslogtreecommitdiff
path: root/policy.c
diff options
context:
space:
mode:
authorLukasz Dorau <lukasz.dorau@intel.com>2013-12-19 13:02:12 +0100
committerNeilBrown <neilb@suse.de>2014-01-06 17:09:19 +1100
commit75a721fd7d5e5ee7e578571fe58755fe07e446fc (patch)
tree9fba2f8c7008e4a098d8863860d579aaf308add4 /policy.c
parent2ca20929fa2471bf485218ed37a01ab36d160f17 (diff)
policy: NULL path isn't really acceptable - use the devname
According to: commit b451aa4846c5ccca5447a6b6d45e5623b8c8e961 Fix handling for "auto" line in mdadm.conf a NULL path isn't really acceptable and the devname should be used instead. Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'policy.c')
-rw-r--r--policy.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/policy.c b/policy.c
index b4f39434..104695d3 100644
--- a/policy.c
+++ b/policy.c
@@ -200,26 +200,25 @@ static char *disk_path(struct mdinfo *disk)
int rv;
by_path = opendir(symlink);
- if (!by_path)
- return NULL;
- prefix_len = strlen(symlink);
-
- while ((ent = readdir(by_path)) != NULL) {
- if (ent->d_type != DT_LNK)
- continue;
- strncpy(symlink + prefix_len,
- ent->d_name,
- sizeof(symlink) - prefix_len);
- if (stat(symlink, &stb) < 0)
- continue;
- if ((stb.st_mode & S_IFMT) != S_IFBLK)
- continue;
- if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
- continue;
+ if (by_path) {
+ prefix_len = strlen(symlink);
+ while ((ent = readdir(by_path)) != NULL) {
+ if (ent->d_type != DT_LNK)
+ continue;
+ strncpy(symlink + prefix_len,
+ ent->d_name,
+ sizeof(symlink) - prefix_len);
+ if (stat(symlink, &stb) < 0)
+ continue;
+ if ((stb.st_mode & S_IFMT) != S_IFBLK)
+ continue;
+ if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
+ continue;
+ closedir(by_path);
+ return xstrdup(ent->d_name);
+ }
closedir(by_path);
- return xstrdup(ent->d_name);
}
- closedir(by_path);
/* A NULL path isn't really acceptable - use the devname.. */
sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
rv = readlink(symlink, nm, sizeof(nm)-1);