xref: /illumos-gate/usr/src/cmd/svc/milestone/rmtmpfiles (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
62f349fb3STom Whitten# Common Development and Distribution License (the "License").
72f349fb3STom Whitten# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
232f349fb3STom Whitten# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
252f349fb3STom Whitten
262f349fb3STom Whitten# For modifying the behavior of rmtmpfiles, do not edit this script.
27*bbf21555SRichard Lowe# Instead use svccfg(8) to modify the SMF repository.  To achieve
282f349fb3STom Whitten# traditional System V treatment of /var/tmp, invoke the following
292f349fb3STom Whitten# commands.:
307c478bd9Sstevel@tonic-gate#
312f349fb3STom Whitten# # svccfg
322f349fb3STom Whitten# svc:> select system/rmtmpfiles
332f349fb3STom Whitten# svc:/system/rmtmpfiles> setprop options/clean_vartmp="true"
342f349fb3STom Whitten# svc:/system/rmtmpfiles> select default
352f349fb3STom Whitten# svc:/system/rmtmpfiles:default> refresh
362f349fb3STom Whitten# svc:/system/rmtmpfiles:default> exit
372f349fb3STom Whitten#
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate# Traditional SunOS 4.x behavior has been to not remove directories in
407c478bd9Sstevel@tonic-gate# the /tmp directory; only simple files were removed. This lead to an
417c478bd9Sstevel@tonic-gate# inconsistency when the tmpfs file system was used (which isn't persistent
427c478bd9Sstevel@tonic-gate# across boots. The following adopts the traditional System V behavior
437c478bd9Sstevel@tonic-gate# of removing everything in /tmp, unless /tmp or any of its subdirectories
447c478bd9Sstevel@tonic-gate# are mount points for another filesystem.
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate/sbin/mount | /usr/bin/egrep '^/tmp(/| )' >/dev/null 2>&1 || {
477c478bd9Sstevel@tonic-gate	if [ -h /tmp ]; then
487c478bd9Sstevel@tonic-gate		# Just remove files under directory if symbolic link
497c478bd9Sstevel@tonic-gate		/usr/bin/rm -rf /tmp/*
507c478bd9Sstevel@tonic-gate	else
517c478bd9Sstevel@tonic-gate		/usr/bin/rm -rf /tmp
527c478bd9Sstevel@tonic-gate		/usr/bin/mkdir -m 1777 /tmp
537c478bd9Sstevel@tonic-gate		/usr/bin/chown root:sys /tmp
547c478bd9Sstevel@tonic-gate	fi
557c478bd9Sstevel@tonic-gate}
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate# Clean up /etc directory
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gatefor file in /etc/rem_name_to_major /etc/nologin; do
607c478bd9Sstevel@tonic-gate	[ -f $file ] && /usr/bin/rm -f $file
617c478bd9Sstevel@tonic-gatedone
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate# Traditional SunOS 4.x behavior has been to not alter the contents of
647c478bd9Sstevel@tonic-gate# /var/tmp (/usr/tmp) at boot time. This behavior is maintained as the
652f349fb3STom Whitten# current default behavior. If the traditional System V behavior of
662f349fb3STom Whitten# removing everything in /var/tmp is desired then clean up /var/tmp,
672f349fb3STom Whitten# unless /var/tmp or any of its subdirectories are mount points for
682f349fb3STom Whitten# another filesystem.
697c478bd9Sstevel@tonic-gate
702f349fb3STom WhittenCLEAN_VARTMP=`svcprop -c -p options/clean_vartmp $SMF_FMRI`
712f349fb3STom Whittenif [ "$CLEAN_VARTMP" = "true" ]; then
727c478bd9Sstevel@tonic-gate    /sbin/mount | /usr/bin/egrep '^/var/tmp(/| )' >/dev/null 2>&1 || {
737c478bd9Sstevel@tonic-gate	cd /var/tmp || exit 0
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate	# We carefully remove all files except the Ex* files (editor
767c478bd9Sstevel@tonic-gate	# temporary files), which expreserve will process later (in
772f349fb3STom Whitten	# S89PRESERVE).  Of course, it would be simpler to just run
787c478bd9Sstevel@tonic-gate	# expreserve before this script, but that doesn't work --
797c478bd9Sstevel@tonic-gate	# expreserve requires the name service, which is not available
807c478bd9Sstevel@tonic-gate	# until much later.
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate	/usr/bin/ls -a | /usr/bin/egrep -v '^(Ex.*|\.|\.\.)$' |
837c478bd9Sstevel@tonic-gate	    /usr/bin/xargs /usr/bin/rm -rf -- 2>/dev/null
847c478bd9Sstevel@tonic-gate    }
852f349fb3STom Whittenfi
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gateexit 0
88