From 881983d98c30c4b633b31d9e3b3a70acdbafcb21 Mon Sep 17 00:00:00 2001 From: bapt Date: Sat, 16 Apr 2016 13:10:31 +0000 Subject: [PATCH] Use the SOCK_CLOEXEC flags in the socket(2) 'type' attribute instead of calling fcntl(2) MFC after: 1 week --- usr.sbin/inetd/inetd.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index f2d504f6243c..752a7a4b5138 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -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) &&