From owner-freebsd-bugs@FreeBSD.ORG Sun Sep 7 09:20:04 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35E0316A4BF for ; Sun, 7 Sep 2003 09:20:04 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4737444001 for ; Sun, 7 Sep 2003 09:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h87GK1Up031013 for ; Sun, 7 Sep 2003 09:20:01 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h87GK1st031012; Sun, 7 Sep 2003 09:20:01 -0700 (PDT) Resent-Date: Sun, 7 Sep 2003 09:20:01 -0700 (PDT) Resent-Message-Id: <200309071620.h87GK1st031012@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, Eugene Grosbein Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9C17216A4BF for ; Sun, 7 Sep 2003 09:15:06 -0700 (PDT) Received: from grosbein.pp.ru (D00015.dialonly.kemerovo.su [213.184.66.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7462D43FF2 for ; Sun, 7 Sep 2003 09:15:02 -0700 (PDT) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (smmsp@localhost [127.0.0.1]) by grosbein.pp.ru (8.12.9/8.12.9) with ESMTP id h87G7wZ1001880 for ; Mon, 8 Sep 2003 00:07:58 +0800 (KRAST) (envelope-from eugen@grosbein.pp.ru) Received: (from eugen@localhost) by grosbein.pp.ru (8.12.9/8.12.9/Submit) id h87G6l5t001833; Mon, 8 Sep 2003 00:06:47 +0800 (KRAST) (envelope-from eugen) Message-Id: <200309071606.h87G6l5t001833@grosbein.pp.ru> Date: Mon, 8 Sep 2003 00:06:47 +0800 (KRAST) From: Eugene Grosbein To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/56558: [PATCH] locate(1) cannot be safely used with xargs(1) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Eugene Grosbein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Sep 2003 16:20:04 -0000 >Number: 56558 >Category: bin >Synopsis: [PATCH] locate(1) cannot be safely used with xargs(1) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Sep 07 09:20:00 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Eugene Grosbein >Release: FreeBSD 4.9-PRERELEASE i386 >Organization: Svyaz Service JSC >Environment: System: FreeBSD grosbein.pp.ru 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #19: Fri Sep 5 23:33:57 KRAST 2003 eu@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV i386 >Description: 'locate pattern | xargs' will fail when found pathname contains signle quote character, for example. >How-To-Repeat: Obvious. >Fix: Implement an option -0 for locate(1) to make it compatible with xargs -0. A patch for locate(1) man page and source follows. --- locate.1.orig Tue Jul 9 05:31:28 2002 +++ locate.1 Sun Sep 7 23:58:21 2003 @@ -41,7 +41,7 @@ .Nd find filenames quickly .Sh SYNOPSIS .Nm -.Op Fl Scims +.Op Fl 0Scims .Op Fl l Ar limit .Op Fl d Ar database .Ar pattern ... @@ -89,6 +89,11 @@ .Pp The following options are available: .Bl -tag -width 10n +.It Fl 0 +Print pathnames separated by an +.Tn ASCII NUL +character (character code 0) instead of default NL +(newline, character code 10). .It Fl S Print some statistic about the database and exit. .It Fl c --- fastfind.c.orig Sun Sep 7 23:49:30 2003 +++ fastfind.c Sun Sep 7 23:44:23 2003 @@ -103,6 +103,7 @@ } #endif /* _LOCATE_STATISTIC_ */ +extern char separator; void #ifdef FF_MMAP @@ -315,11 +316,11 @@ else if (f_limit) { counter++; if (f_limit >= counter) - (void)puts(path); + (void)printf("%s%c",path,separator); else errx(0, "[show only %d lines]", counter - 1); } else - (void)puts(path); + (void)printf("%s%c",path,separator); } break; } --- locate.c.orig Sun Mar 4 15:47:25 2001 +++ locate.c Sun Sep 7 23:44:30 2003 @@ -120,6 +120,7 @@ int f_silent; /* suppress output, show only count of matches */ int f_limit; /* limit number of output lines, 0 == infinite */ u_int counter; /* counter for matches [-c] */ +char separator='\n'; /* line separator */ void usage __P((void)); @@ -152,8 +153,11 @@ #endif (void) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "Scd:il:ms")) != -1) + while ((ch = getopt(argc, argv, "0Scd:il:ms")) != -1) switch(ch) { + case '0': /* 'find -print0' style */ + separator = '\0'; + break; case 'S': /* statistic lines */ f_statistic = 1; break; Eugene Grosbein >Release-Note: >Audit-Trail: >Unformatted: