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