Skip to content

Commit

Permalink
rpc: added kill() function that gently kills RPD
Browse files Browse the repository at this point in the history
  • Loading branch information
trapd00r committed Jun 28, 2010
1 parent bc4e335 commit f3a9597
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions rpc
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ use Mplayer::NowPlaying qw(stream_np $np_log);
use Data::Dumper;

my $options;
my $action = shift;
my $arg = shift;
my($action,$arg) = @ARGV;
my $pipe_w = "$ENV{HOME}/.mplayer/rpd.fifo";
my $log = "$ENV{HOME}/.mplayer/rpd.log";
my $favtracks = "$ENV{HOME}/.mplayer/rpd.fav";
$np_log = $log;
my $rpd_pid = '/tmp/rpd.pid';

if(!-f $rpd_pid) {
if(!(-f $rpd_pid)) {
print "RPD is not running, starting...\n";
system("rpd psy") == 0 or print "RPD could not start. $!\n";
system("rpd") == 0 or print "RPD could not start. $!\n";
exit 0;
}

Expand Down Expand Up @@ -131,16 +130,28 @@ $options = {
close($fh);

yell(@favs);
}
},
kill => sub {
open(my $fh, '<', $rpd_pid) or croak("Cant open $rpd_pid: $!");
my $target = <$fh>;
close($fh);
if(kill(9, $target)) {
print "RPD ($target) have been killed\n";
unlink($rpd_pid);
exit(0);
}
else {
print "Could not kill $target: $!\n";
}
},
};


$options->{'help'}->() unless $action;
defined $options->{$action} && $options->{$action}->();

sub fifo_w {
my $action = shift;
my $arg = shift;
my($action,$arg) = @_;
open(my $fh, '>', $pipe_w) or die "Can not open $pipe_w for writing: $!";
print {$fh} "$action $arg\n";
}
Expand Down

0 comments on commit f3a9597

Please sign in to comment.