]> git.sesse.net Git - cubemap/blobdiff - util.cpp
Do not crash on re-exec if we do not have an access log.
[cubemap] / util.cpp
index b8862ed48c79719b632dd1575a6cd1cc6e057b39..d6d39f29ada05dc4437886d61178d190df189d02 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 #include "log.h"
 #include "util.h"
@@ -12,7 +14,9 @@ using namespace std;
 int make_tempfile(const std::string &contents)
 {
        char filename[] = "/tmp/cubemap.XXXXXX";
+       mode_t old_umask = umask(0600);
        int fd = mkstemp(filename);
+       umask(old_umask);
        if (fd == -1) {
                log_perror("mkstemp");
                return -1;
@@ -29,7 +33,9 @@ int make_tempfile(const std::string &contents)
                ssize_t ret = write(fd, ptr, to_write);
                if (ret == -1) {
                        log_perror("write");
-                       close(fd);
+                       if (close(fd) == -1) {
+                               log_perror("close");
+                       }
                        return -1;
                }