From owner-svn-src-all@FreeBSD.ORG Thu Aug 9 22:05:41 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B0D25106566C; Thu, 9 Aug 2012 22:05:41 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9127E8FC08; Thu, 9 Aug 2012 22:05:41 +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 q79M5f6j058913; Thu, 9 Aug 2012 22:05:41 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q79M5fvN058909; Thu, 9 Aug 2012 22:05:41 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201208092205.q79M5fvN058909@svn.freebsd.org> From: Jilles Tjoelker Date: Thu, 9 Aug 2012 22:05:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239160 - in head: lib/libc/gen tools/regression/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Thu, 09 Aug 2012 22:05:41 -0000 Author: jilles Date: Thu Aug 9 22:05:40 2012 New Revision: 239160 URL: http://svn.freebsd.org/changeset/base/239160 Log: nftw(): POSIX says directories causing loops should be silently skipped. Formerly, loops caused nftw() to abort the traversal with ELOOP. Added: head/tools/regression/lib/libc/gen/test-ftw.c (contents, props changed) Modified: head/lib/libc/gen/nftw.c head/tools/regression/lib/libc/gen/Makefile Modified: head/lib/libc/gen/nftw.c ============================================================================== --- head/lib/libc/gen/nftw.c Thu Aug 9 20:27:11 2012 (r239159) +++ head/lib/libc/gen/nftw.c Thu Aug 9 22:05:40 2012 (r239160) @@ -65,6 +65,8 @@ nftw(const char *path, int (*fn)(const c continue; fnflag = FTW_D; break; + case FTS_DC: + continue; case FTS_DNR: fnflag = FTW_DNR; break; @@ -87,9 +89,6 @@ nftw(const char *path, int (*fn)(const c case FTS_SLNONE: fnflag = FTW_SLN; break; - case FTS_DC: - errno = ELOOP; - /* FALLTHROUGH */ default: error = -1; goto done; Modified: head/tools/regression/lib/libc/gen/Makefile ============================================================================== --- head/tools/regression/lib/libc/gen/Makefile Thu Aug 9 20:27:11 2012 (r239159) +++ head/tools/regression/lib/libc/gen/Makefile Thu Aug 9 22:05:40 2012 (r239160) @@ -1,7 +1,7 @@ # $FreeBSD$ TESTS= test-arc4random test-fmtcheck test-fmtmsg test-fnmatch \ - test-fpclassify test-posix_spawn test-wordexp + test-fpclassify test-ftw test-posix_spawn test-wordexp .PHONY: tests tests: ${TESTS} Added: head/tools/regression/lib/libc/gen/test-ftw.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/lib/libc/gen/test-ftw.c Thu Aug 9 22:05:40 2012 (r239160) @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2012 Jilles Tjoelker + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* + * Limited test program for nftw() as specified by IEEE Std. 1003.1-2008. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +extern char **environ; + +static char dir[] = "/tmp/testftw.XXXXXXXXXX"; +static int failures; +static int ftwflags; + +static void +cleanup(int ustatus __unused) +{ + int error, status; + pid_t pid, waitres; + const char *myargs[5]; + + err_set_exit(NULL); + myargs[0] = "rm"; + myargs[1] = "-rf"; + myargs[2] = "--"; + myargs[3] = dir; + myargs[4] = NULL; + error = posix_spawnp(&pid, myargs[0], NULL, NULL, + __DECONST(char **, myargs), environ); + if (error != 0) + warn("posix_spawnp rm"); + else { + waitres = waitpid(pid, &status, 0); + if (waitres != pid) + warnx("waitpid rm failed"); + else if (status != 0) + warnx("rm failed"); + } +} + +static int +cb(const char *path, const struct stat *st, int type, struct FTW *f) +{ + + switch (type) { + case FTW_D: + if ((ftwflags & FTW_DEPTH) == 0) + return (0); + break; + case FTW_DP: + if ((ftwflags & FTW_DEPTH) != 0) + return (0); + break; + case FTW_SL: + if ((ftwflags & FTW_PHYS) != 0) + return (0); + break; + } + warnx("unexpected path=%s type=%d f.level=%d\n", + path, type, f->level); + failures++; + return (0); +} + +int +main(int argc, char *argv[]) +{ + int fd; + + if (!mkdtemp(dir)) + err(2, "mkdtemp"); + + err_set_exit(cleanup); + + fd = open(dir, O_DIRECTORY | O_RDONLY); + if (fd == -1) + err(2, "open %s", dir); + + if (mkdirat(fd, "d1", 0777) == -1) + err(2, "mkdirat d1"); + + if (symlinkat(dir, fd, "d1/looper") == -1) + err(2, "symlinkat looper"); + + ftwflags = FTW_PHYS; + if (nftw(dir, cb, 10, ftwflags) == -1) + err(2, "nftw FTW_PHYS"); + ftwflags = FTW_PHYS | FTW_DEPTH; + if (nftw(dir, cb, 10, ftwflags) == -1) + err(2, "nftw FTW_PHYS | FTW_DEPTH"); + ftwflags = 0; + if (nftw(dir, cb, 10, ftwflags) == -1) + err(2, "nftw 0"); + ftwflags = FTW_DEPTH; + if (nftw(dir, cb, 10, ftwflags) == -1) + err(2, "nftw FTW_DEPTH"); + + close(fd); + + printf("PASS nftw()\n"); + + cleanup(failures != 0); + + return (failures != 0); +}