xref: /illumos-gate/usr/src/cmd/svc/milestone/rmtmpfiles (revision 73b80b821da76082173547dd650e417f6916eb8b)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25
26# For modifying the behavior of rmtmpfiles, do not edit this script.
27# Instead use svccfg(8) to modify the SMF repository.  To achieve
28# traditional System V treatment of /var/tmp, invoke the following
29# commands.:
30#
31# # svccfg
32# svc:> select system/rmtmpfiles
33# svc:/system/rmtmpfiles> setprop options/clean_vartmp="true"
34# svc:/system/rmtmpfiles> select default
35# svc:/system/rmtmpfiles:default> refresh
36# svc:/system/rmtmpfiles:default> exit
37#
38
39# Traditional SunOS 4.x behavior has been to not remove directories in
40# the /tmp directory; only simple files were removed. This lead to an
41# inconsistency when the tmpfs file system was used (which isn't persistent
42# across boots. The following adopts the traditional System V behavior
43# of removing everything in /tmp, unless /tmp or any of its subdirectories
44# are mount points for another filesystem.
45
46/sbin/mount | /usr/bin/egrep '^/tmp(/| )' >/dev/null 2>&1 || {
47	if [ -h /tmp ]; then
48		# Just remove files under directory if symbolic link
49		/usr/bin/rm -rf /tmp/*
50	else
51		/usr/bin/rm -rf /tmp
52		/usr/bin/mkdir -m 1777 /tmp
53		/usr/bin/chown root:sys /tmp
54	fi
55}
56
57# Clean up /etc directory
58
59for file in /etc/rem_name_to_major /etc/nologin; do
60	[ -f $file ] && /usr/bin/rm -f $file
61done
62
63# Traditional SunOS 4.x behavior has been to not alter the contents of
64# /var/tmp (/usr/tmp) at boot time. This behavior is maintained as the
65# current default behavior. If the traditional System V behavior of
66# removing everything in /var/tmp is desired then clean up /var/tmp,
67# unless /var/tmp or any of its subdirectories are mount points for
68# another filesystem.
69
70CLEAN_VARTMP=`svcprop -c -p options/clean_vartmp $SMF_FMRI`
71if [ "$CLEAN_VARTMP" = "true" ]; then
72    /sbin/mount | /usr/bin/egrep '^/var/tmp(/| )' >/dev/null 2>&1 || {
73	cd /var/tmp || exit 0
74
75	# We carefully remove all files except the Ex* files (editor
76	# temporary files), which expreserve will process later (in
77	# S89PRESERVE).  Of course, it would be simpler to just run
78	# expreserve before this script, but that doesn't work --
79	# expreserve requires the name service, which is not available
80	# until much later.
81
82	/usr/bin/ls -a | /usr/bin/egrep -v '^(Ex.*|\.|\.\.)$' |
83	    /usr/bin/xargs /usr/bin/rm -rf -- 2>/dev/null
84    }
85fi
86
87exit 0
88