Quote variables in the zpool_id script.

For consistency and safety, quote all variables in the zpool_id
script. This accomodates a `-c CONFIG` parameter value with
whitespace in the path name.

Also fix a typo in the usage synopsis for `-h`.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #439
This commit is contained in:
Darik Horn 2011-12-04 13:50:27 -06:00 committed by Brian Behlendorf
parent 9c8254f6f9
commit 04bf5ecc1f

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
CONFIG=${CONFIG:-/etc/zfs/zdev.conf} CONFIG="${CONFIG:-/etc/zfs/zdev.conf}"
AWK=${AWK:-/usr/bin/awk} AWK="${AWK:-/usr/bin/awk}"
if [ -z "${PATH_ID}" ]; then if [ -z "${PATH_ID}" ]; then
# The path_id helper became a builtin command in udev 174. # The path_id helper became a builtin command in udev 174.
@ -19,7 +19,7 @@ die() {
usage() { usage() {
cat << EOF cat << EOF
Usage: zpool_id [h] [-c configfile] <devpath> Usage: zpool_id [-h] [-c configfile] <devpath>
-c Alternate config file [default /etc/zfs/zdev.conf] -c Alternate config file [default /etc/zfs/zdev.conf]
-d Use path_id from device as the mapping key -d Use path_id from device as the mapping key
-h Show this message -h Show this message
@ -30,10 +30,10 @@ EOF
while getopts 'c:d:h' OPTION; do while getopts 'c:d:h' OPTION; do
case ${OPTION} in case ${OPTION} in
c) c)
CONFIG=${OPTARG} CONFIG="${OPTARG}"
;; ;;
d) d)
DEVICE=${OPTARG} DEVICE="${OPTARG}"
;; ;;
h) h)
usage usage
@ -42,21 +42,21 @@ while getopts 'c:d:h' OPTION; do
done done
# Check that a device was requested # Check that a device was requested
[ -z ${DEVICE} ] && usage [ -z "${DEVICE}" ] && usage
# Check for the existence of a configuration file # Check for the existence of a configuration file
[ ! -f ${CONFIG} ] && die "Missing config file: ${CONFIG}" [ ! -f "${CONFIG}" ] && die "Missing config file: ${CONFIG}"
# If we are handling a multipath device then $DM_UUID will be # If we are handling a multipath device then $DM_UUID will be
# exported and we'll use its value (prefixed with dm-uuid per # exported and we'll use its value (prefixed with dm-uuid per
# multipathd's naming convention) as our unique persistent key. # multipathd's naming convention) as our unique persistent key.
# For traditional devices we'll obtain the key from udev's # For traditional devices we'll obtain the key from udev's
# path_id. # path_id.
if [ -n "${DM_UUID}" ] && echo ${DM_UUID} | egrep -q -e '^mpath' ; then if [ -n "${DM_UUID}" ] && echo "${DM_UUID}" | egrep -q -e '^mpath' ; then
ID_PATH="dm-uuid-${DM_UUID}" ID_PATH="dm-uuid-${DM_UUID}"
else else
eval `${PATH_ID} ${DEVICE}` eval `${PATH_ID} ${DEVICE}`
[ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}" [ -z "${ID_PATH}" ] && die "Missing ID_PATH for ${DEVICE}"
fi fi
# Use the persistent key to lookup the zpool device id in the # Use the persistent key to lookup the zpool device id in the
@ -65,10 +65,10 @@ fi
# Exact matches are required, wild cards are not supported, # Exact matches are required, wild cards are not supported,
# and only the first match is returned. Also note the following # and only the first match is returned. Also note the following
# regex pattern only appears to work with gawk, not mawk or awk. # regex pattern only appears to work with gawk, not mawk or awk.
ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}` ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" "${CONFIG}"`
[ -z ${ID_ZPOOL} ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}" [ -z "${ID_ZPOOL}" ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
if [ ${ID_ZPOOL} ]; then if [ -n "${ID_ZPOOL}" ]; then
echo "ID_PATH=${ID_PATH}" echo "ID_PATH=${ID_PATH}"
echo "ID_ZPOOL=${ID_ZPOOL}" echo "ID_ZPOOL=${ID_ZPOOL}"
echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}" echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"