int commSetNonBlocking(int fd);
int commUnsetNonBlocking(int fd);
+
+/// On platforms where FD_CLOEXEC is defined, close the given descriptor during
+/// a function call from the exec(3) family. Otherwise, do nothing; the platform
+/// itself may close-on-exec by default (e.g., MS Win32 is said to do that at
+/// https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873); other
+/// platforms are unsupported. Callers that want close-on-exec behavior must
+/// call this function on all platforms and are not responsible for the outcome
+/// on platforms without FD_CLOEXEC.
void commSetCloseOnExec(int fd);
+
void _comm_close(int fd, char const *file, int line);
#define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
void old_comm_reset_close(int fd);
*/
#include "squid.h"
+#include "comm.h"
#include "debug/Stream.h"
#include "fd.h"
debugs(51, 3, "FD " << fd);
}
+void
+commSetCloseOnExec(int)
+{
+ // This stub is needed because DebugFile sets this flag for the open
+ // cache.log file descriptor. Helpers and such must use stdout/stderr
+ // instead of opening a cache.log file. They should never reach this code.
+ assert(false);
+}
+
#include "squid.h"
#include "base/TextException.h"
+#include "comm.h"
#include "debug/Stream.h"
#include "fatal.h"
#include "fd.h"
}
file_ = newFile; // may be nil
- if (file_)
+ if (file_) {
+ commSetCloseOnExec(fileno(file_));
fd_open(fileno(file_), FD_LOG, Debug::cache_log);
+ }
xfree(name);
name = newName ? xstrdup(newName) : nullptr;