LOG_FATAL(LOGF_Acquire, "Could not open socket : %s", strerror(errno));
}
+ /* Close on exec */
+ UTI_FdSetCloexec(sock_fd);
+
if (port_number == 0) {
/* Don't bother binding this socket - we're not fussed what port
number it gets */
return -1;
}
+ /* Close on exec */
+ UTI_FdSetCloexec(sock_fd);
+
/* Allow reuse of port number */
if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on_off, sizeof(on_off)) < 0) {
LOG(LOGS_ERR, LOGF_CmdMon, "Could not set reuseaddr socket options");
#include "logging.h"
#include "version.h"
#include "mkdirpp.h"
+#include "util.h"
/* ================================================== */
/* Flag indicating we have initialised */
logfiles[id].name = NULL;
return;
}
+
+ /* Close on exec */
+ UTI_FdSetCloexec(fileno(logfiles[id].file));
}
banner = CNF_GetLogBanner();
return -1;
}
+ /* Close on exec */
+ UTI_FdSetCloexec(sock_fd);
+
/* Make the socket capable of re-using an old address */
if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on_off, sizeof(on_off)) < 0) {
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set reuseaddr socket options");
return 0;
}
+ UTI_FdSetCloexec(fd);
+
if (time_pps_create(fd, &handle) < 0) {
LOG_FATAL(LOGF_Refclock, "time_pps_create() failed on %s", path);
return 0;
return 0;
}
+
pps = MallocNew(struct pps_instance);
pps->handle = handle;
pps->last_seq = 0;
return 0;
}
+ UTI_FdSetCloexec(sockfd);
+
unlink(path);
if (bind(sockfd, (struct sockaddr *)&s, sizeof (s)) < 0) {
LOG_FATAL(LOGF_Refclock, "bind() failed");
return 0;
}
+ /* Close on exec */
+ UTI_FdSetCloexec(fd);
+
n_samples = 0;
n_samples_since_regression = 0;
n_runs = 0;
}
/* ================================================== */
+
+void
+UTI_FdSetCloexec(int fd)
+{
+ int flags;
+
+ flags = fcntl(fd, F_GETFD);
+ if (flags != -1) {
+ flags |= FD_CLOEXEC;
+ fcntl(fd, F_SETFD, flags);
+ }
+}
+
+/* ================================================== */
extern double UTI_FloatNetworkToHost(Float x);
extern Float UTI_FloatHostToNetwork(double x);
+/* Set FD_CLOEXEC on descriptor */
+extern void UTI_FdSetCloexec(int fd);
+
#if defined (INLINE_UTILITIES)
#define INLINE_STATIC inline static
#include "util.c"