Module Name: src Committed By: mlelstv Date: Fri Jan 11 23:49:23 UTC 2013
Modified Files: src/distrib/sets/lists/base: mi src/sbin/devpubd: Makefile devpubd.8 Added Files: src/sbin/devpubd/hooks: 02-wedgenames Log Message: Provide a script for devpubd(8) that creates symlinks for each dk(4) device under /dev/wedges so that you can access them by name. To generate a diff of this commit: cvs rdiff -u -r1.1015 -r1.1016 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.2 -r1.3 src/sbin/devpubd/Makefile src/sbin/devpubd/devpubd.8 cvs rdiff -u -r0 -r1.1 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/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1015 src/distrib/sets/lists/base/mi:1.1016 --- src/distrib/sets/lists/base/mi:1.1015 Tue Dec 4 23:38:57 2012 +++ src/distrib/sets/lists/base/mi Fri Jan 11 23:49:23 2013 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1015 2012/12/04 23:38:57 spz Exp $ +# $NetBSD: mi,v 1.1016 2013/01/11 23:49:23 mlelstv Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -201,6 +201,7 @@ ./libexec base-sys-root ./libexec/devpubd-hooks base-sysutil-root ./libexec/devpubd-hooks/01-makedev base-sysutil-root +./libexec/devpubd-hooks/02-wedgenames base-sysutil-root ./libexec/devpubd-run-hooks base-sysutil-root ./libexec/dhcpcd-hooks base-dhcpcd-root ./libexec/dhcpcd-hooks/01-test base-dhcpcd-root Index: src/sbin/devpubd/Makefile diff -u src/sbin/devpubd/Makefile:1.2 src/sbin/devpubd/Makefile:1.3 --- src/sbin/devpubd/Makefile:1.2 Tue Sep 6 21:30:12 2011 +++ src/sbin/devpubd/Makefile Fri Jan 11 23:49:23 2013 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2011/09/06 21:30:12 riz Exp $ +# $NetBSD: Makefile,v 1.3 2013/01/11 23:49:23 mlelstv Exp $ PROG= devpubd SRCS= devpubd.c @@ -13,7 +13,7 @@ SCRIPTS= devpubd-run-hooks SCRIPTSDIR_devpubd-run-hooks= /libexec .PATH: ${.CURDIR}/hooks -HOOKS= 01-makedev +HOOKS= 01-makedev 02-wedgenames SCRIPTS+= ${HOOKS:C,^,hooks/,} .for f in ${HOOKS} SCRIPTSDIR_hooks/${f}= /libexec/devpubd-hooks Index: src/sbin/devpubd/devpubd.8 diff -u src/sbin/devpubd/devpubd.8:1.2 src/sbin/devpubd/devpubd.8:1.3 --- src/sbin/devpubd/devpubd.8:1.2 Thu Nov 22 17:16:30 2012 +++ src/sbin/devpubd/devpubd.8 Fri Jan 11 23:49:23 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: devpubd.8,v 1.2 2012/11/22 17:16:30 reed Exp $ +.\" $NetBSD: devpubd.8,v 1.3 2013/01/11 23:49:23 mlelstv Exp $ .\" .\" Copyright (c) 2011 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -62,7 +62,9 @@ or and the device file name. The default installation supplies the .Pa 01-makedev -script for creating a device node. +script for creating a device node and the +.Pa 02-wedgenames +script for creating symlinks to wedge devices under /dev/wedges. Additional scripts may be added for other dynamic device actions. .Sh SEE ALSO .Xr drvctl 8 , Added files: Index: src/sbin/devpubd/hooks/02-wedgenames diff -u /dev/null src/sbin/devpubd/hooks/02-wedgenames:1.1 --- /dev/null Fri Jan 11 23:49:24 2013 +++ src/sbin/devpubd/hooks/02-wedgenames Fri Jan 11 23:49:23 2013 @@ -0,0 +1,71 @@ +#!/bin/sh +# +# $NetBSD: 02-wedgenames,v 1.1 2013/01/11 23:49:23 mlelstv Exp $ +# +# Try to maintain symlinks to wedge devices +# + +event="$1" +device="$2" + +wedgedir=/dev/wedges + +remove_wedge() { + find $wedgedir -print \ + | sed -e 's# #\\ #g' \ + | while read w; do + t=$(readlink "$w") + if [ x"$t" = x"/dev/$device" ]; then + rm -f "$w" + basedir=$(dirname "$w") + rmdir -p "$basedir" 2>/dev/null + fi + done +} + +add_wedge() { + n=$(dkctl "$device" 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" + ln -s "/dev/$device" "$wedgedir/$n" + ;; + esac +} + +case $device in +dk*) + case $event in + device-attach) + remove_wedge + add_wedge + ;; + device-detach) + remove_wedge + ;; + esac + ;; +esac