summaryrefslogtreecommitdiffstats
path: root/libmount/src/utils.c
diff options
context:
space:
mode:
authorNamhyung Kim2013-09-29 12:11:37 +0200
committerKarel Zak2013-09-30 13:41:12 +0200
commit1dbaf5cc72a7af5a2ee4692366a74acb960203fe (patch)
tree35624edcfdbceda84d3ef0f48856eb13af10d59e /libmount/src/utils.c
parentbuild-sys: simplify python detection (diff)
downloadkernel-qcow2-util-linux-1dbaf5cc72a7af5a2ee4692366a74acb960203fe.tar.gz
kernel-qcow2-util-linux-1dbaf5cc72a7af5a2ee4692366a74acb960203fe.tar.xz
kernel-qcow2-util-linux-1dbaf5cc72a7af5a2ee4692366a74acb960203fe.zip
libmount: Save errno if mkostemp() failed
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>
Diffstat (limited to 'libmount/src/utils.c')
-rw-r--r--libmount/src/utils.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 3cab93644..7930e29de 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -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;
}
/**