Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Provide a script for devpubd(8) that creates symlinks for ea...
details: https://anonhg.NetBSD.org/src/rev/263fffbd178e
branches: trunk
changeset: 783895:263fffbd178e
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Fri Jan 11 23:49:23 2013 +0000
description:
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.
diffstat:
distrib/sets/lists/base/mi | 3 +-
sbin/devpubd/Makefile | 4 +-
sbin/devpubd/devpubd.8 | 6 ++-
sbin/devpubd/hooks/02-wedgenames | 71 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 79 insertions(+), 5 deletions(-)
diffs (130 lines):
diff -r 48fb1f2aa333 -r 263fffbd178e distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi Fri Jan 11 20:42:20 2013 +0000
+++ b/distrib/sets/lists/base/mi Fri Jan 11 23:49:23 2013 +0000
@@ -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
diff -r 48fb1f2aa333 -r 263fffbd178e sbin/devpubd/Makefile
--- a/sbin/devpubd/Makefile Fri Jan 11 20:42:20 2013 +0000
+++ b/sbin/devpubd/Makefile Fri Jan 11 23:49:23 2013 +0000
@@ -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 @@
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
diff -r 48fb1f2aa333 -r 263fffbd178e sbin/devpubd/devpubd.8
--- a/sbin/devpubd/devpubd.8 Fri Jan 11 20:42:20 2013 +0000
+++ b/sbin/devpubd/devpubd.8 Fri Jan 11 23:49:23 2013 +0000
@@ -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 @@
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 ,
diff -r 48fb1f2aa333 -r 263fffbd178e sbin/devpubd/hooks/02-wedgenames
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/devpubd/hooks/02-wedgenames Fri Jan 11 23:49:23 2013 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index