From owner-svn-src-head@FreeBSD.ORG Sun Jan 5 23:01:29 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 BE228802; Sun, 5 Jan 2014 23:01:29 +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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 912EE1D4A; Sun, 5 Jan 2014 23:01:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s05N1TcH022660; Sun, 5 Jan 2014 23:01:29 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s05N1TjX022655; Sun, 5 Jan 2014 23:01:29 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201401052301.s05N1TjX022655@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 5 Jan 2014 23:01:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260355 - 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, 05 Jan 2014 23:01:29 -0000 Author: jilles Date: Sun Jan 5 23:01:28 2014 New Revision: 260355 URL: http://svnweb.freebsd.org/changeset/base/260355 Log: find: Fix two more problems with -lname and -ilname: * Do not match symlinks that are followed because of -H or -L. This is explicitly documented in GNU find's info file and is like -type l. * Fix matching symlinks in subdirectories when fts changes directories. Also, avoid some readlink() calls on files that are obviously not symlinks (because of fts(3) restrictions, not all of them). MFC after: 1 week Modified: head/usr.bin/find/find.1 head/usr.bin/find/function.c Modified: head/usr.bin/find/find.1 ============================================================================== --- head/usr.bin/find/find.1 Sun Jan 5 23:00:38 2014 (r260354) +++ head/usr.bin/find/find.1 Sun Jan 5 23:01:28 2014 (r260355) @@ -31,7 +31,7 @@ .\" @(#)find.1 8.7 (Berkeley) 5/9/95 .\" $FreeBSD$ .\" -.Dd November 18, 2012 +.Dd January 5, 2014 .Dt FIND 1 .Os .Sh NAME @@ -520,6 +520,8 @@ Like .Ic -name , but the contents of the symbolic link are matched instead of the file name. +Note that this only matches broken symbolic links +if symbolic links are being followed. This is a GNU find extension. .It Ic -ls This primary always evaluates to true. Modified: head/usr.bin/find/function.c ============================================================================== --- head/usr.bin/find/function.c Sun Jan 5 23:00:38 2014 (r260354) +++ head/usr.bin/find/function.c Sun Jan 5 23:01:28 2014 (r260355) @@ -1125,7 +1125,17 @@ f_name(PLAN *plan, FTSENT *entry) ssize_t len; if (plan->flags & F_LINK) { - len = readlink(entry->fts_path, fn, sizeof(fn) - 1); + /* + * The below test both avoids obviously useless readlink() + * calls and ensures that symlinks with existent target do + * not match if symlinks are being followed. + * Assumption: fts will stat all symlinks that are to be + * followed and will return the stat information. + */ + if (entry->fts_info != FTS_NSOK && entry->fts_info != FTS_SL && + entry->fts_info != FTS_SLNONE) + return 0; + len = readlink(entry->fts_accpath, fn, sizeof(fn) - 1); if (len == -1) return 0; fn[len] = '\0';