]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/cleartmp
This commit was generated by cvs2svn to compensate for changes in r162852,
[FreeBSD/FreeBSD.git] / etc / rc.d / cleartmp
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: cleartmp
7 # REQUIRE: mountcritremote tmp
8 # BEFORE: DAEMON
9
10 . /etc/rc.subr
11
12 name="cleartmp"
13 rcvar=`set_rcvar clear_tmp`
14
15 start_cmd="${name}_start"
16
17 cleartmp_prestart()
18 {
19         checkyesno clear_tmp_X || return
20
21         local x11_socket_dirs="/tmp/.X11-unix /tmp/.ICE-unix /tmp/.font-unix \
22             /tmp/.XIM-unix"
23
24         # Remove X lock files, since they will prevent you from restarting X.
25         rm -f /tmp/.X[0-9]-lock
26
27         # Create socket directories with correct permissions to avoid
28         # security problem.
29         #
30         rm -fr ${x11_socket_dirs}
31         mkdir -m 1777 ${x11_socket_dirs}
32 }
33
34 cleartmp_start()
35 {
36         echo "Clearing /tmp."
37         #
38         #       Prune quickly with one rm, then use find to clean up
39         #       /tmp/[lq]* (this is not needed with mfs /tmp, but
40         #       doesn't hurt anything).
41         #
42         (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
43             find -x . ! -name . ! -name lost+found ! -name quota.user \
44                 ! -name quota.group ! -name .X11-unix ! -name .ICE-unix \
45                 ! -name .font-unix ! -name .XIM-unix \
46                 -exec rm -rf -- {} \; -type d -prune)
47 }
48
49 load_rc_config $name
50
51 # The clear_tmp_X variable should be tested even if clear_tmp_enable is NO
52 case "$1" in
53 *start) cleartmp_prestart ;;
54 esac
55
56 run_rc_command "$1"