NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/45130 (/etc/locate.conf cannot deal with pathnames containing spaces)
The following reply was made to PR bin/45130; it has been noted by GNATS.
From: "Greg A. Woods" <woods%planix.ca@localhost>
To: NetBSD GNATS <gnats-bugs%NetBSD.org@localhost>, Alan Barrett
<apb%NetBSD.org@localhost>
Cc:
Subject: Re: bin/45130 (/etc/locate.conf cannot deal with pathnames containing
spaces)
Date: Tue, 12 Jul 2011 15:17:14 -0700
--Multipart_Tue_Jul_12_15:17:10_2011-1
Content-Type: text/plain; charset=US-ASCII
Ooops!
"Nothing works until it has been tested." :-)
Testing revealed you got the '!' stripping backwards for the "ignorefs"
directive.
Also, I added back the warning about running as root, just as a
suggestion. Indeed it should be a separate PR, but.... :-)
Also, I separated the case clause ";;" terminators -- I really don't
like scrunching code together too much -- makes it too hard to read.
That's how I first found the cause of this new bug -- by first opening
up the code a bit, then I very quickly spotted the "inversion".
I removed a bit of extra, unnecessary, quoting (it makes syntax
highlighting work better and cleans up the readability). :-)
I.e. these two must always produce the same value (and they do on NetBSD
for both sh and ksh, and even for bash and zsh):
BAR=$(echo "foo bar ")
BAR="$(echo "foo bar ")"
Same for assignments containing only variable expansions.
I added a comment about the "extra" cat -- things like this are not
always obvious, even to experts, and perhaps especially not to someone
accustomed to getting rid of "extra" processes like this in novice shell
code. :-) (Here I was surprised enough by it that I checked the CVS
annotation and then the CVS log to be sure it was on purpose, then I
went "Duh, of course!".)
In some ways the quoted-parameter handling by use of the special case
quoted "$@" should probably also be documented -- in my experience it's
a relatively rare idiom (all too rare, perhaps).
Finally I fixed a style nit with the "if" after the find call.
PS, I didn't PGP-sign this one, thus I didn't have to use any encoding,
hopefully to make this easier to pick out of Gnats, but given I CC'ed
you directly, then perhaps I could have encoded and signed it. I really
wish Gnats did MIME properly. :-) I'd prefer to sign everything I send
these days.
--
Greg A. Woods
Planix, Inc.
<woods%planix.com@localhost> +1 250 762-7675
http://www.planix.com/
--Multipart_Tue_Jul_12_15:17:10_2011-1
Content-Type: text/plain; charset=US-ASCII
Index: updatedb.sh
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/usr.bin/locate/locate/updatedb.sh,v
retrieving revision 1.12
diff -u -u -r1.12 updatedb.sh
--- updatedb.sh 10 Jul 2011 13:42:49 -0000 1.12
+++ updatedb.sh 12 Jul 2011 22:15:21 -0000
@@ -43,7 +43,7 @@
# for temp files
TMPDIR=/tmp
FCODES="/var/db/locate.database" # the database
-CONF=/etc/locate.conf # configuration file
+CONF=${CONF:-/etc/locate.conf} # the configuration file
PATH="/bin:/usr/bin"
@@ -62,54 +62,76 @@
#
shell_quote()
{
- local result=''
+ local result=
local arg
for arg in "$@" ; do
# Append a space if necessary
- result="${result}${result:+ }"
+ #
+ result=${result}${result:+ }
+
# Convert each embedded ' to '\'',
# then insert ' at the beginning of the first line,
# and append ' at the end of the last line.
- result="${result}$(printf "%s\n" "$arg" | \
- sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ #
+ result=${result}$(printf "%s\n" "$arg" | \
+ sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")
done
printf "%s\n" "$result"
}
+if [ "$(id -u)" -eq 0 ]; then
+ echo ">>> WARNING"
+ echo ">>> Executing updatedb as root. This WILL reveal all filenames"
+ echo ">>> on your machine to all login users, which may be a security
risk."
+fi 1>&2
+
# read configuration file
if [ -f "$CONF" ]; then
while read -r com args; do
case "$com" in
''|'#'*)
- continue ;; # skip blank lines and comment lines
+ continue # skip blank lines and comment lines
+ ;;
esac
eval "set -- $args"
case "$com" in
searchpath)
- SRCHPATHS="${SRCHPATHS}${SRCHPATHS:+ }$(shell_quote
"$@")";;
+ SRCHPATHS=${SRCHPATHS}${SRCHPATHS:+ }$(shell_quote "$@")
+ ;;
ignorefs)
for i in "$@"; do
fs=
case "$i" in
- none) ignorefs=;;
- \!*) fs="! -fstype $(shell_quote "$i")";;
- *) fs="-fstype $(shell_quote "${i#?}")";;
+ none)
+ ignorefs=
+ ;;
+ \!*)
+ fs="! -fstype $(shell_quote "${i#!}")"
+ ;;
+ *)
+ fs="-fstype $(shell_quote "${i}")"
+ ;;
esac
case "$fs" in
- '') ;;
- *) ignorefs="${ignorefs:+${ignorefs} -o
}${fs}";;
+ '')
+ ;;
+ *)
+ ignorefs="${ignorefs:+${ignorefs} -o
}${fs}"
+ ;;
esac
done;;
ignore)
for i in "$@"; do
- q="$(shell_quote "$i")"
+ q=$(shell_quote "$i")
ignore="${ignore:+${ignore} -o }-path ${q}"
- done;;
+ done
+ ;;
ignorecontents)
for i in "$@"; do
- q="$(shell_quote "$i")"
+ q=$(shell_quote "$i")
ignore="${ignore:+${ignore} -o }-path ${q}
-print"
- done;;
+ done
+ ;;
workdir)
if [ $# -ne 1 ]; then
echo "$CONF: workdir takes exactly one
argument" >&2
@@ -117,10 +139,12 @@
TMPDIR="$1"
else
echo "$CONF: workdir: $1 nonexistent" >&2
- fi;;
+ fi
+ ;;
*)
echo "$CONF: $com: unknown config command" >&2
- exit 1;;
+ exit 1
+ ;;
esac
done < "$CONF"
fi
@@ -145,11 +169,12 @@
# Make a file list and compute common bigrams.
# Entries of each directory shall be sorted (find -s).
+# (note: the "extra" cat process lets us detect write errors)
(eval "find -s ${SRCHPATHS} $lp $ignorefs $ignore $rp -print"; true) \
| cat >> "$FILELIST"
-if [ $? != 0 ]
-then
+
+if [ $? != 0 ]; then
exit 1
fi
--Multipart_Tue_Jul_12_15:17:10_2011-1--
Home |
Main Index |
Thread Index |
Old Index