Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using awk in the zpool_id script. #508

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cmd/zpool_id/zpool_id
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

CONFIG="${CONFIG:-/etc/zfs/zdev.conf}"
AWK="${AWK:-/usr/bin/awk}"

if [ -z "${PATH_ID}" ]; then
# The path_id helper became a builtin command in udev 174.
Expand Down Expand Up @@ -63,9 +62,19 @@ fi
# configuration file which is of the format <device id> <key>.
# Lines starting with #'s are treated as comments and ignored.
# Exact matches are required, wild cards are not supported,
# and only the first match is returned. Also note the following
# regex pattern only appears to work with gawk, not mawk or awk.
ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" "${CONFIG}"`
# and only the first match is returned.
ID_ZPOOL=''
while read CONFIG_ZPOOL CONFIG_PATH REPLY; do
if [ "${CONFIG_ZPOOL}" != "${CONFIG_ZPOOL#\#}" ]; then
# Skip comment lines.
continue
fi
if [ "${CONFIG_PATH}" = "${ID_PATH}" ]; then
ID_ZPOOL="${CONFIG_ZPOOL}"
break
fi
done <"${CONFIG}"

[ -z "${ID_ZPOOL}" ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"

if [ -n "${ID_ZPOOL}" ]; then
Expand Down