From 601aa1e5a005826f49342f9020c92d831c3a54d3 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Tue, 25 Oct 2022 20:25:55 -0500 Subject: [PATCH] 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. --- gatekeeper.pl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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; } -- 2.25.1