~ubuntu-branches/debian/experimental/sysvinit/experimental

« back to all changes in this revision

Viewing changes to debian/initscripts/lib/init/bootclean.sh

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2009-09-13 00:13:49 UTC
  • Revision ID: james.westby@ubuntu.com-20090913001349-c4hnvhp0titxdpw9
Tags: 2.87dsf-5
* Uploading to experimental, to test the new build rules.

* Make sysv-rc postinst report detected problems to stderr too when
  failing to migrate.
* Fix typo in error message from postinst (Closes: #545409).
* Make initscripts depend on sysvinit-utils (>= 2.86.ds1-64), to
  make sure the fstab-decode program is available (Closes: #545356).
* Make sure the calls to 'update-rc.d X remove' in initscripts
  postinst do not ignore errors (Closes: #406361).
* Make sysvinit depend on sysvinit-utils (>= 2.86.ds1-66) to avoid
  that bootlogd disappear during partial upgrades (Closes: #545368).
* Restructure source package to make it possible to use debhelper in
  the common way to build the source, by moving debian/initscripts/
  and debian/sysv-rc/ into debian/src/.  Restructure build rules to
  use debhelper more, and migrate to debhelper 7.
* New patch 98_installtarget.patch to improve the sysvinit install
  target.
* Remove /etc/init.d/.depend.* in prerm, not postrm, to avoid
  surprises.
* Remove /var/lib/update-rc.d/* when the package is purged.
* Change cut-off point for the trimmed changelog entries in
  sysvinit-utils, initscripts and sysv-rc from version 2.84-3 to
  version 2.86.ds1-47, to reduce the package sizes.
* Drop hurd specific dependency on libc0.3 (>= 2.3.2.ds1-12).  It is
  no longer needed according to Michael Bunk.  Patch from Michael
  Biebl.
* Remove information about scripts in /var/lib/update-rc.d/ when
  their runlevel symlinks are removed (Closes: #545949).  Remove
  such files left behind earlier during upgrade.
* Bootlogd now starts as late as possible (Closes: #265801)
* Drop the binary /lib/init/readlink from initscripts and depend on
  coreutils (>= 5.93) instead.  Adjust scripts to use the program
  from coreutils from now on (Closes: #239342).
* Make sure insserv exit values propagate through update-rc.d to make
  sure packages with errors fail to install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# bootclean
4
 
#
5
 
# Clean /tmp.  Clean /var/run and /var/lock if not mounted as tmpfs
6
 
#
7
 
# DO NOT RUN AFTER S:55bootmisc.sh and do not run this script directly
8
 
# in runlevel S. Instead write an initscript to call it.
9
 
#
10
 
 
11
 
. /lib/init/vars.sh
12
 
 
13
 
. /lib/lsb/init-functions
14
 
 
15
 
# Should be called outside verbose message block
16
 
mkflagfile()
17
 
{
18
 
        # Prevent symlink attack  (See #264234.)
19
 
        [ -L "$1" ] && log_warning_msg "bootclean: Deleting symbolic link '$1'."
20
 
        rm -f "$1" || { log_failure_msg "bootclean: Failure deleting '$1'." ; return 1 ; }
21
 
        # No user processes should be running, so no one should be able to introduce
22
 
        # a symlink here.  As an extra precaution, set noclobber.
23
 
        set -o noclobber
24
 
        :> "$1" || { log_failure_msg "bootclean: Failure creating '$1'." ; return 1 ; }
25
 
        return 0
26
 
}
27
 
 
28
 
clean_tmp() {
29
 
        cd /tmp || { log_failure_msg "bootclean: Could not cd to /tmp." ; return 1 ; }
30
 
 
31
 
        #
32
 
        # Only clean out /tmp if it is world-writable. This ensures
33
 
        # it really is a/the temp directory we're cleaning.
34
 
        #
35
 
        [ "$(find . -maxdepth 0 -perm -002)" = "." ] || return 0
36
 
 
37
 
        if [ ! "$TMPTIME" ]
38
 
        then
39
 
                log_warning_msg "Using default TMPTIME 0."
40
 
                TMPTIME=0
41
 
        fi
42
 
 
43
 
        [ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /tmp"
44
 
 
45
 
        #
46
 
        # Remove regardless of TMPTIME setting
47
 
        #
48
 
        rm -f .X*-lock
49
 
 
50
 
        #
51
 
        # Don't clean remaining files if TMPTIME is negative or 'infinite'
52
 
        #
53
 
        case "$TMPTIME" in
54
 
          -*|infinite|infinity)
55
 
                [ "$VERBOSE" = no ] || log_action_end_msg 0 "skipped"
56
 
                return 0
57
 
                ;;
58
 
        esac
59
 
 
60
 
        #
61
 
        # Wipe /tmp, excluding system files, but including lost+found
62
 
        #
63
 
        # If TMPTIME is set to 0, we do not use any ctime expression
64
 
        # at all, so we can also delete files with timestamps
65
 
        # in the future!
66
 
        #
67
 
        if [ "$TMPTIME" = 0 ] 
68
 
        then
69
 
                TEXPR=""
70
 
                DEXPR=""
71
 
        else
72
 
                TEXPR="-mtime +$TMPTIME -ctime +$TMPTIME -atime +$TMPTIME"
73
 
                DEXPR="-mtime +$TMPTIME -ctime +$TMPTIME"
74
 
        fi
75
 
 
76
 
        EXCEPT='! -name .
77
 
                ! ( -path ./lost+found -uid 0 )
78
 
                ! ( -path ./quota.user -uid 0 )
79
 
                ! ( -path ./aquota.user -uid 0 )
80
 
                ! ( -path ./quota.group -uid 0 )
81
 
                ! ( -path ./aquota.group -uid 0 )
82
 
                ! ( -path ./.journal -uid 0 )
83
 
                ! ( -path ./.clean -uid 0 )
84
 
                ! ( -path './...security*' -uid 0 )'
85
 
 
86
 
        mkflagfile /tmp/.clean || return 1
87
 
 
88
 
        report_err()
89
 
        {
90
 
                if [ "$VERBOSE" = no ]
91
 
                then
92
 
                        log_failure_msg "bootclean: Failure cleaning /tmp."
93
 
                else
94
 
                        log_action_end_msg 1 "bootclean: Failure cleaning /tmp"
95
 
                fi
96
 
        }
97
 
 
98
 
        #
99
 
        # First remove all old files...
100
 
        #
101
 
        find . -depth -xdev $TEXPR $EXCEPT ! -type d -delete \
102
 
                || { report_err ; return 1 ; }
103
 
 
104
 
        #
105
 
        # ...and then all empty directories
106
 
        #
107
 
        find . -depth -xdev $DEXPR $EXCEPT -type d -empty -delete \
108
 
                || { report_err ; return 1 ; }
109
 
 
110
 
        [ "$VERBOSE" = no ] || log_action_end_msg 0
111
 
        return 0
112
 
}
113
 
 
114
 
clean_lock() {
115
 
        if [ yes = "$RAMLOCK" ] ; then
116
 
            return 0
117
 
        fi
118
 
 
119
 
        cd /var/lock || { log_failure_msg "bootclean: Could not cd to /var/lock." ; return 1 ; }
120
 
 
121
 
        [ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /var/lock"
122
 
        report_err()
123
 
        {
124
 
                if [ "$VERBOSE" = no ]
125
 
                then
126
 
                        log_failure_msg "bootclean: Failure cleaning /var/lock."
127
 
                else
128
 
                        log_action_end_msg 1 "bootclean: Failure cleaning /var/lock"
129
 
                fi
130
 
        }
131
 
        find . ! -type d -delete \
132
 
                || { report_err ; return 1 ; }
133
 
        [ "$VERBOSE" = no ] || log_action_end_msg 0
134
 
        mkflagfile /var/lock/.clean || return 1
135
 
        return 0
136
 
}
137
 
 
138
 
clean_run() {
139
 
        if [ yes = "$RAMRUN" ] ; then
140
 
            return 0
141
 
        fi
142
 
 
143
 
        cd /var/run || { log_action_end_msg 1 "bootclean: Could not cd to /var/run." ; return 1 ; }
144
 
 
145
 
        [ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /var/run"
146
 
        report_err()
147
 
        {
148
 
                if [ "$VERBOSE" = no ]
149
 
                then
150
 
                        log_failure_msg "bootclean: Failure cleaning /var/run."
151
 
                else
152
 
                        log_action_end_msg 1 "bootclean: Failure cleaning /var/run"
153
 
                fi
154
 
        }
155
 
        find . ! -xtype d ! -name utmp ! -name innd.pid -delete \
156
 
                || { report_err ; return 1 ; }
157
 
        [ "$VERBOSE" = no ] || log_action_end_msg 0
158
 
        mkflagfile /var/run/.clean || return 1
159
 
        return 0
160
 
}
161
 
 
162
 
which find >/dev/null 2>&1 || exit 1
163
 
log_begin_msg "Cleaning up temporary files..."
164
 
 
165
 
# If there are flag files that have not been created by root
166
 
# then remove them
167
 
for D in /tmp /var/run /var/lock
168
 
do
169
 
        if [ -f $D/.clean ]
170
 
        then
171
 
                which stat >/dev/null 2>&1 && cleanuid="$(stat -c %u $D/.clean)"
172
 
                # Poor's man stat %u, since stat (and /usr) might not be
173
 
                # available in some bootup stages
174
 
                [ "$cleanuid" ] || cleanuid="$(find $D/.clean -printf %U)"
175
 
                [ "$cleanuid" ] || { log_failure_msg "bootclean: Could not stat '$D/.clean'." ; exit 1 ; }
176
 
                if [ "$cleanuid" -ne 0 ]
177
 
                then
178
 
                        rm -f $D/.clean || { log_failure_msg "bootclean: Could not delete '$D/.clean'." ; exit 1 ; }
179
 
                fi
180
 
        fi
181
 
done
182
 
 
183
 
[ -f /tmp/.clean ] && [ -f /var/run/.clean ] && [ -f /var/lock/.clean ] && { log_end_msg 0 ; exit 0 ; }
184
 
 
185
 
ES=0
186
 
[ -d /tmp ] && ! [ -f /tmp/.clean ] && { clean_tmp || ES=1 ; }
187
 
[ -d /var/run ] && ! [ -f /var/run/.clean ] && { clean_run || ES=1 ; }
188
 
[ -d /var/lock ] && ! [ -f /var/lock/.clean ] && { clean_lock || ES=1 ; }
189
 
log_end_msg $ES
190
 
exit $ES