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