From: Joey Hess Date: Fri, 11 Apr 2008 21:47:28 +0000 (-0400) Subject: set umask before calling mkstemp X-Git-Tag: 0.29~7 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0595609018095dabd5d1a56cf03ddcc008a9e928;p=moreutils set umask before calling mkstemp This is a POSIX portability thing. Restore the original umask after. --- diff --git a/sponge.c b/sponge.c index d232b5d..dcd4aba 100644 --- a/sponge.c +++ b/sponge.c @@ -219,14 +219,16 @@ static void copy_tmpfile(FILE *tmpfile, FILE *outfd) { } FILE *open_tmpfile(void) { - /* umask(077); FIXME: Should we be setting umask, or using default? */ struct cs_status cs; int tmpfd; FILE *tmpfile; + mode_t mask; trapsignals(); cs = cs_enter(); + mask=umask(077); tmpfd = mkstemp(tmpname); + umask(mask); atexit(onexit_cleanup); // solaris on_exit(onexit_cleanup, 0); cs_leave(cs); if (tmpfd < 0) {