]> err.no Git - moreutils/commitdiff
set up signal handlers before creating temp file
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 19:53:38 +0000 (15:53 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 19:53:38 +0000 (15:53 -0400)
Avoids a small race..

sponge.c

index a88fe0e716fe35cdfa848d8d08cd33bd559175b7..66fd97dbcc923f5c90d45cd82c3f6d52b9dc0d8d 100644 (file)
--- a/sponge.c
+++ b/sponge.c
@@ -237,10 +237,13 @@ int main (int argc, char **argv) {
                        if ((bufsize*2) >= mem_available) {
                                if (!tmpfile) {
                                        /* umask(077); FIXME: Should we be setting umask, or using default?  */
-                                       struct cs_status cs = cs_enter();
-                                       int tmpfd = mkstemp(tmpname);
-                                       atexit(onexit_cleanup); // solaris on_exit(onexit_cleanup, 0);
+                                       struct cs_status cs;
+                                       int tmpfd;
+
                                        trapsignals();
+                                       cs = cs_enter();
+                                       tmpfd = mkstemp(tmpname);
+                                       atexit(onexit_cleanup); // solaris on_exit(onexit_cleanup, 0);
                                        cs_leave(cs);
                                        if (tmpfd < 0) {
                                                perror("mkstemp failed");