Date: Mon, 8 Sep 2003 00:06:47 +0800 (KRAST) From: Eugene Grosbein <eugen@grosbein.pp.ru> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/56558: [PATCH] locate(1) cannot be safely used with xargs(1) Message-ID: <200309071606.h87G6l5t001833@grosbein.pp.ru> Resent-Message-ID: <200309071620.h87GK1st031012@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309071606.h87G6l5t001833>