diff --git a/src/cgi/sympa_soap_server.fcgi.in b/src/cgi/sympa_soap_server.fcgi.in index 7c626c918..f689208d1 100644 --- a/src/cgi/sympa_soap_server.fcgi.in +++ b/src/cgi/sympa_soap_server.fcgi.in @@ -52,11 +52,7 @@ unless (Conf::load()) { # Open log my $log = Sympa::Log->instance; $log->{level} = $Conf::Conf{'log_level'}; -$log->openlog( - $Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}, - service => 'sympasoap' -); +$log->openlog(service => 'sympasoap'); $log->syslog('info', 'SympaSOAP started'); ## We set the real UID with the effective UID value diff --git a/src/cgi/wwsympa.fcgi.in b/src/cgi/wwsympa.fcgi.in index 5dd9a8e86..28eea2dfe 100644 --- a/src/cgi/wwsympa.fcgi.in +++ b/src/cgi/wwsympa.fcgi.in @@ -131,8 +131,7 @@ unless (Conf::load()) { # Open log my $log = Sympa::Log->instance; $log->{level} = $Conf::Conf{'log_level'}; -$log->openlog($Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}); +$log->openlog; Sympa::Spool::Listmaster->instance->{use_bulk} = 1; diff --git a/src/lib/Conf.pm b/src/lib/Conf.pm index 10610fcb8..adad50534 100644 --- a/src/lib/Conf.pm +++ b/src/lib/Conf.pm @@ -1517,6 +1517,11 @@ sub _infer_server_specific_parameter_values { $param->{'config_hash'}{'robot_name'} = ''; + $param->{'config_hash'}{'syslog_socket.type'} = [ + grep {length} split /\*,\*/, + ($param->{'config_hash'}{'syslog_socket.type'} // '') + ]; + $param->{'config_hash'}{'dkim_signer_domain'} ||= $param->{'config_hash'}{'domain'}; @@ -2001,9 +2006,6 @@ sub _load_wwsconf { $conf->{'mhonarc'}); } - ## set default - $conf->{'log_facility'} ||= $config_hash->{'syslog'}; - foreach my $k (keys %$conf) { $config_hash->{$k} = $conf->{$k}; } diff --git a/src/lib/Sympa/CLI.pm b/src/lib/Sympa/CLI.pm index ff1154bdb..5cb3cff4d 100644 --- a/src/lib/Sympa/CLI.pm +++ b/src/lib/Sympa/CLI.pm @@ -252,7 +252,7 @@ sub arrange { } ## Open the syslog and say we're read out stuff. - $log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); + $log->openlog; # Enable SMTP logging if required $mailer->{log_smtp} = $options{'mail'} @@ -298,7 +298,7 @@ sub arrange { # end _load() - $log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); + $log->openlog; # Set the User ID & Group ID for the process $GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2]; diff --git a/src/lib/Sympa/CLI/check.pm b/src/lib/Sympa/CLI/check.pm index 14d659c01..da776a0e1 100644 --- a/src/lib/Sympa/CLI/check.pm +++ b/src/lib/Sympa/CLI/check.pm @@ -52,11 +52,7 @@ sub _run { } ## Open the syslog and say we're read out stuff. - $log->openlog( - $Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}, - service => 'sympa/health_check' - ); + $log->openlog(service => 'sympa/health_check'); ## Setting log_level using conf unless it is set by calling option #FIXME: Redundant code? diff --git a/src/lib/Sympa/CLI/test/syslog.pm b/src/lib/Sympa/CLI/test/syslog.pm index 9007c2050..aebe330d5 100755 --- a/src/lib/Sympa/CLI/test/syslog.pm +++ b/src/lib/Sympa/CLI/test/syslog.pm @@ -41,11 +41,7 @@ sub _run { my $log = Sympa::Log->instance; # Open the syslog and say we're read out stuff. - $log->openlog( - $Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}, - service => 'sympa/testlogs' - ); + $log->openlog(service => 'sympa/testlogs'); # setting log_level using conf unless it is set by calling option if ($options->{log_level}) { diff --git a/src/lib/Sympa/Config/Schema.pm b/src/lib/Sympa/Config/Schema.pm index 9b9358d3c..b157b3f1b 100644 --- a/src/lib/Sympa/Config/Schema.pm +++ b/src/lib/Sympa/Config/Schema.pm @@ -444,14 +444,65 @@ our %pinfo = ( gettext_comment => 'Do not forget to configure syslog server.', format => '\S+', }, - log_socket_type => { + syslog_socket => { context => [qw(site)], order => 3.02, group => 'logging', - importance => 100, - default => 'unix', - gettext_id => 'Communication mode with syslog server', - format => '\w+', + gettext_id => 'System log socket options', + gettext_comment => + 'The options to be used for system log socket. Options come from Sys::Syslog https://metacpan.org/pod/Sys::Syslog#setlogsock%28%29', + format => { + type => { + context => [qw(site)], + order => 1, + importance => 100, + gettext_id => 'Communication mode with syslog server', + gettext_comment => + 'In most cases, an appropriate default value should be automatically chosen.', + format => [ + 'native', 'tcp', 'udp', 'inet', + 'unix', 'stream', 'pipe', 'console', + ], + occurrence => '0-n', + split_char => ',', + }, + path => { + context => [qw(site)], + order => 2, + gettext_id => 'Stream location', + gettext_comment => + 'Defaults to the standard location on the system.', + format => '.+', + }, + timeout => { + context => [qw(site)], + order => 3, + gettext_id => 'Socket timeout', + gettext_unit => 'seconds', + format => '\d+([.]\d+)?', + }, + host => { + context => [qw(site)], + order => 4, + gettext_id => 'Host name to send the messages to', + gettext_comment => 'Defaults to the local host.', + format_s => '$host', + }, + port => { + context => [qw(site)], + order => 5, + gettext_id => 'TCP or UDP port to connect to', + gettext_comment => + 'Defaults to the standard port on the system.', + format => '\d+', + }, + }, + not_before => '6.2.73b.1', + }, + log_socket_type => { + context => [qw(site)], + obsolete => 'syslog_socket.type', + not_after => '6.2.72', }, log_level => { context => [qw(domain site)], #FIXME "domain" possible? diff --git a/src/lib/Sympa/Log.pm b/src/lib/Sympa/Log.pm index 44fcc5160..0d8f88ef3 100644 --- a/src/lib/Sympa/Log.pm +++ b/src/lib/Sympa/Log.pm @@ -49,14 +49,10 @@ sub _new_instance { # Old name: Log::do_openlog(). sub openlog { - my $self = shift; - my $facility = shift; - my $socket_type = shift; - my %options = @_; - - $self->{_facility} = $facility; - $self->{_socket_type} = $socket_type; - $self->{_service} = $options{service} || _daemon_name() || 'sympa'; + my $self = shift; + my %options = @_; + + $self->{_service} = $options{service} || _daemon_name() || 'sympa'; $self->{_database_backend} = (exists $options{database_backend}) ? $options{database_backend} @@ -223,15 +219,30 @@ sub _daemon_name { sub _connect { my $self = shift; - if ($self->{_socket_type} =~ /^(unix|inet)$/i) { - Sys::Syslog::setlogsock(lc($self->{_socket_type})); + if (@{$Conf::Conf{'syslog_socket.type'} || []}) { + Sys::Syslog::setlogsock( + { (type => $Conf::Conf{'syslog_socket.type'}), + map { + length($Conf::Conf{"syslog_socket.$_"} // '') + ? ($_ => $Conf::Conf{"syslog_socket.$_"}) + : () + } qw(path timeout host port) + } + ); } + + my $facility = + (grep { $self->{_service} eq $_ } + qw(wwsympa sympasoap archived bounced task_manager) + and $Conf::Conf{'log_facility'}) + || $Conf::Conf{'syslog'}; + # Close log may be useful: If parent processus did open log child # process inherit the openlog with parameters from parent process. Sys::Syslog::closelog; eval { Sys::Syslog::openlog(sprintf('%s[%s]', $self->{_service}, $PID), - 'ndelay,nofatal', $self->{_facility}); + 'ndelay,nofatal', $facility); }; if ($EVAL_ERROR && ($warning_date < time - $warning_timeout)) { warn sprintf 'No logs available: %s', $EVAL_ERROR; @@ -852,7 +863,7 @@ Sympa::Log - Logging facility of Sympa use Sympa::Log; my $log = Sympa::Log->instance; - $log->openlog($facility, 'inet'); + $log->openlog(facility => $facility); $log->{level} = 0; $log->syslog('info', '%s: Stat logging', $$); @@ -869,7 +880,7 @@ TBD. I. Creates new singleton instance of L. -=item openlog ( $facility, $socket_type, [ options ... ] ) +=item openlog ( [ options ... ] ) TBD. diff --git a/src/lib/Sympa/Spindle/ProcessOutgoing.pm b/src/lib/Sympa/Spindle/ProcessOutgoing.pm index c14e6ee7c..baa10f1f9 100644 --- a/src/lib/Sympa/Spindle/ProcessOutgoing.pm +++ b/src/lib/Sympa/Spindle/ProcessOutgoing.pm @@ -139,8 +139,7 @@ sub _fork_children { close STDERR; $process->direct_stderr_to_file; $self->{_last_activity} = time; - $log->openlog($Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}); + $log->openlog; $log->syslog('info', 'Bulk slave daemon started with PID %s', $PID); last; diff --git a/src/lib/Sympa/Upgrade.pm b/src/lib/Sympa/Upgrade.pm index 12f4e45d6..a7f15ccaf 100644 --- a/src/lib/Sympa/Upgrade.pm +++ b/src/lib/Sympa/Upgrade.pm @@ -2233,6 +2233,23 @@ sub upgrade { $log->syslog('notice', '...Done.'); } + if (lower_version($previous_version, '6.2.74')) { + # syslog_socket.type no longer has the default. + # Previously, log_socket_type had a default value "unix". + if (open my $fh, '+<', Conf::get_sympa_conf()) { + my @p = grep {/\A\s*log_socket_type\s+\S+/} <$fh>; + if (not @p and seek $fh, 0, 2) { + my $human_date = + $language->gettext_strftime('%d %b %Y at %H:%M:%S', + localtime time); + printf $fh + "\n\n# Upgrade from %s to %s\n# %s\nsyslog_socket.type unix\n", + $previous_version, $new_version, $human_date; + } + close $fh; + } + } + return 1; } diff --git a/src/libexec/alias_manager.pl.in b/src/libexec/alias_manager.pl.in index a145562fe..a5cceec86 100644 --- a/src/libexec/alias_manager.pl.in +++ b/src/libexec/alias_manager.pl.in @@ -56,7 +56,7 @@ unless (defined Conf::load()) { my $log = Sympa::Log->instance; $log->{level} = $Conf::Conf{'log_level'}; -$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; my ($operation, $listname, $domain, $file) = @ARGV; diff --git a/src/sbin/archived.pl.in b/src/sbin/archived.pl.in index 9f57e302c..0e3f94a3a 100644 --- a/src/sbin/archived.pl.in +++ b/src/sbin/archived.pl.in @@ -111,8 +111,7 @@ if ($main::options{'log_level'}) { ); } -my $log_facility = $Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'}; -$log->openlog($log_facility, $Conf::Conf{'log_socket_type'}); +$log->openlog; ## Set the User ID & Group ID for the process $GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2]; diff --git a/src/sbin/bounced.pl.in b/src/sbin/bounced.pl.in index 5abb92264..99abc0d8e 100644 --- a/src/sbin/bounced.pl.in +++ b/src/sbin/bounced.pl.in @@ -119,8 +119,7 @@ if ($main::options{'log_level'}) { ); } -my $log_facility = $Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'}; -$log->openlog($log_facility, $Conf::Conf{'log_socket_type'}); +$log->openlog; ## Set the User ID & Group ID for the process $GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2]; diff --git a/src/sbin/bulk.pl.in b/src/sbin/bulk.pl.in index ecfb53e2c..9521258a9 100644 --- a/src/sbin/bulk.pl.in +++ b/src/sbin/bulk.pl.in @@ -83,7 +83,7 @@ unless (Conf::load()) { Conf::get_sympa_conf(); } -$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; my $mailer = Sympa::Mailer->instance; @@ -112,7 +112,7 @@ if ($main::options{log_level}) { unless ($main::options{'foreground'}) { $process->daemonize; } -$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; # Create and write the PID file. $process->write_pid(initial => 1); diff --git a/src/sbin/sympa_automatic.pl.in b/src/sbin/sympa_automatic.pl.in index b0ba9d181..38def9b0e 100644 --- a/src/sbin/sympa_automatic.pl.in +++ b/src/sbin/sympa_automatic.pl.in @@ -86,7 +86,7 @@ unless ($main::options{'foreground'}) { $process->daemonize; } -$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; # Create and write the PID file. $process->write_pid(initial => 1); @@ -203,7 +203,7 @@ sub _load { } ## Open the syslog and say we're read out stuff. - $log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); + $log->openlog; # Enable SMTP logging if required $mailer->{log_smtp} = $main::options{'mail'} diff --git a/src/sbin/sympa_msg.pl.in b/src/sbin/sympa_msg.pl.in index 8164767eb..c1532ce40 100644 --- a/src/sbin/sympa_msg.pl.in +++ b/src/sbin/sympa_msg.pl.in @@ -113,7 +113,7 @@ unless ($main::options{'foreground'}) { } } -$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; # Create and write the PID file. $process->write_pid(initial => 1); @@ -147,8 +147,7 @@ unless ($main::options{'foreground'}) { # We're in a child process close STDERR; $process->direct_stderr_to_file; - $log->openlog($Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}); + $log->openlog; $log->syslog('info', 'Slave daemon started with PID %s', $PID); last; @@ -283,7 +282,7 @@ sub _load { } ## Open the syslog and say we're read out stuff. - $log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'}); + $log->openlog; # Enable SMTP logging if required $mailer->{log_smtp} = $main::options{'mail'} diff --git a/src/sbin/sympa_newaliases.pl.in b/src/sbin/sympa_newaliases.pl.in index 398cefca6..26bc65f14 100644 --- a/src/sbin/sympa_newaliases.pl.in +++ b/src/sbin/sympa_newaliases.pl.in @@ -67,11 +67,7 @@ unless (Conf::load()) { exit 1; } -$log->openlog( - $Conf::Conf{'syslog'}, - $Conf::Conf{'log_socket_type'}, - database_backend => undef -); +$log->openlog(database_backend => undef); # setting log_level using conf unless it is set by calling option $log->{level} = $Conf::Conf{'log_level'}; diff --git a/src/sbin/task_manager.pl.in b/src/sbin/task_manager.pl.in index 23b5753b9..c137df48c 100644 --- a/src/sbin/task_manager.pl.in +++ b/src/sbin/task_manager.pl.in @@ -79,7 +79,7 @@ unless (Conf::load()) { Conf::get_sympa_conf(); } -$log->openlog($Conf::Conf{'log_facility'}, $Conf::Conf{'log_socket_type'}); +$log->openlog; # setting log_level using conf unless it is set by calling option if ($main::options{'log_level'}) { diff --git a/sympa.conf.in b/sympa.conf.in index 63f3b5312..4c98cece3 100644 --- a/sympa.conf.in +++ b/sympa.conf.in @@ -27,7 +27,7 @@ db_name sympa ######################################################################## #syslog LOCAL1 -#log_socket_type unix +#syslog_socket.type ######################################################################## # Configure mail server diff --git a/t/Database_SQLite.t b/t/Database_SQLite.t index e5859a842..19ff0cb1c 100644 --- a/t/Database_SQLite.t +++ b/t/Database_SQLite.t @@ -24,15 +24,14 @@ my $test_listmaster = 'dude@example.com'; my $tempdir = File::Temp->newdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1)); %Conf::Conf = ( - domain => 'mail.example.org', # mandatory - listmaster => $test_listmaster, # mandatory - db_type => 'SQLite', - db_name => ':memory:', - queuebulk => $tempdir . '/bulk', - queuesubscribe => $tempdir . '/auth', - home => $tempdir, - log_socket_type => 'stream', - db_list_cache => 'off', + domain => 'mail.example.org', # mandatory + listmaster => $test_listmaster, # mandatory + db_type => 'SQLite', + db_name => ':memory:', + queuebulk => $tempdir . '/bulk', + queuesubscribe => $tempdir . '/auth', + home => $tempdir, + db_list_cache => 'off', ); # Apply defaults. foreach my $pinfo (grep { $_->{name} and exists $_->{default} } diff --git a/t/Request_Handler_set.t b/t/Request_Handler_set.t index 60d6cb9c0..cce45cb06 100644 --- a/t/Request_Handler_set.t +++ b/t/Request_Handler_set.t @@ -33,15 +33,14 @@ my $list = bless { } => 'Sympa::List'; %Conf::Conf = ( - domain => 'mail.example.org', # mandatory - listmaster => $test_listmaster, # mandatory - db_type => 'SQLite', - db_name => ':memory:', - queuebulk => $tempdir . '/bulk', - queuesubscribe => $tempdir . '/auth', - home => $tempdir, - log_socket_type => 'stream', - db_list_cache => 'off', + domain => 'mail.example.org', # mandatory + listmaster => $test_listmaster, # mandatory + db_type => 'SQLite', + db_name => ':memory:', + queuebulk => $tempdir . '/bulk', + queuesubscribe => $tempdir . '/auth', + home => $tempdir, + db_list_cache => 'off', ); # Apply defaults. foreach my $pinfo (grep { $_->{name} and exists $_->{default} }