# Imported into Git by Jacob Bachmeyer (jcb@gnu.org), July 2020
# Further changes are tracked in Git.
+\f
+#
+# - Message reporting
+#
+
+sub ftp_syslog {
+ my ($priority,$message) = @_;
+
+ # 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;
+}
+
\f
#
# - Initialization and preliminaries
my %info; # package being processed; a global so fatal and mail can use it
-\f
-#
-# - Message reporting and email
-#
-
-sub ftp_syslog {
- my ($priority,$message) = @_;
-
- # 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];
+# Initialize our syslogging
+if (IN_TEST_MODE) {
+ $ENV{TEST_SYSLOG_SOCKET} =~ m/^([[:alnum:]\/]+)$/
+ or die "strange test syslog socket";
+ -S $1 or die "test syslog socket is not a socket";
+ setlogsock(unix => $1);
}
+openlog("ftp-upload", 'pid', $facility);
+ftp_syslog('info', "($log_style) Beginning upload processing run.");
-sub ftp_die($;$) {
- my $msg = shift;
- my $exitcode = shift;
- $exitcode ||= 1;
- ftp_syslog('err', "($log_style) " . $msg);
- exit $exitcode;
+# 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,
+ $destfinal, $desttmp) {
+ -d $dir || ftp_die("FATAL: configuration problem, $dir is not a directory");
}
\f
# - Main execution path
#
-# Initialize our syslogging
-if (IN_TEST_MODE) {
- $ENV{TEST_SYSLOG_SOCKET} =~ m/^([[:alnum:]\/]+)$/
- or die "strange test syslog socket";
- -S $1 or die "test syslog socket is not a socket";
- setlogsock(unix => $1);
-}
-openlog("ftp-upload", 'pid', $facility);
-ftp_syslog('info', "($log_style) Beginning upload processing run.");
-
-# 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,
- $destfinal, $desttmp) {
- -d $dir || ftp_die("FATAL: configuration problem, $dir is not a directory");
-}
# the chdir simplifies our filename parsing, so the base names don't
# have any directory.
chdir ($incoming_dir) || ftp_die("FATAL: chdir($incoming_dir) failed: $!");