]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: more robust sysfs_opendir() [coverity scan]
authorKarel Zak <kzak@redhat.com>
Fri, 7 Sep 2012 10:15:39 +0000 (12:15 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Sep 2012 10:15:39 +0000 (12:15 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs.c

index 7b2c5f7b149db403c535a9d2764b49b385c4b905..d1eccb585cc900710e30544ed74fd39d0339d2c5 100644 (file)
@@ -233,11 +233,12 @@ ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr,
 DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr)
 {
        DIR *dir;
-       int fd;
+       int fd = -1;
 
        if (attr)
                fd = sysfs_open(cxt, attr);
-       else
+
+       else if (cxt->dir_fd >= 0)
                /* request to open root of device in sysfs (/sys/block/<dev>)
                 * -- we cannot use cxt->sysfs_fd directly, because closedir()
                 * will close this our persistent file descriptor.