summaryrefslogtreecommitdiffstats
path: root/rescue/tree/sbin/fakeshutdown
blob: c6d9b84400d8515a34aff32bc66f25d732c10ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl

#
# Guillaume Cottenceau (gc@mandrakesoft.com)
#
# Copyright 2001 MandrakeSoft
#
# This software may be freely redistributed under the terms of the GNU
# public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l }

print "\n";


#- try to umount as much as possible; uses Pixel's ultra optimized algo (let you guess how it works..)
print "Umounting:\n";
my @mounts = cat_('/proc/mounts');
my $something_moved;
do {
    $something_moved = 0;
    foreach (@mounts) {
	my $where = (split)[1];
	next if $where eq '/'; #- ouch! umounting the ramdisk on / always succeeds, and makes it becoming ro :-(
	if (!system("umount $where 2>/dev/null")) {
	    print "\t$where\n";
	    $something_moved++;
	}
    }
} while $something_moved;


#- shutdown with init
exec '/sbin/init', 6;