Date: Sat, 23 Apr 2016 10:06:57 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r298509 - stable/10/usr.sbin/inetd Message-ID: <201604231006.u3NA6vcu017441@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Sat Apr 23 10:06:57 2016 New Revision: 298509 URL: https://svnweb.freebsd.org/changeset/base/298509 Log: MFC: r298111 r298114 Directly set the O_CLOEXEC flags via the open(2) attributes Use the SOCK_CLOEXEC flags in the socket(2) 'type' attribute instead of calling fcntl(2) Sponsored by: Essen Hackathon Modified: stable/10/usr.sbin/inetd/inetd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/inetd/inetd.c ============================================================================== --- stable/10/usr.sbin/inetd/inetd.c Sat Apr 23 09:15:58 2016 (r298508) +++ stable/10/usr.sbin/inetd/inetd.c Sat Apr 23 10:06:57 2016 (r298509) @@ -539,15 +539,10 @@ main(int argc, char **argv) (void)setenv("inetd_dummy", dummy, 1); } - if (pipe(signalpipe) != 0) { + if (pipe2(signalpipe, O_CLOEXEC) != 0) { syslog(LOG_ERR, "pipe: %m"); exit(EX_OSERR); } - if (fcntl(signalpipe[0], F_SETFD, FD_CLOEXEC) < 0 || - fcntl(signalpipe[1], F_SETFD, FD_CLOEXEC) < 0) { - syslog(LOG_ERR, "signalpipe: fcntl (F_SETFD, FD_CLOEXEC): %m"); - exit(EX_OSERR); - } FD_SET(signalpipe[0], &allsock); #ifdef SANITY_CHECK nsock++; @@ -1256,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); @@ -1264,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) &&
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604231006.u3NA6vcu017441>