]> err.no Git - moreutils/commitdiff
set umask before calling mkstemp
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 21:47:28 +0000 (17:47 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 21:47:28 +0000 (17:47 -0400)
This is a POSIX portability thing.

Restore the original umask after.

sponge.c

index d232b5d4b018e87f8479a09fa1a6a26eff2fc16c..dcd4abaaa37c30c00b15f3f0ef64391f90231a73 100644 (file)
--- 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) {