5
# Kills bonobo processes
7
# Return code of -1 (255) returned if usage error.
8
# Return code of 1 indicates bonobo processes were running
10
# Return code of 0 indicates no bonobo processes were
11
# running when script was run.
15
Getopt::Long::Configure( "no_auto_abbrev" );
16
Getopt::Long::Configure( "bundling" );
19
$opt_h = 0, $opt_i = 0, $opt_l = 0, $opt_s = 0;
21
$rc = GetOptions("help" => \$usage_error,
33
if ($opt_l && $opt_s) {
41
# Print usage if necessary.
43
if ($usage_error == 1 || $opt_h) {
45
print "Usage : bonobo-slay [-hls] [regexp]\n";
46
print "\tKill Bonobo processes still running.\n";
47
print "\t -h,--help Print this help message.\n";
48
print "\t -i Ask before killing the processes.\n";
49
print "\t -l List processes running, but do not kill them. Not valid with -s\n";
50
print "\t -s Silent. Kill processes quietly\n";
51
print "\t [regexp] only kill proccesses matching this\n";
58
$username = $ENV{USER} || $ENV{LOGNAME} || `logname`;
61
@IF_POSIX_PS@ $ps_cmd = "@PS_PATH@ -U $username -opid,args";
62
@IF_BSD_PS@ $ps_cmd = "@PS_PATH@ -U $username -xww -opid,command";
66
@bonobo_dirs = ( "@prefix@/lib/bonobo/servers" );
67
foreach $dir (split(':', $ENV{'BONOBO_ACTIVATION_INFO_PATH'})) {
69
push @bonobo_dirs, $dir;
72
foreach $dir (split(':', $ENV{'GNOME2_PATH'})) {
73
if (-d "$dir/lib/bonobo/servers") {
74
push @bonobo_dirs, "$dir/lib/bonobo/servers";
78
foreach $dir (@bonobo_dirs) {
79
opendir(DIR, $dir) || die "\nCan not open directory $dir\n\t$!\n\n";
80
push @bonobo_files, map ("$dir/$_", readdir(DIR));
84
# Initialize variables
89
# Loop until no more processes are found. This typically loops only once,
90
# but if an Bonobo process is launched while this script is running an Bonobo
91
# process can be left behind and be caught on the second loop, etc.
94
# Initialize variables.
96
@files = @bonobo_files;
104
@ps_result = `$ps_cmd`;
106
# Loop through files, and see if any Bonobo processes are running. If
107
# so, then build the @list_array and @process_pids arrays.
108
# @list_array contains the process names
109
# @process_pids contains the process IDs
111
while ($fname = shift(@files)) {
113
if ("$fname" =~ /\.server$/) {
119
if ($line =~m/location[ \t]*\=/ &&
120
!($line =~m/type=\"shlib\"/)) {
122
$line =~s/.*location[ \t]*\="//;
127
# bonobo-activation-server needs to be last.
129
if ($line ne "bonobo-activation-server" and
130
not ($line =~m/^OAFIID:/) and
131
($regexp and $line =~m/$regexp/) or (not $regexp)) {
132
push @file_process, $line;
140
# Add bonobo-activation-server so that it is last,
141
# but only if we're killing without a regexp
143
push @file_process, "bonobo-activation-server";
146
foreach $filep (@file_process) {
148
# Search through @ps_result and look for matches
150
foreach $el (@ps_result) {
152
@ps_array = split(' ', $el, 3);
154
if ($ps_array[1] =~m/(\A|\/)$filep$/ ) {
155
$list_array[$index]=$ps_array[0]."\t".$ps_array[1]."\n";
156
$process_pids[$index]=$ps_array[0]."\n";
164
if ($#list_array != -1) {
166
# Print output if -s (silent) argument is not specified.
169
if ($first_time == 1) {
171
print "The following processes are still running on the system.\n";
174
print "These processes will be terminated.\n";
177
print "NOTE: Killing these processes may affect other applications\n";
178
print "on the system that use bonobo.\n";
183
# Just some feedback to indicate it had to loop...
188
# Print list of processes...
194
# Kill if the -l argument is not specified.
198
print "Do you really want to continue (y/N) ? ";
205
$killall = "/bin/kill";
206
$kill_params = ' -9 ';
207
foreach $proc (@process_pids) {
210
$cmd = $killall.$kill_params.$proc." 2>/dev/null";
218
# Only loop once if opt_l is used, otherwise loop until
219
# no more processes are killed
221
} while ($#list_array != -1 && !opt_l);
225
if ($process_exists == 0) {
227
# Show feedback if -l argument is used
231
print "No processes.\n";