From owner-svn-src-all@FreeBSD.ORG Sun May 5 10:51:41 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B100CDB4; Sun, 5 May 2013 10:51:41 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id A3A4C955; Sun, 5 May 2013 10:51:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r45Apfnu037529; Sun, 5 May 2013 10:51:41 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r45Apewp037524; Sun, 5 May 2013 10:51:40 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201305051051.r45Apewp037524@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 5 May 2013 10:51:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250267 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 May 2013 10:51:41 -0000 Author: jilles Date: Sun May 5 10:51:40 2013 New Revision: 250267 URL: http://svnweb.freebsd.org/changeset/base/250267 Log: sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call. Modified: head/bin/sh/input.c head/bin/sh/jobs.c head/bin/sh/main.c head/bin/sh/redir.c Modified: head/bin/sh/input.c ============================================================================== --- head/bin/sh/input.c Sun May 5 09:38:25 2013 (r250266) +++ head/bin/sh/input.c Sun May 5 10:51:40 2013 (r250267) @@ -397,10 +397,10 @@ setinputfile(const char *fname, int push int fd2; INTOFF; - if ((fd = open(fname, O_RDONLY)) < 0) + if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0) error("cannot open %s: %s", fname, strerror(errno)); if (fd < 10) { - fd2 = fcntl(fd, F_DUPFD, 10); + fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 10); close(fd); if (fd2 < 0) error("Out of file descriptors"); @@ -412,14 +412,13 @@ setinputfile(const char *fname, int push /* - * Like setinputfile, but takes an open file descriptor. Call this with - * interrupts off. + * Like setinputfile, but takes an open file descriptor (which should have + * its FD_CLOEXEC flag already set). Call this with interrupts off. */ void setinputfd(int fd, int push) { - (void)fcntl(fd, F_SETFD, FD_CLOEXEC); if (push) { pushfile(); parsefile->buf = ckmalloc(BUFSIZ + 1); Modified: head/bin/sh/jobs.c ============================================================================== --- head/bin/sh/jobs.c Sun May 5 09:38:25 2013 (r250266) +++ head/bin/sh/jobs.c Sun May 5 10:51:40 2013 (r250267) @@ -127,11 +127,12 @@ setjobctl(int on) if (on) { if (ttyfd != -1) close(ttyfd); - if ((ttyfd = open(_PATH_TTY, O_RDWR)) < 0) { + if ((ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC)) < 0) { i = 0; while (i <= 2 && !isatty(i)) i++; - if (i > 2 || (ttyfd = fcntl(i, F_DUPFD, 10)) < 0) + if (i > 2 || + (ttyfd = fcntl(i, F_DUPFD_CLOEXEC, 10)) < 0) goto out; } if (ttyfd < 10) { @@ -139,7 +140,7 @@ setjobctl(int on) * Keep our TTY file descriptor out of the way of * the user's redirections. */ - if ((i = fcntl(ttyfd, F_DUPFD, 10)) < 0) { + if ((i = fcntl(ttyfd, F_DUPFD_CLOEXEC, 10)) < 0) { close(ttyfd); ttyfd = -1; goto out; @@ -147,11 +148,6 @@ setjobctl(int on) close(ttyfd); ttyfd = i; } - if (fcntl(ttyfd, F_SETFD, FD_CLOEXEC) < 0) { - close(ttyfd); - ttyfd = -1; - goto out; - } do { /* while we are in the background */ initialpgrp = tcgetpgrp(ttyfd); if (initialpgrp < 0) { Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Sun May 5 09:38:25 2013 (r250266) +++ head/bin/sh/main.c Sun May 5 10:51:40 2013 (r250267) @@ -248,7 +248,7 @@ read_profile(const char *name) if (expandedname == NULL) return; INTOFF; - if ((fd = open(expandedname, O_RDONLY)) >= 0) + if ((fd = open(expandedname, O_RDONLY | O_CLOEXEC)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) Modified: head/bin/sh/redir.c ============================================================================== --- head/bin/sh/redir.c Sun May 5 09:38:25 2013 (r250266) +++ head/bin/sh/redir.c Sun May 5 10:51:40 2013 (r250267) @@ -121,7 +121,7 @@ redirect(union node *redir, int flags) if ((flags & REDIR_PUSH) && sv->renamed[fd] == EMPTY) { INTOFF; - if ((i = fcntl(fd, F_DUPFD, 10)) == -1) { + if ((i = fcntl(fd, F_DUPFD_CLOEXEC, 10)) == -1) { switch (errno) { case EBADF: i = CLOSED; @@ -131,8 +131,7 @@ redirect(union node *redir, int flags) error("%d: %s", fd, strerror(errno)); break; } - } else - (void)fcntl(i, F_SETFD, FD_CLOEXEC); + } sv->renamed[fd] = i; INTON; }