]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: Save errno if mkostemp() failed
authorNamhyung Kim <namhyung@gmail.com>
Sun, 29 Sep 2013 10:11:37 +0000 (19:11 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 30 Sep 2013 11:41:12 +0000 (13:41 +0200)
After mkostemp() failed, umask() and free() might alter the errno
to another value.  Not sure those calls really changes the errno
or not.  But let's be more conservative.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
libmount/src/utils.c

index 3cab936441de596186a0163af777693ca02bca9c..7930e29debdaf45874c68d80e0da31a12d45baf0 100644 (file)
@@ -849,6 +849,8 @@ int mnt_open_uniq_filename(const char *filename, char **name)
        oldmode = umask(S_IRGRP|S_IWGRP|S_IXGRP|
                        S_IROTH|S_IWOTH|S_IXOTH);
        fd = mkostemp(n, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+       if (fd < 0)
+               fd = -errno;
        umask(oldmode);
 
        if (fd >= 0 && name)
@@ -856,7 +858,7 @@ int mnt_open_uniq_filename(const char *filename, char **name)
        else
                free(n);
 
-       return fd < 0 ? -errno : fd;
+       return fd;
 }
 
 /**