summaryrefslogtreecommitdiffstats
path: root/src.etc/init.d/rc
blob: e6985dd7ce215b3a32be92ce7b4da4ffd844b929 (plain)
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
#!/bin/sh
#
# /etc/init.d/rc
# Executes init scripts on init and shutdown.
#
# Copyright (C) 2012, 2014  Patrick "P. J." McDermott
#
# This file may be reproduced, distributed, modified, and otherwise dealt in
# under the terms of the Expat License.

LF='
'

[ -x /usr/bin/logger ] && logger='logger -p 6 -t sysinit' || logger=cat

# Buffer log lines until syslogd is running.
log()
{
	local line=
	local buf=

	while read -r line; do
		buf="${buf}${line}${LF}"
		if [ -f /var/run/syslogd.pid ]; then
			printf '%s' "${buf}" | ${logger}
			exec ${logger}
		fi
	done
	if [ -f /var/run/syslogd.pid ]; then
		printf '%s' "${buf}" | ${logger}
	fi
}

level=${0#*/rc}
case ${level} in
	S)
		action=start
		;;
	K)
		action=stop
		;;
	*)
		exit 1
		;;
esac

{
	for i in /etc/rc.d/${level}[0-1]*; do
		[ -x "${i}" ] && "${i}" ${action} 2>&1
	done
	for i in /etc/rc.d/${level}[2-9]*; do
		[ -x "${i}" ] && "${i}" ${action} 2>&1
	done
} | log