xref: /aosp_15_r20/external/selinux/restorecond/restorecond.init (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1#!/bin/sh
2#
3# restorecond:		Daemon used to maintain path file context
4#
5# chkconfig:	- 12 87
6# description:	restorecond uses inotify to look for creation of new files \
7# listed in the /etc/selinux/restorecond.conf file, and restores the \
8# correct security context.
9#
10# processname: /usr/sbin/restorecond
11# config: /etc/selinux/restorecond.conf
12# pidfile: /run/restorecond.pid
13#
14# Return values according to LSB for all commands but status:
15# 0 - success
16# 1 - generic or unspecified error
17# 2 - invalid or excess argument(s)
18# 3 - unimplemented feature (e.g. "reload")
19# 4 - insufficient privilege
20# 5 - program is not installed
21# 6 - program is not configured
22# 7 - program is not running
23
24PATH=/sbin:/bin:/usr/bin:/usr/sbin
25
26# Source function library.
27. /etc/rc.d/init.d/functions
28
29[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || exit 7
30
31# Check that we are root ... so non-root users stop here
32if [ $EUID  ]; then
33	test $EUID = 0  || exit 4
34else
35	test `id -u` = 0  || exit 4
36fi
37
38test -x /usr/sbin/restorecond  || exit 5
39test -f /etc/selinux/restorecond.conf  || exit 6
40
41RETVAL=0
42
43start()
44{
45        echo -n $"Starting restorecond: "
46	unset HOME MAIL USER USERNAME
47        daemon /usr/sbin/restorecond
48	RETVAL=$?
49	touch /var/lock/subsys/restorecond
50        echo
51	return $RETVAL
52}
53
54stop()
55{
56        echo -n $"Shutting down restorecond: "
57	killproc restorecond
58	RETVAL=$?
59	rm -f  /var/lock/subsys/restorecond
60        echo
61	return $RETVAL
62}
63
64restart()
65{
66    stop
67    start
68}
69
70# See how we were called.
71case "$1" in
72  start)
73	start
74        ;;
75  stop)
76	stop
77        ;;
78  status)
79	status restorecond
80	RETVAL=$?
81	;;
82  force-reload|restart|reload)
83	restart
84	;;
85  condrestart)
86	[ -e /var/lock/subsys/restorecond ] && restart || :
87	;;
88  *)
89        echo $"Usage: $0 {start|stop|restart|force-reload|status|condrestart}"
90        RETVAL=3
91esac
92
93exit $RETVAL
94