From owner-svn-src-all@FreeBSD.ORG Sun Apr 20 16:41:32 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B0A428EA; Sun, 20 Apr 2014 16:41:32 +0000 (UTC) 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)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9022C1DFD; Sun, 20 Apr 2014 16:41:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3KGfWYh032230; Sun, 20 Apr 2014 16:41:32 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3KGfVm7032220; Sun, 20 Apr 2014 16:41:31 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201404201641.s3KGfVm7032220@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 20 Apr 2014 16:41:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r264699 - stable/9/usr.bin/find X-SVN-Group: stable-9 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.17 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, 20 Apr 2014 16:41:32 -0000 Author: jilles Date: Sun Apr 20 16:41:30 2014 New Revision: 264699 URL: http://svnweb.freebsd.org/changeset/base/264699 Log: MFC r238780,r238948: find: Implement real -ignore_readdir_race. If -ignore_readdir_race is present, [ENOENT] errors caused by deleting a file after find has read its name from a directory are ignored. Formerly, -ignore_readdir_race did nothing. PR: bin/169723 Submitted by: Valery Khromov and Andrey Ignatov (original version) Relnotes: yes Modified: stable/9/usr.bin/find/extern.h stable/9/usr.bin/find/find.1 stable/9/usr.bin/find/find.c stable/9/usr.bin/find/function.c stable/9/usr.bin/find/main.c stable/9/usr.bin/find/option.c Directory Properties: stable/9/usr.bin/find/ (props changed) Modified: stable/9/usr.bin/find/extern.h ============================================================================== --- stable/9/usr.bin/find/extern.h Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/extern.h Sun Apr 20 16:41:30 2014 (r264699) @@ -58,6 +58,7 @@ creat_f c_flags; creat_f c_follow; creat_f c_fstype; creat_f c_group; +creat_f c_ignore_readdir_race; creat_f c_inum; creat_f c_links; creat_f c_ls; @@ -111,7 +112,8 @@ exec_f f_size; exec_f f_type; exec_f f_user; -extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs; +extern int ftsoptions, ignore_readdir_race, isdeprecated, isdepth, isoutput; +extern int issort, isxargs; extern int mindepth, maxdepth; extern int regexp_flags; extern time_t now; Modified: stable/9/usr.bin/find/find.1 ============================================================================== --- stable/9/usr.bin/find/find.1 Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/find.1 Sun Apr 20 16:41:30 2014 (r264699) @@ -468,7 +468,9 @@ is numeric and there is no such group na .Ar gname is treated as a group ID. .It Ic -ignore_readdir_race -This option is for GNU find compatibility and is ignored. +Ignore errors because a file or a directory is deleted +after reading the name from a directory. +This option does not affect errors occurring on starting points. .It Ic -ilname Ar pattern Like .Ic -lname , @@ -618,7 +620,9 @@ is equivalent to .It Ic -nogroup True if the file belongs to an unknown group. .It Ic -noignore_readdir_race -This option is for GNU find compatibility and is ignored. +Turn off the effect of +.Ic -ignore_readdir_race . +This is default behaviour. .It Ic -noleaf This option is for GNU find compatibility. In GNU find it disables an optimization not relevant to Modified: stable/9/usr.bin/find/find.c ============================================================================== --- stable/9/usr.bin/find/find.c Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/find.c Sun Apr 20 16:41:30 2014 (r264699) @@ -197,8 +197,12 @@ find_execute(PLAN *plan, char *paths[]) continue; break; case FTS_DNR: - case FTS_ERR: case FTS_NS: + if (ignore_readdir_race && + entry->fts_errno == ENOENT && entry->fts_level > 0) + continue; + /* FALLTHROUGH */ + case FTS_ERR: (void)fflush(stdout); warnx("%s: %s", entry->fts_path, strerror(entry->fts_errno)); @@ -228,7 +232,7 @@ find_execute(PLAN *plan, char *paths[]) for (p = plan; p && (p->execute)(p, entry); p = p->next); } finish_execplus(); - if (errno) + if (errno && (!ignore_readdir_race || errno != ENOENT)) err(1, "fts_read"); return (rval); } Modified: stable/9/usr.bin/find/function.c ============================================================================== --- stable/9/usr.bin/find/function.c Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/function.c Sun Apr 20 16:41:30 2014 (r264699) @@ -977,6 +977,25 @@ c_group(OPTION *option, char ***argvp) } /* + * -ignore_readdir_race functions -- + * + * Always true. Ignore errors which occur if a file or a directory + * in a starting point gets deleted between reading the name and calling + * stat on it while find is traversing the starting point. + */ + +PLAN * +c_ignore_readdir_race(OPTION *option, char ***argvp __unused) +{ + if (strcmp(option->name, "-ignore_readdir_race") == 0) + ignore_readdir_race = 1; + else + ignore_readdir_race = 0; + + return palloc(option); +} + +/* * -inum n functions -- * * True if the file has inode # n. Modified: stable/9/usr.bin/find/main.c ============================================================================== --- stable/9/usr.bin/find/main.c Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/main.c Sun Apr 20 16:41:30 2014 (r264699) @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); time_t now; /* time find was run */ int dotfd; /* starting directory */ int ftsoptions; /* options for the ftsopen(3) call */ +int ignore_readdir_race; /* ignore readdir race */ int isdeprecated; /* using deprecated syntax */ int isdepth; /* do directories on post-order visit */ int isoutput; /* user specified output operator */ Modified: stable/9/usr.bin/find/option.c ============================================================================== --- stable/9/usr.bin/find/option.c Sun Apr 20 16:34:10 2014 (r264698) +++ stable/9/usr.bin/find/option.c Sun Apr 20 16:41:30 2014 (r264699) @@ -88,7 +88,7 @@ static OPTION const options[] = { { "-fstype", c_fstype, f_fstype, 0 }, { "-gid", c_group, f_group, 0 }, { "-group", c_group, f_group, 0 }, - { "-ignore_readdir_race",c_simple, f_always_true,0 }, + { "-ignore_readdir_race",c_ignore_readdir_race, f_always_true,0 }, { "-ilname", c_name, f_name, F_LINK | F_IGNCASE }, { "-iname", c_name, f_name, F_IGNCASE }, { "-inum", c_inum, f_inum, 0 }, @@ -127,7 +127,7 @@ static OPTION const options[] = { { "-newermm", c_newer, f_newer, 0 }, { "-newermt", c_newer, f_newer, F_TIME2_T }, { "-nogroup", c_nogroup, f_nogroup, 0 }, - { "-noignore_readdir_race",c_simple, f_always_true,0 }, + { "-noignore_readdir_race",c_ignore_readdir_race, f_always_true,0 }, { "-noleaf", c_simple, f_always_true, 0 }, { "-not", c_simple, f_not, 0 }, { "-nouser", c_nouser, f_nouser, 0 },