From owner-svn-src-head@FreeBSD.ORG Wed Aug 28 21:10:39 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5CE8E17E; Wed, 28 Aug 2013 21:10:39 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4A3FF27ED; Wed, 28 Aug 2013 21:10:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7SLAdKg092583; Wed, 28 Aug 2013 21:10:39 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7SLAcWP092577; Wed, 28 Aug 2013 21:10:38 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201308282110.r7SLAcWP092577@svn.freebsd.org> From: Jilles Tjoelker Date: Wed, 28 Aug 2013 21:10:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255007 - head/lib/libutil X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Aug 2013 21:10:39 -0000 Author: jilles Date: Wed Aug 28 21:10:37 2013 New Revision: 255007 URL: http://svnweb.freebsd.org/changeset/base/255007 Log: libutil: Use O_CLOEXEC for internal file descriptors from open(). Modified: head/lib/libutil/login_auth.c head/lib/libutil/login_cap.c head/lib/libutil/pidfile.c head/lib/libutil/quotafile.c head/lib/libutil/uucplock.c Modified: head/lib/libutil/login_auth.c ============================================================================== --- head/lib/libutil/login_auth.c Wed Aug 28 20:59:22 2013 (r255006) +++ head/lib/libutil/login_auth.c Wed Aug 28 21:10:37 2013 (r255007) @@ -98,7 +98,7 @@ auth_cat(const char *file) int fd, count; char buf[BUFSIZ]; - if ((fd = open(file, O_RDONLY)) < 0) + if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) return 0; while ((count = read(fd, buf, sizeof(buf))) > 0) (void)write(fileno(stdout), buf, count); Modified: head/lib/libutil/login_cap.c ============================================================================== --- head/lib/libutil/login_cap.c Wed Aug 28 20:59:22 2013 (r255006) +++ head/lib/libutil/login_cap.c Wed Aug 28 21:10:37 2013 (r255007) @@ -239,7 +239,7 @@ login_getclassbyname(char const *name, c break; /* Don't retry default on 'me' */ if (i == 0) r = -1; - else if ((r = open(login_dbarray[0], O_RDONLY)) >= 0) + else if ((r = open(login_dbarray[0], O_RDONLY | O_CLOEXEC)) >= 0) close(r); /* * If there's at least one login class database, Modified: head/lib/libutil/pidfile.c ============================================================================== --- head/lib/libutil/pidfile.c Wed Aug 28 20:59:22 2013 (r255006) +++ head/lib/libutil/pidfile.c Wed Aug 28 21:10:37 2013 (r255007) @@ -73,7 +73,7 @@ pidfile_read(const char *path, pid_t *pi char buf[16], *endptr; int error, fd, i; - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY | O_CLOEXEC); if (fd == -1) return (errno); Modified: head/lib/libutil/quotafile.c ============================================================================== --- head/lib/libutil/quotafile.c Wed Aug 28 20:59:22 2013 (r255006) +++ head/lib/libutil/quotafile.c Wed Aug 28 21:10:37 2013 (r255007) @@ -137,7 +137,7 @@ quota_open(struct fstab *fs, int quotaty goto error; } qf->accmode = openflags & O_ACCMODE; - if ((qf->fd = open(qf->qfname, qf->accmode)) < 0 && + if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 && (openflags & O_CREAT) != O_CREAT) goto error; /* File open worked, so process it */ @@ -168,7 +168,8 @@ quota_open(struct fstab *fs, int quotaty /* not reached */ } /* open failed, but O_CREAT was specified, so create a new file */ - if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC, 0)) < 0) + if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0)) < + 0) goto error; qf->wordsize = 64; memset(&dqh, 0, sizeof(dqh)); @@ -534,7 +535,8 @@ quota_convert(struct quotafile *qf, int free(newqf); return (-1); } - if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC, 0)) < 0) { + if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, + 0)) < 0) { serrno = errno; goto error; } Modified: head/lib/libutil/uucplock.c ============================================================================== --- head/lib/libutil/uucplock.c Wed Aug 28 20:59:22 2013 (r255006) +++ head/lib/libutil/uucplock.c Wed Aug 28 21:10:37 2013 (r255007) @@ -76,7 +76,8 @@ uu_lock(const char *tty_name) pid); (void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name); - if ((tmpfd = creat(lcktmpname, 0664)) < 0) + if ((tmpfd = open(lcktmpname, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, + 0664)) < 0) GORET(0, UU_LOCK_CREAT_ERR); for (i = 0; i < MAXTRIES; i++) { @@ -88,7 +89,7 @@ uu_lock(const char *tty_name) * check to see if the process holding the lock * still exists */ - if ((fd = open(lckname, O_RDONLY)) < 0) + if ((fd = open(lckname, O_RDONLY | O_CLOEXEC)) < 0) GORET(1, UU_LOCK_OPEN_ERR); if ((pid_old = get_pid (fd, &err)) == -1) @@ -132,7 +133,7 @@ uu_lock_txfr(const char *tty_name, pid_t snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name); - if ((fd = open(lckname, O_RDWR)) < 0) + if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) < 0) return UU_LOCK_OWNER_ERR; if (get_pid(fd, &err) != getpid()) err = UU_LOCK_OWNER_ERR;