From: Jacob Bachmeyer Date: Fri, 7 Oct 2022 03:37:48 +0000 (-0500) Subject: Fix oversight with location of logging definitions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6f22885e88103aabc594e864757fbcd030e4bcea;p=gatekeeper.git Fix oversight with location of logging definitions --- diff --git a/gatekeeper.pl b/gatekeeper.pl index 40b13e4..2937dda 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -101,49 +101,6 @@ # and Ward Vandewege with internal # timestamp 2013/01/23 20:26:29 was merged into this main script. - -# -# - Message reporting -# - -sub ftp_syslog { - my $priority = shift; - my $message = shift; - - # Remove a trailing newline - $message =~ s/[\r\n]+$//; - # Collapse the message to a single line for syslog - $message =~ s/[\r\n]+/ \/ /g; - - # The syslog function is pretty picky, and (sometimes) dies silently - # when using non-valid syslog priorities. - # That's why we run it inside an eval, and print out any errors to STDERR. - eval { - syslog($priority, $message); - }; - if ($@) { - print STDERR "$@\n"; - } -} - -sub ftp_warn($) { - ftp_syslog('warning', "($log_style) " . $_[0]); - warn $_[0]; -} - -sub ftp_die($;$) { - my $msg = shift; - my $exitcode = shift; - $exitcode ||= 1; - ftp_syslog('err', "($log_style) " . $msg); - exit $exitcode; -} - - -# -# - Initialization and preliminaries -# - use strict; use warnings; @@ -160,6 +117,12 @@ use Text::Wrap; use POSIX qw(strftime); use Cwd; use Email::MessageID; + + +# +# - Initialization and preliminaries +# + umask (022); BEGIN { @@ -368,6 +331,44 @@ if (IN_TEST_MODE) { # override the above for testing my %info; # package being processed; a global so fatal and mail can use it + +# +# - Logging +# + +sub ftp_syslog { + my $priority = shift; + my $message = shift; + + # Remove a trailing newline + $message =~ s/[\r\n]+$//; + # Collapse the message to a single line for syslog + $message =~ s/[\r\n]+/ \/ /g; + + # The syslog function is pretty picky, and (sometimes) dies silently + # when using non-valid syslog priorities. + # That's why we run it inside an eval, and print out any errors to STDERR. + eval { + syslog($priority, $message); + }; + if ($@) { + print STDERR "$@\n"; + } +} + +sub ftp_warn($) { + ftp_syslog('warning', "($log_style) " . $_[0]); + warn $_[0]; +} + +sub ftp_die($;$) { + my $msg = shift; + my $exitcode = shift; + $exitcode ||= 1; + ftp_syslog('err', "($log_style) " . $msg); + exit $exitcode; +} + # Initialize our syslogging if (IN_TEST_MODE) { $ENV{TEST_SYSLOG_SOCKET} =~ m/^([[:alnum:]\/]+)$/ @@ -378,6 +379,10 @@ if (IN_TEST_MODE) { openlog(SYSLOG_APP_IDENT, 'pid', SYSLOG_FACILITY); ftp_syslog('info', "($log_style) Beginning upload processing run."); +# +# -- Configuration sanity check +# + # make sure our directories all exist, or it's hopeless. # Use die instead of fatal - this error should "never" happen. for my $dir ($package_config_base, $incoming_dir, $incoming_tmp,