]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - etc/rc.d/cleartmp
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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 # Disguise rcvar for the start method to run irrespective of its setting.
14 rcvar1=`set_rcvar clear_tmp`
15 start_cmd="${name}_start"
16 stop_cmd=":"
17
18 cleartmp_start()
19 {
20         # Make /tmp location variable for easier debugging.
21         local tmp="/tmp"
22
23         # X related directories to create in /tmp.
24         local x11_socket_dirs="${tmp}/.X11-unix ${tmp}/.XIM-unix \
25                                ${tmp}/.ICE-unix ${tmp}/.font-unix"
26
27         if checkyesno ${rcvar1}; then
28                 check_startmsgs && echo "Clearing ${tmp}."
29
30                 # This is not needed for mfs, but doesn't hurt anything.
31                 # Things to note:
32                 # + The dot in ${tmp}/. is important.
33                 # + Put -prune before -exec so find never descends
34                 #   into a directory that was already passed to rm -rf.
35                 # + "--" in rm arguments isn't strictly necessary, but
36                 #   it can prevent foot-shooting in future.
37                 # + /tmp/lost+found is preserved, but its contents are removed.
38                 # + lost+found and quota.* in subdirectories are removed.
39                 find -x ${tmp}/. ! -name . \
40                     ! \( -name lost+found -type d -user root \) \
41                     ! \( \( -name quota.user -or -name quota.group \) \
42                         -type f -user root \) \
43                     -prune -exec rm -rf -- {} +
44         elif checkyesno clear_tmp_X; then
45                 # Remove X lock files, since they will prevent you from
46                 # restarting X.  Remove other X related directories.
47                 check_startmsgs && echo "Clearing ${tmp} (X related)."
48                 rm -rf ${tmp}/.X[0-9]-lock ${x11_socket_dirs}
49         fi
50         if checkyesno clear_tmp_X; then
51                 # Create X related directories with proper permissions.
52                 mkdir -m 1777 ${x11_socket_dirs}
53         fi
54 }
55
56 load_rc_config $name
57 run_rc_command "$1"