From owner-svn-src-projects@FreeBSD.ORG Mon Aug 22 23:54:13 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0E0E1106566C; Mon, 22 Aug 2011 23:54:13 +0000 (UTC) (envelope-from mdf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EF5358FC13; Mon, 22 Aug 2011 23:54:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7MNsC5s074765; Mon, 22 Aug 2011 23:54:12 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7MNsC9B074753; Mon, 22 Aug 2011 23:54:12 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201108222354.p7MNsC9B074753@svn.freebsd.org> From: Matthew D Fleming Date: Mon, 22 Aug 2011 23:54:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225097 - in projects/ino64: include lib/libc/gen usr.sbin/cpucontrol usr.sbin/lpr/common_source usr.sbin/newsyslog X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2011 23:54:13 -0000 Author: mdf Date: Mon Aug 22 23:54:12 2011 New Revision: 225097 URL: http://svn.freebsd.org/changeset/base/225097 Log: Avoid using dirfd name there is dirfd() macro already. Use dirfd() instead of dirp->dd_fd. Replace dirfd() macro with exported libc symbol. Use _dirfd() macro internally. GSoC r222835, r222836, r222837. Code by Gleb Kurtsou. Added: projects/ino64/lib/libc/gen/dirfd.c (contents, props changed) Modified: projects/ino64/include/dirent.h projects/ino64/lib/libc/gen/Makefile.inc projects/ino64/lib/libc/gen/Symbol.map projects/ino64/lib/libc/gen/dirent-private.h projects/ino64/lib/libc/gen/fts-compat.c projects/ino64/lib/libc/gen/fts.c projects/ino64/lib/libc/gen/getcwd.c projects/ino64/usr.sbin/cpucontrol/cpucontrol.c projects/ino64/usr.sbin/lpr/common_source/common.c projects/ino64/usr.sbin/newsyslog/newsyslog.c Modified: projects/ino64/include/dirent.h ============================================================================== --- projects/ino64/include/dirent.h Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/include/dirent.h Mon Aug 22 23:54:12 2011 (r225097) @@ -80,6 +80,7 @@ int alphasort(const struct dirent **, c DIR *__opendir2(const char *, int); int getdents(int, char *, int); int getdirentries(int, char *, int, long *); +int dirfd(DIR *); #endif DIR *opendir(const char *); DIR *fdopendir(int); Modified: projects/ino64/lib/libc/gen/Makefile.inc ============================================================================== --- projects/ino64/lib/libc/gen/Makefile.inc Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/Makefile.inc Mon Aug 22 23:54:12 2011 (r225097) @@ -9,7 +9,7 @@ SRCS+= __getosreldate.c __xuname.c \ _thread_init.c \ alarm.c arc4random.c assert.c aux.c basename.c check_utility_compat.c \ clock.c closedir.c confstr.c \ - crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ + crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \ dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \ exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \ fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \ Modified: projects/ino64/lib/libc/gen/Symbol.map ============================================================================== --- projects/ino64/lib/libc/gen/Symbol.map Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/Symbol.map Mon Aug 22 23:54:12 2011 (r225097) @@ -359,6 +359,7 @@ FBSD_1.1 { FBSD_1.2 { basename_r; cfmakesane; + dirfd; endutxent; getpagesizes; getutxent; Modified: projects/ino64/lib/libc/gen/dirent-private.h ============================================================================== --- projects/ino64/lib/libc/gen/dirent-private.h Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/dirent-private.h Mon Aug 22 23:54:12 2011 (r225097) @@ -49,6 +49,6 @@ struct _dirdesc { struct _telldir *dd_td; /* telldir position recording */ }; -#define dirfd(dirp) ((dirp)->dd_fd) +#define _dirfd(dirp) ((dirp)->dd_fd) #endif /* !_DIRENT_PRIVATE_H_ */ Added: projects/ino64/lib/libc/gen/dirfd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/ino64/lib/libc/gen/dirfd.c Mon Aug 22 23:54:12 2011 (r225097) @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include + +#include +#include "un-namespace.h" + +#include "dirent-private.h" + +int +dirfd(DIR *dirp) +{ + if (dirp == NULL) + return (-1); + + return (_dirfd(dirp)); +} Modified: projects/ino64/lib/libc/gen/fts-compat.c ============================================================================== --- projects/ino64/lib/libc/gen/fts-compat.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/fts-compat.c Mon Aug 22 23:54:12 2011 (r225097) @@ -713,7 +713,7 @@ fts_build(sp, type) */ cderrno = 0; if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; Modified: projects/ino64/lib/libc/gen/fts.c ============================================================================== --- projects/ino64/lib/libc/gen/fts.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/fts.c Mon Aug 22 23:54:12 2011 (r225097) @@ -710,7 +710,7 @@ fts_build(sp, type) */ cderrno = 0; if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; Modified: projects/ino64/lib/libc/gen/getcwd.c ============================================================================== --- projects/ino64/lib/libc/gen/getcwd.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/lib/libc/gen/getcwd.c Mon Aug 22 23:54:12 2011 (r225097) @@ -119,7 +119,7 @@ getcwd(pt, size) for (first = 1;; first = 0) { /* Stat the current level. */ - if (dir != NULL ? _fstat(dirfd(dir), &s) : lstat(".", &s)) + if (dir != NULL ? _fstat(_dirfd(dir), &s) : lstat(".", &s)) goto err; /* Save current node values. */ @@ -141,13 +141,13 @@ getcwd(pt, size) } /* Open and stat parent directory. */ - fd = _openat(dir != NULL ? dirfd(dir) : AT_FDCWD, + fd = _openat(dir != NULL ? _dirfd(dir) : AT_FDCWD, "..", O_RDONLY); if (fd == -1) goto err; if (dir) (void) closedir(dir); - if (!(dir = fdopendir(fd)) || _fstat(dirfd(dir), &s)) { + if (!(dir = fdopendir(fd)) || _fstat(_dirfd(dir), &s)) { _close(fd); goto err; } @@ -173,7 +173,7 @@ getcwd(pt, size) continue; /* Save the first error for later. */ - if (fstatat(dirfd(dir), dp->d_name, &s, + if (fstatat(_dirfd(dir), dp->d_name, &s, AT_SYMLINK_NOFOLLOW)) { if (!save_errno) save_errno = errno; Modified: projects/ino64/usr.sbin/cpucontrol/cpucontrol.c ============================================================================== --- projects/ino64/usr.sbin/cpucontrol/cpucontrol.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/usr.sbin/cpucontrol/cpucontrol.c Mon Aug 22 23:54:12 2011 (r225097) @@ -290,7 +290,7 @@ do_update(const char *dev) int error; struct ucode_handler *handler; struct datadir *dir; - DIR *dirfd; + DIR *dirp; struct dirent *direntry; char buf[MAXPATHLEN]; @@ -319,12 +319,12 @@ do_update(const char *dev) * Process every image in specified data directories. */ SLIST_FOREACH(dir, &datadirs, next) { - dirfd = opendir(dir->path); - if (dirfd == NULL) { + dirp = opendir(dir->path); + if (dirp == NULL) { WARNX(1, "skipping directory %s: not accessible", dir->path); continue; } - while ((direntry = readdir(dirfd)) != NULL) { + while ((direntry = readdir(dirp)) != NULL) { if (direntry->d_namlen == 0) continue; error = snprintf(buf, sizeof(buf), "%s/%s", dir->path, @@ -338,7 +338,7 @@ do_update(const char *dev) } handler->update(dev, buf); } - error = closedir(dirfd); + error = closedir(dirp); if (error != 0) WARN(0, "closedir(%s)", dir->path); } Modified: projects/ino64/usr.sbin/lpr/common_source/common.c ============================================================================== --- projects/ino64/usr.sbin/lpr/common_source/common.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/usr.sbin/lpr/common_source/common.c Mon Aug 22 23:54:12 2011 (r225097) @@ -130,7 +130,7 @@ getq(const struct printer *pp, struct jo seteuid(uid); return (-1); } - if (fstat(dirp->dd_fd, &stbuf) < 0) + if (fstat(dirfd(dirp), &stbuf) < 0) goto errdone; seteuid(uid); Modified: projects/ino64/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- projects/ino64/usr.sbin/newsyslog/newsyslog.c Mon Aug 22 23:39:40 2011 (r225096) +++ projects/ino64/usr.sbin/newsyslog/newsyslog.c Mon Aug 22 23:54:12 2011 (r225097) @@ -1448,7 +1448,7 @@ static void delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir) { char *logfname, *s, *dir, errbuf[80]; - int dirfd, i, logcnt, max_logcnt, valid; + int dir_fd, i, logcnt, max_logcnt, valid; struct oldlog_entry *oldlogs; size_t logfname_len; struct dirent *dp; @@ -1483,7 +1483,7 @@ delete_oldest_timelog(const struct conf_ /* First we create a 'list' of all archived logfiles */ if ((dirp = opendir(dir)) == NULL) err(1, "Cannot open log directory '%s'", dir); - dirfd = dirfd(dirp); + dir_fd = dirfd(dirp); while ((dp = readdir(dirp)) != NULL) { if (dp->d_type != DT_REG) continue; @@ -1575,7 +1575,7 @@ delete_oldest_timelog(const struct conf_ if (noaction) printf("\trm -f %s/%s\n", dir, oldlogs[i].fname); - else if (unlinkat(dirfd, oldlogs[i].fname, 0) != 0) { + else if (unlinkat(dir_fd, oldlogs[i].fname, 0) != 0) { snprintf(errbuf, sizeof(errbuf), "Could not delet old logfile '%s'", oldlogs[i].fname);