xref: /onnv-gate/usr/src/cmd/svc/milestone/rmtmpfiles (revision 10370:dcd626b57c18)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*10370SThomas.Whitten@Sun.COM# Common Development and Distribution License (the "License").
7*10370SThomas.Whitten@Sun.COM# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*10370SThomas.Whitten@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
25*10370SThomas.Whitten@Sun.COM
26*10370SThomas.Whitten@Sun.COM# For modifying the behavior of rmtmpfiles, do not edit this script.
27*10370SThomas.Whitten@Sun.COM# Instead use svccfg(1m) to modify the SMF repository.  To achieve
28*10370SThomas.Whitten@Sun.COM# traditional System V treatment of /var/tmp, invoke the following
29*10370SThomas.Whitten@Sun.COM# commands.:
300Sstevel@tonic-gate#
31*10370SThomas.Whitten@Sun.COM# # svccfg
32*10370SThomas.Whitten@Sun.COM# svc:> select system/rmtmpfiles
33*10370SThomas.Whitten@Sun.COM# svc:/system/rmtmpfiles> setprop options/clean_vartmp="true"
34*10370SThomas.Whitten@Sun.COM# svc:/system/rmtmpfiles> select default
35*10370SThomas.Whitten@Sun.COM# svc:/system/rmtmpfiles:default> refresh
36*10370SThomas.Whitten@Sun.COM# svc:/system/rmtmpfiles:default> exit
37*10370SThomas.Whitten@Sun.COM#
380Sstevel@tonic-gate
390Sstevel@tonic-gate# Traditional SunOS 4.x behavior has been to not remove directories in
400Sstevel@tonic-gate# the /tmp directory; only simple files were removed. This lead to an
410Sstevel@tonic-gate# inconsistency when the tmpfs file system was used (which isn't persistent
420Sstevel@tonic-gate# across boots. The following adopts the traditional System V behavior
430Sstevel@tonic-gate# of removing everything in /tmp, unless /tmp or any of its subdirectories
440Sstevel@tonic-gate# are mount points for another filesystem.
450Sstevel@tonic-gate
460Sstevel@tonic-gate/sbin/mount | /usr/bin/egrep '^/tmp(/| )' >/dev/null 2>&1 || {
470Sstevel@tonic-gate	if [ -h /tmp ]; then
480Sstevel@tonic-gate		# Just remove files under directory if symbolic link
490Sstevel@tonic-gate		/usr/bin/rm -rf /tmp/*
500Sstevel@tonic-gate	else
510Sstevel@tonic-gate		/usr/bin/rm -rf /tmp
520Sstevel@tonic-gate		/usr/bin/mkdir -m 1777 /tmp
530Sstevel@tonic-gate		/usr/bin/chown root:sys /tmp
540Sstevel@tonic-gate	fi
550Sstevel@tonic-gate}
560Sstevel@tonic-gate
570Sstevel@tonic-gate# Clean up /etc directory
580Sstevel@tonic-gate
590Sstevel@tonic-gatefor file in /etc/rem_name_to_major /etc/nologin; do
600Sstevel@tonic-gate	[ -f $file ] && /usr/bin/rm -f $file
610Sstevel@tonic-gatedone
620Sstevel@tonic-gate
630Sstevel@tonic-gate# Traditional SunOS 4.x behavior has been to not alter the contents of
640Sstevel@tonic-gate# /var/tmp (/usr/tmp) at boot time. This behavior is maintained as the
65*10370SThomas.Whitten@Sun.COM# current default behavior. If the traditional System V behavior of
66*10370SThomas.Whitten@Sun.COM# removing everything in /var/tmp is desired then clean up /var/tmp,
67*10370SThomas.Whitten@Sun.COM# unless /var/tmp or any of its subdirectories are mount points for
68*10370SThomas.Whitten@Sun.COM# another filesystem.
690Sstevel@tonic-gate
70*10370SThomas.Whitten@Sun.COMCLEAN_VARTMP=`svcprop -c -p options/clean_vartmp $SMF_FMRI`
71*10370SThomas.Whitten@Sun.COMif [ "$CLEAN_VARTMP" = "true" ]; then
72*10370SThomas.Whitten@Sun.COM    /sbin/mount | /usr/bin/egrep '^/var/tmp(/| )' >/dev/null 2>&1 || {
730Sstevel@tonic-gate	cd /var/tmp || exit 0
740Sstevel@tonic-gate
750Sstevel@tonic-gate	# We carefully remove all files except the Ex* files (editor
760Sstevel@tonic-gate	# temporary files), which expreserve will process later (in
77*10370SThomas.Whitten@Sun.COM	# S89PRESERVE).  Of course, it would be simpler to just run
780Sstevel@tonic-gate	# expreserve before this script, but that doesn't work --
790Sstevel@tonic-gate	# expreserve requires the name service, which is not available
800Sstevel@tonic-gate	# until much later.
810Sstevel@tonic-gate
820Sstevel@tonic-gate	/usr/bin/ls -a | /usr/bin/egrep -v '^(Ex.*|\.|\.\.)$' |
830Sstevel@tonic-gate	    /usr/bin/xargs /usr/bin/rm -rf -- 2>/dev/null
84*10370SThomas.Whitten@Sun.COM    }
85*10370SThomas.Whitten@Sun.COMfi
860Sstevel@tonic-gate
870Sstevel@tonic-gateexit 0
88