From owner-freebsd-bugs@FreeBSD.ORG Wed May 13 17:10:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0DE151065678 for ; Wed, 13 May 2009 17:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D99BF8FC30 for ; Wed, 13 May 2009 17:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n4DHA1Th053426 for ; Wed, 13 May 2009 17:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n4DHA19A053425; Wed, 13 May 2009 17:10:01 GMT (envelope-from gnats) Resent-Date: Wed, 13 May 2009 17:10:01 GMT Resent-Message-Id: <200905131710.n4DHA19A053425@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jaakko Heinonen Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B98CE10656B5 for ; Wed, 13 May 2009 17:03:04 +0000 (UTC) (envelope-from jaakko@saunalahti.fi) Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi [195.197.172.115]) by mx1.freebsd.org (Postfix) with ESMTP id 4B4398FC2B for ; Wed, 13 May 2009 17:03:03 +0000 (UTC) (envelope-from jaakko@saunalahti.fi) Received: from ws64.jh.dy.fi (a91-153-125-115.elisa-laajakaista.fi [91.153.125.115]) by gw01.mail.saunalahti.fi (Postfix) with ESMTP id D3D00151A8F for ; Wed, 13 May 2009 20:03:01 +0300 (EEST) Received: from ws64.jh.dy.fi (localhost [127.0.0.1]) by ws64.jh.dy.fi (8.14.3/8.14.3) with ESMTP id n4DH31XI015333 for ; Wed, 13 May 2009 20:03:01 +0300 (EEST) (envelope-from jaakko@ws64.jh.dy.fi) Received: (from jaakko@localhost) by ws64.jh.dy.fi (8.14.3/8.14.3/Submit) id n4DH31KN015332; Wed, 13 May 2009 20:03:01 +0300 (EEST) (envelope-from jaakko) Message-Id: <200905131703.n4DH31KN015332@ws64.jh.dy.fi> Date: Wed, 13 May 2009 20:03:01 +0300 (EEST) From: Jaakko Heinonen To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/134513: [patch] fts(3) FTS_NOCHDIR misbehavior with empty directory X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 May 2009 17:10:02 -0000 >Number: 134513 >Category: kern >Synopsis: [patch] fts(3) FTS_NOCHDIR misbehavior with empty directory >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed May 13 17:10:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Jaakko Heinonen >Release: FreeBSD 7.2-RELEASE / 8.0-CURRENT >Organization: >Environment: FreeBSD 8.0-CURRENT r191987 >Description: If you give an initial path name for fts_open() with trailing slash fts(3) will strip the slash in post-order visit although the fts(3) manual page states that the FTSENT structure will be unchanged from pre-order visit. This happens only when the directory is empty and FTS_NOCHDIR option is used. See also PR bin/133907. >How-To-Repeat: $ cc -Wall -Wextra -O ftstest.c -o ftstest (Compile the test program below.) $ mkdir x $ ./ftstest x/ level: 0 path: x/ info: 1 level: 0 path: x info: 6 (Notice missing trailing slash in post-order.) %%% #include #include #include #include int main(int argc, char **argv) { FTS *fts; FTSENT *ftsent; char *fts_argv[] = {".", NULL}; if (argc == 2) fts_argv[0] = argv[1]; fts = fts_open(fts_argv, FTS_NOCHDIR | FTS_PHYSICAL, NULL); while ((ftsent = fts_read(fts)) != NULL) { printf("level: %ld path: %s info: %d\n", (long)ftsent->fts_level, ftsent->fts_path, ftsent->fts_info); } fts_close(fts); return (0); } %%% >Fix: --- fts-NOCHDIR-trailing-slash.diff begins here --- Index: lib/libc/gen/fts.3 =================================================================== --- lib/libc/gen/fts.3 (revision 191911) +++ lib/libc/gen/fts.3 (working copy) @@ -195,7 +195,7 @@ which was not specified as a file name t .Dv FTS_SEEDOT ) . .It Dv FTS_DP A directory being visited in post-order. -The contents of the +The other fields of the .Vt FTSENT structure will be unchanged from when it was returned in pre-order, i.e., with the Index: lib/libc/gen/fts.c =================================================================== --- lib/libc/gen/fts.c (revision 191911) +++ lib/libc/gen/fts.c (working copy) @@ -836,11 +836,8 @@ mem1: saved_errno = errno; * If not changing directories, reset the path back to original * state. */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } + if (ISSET(FTS_NOCHDIR)) + sp->fts_path[cur->fts_pathlen] = '\0'; /* * If descended after called from fts_children or after called from --- fts-NOCHDIR-trailing-slash.diff ends here --- The patch also clarifies the manual page. fts_info info field has always different value in post-order. Thus it's not exactly true that the structure will be unchanged. >Release-Note: >Audit-Trail: >Unformatted: