CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: martin Date: Sun Aug 8 10:48:35 UTC 2021 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Fix obvious editor mishap in previous To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.7 src/sbin/devpubd/hooks/02-wedgenames:1.8 --- src/sbin/devpubd/hooks/02-wedgenames:1.7 Thu Aug 5 12:52:47 2021 +++ src/sbin/devpubd/hooks/02-wedgenames Sun Aug 8 10:48:35 2021 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.7 2021/08/05 12:52:47 kre Exp $ +# $NetBSD: 02-wedgenames,v 1.8 2021/08/08 10:48:35 martin Exp $ # # Try to maintain symlinks to wedge devices # @@ -160,4 +160,4 @@ for device do esac ;; esac -ce-attach +done
CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: kre Date: Thu Aug 5 12:52:47 UTC 2021 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Obliterate bogus $@ usage. While here, fix some quoting, change some style, and attempt to properly handle wedge names with embedded newlines, and those that end with a '/' character (not particularly happy with the solution to that last one, but it is better than it was). Is there a reason that characters that need encoding in wedge names (white space, and more) are encoded as %%XX (XX is the hex value of the char - but 2 % chars? Why?). That remains unchanged, but as the script already relied upon sh's $'...' quoting, I think we can rely upon printf as well, so replace the old (very elegant, but slow) encoding function with a much simpler one (does the same thing). To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.6 src/sbin/devpubd/hooks/02-wedgenames:1.7 --- src/sbin/devpubd/hooks/02-wedgenames:1.6 Sat Jan 9 16:25:19 2021 +++ src/sbin/devpubd/hooks/02-wedgenames Thu Aug 5 12:52:47 2021 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.6 2021/01/09 16:25:19 mlelstv Exp $ +# $NetBSD: 02-wedgenames,v 1.7 2021/08/05 12:52:47 kre Exp $ # # Try to maintain symlinks to wedge devices # @@ -9,16 +9,15 @@ export LC_ALL=C event="$1" shift -devices=$@ wedgedir=/dev/wedges recurse() { - test -d "$1" && ls -1af "$1" \ - | while read n; do + test -d "$1" && + ls -1af "$1" | while read n; do case $n in - .|..) ;; + .|..) ;; *) echo "$1/$n" if [ -L "$1/$n" ]; then @@ -28,7 +27,7 @@ recurse() fi ;; esac - done + done } simple_readlink() @@ -41,43 +40,49 @@ simple_readlink() esac } -ordtable=$( - for n1 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do - for n2 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do - echo "\$'\x$n1$n2') x=$n1$n2;;" - done - done -) +#ordtable=$( +# for n1 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do +# for n2 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do +# echo "\$'\x$n1$n2') x=$n1$n2;;" +# done +# done +#) +# +#ord() +#{ +# local x +# eval "case \$1 in $ordtable esac" +# echo -n $x +#} ord() { - local x - eval "case \$1 in $ordtable esac" - echo -n $x + printf %2.2x "'$1" } encode() { - local a + local a b c a=$1 + b= while [ -n "$a" ]; do c="${a%"${a#?}"}" a=${a#?} case $c in - [[:alnum:]._:\;!^$\&~\(\)[\]{}=,+\-/]) + [][:alnum:]._:\;!^$\&~\(\)[{}=,+/-]) ;; *) - c='%%'$(ord "$c") + c=%%$(ord "$c") ;; esac - echo -n "$c" + b=${b}${c} done + printf %s "$b" } remove_wedge() { - recurse "$wedgedir" \ - | while read w; do + recurse "$wedgedir" | while read w; do t=$(simple_readlink "$w") if [ x"$t" = x"/dev/$1" ]; then rm -f "$w" @@ -87,43 +92,72 @@ remove_wedge() { done } +wedge_label() { + local l + + # dkctl getwedgeinfo always outputs 2 "lines", the first + # contains the label (and may contain embedded \n chars) + # the second contains the size, offset, and type, and one + # trailing \n (stripped by the $()) - so we can safely + # extract the label by deleting from the final \n in the + # value getwedgeinfo prints to the end + + l=$(dkctl "$1" getwedgeinfo) + l=${l%$'\n'*} + case "${l}" in + $1' at '*': '*) + l=${l#*: } + ;; + *) + l=$1 + ;; + esac + + # The trailing is to ensure a trailing \n in the label + # is not deleted by a command substitution which invokes us. + # That will be rmeoved by the caller. + printf %s "${l}" +} + add_wedge() { - dkctl "$1" getwedgeinfo \ - | while read l; do - case $l in - *': '*) - n="${l#*: }" - n=$(encode "$n") - test -d $wedgedir || mkdir -m 755 $wedgedir - basedir="$wedgedir/$n" - basedir=${basedir%/*} - test -d "$basedir" || mkdir -p -m 755 "$basedir" - if oldlink=$(simple_readlink "$wedgedir/$n"); then -if [ x"$oldlink" != x"/dev/$1" ]; then - rm -f "$wedgedir/$n" - ln -s "/dev/$1" "$wedgedir/$n" -fi - else + local l n + + l=$(wedge_label "$1") + l=${l%''} + case "$l" in */) l="${l}Wedge";; esac + + n=$(encode "${l}") + + ( + umask 022 + + test -d "$wedgedir" || mkdir -m 755 "$wedgedir" + basedir="$wedgedir/$n" + basedir=${basedir%/*} + test -d "$basedir" || mkdir -p -m 755 "$basedir" + if oldlink=$(simple_readlink "$wedgedir/$n"); then + if [ x"$oldlink" != x"/dev/$1" ]; then +rm -f "$wedgedir/$n" ln -s "/dev/$1" "$wedgedir/$n" fi - ;; - esac - break - done + else + ln -s "/dev/$1" "$wedgedir/$n" + fi + ) } -for device in $devices; do +for device do case $device in dk*) case $event in device-attach) - remove_wedge $device - add_wedge $device + remove_wedge "$device" + add_wedge "$device" ;; device-detach) -
CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: mlelstv Date: Sat Jan 9 16:25:19 UTC 2021 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Also replace calls to dirname. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.5 src/sbin/devpubd/hooks/02-wedgenames:1.6 --- src/sbin/devpubd/hooks/02-wedgenames:1.5 Sat Jan 9 14:00:05 2021 +++ src/sbin/devpubd/hooks/02-wedgenames Sat Jan 9 16:25:19 2021 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.5 2021/01/09 14:00:05 mlelstv Exp $ +# $NetBSD: 02-wedgenames,v 1.6 2021/01/09 16:25:19 mlelstv Exp $ # # Try to maintain symlinks to wedge devices # @@ -81,7 +81,7 @@ remove_wedge() { t=$(simple_readlink "$w") if [ x"$t" = x"/dev/$1" ]; then rm -f "$w" - basedir=$(dirname "$w") + basedir=${w%/*} rmdir -p "$basedir" 2>/dev/null fi done @@ -95,7 +95,8 @@ add_wedge() { n="${l#*: }" n=$(encode "$n") test -d $wedgedir || mkdir -m 755 $wedgedir - basedir=$(dirname "$wedgedir/$n") + basedir="$wedgedir/$n" + basedir=${basedir%/*} test -d "$basedir" || mkdir -p -m 755 "$basedir" if oldlink=$(simple_readlink "$wedgedir/$n"); then if [ x"$oldlink" != x"/dev/$1" ]; then
CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: mlelstv Date: Sat Jan 9 14:00:05 UTC 2021 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Remove need for awk/sed/readlink tools. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.4 src/sbin/devpubd/hooks/02-wedgenames:1.5 --- src/sbin/devpubd/hooks/02-wedgenames:1.4 Mon Aug 15 12:54:40 2016 +++ src/sbin/devpubd/hooks/02-wedgenames Sat Jan 9 14:00:05 2021 @@ -1,21 +1,84 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.4 2016/08/15 12:54:40 mlelstv Exp $ +# $NetBSD: 02-wedgenames,v 1.5 2021/01/09 14:00:05 mlelstv Exp $ # # Try to maintain symlinks to wedge devices # +export LC_ALL=C + event="$1" shift devices=$@ wedgedir=/dev/wedges +recurse() +{ + test -d "$1" && ls -1af "$1" \ + | while read n; do + case $n in + .|..) ;; + *) + echo "$1/$n" + if [ -L "$1/$n" ]; then +: #nothing + elif [ -d "$1/$n" ]; then +recurse "$1/$n" + fi + ;; + esac + done +} + +simple_readlink() +{ + local x + + x=$(test -e "$1" && ls -ld "$1") + case $x in + *'-> '*) echo ${x#*-> };; + esac +} + +ordtable=$( + for n1 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do + for n2 in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do + echo "\$'\x$n1$n2') x=$n1$n2;;" + done + done +) + +ord() +{ + local x + eval "case \$1 in $ordtable esac" + echo -n $x +} + +encode() +{ + local a + + a=$1 + while [ -n "$a" ]; do + c="${a%"${a#?}"}" + a=${a#?} + case $c in + [[:alnum:]._:\;!^$\&~\(\)[\]{}=,+\-/]) + ;; + *) + c='%%'$(ord "$c") + ;; + esac + echo -n "$c" + done +} + remove_wedge() { - test -d $wedgedir && find $wedgedir -print \ - | sed -e 's# #\\ #g' \ + recurse "$wedgedir" \ | while read w; do - t=$(readlink "$w") + t=$(simple_readlink "$w") if [ x"$t" = x"/dev/$1" ]; then rm -f "$w" basedir=$(dirname "$w") @@ -25,43 +88,27 @@ remove_wedge() { } add_wedge() { - n=$(dkctl "$1" getwedgeinfo \ - | sed -ne '1s#^[^:]*: ##p' \ - | awk -v GOOD='._:;!^$&~()[]{}=,+-/' ' - BEGIN { - for (i=0; i<256; ++i) -ord[sprintf("%c",i)] = i - } - { - n = length($0) - o = "" - for (i=1; i<=n; ++i) { -c = substr($0,i,1) -if (c ~ /^[[:alnum:]]$/ || index(GOOD,c) > 0) { - o = o c -} else { - o = o sprintf("%%%02x",ord[c]) -} - } - printf "%s",o - }' - ) - case $n in - "") ;; - *) - test -d $wedgedir || mkdir -m 755 $wedgedir - basedir=$(dirname "$wedgedir/$n") - test -d "$basedir" || mkdir -p -m 755 "$basedir" - if oldlink=$(readlink "$wedgedir/$n"); then - if [ x"$oldlink" != "/dev/$1" ]; then -rm -f "$wedgedir/$n" + dkctl "$1" getwedgeinfo \ + | while read l; do + case $l in + *': '*) + n="${l#*: }" + n=$(encode "$n") + test -d $wedgedir || mkdir -m 755 $wedgedir + basedir=$(dirname "$wedgedir/$n") + test -d "$basedir" || mkdir -p -m 755 "$basedir" + if oldlink=$(simple_readlink "$wedgedir/$n"); then +if [ x"$oldlink" != x"/dev/$1" ]; then + rm -f "$wedgedir/$n" + ln -s "/dev/$1" "$wedgedir/$n" +fi + else ln -s "/dev/$1" "$wedgedir/$n" fi - else - ln -s "/dev/$1" "$wedgedir/$n" - fi - ;; - esac + ;; + esac + break + done } for device in $devices; do
CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: mlelstv Date: Mon Aug 15 12:54:40 UTC 2016 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Avoid error message when /dev/wedges doesn't exist yet. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.3 src/sbin/devpubd/hooks/02-wedgenames:1.4 --- src/sbin/devpubd/hooks/02-wedgenames:1.3 Sun Mar 1 14:21:17 2015 +++ src/sbin/devpubd/hooks/02-wedgenames Mon Aug 15 12:54:40 2016 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.3 2015/03/01 14:21:17 mlelstv Exp $ +# $NetBSD: 02-wedgenames,v 1.4 2016/08/15 12:54:40 mlelstv Exp $ # # Try to maintain symlinks to wedge devices # @@ -12,7 +12,7 @@ devices=$@ wedgedir=/dev/wedges remove_wedge() { - find $wedgedir -print \ + test -d $wedgedir && find $wedgedir -print \ | sed -e 's# #\\ #g' \ | while read w; do t=$(readlink "$w")
CVS commit: src/sbin/devpubd/hooks
Module Name:src Committed By: mlelstv Date: Sun Mar 1 14:21:17 UTC 2015 Modified Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: safely update existing wedge links To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sbin/devpubd/hooks/02-wedgenames Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u src/sbin/devpubd/hooks/02-wedgenames:1.2 src/sbin/devpubd/hooks/02-wedgenames:1.3 --- src/sbin/devpubd/hooks/02-wedgenames:1.2 Sun Feb 15 15:56:30 2015 +++ src/sbin/devpubd/hooks/02-wedgenames Sun Mar 1 14:21:17 2015 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: 02-wedgenames,v 1.2 2015/02/15 15:56:30 jmcneill Exp $ +# $NetBSD: 02-wedgenames,v 1.3 2015/03/01 14:21:17 mlelstv Exp $ # # Try to maintain symlinks to wedge devices # @@ -52,7 +52,14 @@ add_wedge() { test -d $wedgedir || mkdir -m 755 $wedgedir basedir=$(dirname $wedgedir/$n) test -d $basedir || mkdir -p -m 755 $basedir - ln -s /dev/$1 $wedgedir/$n + if oldlink=$(readlink $wedgedir/$n); then + if [ x$oldlink != /dev/$1 ]; then +rm -f $wedgedir/$n +ln -s /dev/$1 $wedgedir/$n + fi + else + ln -s /dev/$1 $wedgedir/$n + fi ;; esac }