xref: /netbsd-src/tests/sys/rc/h_args.sh (revision 2c2857e92093ac94279414d442b660bd30b32186)
1*2c2857e9Sjmmv#! /bin/sh
2*2c2857e9Sjmmv#
3*2c2857e9Sjmmv# $NetBSD: h_args.sh,v 1.1 2010/03/15 19:03:08 jmmv Exp $
4*2c2857e9Sjmmv#
5*2c2857e9Sjmmv# Copyright (c) 2010 The NetBSD Foundation, Inc.
6*2c2857e9Sjmmv# All rights reserved.
7*2c2857e9Sjmmv#
8*2c2857e9Sjmmv# This code is derived from software contributed to The NetBSD Foundation
9*2c2857e9Sjmmv# by Julio Merino.
10*2c2857e9Sjmmv#
11*2c2857e9Sjmmv# Redistribution and use in source and binary forms, with or without
12*2c2857e9Sjmmv# modification, are permitted provided that the following conditions
13*2c2857e9Sjmmv# are met:
14*2c2857e9Sjmmv# 1. Redistributions of source code must retain the above copyright
15*2c2857e9Sjmmv#    notice, this list of conditions and the following disclaimer.
16*2c2857e9Sjmmv# 2. Redistributions in binary form must reproduce the above copyright
17*2c2857e9Sjmmv#    notice, this list of conditions and the following disclaimer in the
18*2c2857e9Sjmmv#    documentation and/or other materials provided with the distribution.
19*2c2857e9Sjmmv#
20*2c2857e9Sjmmv# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21*2c2857e9Sjmmv# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22*2c2857e9Sjmmv# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*2c2857e9Sjmmv# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24*2c2857e9Sjmmv# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*2c2857e9Sjmmv# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*2c2857e9Sjmmv# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*2c2857e9Sjmmv# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*2c2857e9Sjmmv# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*2c2857e9Sjmmv# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*2c2857e9Sjmmv# POSSIBILITY OF SUCH DAMAGE.
31*2c2857e9Sjmmv#
32*2c2857e9Sjmmv
33*2c2857e9Sjmmv#
34*2c2857e9Sjmmv# An rc.d script that overrides all standard comands and adds a non-standard
35*2c2857e9Sjmmv# command.  All of them print the set of arguments passed to them and take no
36*2c2857e9Sjmmv# further action.
37*2c2857e9Sjmmv#
38*2c2857e9Sjmmv
39*2c2857e9Sjmmv${_rc_subr_loaded} . /etc/rc.subr
40*2c2857e9Sjmmv
41*2c2857e9Sjmmvname="h_args"
42*2c2857e9Sjmmvrcvar="${name}"
43*2c2857e9Sjmmvcommand="/usr/bin/true"
44*2c2857e9Sjmmvextra_commands="custom"
45*2c2857e9Sjmmv
46*2c2857e9Sjmmvfor command in start stop restart custom; do
47*2c2857e9Sjmmv	eval ${command}_precmd=\'print_args pre${command}\'
48*2c2857e9Sjmmv	eval ${command}_cmd=\'print_args ${command}\'
49*2c2857e9Sjmmv	eval ${command}_postcmd=\'print_args post${command}\'
50*2c2857e9Sjmmvdone
51*2c2857e9Sjmmv
52*2c2857e9Sjmmvprint_args() {
53*2c2857e9Sjmmv	local command="${1}"; shift
54*2c2857e9Sjmmv
55*2c2857e9Sjmmv	printf "${command}:"
56*2c2857e9Sjmmv	while [ ${#} -gt 0 ]; do
57*2c2857e9Sjmmv		printf " >%s<" "${1}"
58*2c2857e9Sjmmv		shift
59*2c2857e9Sjmmv	done
60*2c2857e9Sjmmv	printf ".\n"
61*2c2857e9Sjmmv}
62*2c2857e9Sjmmv
63*2c2857e9Sjmmvload_rc_config "${name}"
64*2c2857e9Sjmmvrun_rc_command "${@}"
65