]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move set_cloexec_flag to Util
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 18:07:06 +0000 (20:07 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 18:31:54 +0000 (20:31 +0200)
src/TemporaryFile.cpp
src/Util.cpp
src/Util.hpp
src/legacy_util.cpp
src/legacy_util.hpp
src/logging.cpp

index 8dad5cf99c8a3366ab6654f04f87a54d902b9601..e057c795f8f1b16c24ccd92819caa8a82b96d357 100644 (file)
@@ -72,7 +72,7 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
     fatal("Failed to create temporary file for {}: {}", path, strerror(errno));
   }
 
-  set_cloexec_flag(*fd);
+  Util::set_cloexec_flag(*fd);
 #ifndef _WIN32
   fchmod(*fd, 0666 & ~get_umask());
 #endif
index f18bed0d0e1c9f9960850b21480e1ed2f7c91f69..23bb4839abd10cddc5fb7dacf0f880897599e767 100644 (file)
@@ -1165,6 +1165,19 @@ send_to_stderr(const std::string& text, bool strip_colors)
   }
 }
 
+void
+set_cloexec_flag(int fd)
+{
+#ifndef _WIN32
+  int flags = fcntl(fd, F_GETFD, 0);
+  if (flags >= 0) {
+    fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+  }
+#else
+  (void)fd;
+#endif
+}
+
 void
 setenv(const std::string& name, const std::string& value)
 {
index 2c4a8d249351245499a79b097cfa4ff8e3cb985c..b48ca55023195bfb5c0bcda4244d06abc51a7010 100644 (file)
@@ -365,6 +365,9 @@ bool same_program_name(const std::string& program_name,
 // `strip_colors` is true. Throws `Error` on error.
 void send_to_stderr(const std::string& text, bool strip_colors);
 
+// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
+void set_cloexec_flag(int fd);
+
 // Set environment variable `name` to `value`.
 void setenv(const std::string& name, const std::string& value);
 
index bd177844372f8a6d195f1cfd5140642f14b3f170..b432f9b9c1e2e07bca0a3895d9002d64e8edefdf 100644 (file)
 #  include <sys/time.h>
 #endif
 
-void
-set_cloexec_flag(int fd)
-{
-#ifndef _WIN32
-  int flags = fcntl(fd, F_GETFD, 0);
-  if (flags >= 0) {
-    fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
-  }
-#else
-  (void)fd;
-#endif
-}
-
 double
 time_seconds()
 {
index 182579acd7124bd610e85e06a1f65199dafe3447..7f6a940b4824b7fe52483dd1c051fea4fc236f70 100644 (file)
@@ -22,5 +22,4 @@
 
 #include <string>
 
-void set_cloexec_flag(int fd);
 double time_seconds();
index 2ed326b3c63c19e72a1946f7c6382b1c42f66ad8..ed26788f71d2b9c3f371aba7a39903bced8103e4 100644 (file)
@@ -89,7 +89,7 @@ init_log(const Config& config)
   logfile.open(logfile_path, "a");
 #ifndef _WIN32
   if (logfile) {
-    set_cloexec_flag(fileno(*logfile));
+    Util::set_cloexec_flag(fileno(*logfile));
   }
 #endif
 }