1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#! /bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# This is the audio_clean program.
#
# Following is the syntax for calling the script:
# scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename]
# [zonepath]
#
# $1: -s for standard cleanup by a user
# -f for forced cleanup by an administrator
# -i for boot-time initialization (when the system is booted with -r)
# -I to suppress error/warning messages; the script is run in the '-i'
# mode
#
# $2: devicename - device to be allocated/deallocated, e.g., sr0
#
# $3: -A if cleanup is for allocation, or -D if cleanup is for deallocation.
#
# $4: username - run the script as this user, rather than as the caller.
#
# $5: zonename - zone in which device to be allocated/deallocated
#
# $6: zonepath - root path of zonename
#
# Unless the clean script is being called for boot-time
# initialization, it may communicate with the user via stdin and
# stdout. To communicate with the user via CDE dialogs, create a
# script or link with the same name, but with ".windowing" appended.
# For example, if the clean script specified in device_allocate is
# /etc/security/xyz_clean, that script must use stdin/stdout. If a
# script named /etc/security/xyz_clean.windowing exists, it must use
# dialogs. To present dialogs to the user, the dtksh script
# /etc/security/lib/wdwmsg may be used.
#
# This particular script, audio_clean, will work using stdin/stdout, or
# using dialogs. A symbolic link audio_clean.windowing points to
# audio_clean.
trap "" INT TERM QUIT TSTP ABRT
USAGE="usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"
PATH="/usr/bin:/usr/sbin"
WDWMSG="/etc/security/lib/wdwmsg"
MODE="allocate"
if [ `basename $0` != `basename $0 .windowing` ]; then
WINDOWING="yes"
else
WINDOWING="no"
fi
#
# *** Shell Function Declarations ***
#
msg() {
if [ "$WINDOWING" = "yes" ]; then
if [ $MODE = "allocate" ]; then
TITLE="Audio Device Allocation"
else
TITLE="Audio Device Dellocation"
fi
$WDWMSG "$*" "$TITLE" OK
else
echo "$*"
fi
}
fail_msg() {
if [ "$MODE" = "allocate" ]; then
msg "$0: Allocate of $DEVICE failed."
else
msg "$0: Deallocate of $DEVICE failed."
fi
exit 1
}
#
# Main program
#
# Check syntax, parse arguments.
while getopts ifsI c
do
case $c in
i)
FLAG=$c;;
f)
FLAG=$c;;
s)
FLAG=$c;;
I)
FLAG=i
silent=y;;
\?) msg $USAGE
exit 1;;
esac
done
shift `expr $OPTIND - 1`
DEVICE=$1
if [ "$2" = "-A" ]; then
MODE="allocate"
elif [ "$2" = "-D" ]; then
MODE="deallocate"
fi
if [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then
msg $USAGE
exit 1
fi
ZONENAME=$4
ZONEPATH=$5
SAVEDIR=/etc/security/audio
MAP=`dminfo -v -n $DEVICE`
DEVICE=`echo $MAP | cut -f1 -d:`
TYPE=`echo $MAP | cut -f2 -d:`
FILES=`echo $MAP | cut -f3 -d:`
if [ ! -d ${SAVEDIR} ]
then
/usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg
/usr/bin/chown root:sys ${SAVEDIR} || fail_msg
fi
for d in $FILES
do
x="`expr $d : '/dev/mixer[0-9][0-9]*'`"
if [ "$x" -ne 0 ] ; then
DEVNM=$d
break
fi
done
SAVEFILE="${SAVEDIR}/`basename ${DEVNM}`"
if [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ]
then
/usr/bin/audioctl save-controls -d ${DEVNM} -f ${SAVEFILE} || fail_msg
else
/usr/bin/audioctl load-controls -d ${DEVNM} ${SAVEFILE} || fail_msg
fi
exit 0
|