setup_uncached_err(void)
{
int uncached_fd = dup(2);
+ set_cloexec_flag(uncached_fd);
if (uncached_fd == -1) {
cc_log("dup(2) failed: %s", strerror(errno));
failed();
bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
char *read_text_file(const char *path, size_t size_hint);
char *subst_env_in_string(const char *str, char **errmsg);
+void set_cloexec_flag (int fd);
// ----------------------------------------------------------------------------
// stats.c
if (logfile) {
#ifndef _WIN32
int fd = fileno(logfile);
- int flags = fcntl(fd, F_GETFD, 0);
- if (flags >= 0) {
- fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
- }
+ set_cloexec_flag(fd);
#endif
return true;
} else {
fatal("Failed to create temporary file for %s: %s",
*fname, strerror(errno));
}
+ set_cloexec_flag(fd);
#ifndef _WIN32
fchmod(fd, 0666 & ~get_umask());
reformat(&result, "%s%.*s", result, (int)(q - p), p);
return result;
}
+
+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);
+ }
+#endif
+}
+