X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/7fa382617fbaccc0ce522b2b3adbbee9db5ad227..e60096926213ce02293a261254ff065cae44c1c8:/cgi-bin/sex?ds=inline diff --git a/cgi-bin/sex b/cgi-bin/sex index d483ebe..62a914a 100755 --- a/cgi-bin/sex +++ b/cgi-bin/sex @@ -15,14 +15,14 @@ die "$0: no $FEXLIB\n" unless -d $FEXLIB; $| = 1; # import from fex.pp -our ($tmpdir,$logdir,$timeout,$fra,$bs); +our ($tmpdir,@logdir,$timeout,$fra,$bs); # load common code, local config: $HOME/lib/fex.ph require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n"; chdir $spooldir or error(500,"$spooldir - $!"); -my $debuglog = "$tmpdir/sex.log"; +# my $debuglog = "$tmpdir/sex.log"; my $ra = $ENV{REMOTE_ADDR}||0; $fra .= '/'.$ENV{HTTP_X_FORWARDED_FOR} if $ENV{HTTP_X_FORWARDED_FOR}; $timeout *= 10; @@ -166,12 +166,20 @@ sub setparam { } sub sexlog { - if (open my $log,'>>',"$logdir/sex.log") { - flock $log,LOCK_EX; - seek $log,0,SEEK_END; - printf {$log} "%s [%s_%s] %s (%s) %s\n", - isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,"@_"; - close $log; + my $msg = "@_"; + + $msg =~ s/\n/ /g; + $msg =~ s/\s+$//; + $msg = sprintf "%s [%s_%s] %s (%s) %s\n", + isodate(time),$$,$ENV{REQUESTCOUNT},$user,$fra,$msg; + + foreach my $log (@logdir) { + if (open $log,'>>',"$log/sex.log") { + flock $log,LOCK_EX; + seek $log,0,SEEK_END; + printf {$log} $msg; + close $log; + } } } @@ -183,10 +191,20 @@ sub sigdie { sub sigexit { my ($sig) = @_; - if (open my $log,'>>',"$logdir/sex.log") { - printf {$log} "%s %s (%s) caught SIGNAL %s\n", - isodate(time),$user||'-',$fra||'-',"@_"; - close $log; + my $msg = "@_"; + + $msg =~ s/\n/ /g; + $msg =~ s/\s+$//; + $msg = sprintf "%s %s (%s) caught SIGNAL %s\n", + isodate(time),$user||'-',$fra||'-',$msg; + + foreach my $log (@logdir) { + if (open $log,'>>',"$log/sex.log") { + flock $log,LOCK_EX; + seek $log,0,SEEK_END; + printf {$log} $msg; + close $log; + } } if ($sig eq 'DIE') { shift;