// shut down properly.
static_cast<void>(remove(file_name.c_str()));
+ // Set this socket to be closed-on-exec.
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
+ const char* errmsg = strerror(errno);
+ ::close(fd);
+ isc_throw(SocketError, "Failed to set close-on-exec on unix socket\
+ "
+ << fd << ": " << errmsg);
+ }
+
// Set this socket to be non-blocking one.
- if (fcntl(fd, F_SETFL, O_NONBLOCK) !=0 ) {
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) != 0) {
const char* errmsg = strerror(errno);
::close(fd);
isc_throw(SocketError, "Failed to set non-block mode on unix socket "
#include <boost/array.hpp>
#include <boost/static_assert.hpp>
+#include <fcntl.h>
#include <stdint.h>
#include <net/if.h>
#include <linux/rtnetlink.h>
isc_throw(Unexpected, "Failed to create NETLINK socket.");
}
+ if (fcntl(fd_, F_SETFD, FD_CLOEXEC) < 0) {
+ isc_throw(Unexpected, "Failed to set close-on-exec in NETLINK socket.");
+ }
+
if (setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &SNDBUF_SIZE, sizeof(SNDBUF_SIZE)) < 0) {
isc_throw(Unexpected, "Failed to set send buffer in NETLINK socket.");
}
-// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
" address " << addr << ", port " << port
<< ", reason: " << strerror(errno));
}
+ // Set the close-on-exec flag.
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ close(sock);
+ isc_throw(SocketConfigError, "Failed to set close-on-exec flag"
+ << " on fallback socket for address " << addr
+ << ", port " << port
+ << ", reason: " << strerror(errno));
+ }
// Bind the socket to a specified address and port.
struct sockaddr_in addr4;
memset(&addr4, 0, sizeof(addr4));
}
}
+ // Set the close-on-exec flag.
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ close(fallback);
+ close(sock);
+ isc_throw(SocketConfigError, "Failed to set close-on-exec flag"
+ << " on BPF device with interface " << iface.getName());
+ }
+
// The BPF device is now open. Now it needs to be configured.
// Associate the device with the interface name.
#include <dhcp/pkt_filter_inet.h>
#include <errno.h>
#include <cstring>
+#include <fcntl.h>
using namespace isc::asiolink;
isc_throw(SocketConfigError, "Failed to create UDP6 socket.");
}
+ // Set the close-on-exec flag.
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ close(sock);
+ isc_throw(SocketConfigError, "Failed to set close-on-exec flag"
+ << " on socket " << sock);
+ }
+
#ifdef SO_BINDTODEVICE
if (receive_bcast && iface.flag_broadcast_) {
// Bind to device so as we receive traffic on a specific interface.
#include <dhcp/pkt_filter_inet6.h>
#include <util/io/pktinfo_utilities.h>
+#include <fcntl.h>
#include <netinet/in.h>
using namespace isc::asiolink;
isc_throw(SocketConfigError, "Failed to create UDP6 socket.");
}
+ // Set the close-on-exec flag.
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ close(sock);
+ isc_throw(SocketConfigError, "Failed to set close-on-exec flag"
+ << " on IPv6 socket.");
+ }
+
// Set SO_REUSEADDR option.
int flag = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
#include <dhcp/pkt_filter_lpf.h>
#include <dhcp/protocol_util.h>
#include <exceptions/exceptions.h>
+#include <fcntl.h>
#include <linux/filter.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
isc_throw(SocketConfigError, "Failed to create raw LPF socket");
}
+ // Set the close-on-exec flag.
+ if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
+ close(sock);
+ close(fallback);
+ isc_throw(SocketConfigError, "Failed to set close-on-exec flag"
+ << " on the socket " << sock);
+ }
+
// Create socket filter program. This program will only allow incoming UDP
// traffic which arrives on the specific (DHCP) port). It will also filter
// out all fragmented packets.
source_ = fds[1];
sink_ = fds[0];
+ if (fcntl(source_, F_SETFD, FD_CLOEXEC)) {
+ const char* errstr = strerror(errno);
+ isc_throw(WatchSocketError, "Cannot set source to close-on-exec: "
+ << errstr);
+ }
+
+ if (fcntl(sink_, F_SETFD, FD_CLOEXEC)) {
+ const char* errstr = strerror(errno);
+ isc_throw(WatchSocketError, "Cannot set sink to close-on-exec: "
+ << errstr);
+ }
+
if (fcntl(sink_, F_SETFL, O_NONBLOCK)) {
const char* errstr = strerror(errno);
isc_throw(WatchSocketError, "Cannot set sink to non-blocking: "