From: Jacob Bachmeyer Date: Wed, 26 Oct 2022 01:25:55 +0000 (-0500) Subject: Revise ftp_abort to be useful in a forked child process X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=601aa1e5a005826f49342f9020c92d831c3a54d3;p=gatekeeper.git Revise ftp_abort to be useful in a forked child process This commit introduces global variables to control the destination of an abort message and the default exit code. These variables are accessed using lexical aliases and are only accessible in the code that uses them. --- diff --git a/gatekeeper.pl b/gatekeeper.pl index 8523346..6c03888 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -424,11 +424,27 @@ sub ftp_warn($) { warn $_[0]; } +{ + # If this is set to a defined value, ftp_abort will write the message + # here instead of using syslog. + our $AbortPipe = undef; + # This selects the default exit code, if no code is specified. + our $AbortExitCode = 1; +} + sub ftp_abort($;$) { my $msg = shift; my $exitcode = shift; - $exitcode ||= 1; - ftp_syslog('err', $msg); + + our $AbortExitCode; + $exitcode = (defined $exitcode ? $exitcode : $AbortExitCode); + + our $AbortPipe; + if (defined $AbortPipe && defined fileno $AbortPipe) + { print $AbortPipe $msg, "\n" } + else + { ftp_syslog('err', $msg) } + exit $exitcode; }