NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/45130: /etc/locate.conf cannot deal with pathnames containing spaces
>Number: 45130
>Category: bin
>Synopsis: /etc/locate.conf cannot deal with pathnames containing spaces
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jul 10 05:05:00 +0000 2011
>Originator: Greg A. Woods
>Release: NetBSD-current
>Organization:
Planix, Inc.; Kelowna, BC; Canada
>Environment:
System: NetBSD
>Description:
it seems locate.updatedb cannot be told to ignore files or
directories which have whitespace in their pathnames, but such
names are becoming increasingly common on shared file stores,
and even on native systems
>How-To-Repeat:
try to configure locate.updatedb to ignore path with spaces
#
# testing locate.updatedb
#
ignore /home/oldfiler/bogus stuff
ignore /home/oldfiler/not a real name
ignorecontents /Volumes/Macintosh HD Part 2/backups
ignorecontents /Volumes/Macintosh HD Part 2/also ignore
>Fix:
the only sane fix seems to me to be to only allow one parameter
each time a configuration option is mentioned
this may be controversial since it will potentially cause
previous configurations to stop working
however I don't see any good alternative since it is impossible
to make any kind of quoting work with shell "for" statements at
this level -- use of some kind of separator character is
required (along with a change of the $IFS setting), but any of
those too are of course valid characters in a pathname
component. (yes, ":" is a possible choice, but it too will
cause problems for some folks!)
the only other option is to rewrite in C and implement proper
quoting (and escaping of quotes, etc.), but this is probably
unnecessary since each of the important configuration options
can appear multiple times in the locate.conf file, so
restricting each one to specifying one pattern should suffice
Index: usr.bin/locate/locate/updatedb.sh
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/usr.bin/locate/locate/updatedb.sh,v
retrieving revision 1.11
diff -u -r1.11 updatedb.sh
--- usr.bin/locate/locate/updatedb.sh 23 Apr 2006 03:04:08 -0000 1.11
+++ usr.bin/locate/locate/updatedb.sh 10 Jul 2011 04:10:07 -0000
@@ -43,7 +43,8 @@
# for temp files
TMPDIR=/tmp
FCODES="/var/db/locate.database" # the database
-CONF=/etc/locate.conf # configuration file
+#CONF=${CONF:-/etc/locate.conf} # for testing
+CONF=/etc/locate.conf # the configuration file
PATH="/bin:/usr/bin"
@@ -53,45 +54,46 @@
# read configuration file
if [ -f "$CONF" ]; then
- exec 5<&0 < "$CONF"
- while read com args; do
- case "$com/$args" in /) continue;; esac # skip blank lines
- case "$com" in
- '#'*) ;; # lines start with # is comment
+ while read opt arg; do
+ case "$opt/$arg" in /) continue;; esac # skip blank lines
+ case "$opt" in
+ '#'*)
+ # a line starting with # is a comment
+ ;;
searchpath)
- SRCHPATHS="$SRCHPATHS $args";;
+ SRCHPATHS="$SRCHPATHS '$arg'"
+ ;;
ignorefs)
- for i in $args; do
- case "$i" in
- none) ignorefs=;;
- *) fs=`echo "$i" | sed -e 's/^!/! -fstype
/' -e t -e 's/^/-fstype /'`
- ignorefs="${ignorefs:+${ignorefs} -o
}${fs}"
- esac
- done;;
+ case "$arg" in
+ none)
+ ignorefs=
+ ;;
+ *)
+ # fstypes cannot contain spaces!
+ fs=$(echo "$arg" | sed -e 's/^!/! -fstype /' -e
t -e 's/^/-fstype /')
+ ignorefs="${ignorefs:+${ignorefs} -o }${fs}"
+ ;;
+ esac
+ ;;
ignore)
- set -f
- for i in $args; do
- ignore="${ignore:+${ignore} -o }-path ${i}"
- done
- set +f;;
+ ignore="${ignore:+${ignore} -o }-path '${arg}'"
+ ;;
ignorecontents)
- set -f
- for i in $args; do
- ignore="${ignore:+${ignore} -o }-path ${i}
-print"
- done
- set +f;;
+ ignore="${ignore:+${ignore} -o }-path '${arg}' -print"
+ ;;
workdir)
- if [ -d "$args" ]; then
- TMPDIR="$args"
+ if [ -d "$arg" ]; then
+ TMPDIR="$arg"
else
- echo "$CONF: workdir: $args nonexistent" >&2
- fi;;
+ echo "$CONF: workdir: $arg nonexistent" >&2
+ fi
+ ;;
*)
- echo "$CONF: $com: unknown config command" >&2
- exit 1;;
+ echo "$CONF: $opt: unknown config option" >&2
+ exit 1
+ ;;
esac
- done
- exec <&5 5>&-
+ done < "$CONF"
fi
: ${SRCHPATHS:=/} # directories to be put in the database
@@ -114,11 +116,11 @@
# Make a file list and compute common bigrams.
# Entries of each directory shall be sorted (find -s).
+# (the "extra" cat process lets us detect write errors)
set -f
(find -s ${SRCHPATHS} $lp $ignorefs $ignore $rp -print; true) | cat >>
"$FILELIST"
-if [ $? != 0 ]
-then
+if [ $? != 0 ]; then
exit 1
fi
Index: usr.bin/locate/locate/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/usr.bin/locate/locate/Makefile,v
retrieving revision 1.10
diff -u -r1.10 Makefile
--- usr.bin/locate/locate/Makefile 5 Oct 2005 06:29:03 -0000 1.10
+++ usr.bin/locate/locate/Makefile 10 Jul 2011 03:41:19 -0000
@@ -4,9 +4,10 @@
PROG= locate
MAN= locate.1 locate.updatedb.8
-FILES=updatedb.sh
-FILESNAME=locate.updatedb
-FILESDIR=/usr/libexec
-FILESMODE=${BINMODE}
+# XXX locate.conf.5 SHOULD be here as well!
+
+SCRIPTS=updatedb.sh
+SCRIPTSNAME=locate.updatedb
+SCRIPTSDIR=/usr/libexec
.include <bsd.prog.mk>
Index: share/man/man5/locate.conf.5
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/share/man/man5/locate.conf.5,v
retrieving revision 1.7
diff -u -r1.7 locate.conf.5
--- share/man/man5/locate.conf.5 30 Apr 2008 13:10:57 -0000 1.7
+++ share/man/man5/locate.conf.5 10 Jul 2011 03:46:26 -0000
@@ -56,23 +56,25 @@
.Pp
The configuration options are as follows:
.Bl -tag -width XXXXXX
-.It Sy ignore Ar pattern ...
-Ignore files or directories.
+.It Sy ignore Ar pattern
+Ignore a file or directory.
When building the database,
-do not descend into files or directories
-which match one of the specified patterns.
-The matched files or directories are not stored to the database.
+do not descend into a file or directory
+which matches the specified pattern.
+The matched file or directory is not stored to the database.
+This option may appear multiple times.
.Pp
Default: Not specified.
-.It Sy ignorecontents Ar pattern ...
-Ignore contents of directories.
+.It Sy ignorecontents Ar pattern
+Ignore contents of a directory.
When building the database,
-do not descend into files or directories
-which match one of the specified patterns.
-The matched files or directories themselves are stored to the database.
+do not descend into a file or directory
+which matches the specified pattern.
+The matched file or directory is itself stored to the database.
+This option may appear multiple times.
.Pp
Default: Not specified.
-.It Sy ignorefs Ar type ...
+.It Sy ignorefs Ar type
Ignore file system by type,
adding
.Ar type
@@ -94,6 +96,7 @@
the
.Sy ignorefs
list is cleared and all file systems are traversed.
+This option may appear multiple times.
.Pp
.Ar type
is used as an argument to
@@ -108,8 +111,9 @@
.Ed
.Pp
Default: !local cd9660 fdesc kernfs procfs
-.It Sy searchpath Ar directory ...
-Specify base directories to be put in the database.
+.It Sy searchpath Ar directory
+Specify a base directory name to be put in the database.
+This option may appear multiple times.
.Pp
Default: /
.It Sy workdir Ar directory
Home |
Main Index |
Thread Index |
Old Index