* [PATCH] libmount: Save errno if mkostemp() failed
@ 2013-09-29 10:11 Namhyung Kim
2013-09-30 12:09 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Namhyung Kim @ 2013-09-29 10:11 UTC (permalink / raw)
To: util-linux
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 | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 3cab936..7930e29 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;
}
/**
--
1.7.9.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libmount: Save errno if mkostemp() failed
2013-09-29 10:11 [PATCH] libmount: Save errno if mkostemp() failed Namhyung Kim
@ 2013-09-30 12:09 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2013-09-30 12:09 UTC (permalink / raw)
To: Namhyung Kim; +Cc: util-linux
On Sun, Sep 29, 2013 at 07:11:37PM +0900, Namhyung Kim wrote:
> After mkostemp() failed, umask() and free() might alter the errno
I don't think umask and free alter errno, but
> to another value. Not sure those calls really changes the errno
> or not. But let's be more conservative.
ok, it seems more readable then the old version. Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-30 12:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-29 10:11 [PATCH] libmount: Save errno if mkostemp() failed Namhyung Kim
2013-09-30 12:09 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox