X-Git-Url: https://git.jankratochvil.net/?p=PerlMail.git;a=blobdiff_plain;f=perlmail-submit;h=cc76cca9453db6d407c9e7ed3a5398a961c68d90;hp=d01bc39860cdd09c91475063fd8bb6ec2c60e6dd;hb=0c848de6fd9c35f1ec9640b3adbab036ce0a5a91;hpb=983a15158daf0fe90005e66442ab09a6e4a1bcd7 diff --git a/perlmail-submit b/perlmail-submit index d01bc39..cc76cca 100755 --- a/perlmail-submit +++ b/perlmail-submit @@ -38,6 +38,9 @@ use POSIX qw(mktime); use Fcntl qw(:flock); +my $DBI_CACHE=0; # Cache DBI requests - may cause: MySQL server has gone away + + open DBI_PWD,$DBI_pwd or die "open \"$DBI_pwd\": $!"; $DBI_pwd=; close DBI_PWD or warn "close DBI_pwd: $!"; @@ -46,7 +49,7 @@ chomp $DBI_pwd; my $DBI; sub DBI { - return $DBI if $DBI; + return $DBI if $DBI_CACHE && $DBI; $DBI=DBI->connect("DBI:mysql:database=$DBI_database;host=","$DBI_user",$DBI_pwd,{ "PrintError"=>0, # handled by "RaiseError" below "RaiseError"=>1, @@ -227,16 +230,32 @@ my($keyword,$interval)=@_; } } +my $optwrap_err; +sub optwrap +{ +my($func,@args)=@_; + + # Prevent successful return due to --forkoff in the case of failed --store when using: + # perlmail-submit --store --forkoff --submit + if (!eval { &{$func}(@args); 1; }) { + $optwrap_err||=$@||$!; + die "!FINISH"; + die "NOTREACHED"; + } +} $Getopt::Long::ignorecase=0; -die if !GetOptions( - "initdb" ,\&initdb, - "store" ,\&store, - "forkoff",\&forkoff, - "submit" ,\&submit, - "pending",\&pending, - "dump" ,\&dump, - "clean:s",\&clean, +# &GetOptions will return success due to: die "!FINISH" +# but our error detection is done by $optwrap_err. +GetOptions( + "initdb" ,sub { optwrap \&initdb,@_; }, + "store" ,sub { optwrap \&store,@_; }, + "forkoff",sub { optwrap \&forkoff,@_; }, + "submit" ,sub { optwrap \&submit,@_; }, + "pending",sub { optwrap \&pending,@_; }, + "dump" ,sub { optwrap \&dump,@_; }, + "clean:s",sub { optwrap \&clean,@_; }, "V|version",sub { print "perlmail-submit: $VERSION\n"; exit 0; }, ); +die $optwrap_err if defined $optwrap_err; exit 0;