summaryrefslogtreecommitdiff
path: root/sys-freebsd/freebsd-sbin/files/devd_queue
blob: d42cb830c962b1ef9228f0c608f3b4c7ef7a42fe (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
#!/bin/sh

# Notify the rc system that we're in the background
export IN_BACKGROUND=true

arg1="$1"
if [ -z "$arg1" ] ; then
	echo "Command required" > /dev/stderr
	exit 1
fi
shift

case "$arg1" in
	add)
		if [ -z "$1" ] ; then
			echo "Command missing!" > /dev/stderr
			exit 1
		fi

		# If we don't have a queue then just run
		if [ ! -d /var/run/devd ] ; then
			"$@"
			exit $?
		fi

		cmd="$1"
		args="$*"
		if [ "$cmd" = "env" ] ; then
			shift
			while echo "$1" | grep -q "="; do
				shift
				[ "$1" = "--" ] && shift && break
			done
			cmd="$1"
		fi
		echo "$args" > /var/run/devd/$(basename "$cmd")
		;;
	flush)
		while ! rmdir /var/run/devd 2>/dev/null ; do
			for cmd in $(cd /var/run/devd; ls) ; do
				args=$(cat /var/run/devd/$cmd)
				rm -f /var/run/devd/$cmd
				$args
			done
		done
		;;
	*)
		echo "Unknown command $arg1"
		;;
esac