19cab9fdeSChristos Margiolis#!/bin/sh 29cab9fdeSChristos Margiolis 39cab9fdeSChristos Margiolis# PROVIDE: virtual_oss 4188ddc15SChristos Margiolis# REQUIRE: NETWORKING kld ldconfig 5188ddc15SChristos Margiolis# BEFORE: LOGIN 69cab9fdeSChristos Margiolis# KEYWORD: shutdown 79cab9fdeSChristos Margiolis 89cab9fdeSChristos Margiolis. /etc/rc.subr 99cab9fdeSChristos Margiolis 109cab9fdeSChristos Margiolisname="virtual_oss" 119cab9fdeSChristos Margiolisdesc="virtual_oss device manager" 129cab9fdeSChristos Margiolisrcvar="${name}_enable" 139cab9fdeSChristos Margiolis 149cab9fdeSChristos Margioliscommand="/usr/sbin/${name}" 159cab9fdeSChristos Margioliscommand_args="-B" 169cab9fdeSChristos Margiolis 179cab9fdeSChristos Margiolisload_rc_config "$name" 189cab9fdeSChristos Margiolisstart_precmd="${name}_precmd" 199cab9fdeSChristos Margiolisstart_cmd="${name}_start" 209cab9fdeSChristos Margiolisstop_cmd="${name}_stop" 219cab9fdeSChristos Margiolisstatus_cmd="${name}_status" 229cab9fdeSChristos Margiolis 23ac2aa9e8SChristos Margiolisrequired_modules="cuse" 24ac2aa9e8SChristos Margiolis 259cab9fdeSChristos Margiolisconfigs= 269cab9fdeSChristos Margiolispidpath="/var/run/${name}" 27*e85f221dSChristos Margiolisdefault_unit=$(sysctl -n hw.snd.default_unit 2> /dev/null) 289cab9fdeSChristos Margiolisvirtual_oss_default_args="\ 299cab9fdeSChristos Margiolis -S \ 309cab9fdeSChristos Margiolis -C 2 \ 319cab9fdeSChristos Margiolis -c 2 \ 329cab9fdeSChristos Margiolis -r 48000 \ 339cab9fdeSChristos Margiolis -b 24 \ 349cab9fdeSChristos Margiolis -s 8ms \ 359cab9fdeSChristos Margiolis -i 8 \ 3606b46652SQuentin Thébault -f /dev/dsp${default_unit} \ 379cab9fdeSChristos Margiolis -d dsp \ 389cab9fdeSChristos Margiolis -t vdsp.ctl" 399cab9fdeSChristos Margiolis 409cab9fdeSChristos Margiolis# Set to NO by default. Set it to "YES" to enable virtual_oss. 419cab9fdeSChristos Margiolis: "${virtual_oss_enable:="NO"}" 429cab9fdeSChristos Margiolis 439cab9fdeSChristos Margiolis# List of configurations to use. Default is "dsp". 449cab9fdeSChristos Margiolis: "${virtual_oss_configs:="dsp"}" 459cab9fdeSChristos Margiolis 469cab9fdeSChristos Margiolis# Default (dsp) virtual_oss config. 479cab9fdeSChristos Margiolis: "${virtual_oss_dsp:="${virtual_oss_default_args}"}" 489cab9fdeSChristos Margiolis 499cab9fdeSChristos Margiolisvirtual_oss_pids() 509cab9fdeSChristos Margiolis{ 519cab9fdeSChristos Margiolis pids=$(pgrep -d ' ' ${name}) 529cab9fdeSChristos Margiolis pids=${pids% } 539cab9fdeSChristos Margiolis printf '%s\n' "${pids}" 549cab9fdeSChristos Margiolis} 559cab9fdeSChristos Margiolis 569cab9fdeSChristos Margiolisvirtual_oss_precmd() 579cab9fdeSChristos Margiolis{ 589cab9fdeSChristos Margiolis /usr/bin/install -d -m 0755 -o root "${pidpath}" 599cab9fdeSChristos Margiolis} 609cab9fdeSChristos Margiolis 619cab9fdeSChristos Margiolisstart_instance() 629cab9fdeSChristos Margiolis{ 639cab9fdeSChristos Margiolis config="$1" 649cab9fdeSChristos Margiolis instance_args=$(eval "echo \$virtual_oss_${config}") 659cab9fdeSChristos Margiolis if [ -z "${instance_args}" ]; then 669cab9fdeSChristos Margiolis warn "no such config: ${config}" 679cab9fdeSChristos Margiolis else 689cab9fdeSChristos Margiolis startmsg -n "Starting virtual_oss config: ${config}: " 699cab9fdeSChristos Margiolis ${command} \ 709cab9fdeSChristos Margiolis ${command_args} \ 719cab9fdeSChristos Margiolis -D "${pidpath}/${config}.pid" \ 729cab9fdeSChristos Margiolis ${instance_args} 739cab9fdeSChristos Margiolis startmsg "done" 749cab9fdeSChristos Margiolis fi 759cab9fdeSChristos Margiolis} 769cab9fdeSChristos Margiolis 779cab9fdeSChristos Margiolisstop_instance() 789cab9fdeSChristos Margiolis{ 799cab9fdeSChristos Margiolis config="$1" 809cab9fdeSChristos Margiolis instance_args=$(eval "echo \$virtual_oss_${config}") 819cab9fdeSChristos Margiolis if [ -z "${instance_args}" ]; then 829cab9fdeSChristos Margiolis warn "no such config: ${config}" 839cab9fdeSChristos Margiolis else 849cab9fdeSChristos Margiolis startmsg -n "Stopping virtual_oss config: ${config}: " 859cab9fdeSChristos Margiolis kill "$(cat "${pidpath}/${config}.pid")" 869cab9fdeSChristos Margiolis rm -f "${pidpath}/${config}.pid" 879cab9fdeSChristos Margiolis startmsg "done" 889cab9fdeSChristos Margiolis fi 899cab9fdeSChristos Margiolis} 909cab9fdeSChristos Margiolis 919cab9fdeSChristos Margiolisvirtual_oss_start() 929cab9fdeSChristos Margiolis{ 939cab9fdeSChristos Margiolis configs="$1" 949cab9fdeSChristos Margiolis [ -z "${configs}" ] && configs="${virtual_oss_configs}" 959cab9fdeSChristos Margiolis for config in ${configs}; do 969cab9fdeSChristos Margiolis start_instance "${config}" 979cab9fdeSChristos Margiolis done 989cab9fdeSChristos Margiolis} 999cab9fdeSChristos Margiolis 1009cab9fdeSChristos Margiolisvirtual_oss_stop() 1019cab9fdeSChristos Margiolis{ 1029cab9fdeSChristos Margiolis configs="$1" 1039cab9fdeSChristos Margiolis [ -z "${configs}" ] && configs="${virtual_oss_configs}" 1049cab9fdeSChristos Margiolis for config in ${configs}; do 1059cab9fdeSChristos Margiolis stop_instance "${config}" 1069cab9fdeSChristos Margiolis done 1079cab9fdeSChristos Margiolis} 1089cab9fdeSChristos Margiolis 1099cab9fdeSChristos Margiolisvirtual_oss_status() 1109cab9fdeSChristos Margiolis{ 1119cab9fdeSChristos Margiolis pids=$(virtual_oss_pids) 1129cab9fdeSChristos Margiolis 1139cab9fdeSChristos Margiolis if [ "${pids}" ]; then 1149cab9fdeSChristos Margiolis echo "${name} is running as pid ${pids}." 1159cab9fdeSChristos Margiolis else 1169cab9fdeSChristos Margiolis echo "${name} is not running." 1179cab9fdeSChristos Margiolis return 1 1189cab9fdeSChristos Margiolis fi 1199cab9fdeSChristos Margiolis} 1209cab9fdeSChristos Margiolis 1219cab9fdeSChristos Margiolisrun_rc_command "$@" 122