X-Git-Url: https://git.jankratochvil.net/?a=blobdiff_plain;f=perlmail-submit;h=c7fe19fd9a69788e6ae170ecbfea3a3f9172d631;hb=5d346256a5c3b4b4266b00d1adda8a56320c6171;hp=43d3fdcf5a7545ecbe49b65205521852eb407970;hpb=2b4b3458493f6134d91065512a14948e759f8d41;p=PerlMail.git diff --git a/perlmail-submit b/perlmail-submit index 43d3fdc..c7fe19f 100755 --- a/perlmail-submit +++ b/perlmail-submit @@ -7,6 +7,12 @@ $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; }; use strict; use warnings; +use File::Basename; +BEGIN { + use lib $ENV{"PERLMAIL_BASEDIR"} || File::Basename::dirname($0); + use PerlMail::Config; + } + use Getopt::Long; use DBI; use Carp qw(cluck confess); @@ -15,18 +21,7 @@ use IO::Handle; use POSIX qw(mktime); use Fcntl qw(:flock); -my $ExitCode; -END { - exit $ExitCode if defined $ExitCode; - } -my $Lock_pathname="/tmp/LaceMail.lock"; -my $PeerAddr="dejhome.dyn.jankratochvil.net.:852"; -my $Socket_timeout=600; # 15sec is NOT enough! -my $DB_table="LaceMail_folder"; -my $DBI_database="short"; -my $DBI_user="short"; -my $DBI_pwd=$ENV{"HOME"}."/priv/mysql.".$DBI_user.".pwd"; open DBI_PWD,$DBI_pwd or die "open \"$DBI_pwd\": $!"; $DBI_pwd=; close DBI_PWD or warn "close DBI_pwd: $!"; @@ -69,6 +64,7 @@ sub store local $/; $message=; } + close STDIN or cluck "close STDIN: $!"; my %row=( "message"=>$message, # assume "retries"=>0, @@ -77,7 +73,14 @@ sub store ." values (".join(",",map("?",keys(%row))).")"); $prep->execute(values(%row)); print $prep->{"mysql_insertid"}."\n"; - $ExitCode=0; # we will succeed even if --submit fails +} + +sub forkoff +{ + my $pid=fork(); + confess if !defined $pid; + exit 0 if $pid; # parent + # child } my $submitonce_run=0; @@ -177,7 +180,7 @@ my($keyword,$interval)=@_; $sec+=$1 while s/(\d+)s//g; die "Interval parse error; left \"$_\", parsed: $interval" if $_ ne ""; $sth=$DBI->prepare(($print ? "select id" : "delete") - ." from $DB_table where timeexecute(); if (!$print) { print $sth->rows()."\n"; @@ -194,9 +197,10 @@ $Getopt::Long::ignorecase=0; die if !GetOptions( "initdb" ,\&initdb, "store" ,\&store, + "forkoff",\&forkoff, "submit" ,\&submit, "pending",\&pending, "clean:s",\&clean, - "V|version",sub { print "lacemail-submit: $VERSION\n"; exit 0; }, + "V|version",sub { print "perlmail-submit: $VERSION\n"; exit 0; }, ); exit 0;