use Mail::Address;
use Email::Valid;
use IPC::Open3;
+use English '-no_match_vars';
+use Config;
$| = 1;
my $reload = 0;
my $childs = 0;
my $zombies = 0;
+my $timeout = 30;
-my ( $help, $show_version, $cmdline_verbose );
+my ( $help, $show_version, $cmdline_verbose, $signal_name, $i );
my $o_inbox = 1;
my $o_outbox = 1;
+my %signo;
+my @signame;
my $config_file = $0;
$config_file =~ s/\.pl$//i;
my $o_config_file = undef;
my $dedicated_conf = undef;
+# Signalnamen einlesen ...
+defined $Config{'sig_name'} || die "Keine Signame definiert ?";
+$i = 0;
+
+foreach $signal_name ( split(' ', $Config{'sig_name'}) ) {
+ $signo{$signal_name} = $i;
+ $signame[$i] = $signal_name;
+ $i++;
+}
+
unless (
GetOptions(
"conf|config|c=s" => \$o_config_file,
my $sms = shift;
my ( @EMailRcpt, @R, @S );
- my ( $rec, $CmdLine, $smsc, $res, $mail_subject, $out );
+ my ( $rec, $CmdLine, $smsc, $res, $mail_subject, $out, $gammu_pid );
my $rcpt = $sms->{'header'}->recipient();
my $emails = $sms->{'header'}->confirmemailaddress() ||
$sms->{'header'}->confirmemailrecipient() ||
$sms->{'header'}->confirmemail();
- my $params = sprintf "--sendsms TEXT %%s -autolen %d -validity MAX", $maxlen;
+ # my $params = sprintf "--sendsms TEXT %%s -autolen %d -validity MAX", $maxlen;
+ my @Params = (
+ '--sendsms',
+ 'TEXT' => 'recipient',
+ '-autolen' => $maxlen,
+ '-validity' => 'MAX',
+ );
$smsc = $sms->{'header'}->smscnumber() || $sms->{'header'}->smsc();
- $params .= sprintf( " -smscnumber %s", $smsc ) if $smsc;
+ push @Params, '-smscnumber' => $smsc if $smsc;
+ #$params .= sprintf( " -smscnumber %s", $smsc ) if $smsc;
if ( $emails ) {
}
- $CmdLine = "| $GammuExe " . sprintf( $params, $sms->{'header'}->recipient() );
+ $Params[2] = $sms->{'header'}->recipient();
+ #$CmdLine = "$GammuExe " . sprintf( $params, $sms->{'header'}->recipient() );
+ $CmdLine = join " ", $GammuExe, @Params;
debug "Calling '" . $CmdLine . "'.";
$res = 1;
$mail_subject = sprintf( "SMS to %s successfully sent.", $sms->{'header'}->recipient() );
+
unless ( $test ) {
+
+ {
+
+ # sicheres Forken
+ $gammu_pid = open( GAMMU, "|-");
+
+ local $SIG{'PIPE'} = sub { die "whoops, $GammuExe pipe broke" };
+ local $SIG{'ALRM'} = sub { die "Timeout\n" };
+
+ if ( $gammu_pid ) { # parent
+
+ eval {
+ alarm $timeout;
+ print GAMMU $sms->body();
+ close( GAMMU ) || error "kid exited $?";
+ };
+
+ if ( $@ ) {
+
+ chomp $@;
+ error "Irgendwas ging schief: " . $@;
+
+ if ( kill 0, $gammu_pid ) {
+ error "Kindprozess $gammu_pid laeuft noch, wird gekillt.";
+ kill $signo{'TERM'}, $gammu_pid;
+ error "Warte 2 Sekunden ...";
+ sleep 2;
+ if ( kill 0, $gammu_pid ) {
+ error "Kindprozess $gammu_pid laeuft immer noch, wird mit der Keule erschlagen!";
+ kill $signo{'KILL'}, $gammu_pid;
+ }
+ }
+
+ }
+
+ } else { # child
+
+ ($EUID, $EGID) = ($UID, $GID);
+ exec($GammuExe, @Params) || error( "can't exec program: $!"), die;
+ # Bis hierhin sollte ich niemals kommen
+ }
+
+ }
+
if ( open GAMMU, $CmdLine ) {
print GAMMU $sms->body();
close GAMMU;