]> diplodocus.org Git - flac-archive/blobdiff - fa-flacd
Make handling of child process death consistent.
[flac-archive] / fa-flacd
index 2cc12102be26e31764a349b6370b2e03be647b11..3e9e7cb8059bdbdb7c55830d3fc1a76784e5c3c1 100755 (executable)
--- a/fa-flacd
+++ b/fa-flacd
@@ -1,6 +1,7 @@
 #! /usr/bin/env perl
 
 # $Id$
+# $URL$
 
 =head1 NAME
 
@@ -8,7 +9,7 @@ B<fa-flacd> - archive CDs to single FLAC files
 
 =head1 SYNOPSIS
 
-B<fa-flacd> [B<-jv>]
+B<fa-flacd> [B<-j> I<jobs>] [B<-v>]
 
 =cut
 
@@ -16,10 +17,9 @@ use strict;
 use warnings;
 
 use File::Basename;
-use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1;
+use Getopt::Long qw(:config gnu_getopt no_ignore_case);
 use POSIX ':sys_wait_h';
-
-our $VERSION = 1;
+use Pod::Usage;
 
 my $verbose;
 my @jobs;
@@ -90,12 +90,16 @@ sub flac {
                      'cue', '--no-padding', '--best',
                      map({ ('-T', $_) } @tags),
                      'wav');
-    if (WIFEXITED($status) and ($status = WEXITSTATUS($status)) != 0) {
-        die("flac: $status");
+    if (WIFEXITED($status)) {
+        if (($status = WEXITSTATUS($status)) != 0) {
+            die("flac exited with status $status");
+        }
     } elsif (WIFSIGNALED($status)) {
         die("flac killed with signal ", WTERMSIG($status));
     } elsif (WIFSTOPPED($status)) {
         die("flac stopped with signal ", WSTOPSIG($status));
+    } else {
+        die("Major horkage on system(flac): \$? = $? \$! = $!");
     }
 
     verbose("Cleaning up $dir\n");
@@ -150,11 +154,11 @@ sub deljob {
 
     verbose("$pid finished (");
     if (WIFEXITED($status)) {
-        verbose('exited ', WEXITSTATUS($status));
+        verbose('exited with status ', WEXITSTATUS($status));
     } elsif (WIFSIGNALED($status)) {
-        verbose('signalled ', WTERMSIG($status));
+        verbose('killed with signal ', WTERMSIG($status));
     } elsif (WIFSTOPPED($status)) {
-        verbose('stopped ', WSTOPSIG($status));
+        verbose('stopped with signal ', WSTOPSIG($status));
     }
     verbose(")\n");
 
@@ -189,18 +193,18 @@ sub flacloop {
 }
 
 MAIN: {
-    my %opts;
-
-    $opts{'j'} = 4;
-    $opts{'v'} = 0;
-    if (not getopts('j:v', \%opts)) {
-        print(STDERR "usage: flacd [-jN -v]\n");
-        exit(2);
-    }
-
-    $verbose = $opts{'v'};
-
-    flacloop($opts{'j'});
+    my $jobs;
+    my $help;
+
+    $jobs = 4;
+    GetOptions(
+               'jobs|j=i' => \$jobs,
+               'verbose|v' => \$verbose,
+               'help|h|?' => \$help,
+              ) or pod2usage();
+    $help and pod2usage(-exitstatus=>0, -verbose=>1);
+
+    flacloop($jobs);
 }
 
 \f
@@ -237,6 +241,20 @@ the "log" file.  Finally, B<fa-flacd> moves the "cue" and "log" files
 to the artist directory (named by album) and removes the temporary
 directory.
 
+=head1 OPTIONS
+
+=over 4
+
+=item B<-j> [B<--jobs>] I<jobs>
+
+Run up to I<jobs> jobs instead of the default 4.
+
+=item B<-v> [B<--verbose>]
+
+Print diagnostic information.
+
+=back
+
 =head1 AUTHORS
 
 Written by Eric Gillespie <epg@pretzelnet.org>.