Use the SOCK_CLOEXEC flags in the socket(2) 'type' attribute instead of

calling fcntl(2)

MFC after:	1 week
This commit is contained in:
bapt 2016-04-16 13:10:31 +00:00
parent 13b4b9515d
commit 881983d98c

View File

@ -1251,7 +1251,9 @@ setup(struct servtab *sep)
{
int on = 1;
if ((sep->se_fd = socket(sep->se_family, sep->se_socktype, 0)) < 0) {
/* Set all listening sockets to close-on-exec. */
if ((sep->se_fd = socket(sep->se_family,
sep->se_socktype | SOCK_CLOEXEC, 0)) < 0) {
if (debug)
warn("socket failed on %s/%s",
sep->se_service, sep->se_proto);
@ -1259,13 +1261,6 @@ setup(struct servtab *sep)
sep->se_service, sep->se_proto);
return;
}
/* Set all listening sockets to close-on-exec. */
if (fcntl(sep->se_fd, F_SETFD, FD_CLOEXEC) < 0) {
syslog(LOG_ERR, "%s/%s: fcntl (F_SETFD, FD_CLOEXEC): %m",
sep->se_service, sep->se_proto);
close(sep->se_fd);
return;
}
#define turnon(fd, opt) \
setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
if (strcmp(sep->se_proto, "tcp") == 0 && (options & SO_DEBUG) &&