From owner-svn-src-head@FreeBSD.ORG Sun Apr 6 20:04:33 2014 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 ESMTPS id D9849775; Sun, 6 Apr 2014 20:04:33 +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 C5FE46BF; Sun, 6 Apr 2014 20:04:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s36K4XqA063548; Sun, 6 Apr 2014 20:04:33 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s36K4XQX063547; Sun, 6 Apr 2014 20:04:33 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201404062004.s36K4XQX063547@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 6 Apr 2014 20:04:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264201 - head/usr.bin/find 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.17 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: Sun, 06 Apr 2014 20:04:33 -0000 Author: jilles Date: Sun Apr 6 20:04:33 2014 New Revision: 264201 URL: http://svnweb.freebsd.org/changeset/base/264201 Log: find: Treat errno from fts_read() more carefully. fts_read() leaves errno unchanged on EOF and sets it on error, so set errno to 0 before calling it. Also, don't trust finish_execplus() to leave errno unchanged. Modified: head/usr.bin/find/find.c Modified: head/usr.bin/find/find.c ============================================================================== --- head/usr.bin/find/find.c Sun Apr 6 20:00:42 2014 (r264200) +++ head/usr.bin/find/find.c Sun Apr 6 20:04:33 2014 (r264201) @@ -175,13 +175,13 @@ find_execute(PLAN *plan, char *paths[]) { FTSENT *entry; PLAN *p; - int rval; + int e, rval; tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL)); if (tree == NULL) err(1, "ftsopen"); - for (rval = 0; (entry = fts_read(tree)) != NULL;) { + for (rval = 0; errno = 0, (entry = fts_read(tree)) != NULL;) { if (maxdepth != -1 && entry->fts_level >= maxdepth) { if (fts_set(tree, entry, FTS_SKIP)) err(1, "%s", entry->fts_path); @@ -231,8 +231,9 @@ find_execute(PLAN *plan, char *paths[]) */ for (p = plan; p && (p->execute)(p, entry); p = p->next); } + e = errno; finish_execplus(); - if (errno && (!ignore_readdir_race || errno != ENOENT)) - err(1, "fts_read"); + if (e && (!ignore_readdir_race || e != ENOENT)) + errc(1, e, "fts_read"); return (rval); }