diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-11-07 12:22:00 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-11-07 12:22:00 +0000 |
commit | e516dfc40a59b711f2f5b07aead137299d96868f (patch) | |
tree | 8f3248adaa4acf8e5f21980a4c01f7f1265ef6da /move | |
parent | cfc3dab900e934f41196532834f4025efad0891c (diff) | |
download | drakx-e516dfc40a59b711f2f5b07aead137299d96868f.tar drakx-e516dfc40a59b711f2f5b07aead137299d96868f.tar.gz drakx-e516dfc40a59b711f2f5b07aead137299d96868f.tar.bz2 drakx-e516dfc40a59b711f2f5b07aead137299d96868f.tar.xz drakx-e516dfc40a59b711f2f5b07aead137299d96868f.zip |
- look for busy files
- propose different actions when there are busy files
- kill processes busying files when asked
Diffstat (limited to 'move')
-rwxr-xr-x | move/tree/mdk_totem | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/move/tree/mdk_totem b/move/tree/mdk_totem index f340c6303..928723bfe 100755 --- a/move/tree/mdk_totem +++ b/move/tree/mdk_totem @@ -1,6 +1,90 @@ #!/usr/bin/perl -system('mdk_move_loop', 'to_memory', 'always', 'totem'); +use lib qw(../../perl-install /usr/lib/libDrakX); +use common; +use interactive; + +sub busy_pids_and_files() { + my @pids = grep { $_ ne $$ && /^(\d+)$/ } all('/proc'); + + map { + + my @l1 = grep { + $_ && !m!^(/proc/|/dev/|pipe:|socket:)!; + } map { readlink($_) } "/proc/$_/exe", glob_("/proc/$_/fd/*"); + + my @l2 = grep { $_ } map { (split)[5] } cat_("/proc/$_/maps"); + + if (my @l = grep { m!^/image(_boot)?/! } @l1, @l2) { + my ($cmdline) = cat_("/proc/$_/cmdline") =~ /([^\0]*)/; + my $exe = readlink("/proc/$_/exe"); + { pid => $_, cmdline => $cmdline, exe => $exe, files => [ sort(uniq(@l)) ] }; + } else { + (); + } + } @pids; +} + +sub remove_simple_daemons { + my (@busy) = @_; + my @auto_killed = grep { $_->{cmdline} =~ m!\bkdesud$|^kdeinit: kded$! } @busy or return @busy; + + kill 15, map { $_->{pid} } @auto_killed; + sleep 1; + + #- return updated list + busy_pids_and_files(); +} + +my $in = interactive->vnew; + +if (my @busy = remove_simple_daemons(busy_pids_and_files())) { + { #- log it + open(my $LOG, '| sudo sh -c "cat > /dev/tty3"'); + print $LOG '*' x 80, "\n"; + print $LOG join("\n", "$_->{exe} ($_->{cmdline}) =>", map { " $_" } @{$_->{files}}) . "\n" foreach @busy; + print $LOG '*' x 80, "\n"; + } + + my @progs = map { + my $s = $_->{cmdline}; + $s =~ s!/.*/!!; + $s =~ s!^kdeinit:\s+(\S+).*!$1!; + $s =~ s!\s+--.*!!; + $s; + } @busy; + + my $choice = 'quit'; + my @l = my %l = ( + kill => N("Kill those programs"), + keep => N("Run with no CDROM support"), + quit => N("Quit"), + ); + + $in->ask_from_({ ok => undef, + title => N("Busy files"), + messages => N("You can't use another CDROM when the following programs are running: +%s", join(", ", uniq(sort @progs))) }, + [ { type => 'list', val => \$choice, list => first(list2kv(@l)), format => sub { $l{$_[0]} } } ]); + + if ($choice eq 'quit') { + $in->exit; + } elsif ($choice eq 'keep') { + exec 'totem' or $in->exit; + } else { + kill 15, map { $_->{pid} } @busy; + sleep 2; + kill 9, map { $_->{pid} } @busy; + } +} + +{ + $in->wait_message('', N("Copying to memory to allow removing the CDROM")); + system('mdk_move_loop', 'to_memory', 'always', 'totem'); +} + +ugtk2::gtkset_mousecursor_normal(); #- for restoring a normal in any case +ugtk2::flush(); my $totem_pid = $$; |