]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - etc/rc.d/cleartmp
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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="clear_tmp_enable"
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                 # + .sujournal and .snap are preserved.
40                 find -x ${tmp}/. ! -name . \
41                     ! \( -name .sujournal -type f -user root \) \
42                     ! \( -name .snap -type d -user root \) \
43                     ! \( -name lost+found -type d -user root \) \
44                     ! \( \( -name quota.user -or -name quota.group \) \
45                         -type f -user root \) \
46                     -prune -exec rm -rf -- {} +
47         elif checkyesno clear_tmp_X; then
48                 # Remove X lock files, since they will prevent you from
49                 # restarting X.  Remove other X related directories.
50                 check_startmsgs && echo "Clearing ${tmp} (X related)."
51                 rm -rf ${tmp}/.X[0-9]-lock ${x11_socket_dirs}
52         fi
53         if checkyesno clear_tmp_X; then
54                 # Create X related directories with proper permissions.
55                 mkdir -m 1777 ${x11_socket_dirs}
56         fi
57 }
58
59 load_rc_config $name
60 run_rc_command "$1"