Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter for syslog socket should allow options such as host name #1841

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/cgi/sympa_soap_server.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/lib/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'};

Expand Down Expand Up @@ -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};
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Sympa/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down Expand Up @@ -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];
Expand Down
6 changes: 1 addition & 5 deletions src/lib/Sympa/CLI/check.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 1 addition & 5 deletions src/lib/Sympa/CLI/test/syslog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down
61 changes: 56 additions & 5 deletions src/lib/Sympa/Config/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
37 changes: 24 additions & 13 deletions src/lib/Sympa/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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', $$);

Expand All @@ -869,7 +880,7 @@ TBD.
I<Constructor>.
Creates new singleton instance of L<Sympa::Log>.

=item openlog ( $facility, $socket_type, [ options ... ] )
=item openlog ( [ options ... ] )

TBD.

Expand Down
3 changes: 1 addition & 2 deletions src/lib/Sympa/Spindle/ProcessOutgoing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/lib/Sympa/Upgrade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libexec/alias_manager.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/sbin/archived.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions src/sbin/bounced.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/sbin/bulk.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/sbin/sympa_automatic.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'}
Expand Down
7 changes: 3 additions & 4 deletions src/sbin/sympa_msg.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'}
Expand Down
6 changes: 1 addition & 5 deletions src/sbin/sympa_newaliases.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down
2 changes: 1 addition & 1 deletion src/sbin/task_manager.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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'}) {
Expand Down
2 changes: 1 addition & 1 deletion sympa.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ db_name sympa
########################################################################

#syslog LOCAL1
#log_socket_type unix
#syslog_socket.type

########################################################################
# Configure mail server
Expand Down
Loading
Loading