diff --git a/README.md b/README.md index 75255de8..dd77f9cb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -Shairport v0.04 +Shairport v0.05 ============== James Laird -April 11, 2011 +April 13, 2011 What it is ---------- @@ -41,6 +41,8 @@ Changelog * bugfix: ipv6 didn't work - IO::Socket::INET6 is required too * 0.04 April 12, 2011 * cross-platform count_leading_zeros under GCC - will now compile cleanly on ARM and other platforms +* 0.05 April 13, 2011 + * error-handling cleanup in the Perl script including more meaningful error messages, based on common problems seen How to compile and install on Mac OSX 10.6 diff --git a/shairport.pl b/shairport.pl index 4a523960..a797140c 100755 --- a/shairport.pl +++ b/shairport.pl @@ -66,7 +66,32 @@ sub POPE { $SIG{PIPE} = \&POPE; -my $avahi_publish = fork(); +our $avahi_publish; + +sub REAP { + if ($avahi_publish == waitpid(-1, WNOHANG)) { + die("Avahi publishing failed! Do you have avahi-publish-service on your PATH?"); + } + printf("***CHILD EXITED***\n"); + $SIG{CHLD} = \&REAP; +}; +$SIG{CHLD} = \&REAP; + +my %conns; + +$SIG{TERM} = $SIG{INT} = sub { + print "killed\n"; + map { eval { kill $_->{decoder_pid} } } keys %conns; + kill 9, $avahi_publish; + exit 0; +}; +$SIG{__DIE__} = sub { + print "died\n"; + map { eval { kill $_->{decoder_pid} } } keys %conns; + kill 9, $avahi_publish; +}; + +$avahi_publish = fork(); if ($avahi_publish==0) { exec 'avahi-publish-service', join('', map { sprintf "%02X", $_ } @hw_addr) . "\@$apname", @@ -82,32 +107,14 @@ if ($avahi_publish==0) { die "could not run avahi-publish-service nor dns-sd"; } -sub REAP { - if ($avahi_publish == waitpid(-1, WNOHANG)) { - die("Avahi publishing failed!"); - } - printf("***CHILD EXITED***\n"); - $SIG{CHLD} = \&REAP; -}; -$SIG{CHLD} = \&REAP; - -my %conns; - -$SIG{TERM} = $SIG{INT} = $SIG{__DIE__} = sub { - print "killed\n"; - map { eval { kill $_->{decoder_pid} } } keys %conns; - kill 9, $avahi_publish; - exit(0); -}; - my $airport_pem = join '', ; my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die "RSA private key import failed"; my $listen; { eval { - local $SIG{'__DIE__'}; - $listen = new IO::Socket::INET6(Listen => 1, + local $SIG{__DIE__}; + $listen = new IO::Socket::INET6(Listen => 1, Domain => AF_INET6, LocalPort => 5000, ReuseAddr => 1, @@ -118,12 +125,12 @@ my $listen; "* IO::Socket::INET6 not present! *\n", "* Install this if iTunes won't play. *\n", "**************************************\n\n"; - - $listen = new IO::Socket::INET(Listen => 1, - LocalPort => 5000, - ReuseAddr => 1, - Proto => 'tcp'); } + + $listen ||= new IO::Socket::INET(Listen => 1, + LocalPort => 5000, + ReuseAddr => 1, + Proto => 'tcp'); } die "Can't listen on port 5000: $!" unless $listen;