Changeset 0237078 for debian/lib


Ignore:
Timestamp:
Jun 24, 2010, 1:48:09 AM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
master, debian, mac, no-cups, nodebathena, web
Children:
aef31c3
Parents:
1e04f22
git-author:
root <root@…> (05/31/10 22:25:06)
git-committer:
Jessica B. Hamrick <jhamrick@…> (06/24/10 01:48:09)
Message:

Handle SIGHUP in the backend

File:
1 edited

Legend:

Unmodified
Added
Removed
  • debian/lib/gutenbach

    r4ac44b2 r0237078  
    3131
    3232my $ua = new LWP::UserAgent;
     33
     34# This variable contains the pid of the child process (which runs
     35# mplayer) once it has been forked, so that we can kill it on SIGTERM
     36my $pid;
    3337
    3438# Replace STDERR with a log file in /tmp.
     
    107111# SIGHUP handler, in case we were aborted
    108112sub clear_status {
     113  kill 15, $pid if $pid;
    109114  my @zwrite_command = (qw(/usr/bin/zwrite -d -n -c), $zephyr_class, "-i", $queue.'@'.$host, "-s", "Gutenbach Music Spooler");
    110115  open(ZEPH, "|-", @zwrite_command);
     
    113118  die;
    114119}
     120
    115121$SIG{HUP} = \&clear_status;
     122$SIG{TERM} = \&clear_status;
    116123
    117124# Read the metadata information from the file.
     
    282289  my ($filepath, $opts) = @_;
    283290
    284 
    285291  # Open up a zwrite command to show the mplayer output
    286292  my @zwrite_command = (qw(/usr/bin/zwrite -d -n -c), $zephyr_class, "-i", $queue.'@'.$host, "-s", "Gutenbach Music Spooler");
    287293
    288   print STDERR "Invoking @zwrite_command\n";
    289   open(ZEPHYR, "|-", @zwrite_command) or die "Couldn't launch zwrite: $!";
     294  print STDERR "Invoking (from play_mplayer_audio): @zwrite_command\n";
    290295
    291296  # fork for mplayer
    292   my $pid = open(MP3STATUS, "-|");
     297  $pid = open(MP3STATUS, "-|");
    293298  unless (defined $pid) {
     299    open(ZEPHYR, "|-", @zwrite_command) or die "Couldn't launch zwrite: $!";
    294300    print ZEPHYR "Couldn't fork: $!\n";
    295301    close(ZEPHYR);
     
    299305  if ($pid) { #parent
    300306    # Check if there were any errors
    301    
    302307    if ($_ = <MP3STATUS>) {
     308      open(ZEPHYR, "|-", @zwrite_command) or die "Couldn't launch zwrite: $!";
    303309      print ZEPHYR "Playback completed with the following errors:\n";
    304310      while (<MP3STATUS>) {
    305311        print ZEPHYR $_;
    306312      }
     313      close(ZEPHYR);
    307314    } else {
     315      open(ZEPHYR, "|-", @zwrite_command) or die "Couldn't launch zwrite: $!";
    308316      print ZEPHYR "Playback completed successfully.\n";
     317      close(ZEPHYR);
    309318    }
    310319    close(MP3STATUS) || print ZEPHYR "mplayer exited $?\n";
    311 
    312     close(ZEPHYR);
    313320  }
    314321  else { # child
Note: See TracChangeset for help on using the changeset viewer.