From edwin@mavetju.org  Fri May 30 06:15:46 2008
Return-Path: <edwin@mavetju.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id AA6EE106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 May 2008 06:15:46 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: from mail5out.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	by mx1.freebsd.org (Postfix) with ESMTP id 5D6608FC16
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 May 2008 06:15:46 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: by mail5out.barnet.com.au (Postfix, from userid 1001)
	id 3EFAB221919C; Fri, 30 May 2008 16:15:45 +1000 (EST)
Received: from mail5auth.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail5auth.barnet.com.au", Issuer "*.barnet.com.au" (verified OK))
	by mail5.barnet.com.au (Postfix) with ESMTP id B569721B33E2
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 May 2008 16:15:44 +1000 (EST)
Received: from k7.mavetju (k7.mavetju.org [10.251.1.18])
	by mail5auth.barnet.com.au (Postfix) with ESMTP id 55B0D2218FE0
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 30 May 2008 16:15:44 +1000 (EST)
Received: by k7.mavetju (Postfix, from userid 1001)
	id F3B7F98E; Fri, 30 May 2008 16:15:43 +1000 (EST)
Message-Id: <20080530061543.F3B7F98E@k7.mavetju>
Date: Fri, 30 May 2008 16:15:43 +1000 (EST)
From: Edwin Groothuis <edwin@mavetju.org>
Reply-To: Edwin Groothuis <edwin@mavetju.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: locate(1) doesn't check /etc/locate.rc for the default database
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         124119
>Category:       bin
>Synopsis:       locate(1) doesn't check /etc/locate.rc for the default database
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 30 06:20:01 UTC 2008
>Closed-Date:    
>Last-Modified:  Mon Aug 18 06:10:00 UTC 2008
>Originator:     Edwin Groothuis
>Release:        FreeBSD 7.0-RELEASE i386
>Organization:
-
>Environment:
System: FreeBSD k7.mavetju 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC 2008 root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386


>Description:

    [~] root@k7>grep FCODES /etc/locate.rc 
    FCODES="/usr/var/locate/locate.database"
    [~] root@k7>locate foo
    locate: database too small: /var/db/locate.database

    This PR is more a placeholder for me to remember to fix it. Or
    at least discuss it.

>How-To-Repeat:
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Aug 18 06:00:16 UTC 2008 
Responsible-Changed-Why:  
It's mine 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124119 

From: Edwin Groothuis <edwin@freebsd.org>
To: bde@freebsd.org
Cc: bug-followup@freebsd.org
Subject: bin/124119: locate(1) doesn't check /etc/locate.rc for the default database
Date: Mon, 18 Aug 2008 15:49:00 +1000

 --ZPt4rx8FFjLCG7dd
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 The PR is about that if you change the location of the database in
 /etc/rc.local, not all locate-related tools (locate(1),
 /etc/periodic/weekly/310.locate) do follow up on them.
 
 The first patch is the 310.locate script, which needs to know that
 it should initialize the right database.
 
 The second patch updates the man-page, adds some more comments to
 the locate.rc and the patches locate.c file itself to first see if
 the -d option was given, then if LOCATE_PATH exists in the environment,
 then checks for the line FCODES in /etc/locate.rc, and then if
 everything fails it uses _PATH_FCODES value.
 
 What do you think of it?
 
 -- 
 Edwin Groothuis
 edwin@freebsd.org
 http://www.mavetju.org
 
 --ZPt4rx8FFjLCG7dd
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=a
 
 Index: locate/locate.1
 ===================================================================
 --- locate/locate.1	(revision 181277)
 +++ locate/locate.1	(working copy)
 @@ -195,9 +195,12 @@
  .Sh FILES
  .Bl -tag -width /etc/periodic/weekly/310.locate -compact
  .It Pa /var/db/locate.database
 -locate database
 +The default locate database
  .It Pa /usr/libexec/locate.updatedb
  Script to update the locate database
 +.It Pa /etc/locate.rc
 +The configuration file,
 +checked for the FCODES line to determine the locate database to be used.
  .It Pa /etc/periodic/weekly/310.locate
  Script that starts the database rebuild
  .El
 Index: locate/pathnames.h
 ===================================================================
 --- locate/pathnames.h	(revision 181277)
 +++ locate/pathnames.h	(working copy)
 @@ -34,3 +34,4 @@
   */
  
  #define	_PATH_FCODES	"/var/db/locate.database"
 +#define	_PATH_RCFILE	"/etc/locate.rc"
 Index: locate/locate.c
 ===================================================================
 --- locate/locate.c	(revision 181277)
 +++ locate/locate.c	(working copy)
 @@ -186,17 +186,50 @@
          if (argc < 1 && !(f_statistic))
                  usage();
  
 +	/*
 +	 * Order of preference for the locate database:
 +	 * - Commandline argument -d (done in getopt())
 +	 * - Environment variable LOCATE_PATH
 +	 * - Value of FCODES in /etc/locate.rc
 +	 * - _PATH_FCODES
 +	 */
          /* no (valid) database as argument */
          if (dbv == NULL || *dbv == NULL) {
                  /* try to read database from enviroment */
 -                if ((path_fcodes = getenv("LOCATE_PATH")) == NULL ||
 -		     *path_fcodes == '\0')
 -                        /* use default database */
 -                        dbv = colon(dbv, _PATH_FCODES, _PATH_FCODES);
 -                else		/* $LOCATE_PATH */
 +                if ((path_fcodes = getenv("LOCATE_PATH")) != NULL &&
 +		     *path_fcodes != '\0')
                          dbv = colon(dbv, path_fcodes, _PATH_FCODES);
          }
 +        if (dbv == NULL || *dbv == NULL) {
 +		FILE *f;
 +		#define STRLEN	256
 +		char s[STRLEN];
 +		char *p1, *p2;
 +		p1 = p2 = NULL;
 +		if ((f = fopen(_PATH_RCFILE, "r")) != NULL) {
 +			while (!feof(f)) {
 +				if (fgets(s, sizeof(s) - 1, f) == NULL)
 +					break;
 +				s[STRLEN - 1] = 0;
 +				if (strncmp("FCODES=\"", s, 8) == 0) {
 +					/* Syntax is FCODES="path" */
 +					p1 = s + 8;
 +					p2 = strrchr(s, '"');
 +					break;
 +				}
 +			}
 +			fclose(f);
  
 +			if (p1 < p2) {
 +				*p2 = '\0';
 +				dbv = colon(dbv, p1, _PATH_FCODES);
 +			}
 +		}
 +	}
 +        if (dbv == NULL || *dbv == NULL)
 +		/* use default database */
 +		dbv = colon(dbv, _PATH_FCODES, _PATH_FCODES);
 +
          if (f_icase && UCHAR_MAX < 4096) /* init tolower lookup table */
                  for (ch = 0; ch < UCHAR_MAX + 1; ch++)
                          myctype[ch] = tolower(ch);
 Index: locate/locate.rc
 ===================================================================
 --- locate/locate.rc	(revision 181277)
 +++ locate/locate.rc	(working copy)
 @@ -9,7 +9,7 @@
  # temp directory
  #TMPDIR="/tmp"
  
 -# the actual database
 +# the actual database. This is not a colon-separated list.
  #FCODES="/var/db/locate.database"
  
  # directories to be put in the database
 
 --ZPt4rx8FFjLCG7dd
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=b
 
 Index: periodic/weekly/310.locate
 ===================================================================
 --- periodic/weekly/310.locate	(revision 181277)
 +++ periodic/weekly/310.locate	(working copy)
 @@ -16,7 +16,13 @@
  	echo ""
  	echo "Rebuilding locate database:"
  
 +	if [ -f /etc/locate.rc ]; then
 +		. /etc/locate.rc
 +	fi
  	locdb=/var/db/locate.database
 +	if [ ! -z "${FCODES}" ]; then
 +		locdb=${FCODES}
 +	fi
  
  	touch $locdb && rc=0 || rc=3
  	chown nobody $locdb || rc=3
 
 --ZPt4rx8FFjLCG7dd--
>Unformatted:
