Skip to content

Commit 086ffeb

Browse files
committed
Parameter for syslog socket should allow options such as host name
1 parent 4f62c3a commit 086ffeb

21 files changed

+134
-78
lines changed

src/cgi/sympa_soap_server.fcgi.in

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ unless (Conf::load()) {
5353
my $log = Sympa::Log->instance;
5454
$log->{level} = $Conf::Conf{'log_level'};
5555
$log->openlog(
56-
$Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'},
57-
$Conf::Conf{'log_socket_type'},
58-
service => 'sympasoap'
56+
facility => $Conf::Conf{'log_facility'},
57+
service => 'sympasoap'
5958
);
6059
$log->syslog('info', 'SympaSOAP started');
6160

src/cgi/wwsympa.fcgi.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ unless (Conf::load()) {
132132
# Open log
133133
my $log = Sympa::Log->instance;
134134
$log->{level} = $Conf::Conf{'log_level'};
135-
$log->openlog($Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'},
136-
$Conf::Conf{'log_socket_type'});
135+
$log->openlog(facility => $Conf::Conf{'log_facility'});
137136

138137
Sympa::Spool::Listmaster->instance->{use_bulk} = 1;
139138

src/lib/Conf.pm

+5-3
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,11 @@ sub _infer_server_specific_parameter_values {
15411541

15421542
$param->{'config_hash'}{'robot_name'} = '';
15431543

1544+
$param->{'config_hash'}{'syslog_socket.type'} = [
1545+
grep {length} split /\*,\*/,
1546+
($param->{'config_hash'}{'syslog_socket.type'} // '')
1547+
];
1548+
15441549
unless (
15451550
Sympa::Tools::Data::smart_eq(
15461551
$param->{'config_hash'}{'dkim_feature'}, 'on'
@@ -2055,9 +2060,6 @@ sub _load_wwsconf {
20552060
$conf->{'mhonarc'});
20562061
}
20572062

2058-
## set default
2059-
$conf->{'log_facility'} ||= $config_hash->{'syslog'};
2060-
20612063
foreach my $k (keys %$conf) {
20622064
$config_hash->{$k} = $conf->{$k};
20632065
}

src/lib/Sympa/CLI.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ sub arrange {
252252
}
253253

254254
## Open the syslog and say we're read out stuff.
255-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
255+
$log->openlog;
256256

257257
# Enable SMTP logging if required
258258
$mailer->{log_smtp} = $options{'mail'}
@@ -298,7 +298,7 @@ sub arrange {
298298

299299
# end _load()
300300

301-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
301+
$log->openlog;
302302

303303
# Set the User ID & Group ID for the process
304304
$GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2];

src/lib/Sympa/CLI/check.pm

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ sub _run {
5252
}
5353

5454
## Open the syslog and say we're read out stuff.
55-
$log->openlog(
56-
$Conf::Conf{'syslog'},
57-
$Conf::Conf{'log_socket_type'},
58-
service => 'sympa/health_check'
59-
);
55+
$log->openlog(service => 'sympa/health_check');
6056

6157
## Setting log_level using conf unless it is set by calling option
6258
#FIXME: Redundant code?

src/lib/Sympa/CLI/test/syslog.pm

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ sub _run {
4141
my $log = Sympa::Log->instance;
4242

4343
# Open the syslog and say we're read out stuff.
44-
$log->openlog(
45-
$Conf::Conf{'syslog'},
46-
$Conf::Conf{'log_socket_type'},
47-
service => 'sympa/testlogs'
48-
);
44+
$log->openlog(service => 'sympa/testlogs');
4945

5046
# setting log_level using conf unless it is set by calling option
5147
if ($options->{log_level}) {

src/lib/Sympa/Config/Schema.pm

+56-5
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,65 @@ our %pinfo = (
444444
gettext_comment => 'Do not forget to configure syslog server.',
445445
format => '\S+',
446446
},
447-
log_socket_type => {
447+
syslog_socket => {
448448
context => [qw(site)],
449449
order => 3.02,
450450
group => 'logging',
451-
importance => 100,
452-
default => 'unix',
453-
gettext_id => 'Communication mode with syslog server',
454-
format => '\w+',
451+
gettext_id => 'System log socket options',
452+
gettext_comment =>
453+
'The options to be used for system log socket. Options come from Sys::Syslog https://metacpan.org/pod/Sys::Syslog#setlogsock%28%29',
454+
format => {
455+
type => {
456+
context => [qw(site)],
457+
order => 1,
458+
importance => 100,
459+
gettext_id => 'Communication mode with syslog server',
460+
gettext_comment =>
461+
'In most cases, an appropriate default value should be automatically chosen.',
462+
format => [
463+
'native', 'tcp', 'udp', 'inet',
464+
'unix', 'stream', 'pipe', 'console',
465+
],
466+
occurrence => '0-n',
467+
split_char => ',',
468+
},
469+
path => {
470+
context => [qw(site)],
471+
order => 2,
472+
gettext_id => 'Stream location',
473+
gettext_comment =>
474+
'Defaults to the standard location on the system.',
475+
format => '.+',
476+
},
477+
timeout => {
478+
context => [qw(site)],
479+
order => 3,
480+
gettext_id => 'Socket timeout',
481+
gettext_unit => 'seconds',
482+
format => '\d+([.]\d+)?',
483+
},
484+
host => {
485+
context => [qw(site)],
486+
order => 4,
487+
gettext_id => 'Host name to send the messages to',
488+
gettext_comment => 'Defaults to the local host.',
489+
format_s => '$host',
490+
},
491+
port => {
492+
context => [qw(site)],
493+
order => 5,
494+
gettext_id => 'TCP or UDP port to connect to',
495+
gettext_comment =>
496+
'Defaults to the standard port on the system.',
497+
format => '\d+',
498+
},
499+
},
500+
not_before => '6.2.73b.1',
501+
},
502+
log_socket_type => {
503+
context => [qw(site)],
504+
obsolete => 'syslog_socket.type',
505+
not_after => '6.2.72',
455506
},
456507
log_level => {
457508
context => [qw(domain site)], #FIXME "domain" possible?

src/lib/Sympa/Log.pm

+19-13
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,11 @@ sub _new_instance {
4848

4949
# Old name: Log::do_openlog().
5050
sub openlog {
51-
my $self = shift;
52-
my $facility = shift;
53-
my $socket_type = shift;
54-
my %options = @_;
55-
56-
$self->{_facility} = $facility;
57-
$self->{_socket_type} = $socket_type;
58-
$self->{_service} = $options{service} || _daemon_name() || 'sympa';
51+
my $self = shift;
52+
my %options = @_;
53+
54+
$self->{_facility} = $options{facility};
55+
$self->{_service} = $options{service} || _daemon_name() || 'sympa';
5956
$self->{_database_backend} =
6057
(exists $options{database_backend})
6158
? $options{database_backend}
@@ -222,15 +219,24 @@ sub _daemon_name {
222219
sub _connect {
223220
my $self = shift;
224221

225-
if ($self->{_socket_type} =~ /^(unix|inet)$/i) {
226-
Sys::Syslog::setlogsock(lc($self->{_socket_type}));
222+
if (@{$Conf::Conf{'syslog_socket.type'} || []}) {
223+
Sys::Syslog::setlogsock(
224+
{ (type => $Conf::Conf{'syslog_socket.type'}),
225+
map {
226+
length($Conf::Conf{"syslog_socket.$_"} // '')
227+
? ($_ => $Conf::Conf{"syslog_socket.$_"})
228+
: ()
229+
} qw(path timeout host port)
230+
}
231+
);
227232
}
233+
228234
# Close log may be useful: If parent processus did open log child
229235
# process inherit the openlog with parameters from parent process.
230236
Sys::Syslog::closelog;
231237
eval {
232238
Sys::Syslog::openlog(sprintf('%s[%s]', $self->{_service}, $PID),
233-
'ndelay,nofatal', $self->{_facility});
239+
'ndelay,nofatal', $self->{_facility} || $Conf::Conf{'syslog'});
234240
};
235241
if ($EVAL_ERROR && ($warning_date < time - $warning_timeout)) {
236242
warn sprintf 'No logs available: %s', $EVAL_ERROR;
@@ -819,7 +825,7 @@ Sympa::Log - Logging facility of Sympa
819825
use Sympa::Log;
820826
821827
my $log = Sympa::Log->instance;
822-
$log->openlog($facility, 'inet');
828+
$log->openlog(facility => $facility);
823829
$log->{level} = 0;
824830
$log->syslog('info', '%s: Stat logging', $$);
825831
@@ -836,7 +842,7 @@ TBD.
836842
I<Constructor>.
837843
Creates new singleton instance of L<Sympa::Log>.
838844
839-
=item openlog ( $facility, $socket_type, [ options ... ] )
845+
=item openlog ( [ options ... ] )
840846
841847
TBD.
842848

src/lib/Sympa/Spindle/ProcessOutgoing.pm

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ sub _fork_children {
139139
close STDERR;
140140
$process->direct_stderr_to_file;
141141
$self->{_last_activity} = time;
142-
$log->openlog($Conf::Conf{'syslog'},
143-
$Conf::Conf{'log_socket_type'});
142+
$log->openlog;
144143
$log->syslog('info',
145144
'Bulk slave daemon started with PID %s', $PID);
146145
last;

src/lib/Sympa/Upgrade.pm

+17
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,23 @@ sub upgrade {
22332233
$log->syslog('notice', '...Done.');
22342234
}
22352235

2236+
if (lower_version($previous_version, '6.2.74')) {
2237+
# syslog_socket.type no longer has the default.
2238+
# Previously, log_socket_type had a default value "unix".
2239+
if (open my $fh, '+<', Conf::get_sympa_conf()) {
2240+
my @p = grep {/\A\s*log_socket_type\s+\S+/} <$fh>;
2241+
if (not @p and seek $fh, 0, 2) {
2242+
my $human_date =
2243+
$language->gettext_strftime('%d %b %Y at %H:%M:%S',
2244+
localtime time);
2245+
printf $fh
2246+
"\n\n# Upgrade from %s to %s\n# %s\nsyslog_socket.type unix\n",
2247+
$previous_version, $new_version, $human_date;
2248+
}
2249+
close $fh;
2250+
}
2251+
}
2252+
22362253
return 1;
22372254
}
22382255

src/libexec/alias_manager.pl.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unless (defined Conf::load()) {
5656

5757
my $log = Sympa::Log->instance;
5858
$log->{level} = $Conf::Conf{'log_level'};
59-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
59+
$log->openlog;
6060

6161
my ($operation, $listname, $domain, $file) = @ARGV;
6262

src/sbin/archived.pl.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ if ($main::options{'log_level'}) {
111111
);
112112
}
113113

114-
my $log_facility = $Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'};
115-
$log->openlog($log_facility, $Conf::Conf{'log_socket_type'});
114+
$log->openlog(facility => $Conf::Conf{'log_facility'});
116115

117116
## Set the User ID & Group ID for the process
118117
$GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2];

src/sbin/bounced.pl.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ if ($main::options{'log_level'}) {
119119
);
120120
}
121121

122-
my $log_facility = $Conf::Conf{'log_facility'} || $Conf::Conf{'syslog'};
123-
$log->openlog($log_facility, $Conf::Conf{'log_socket_type'});
122+
$log->openlog(facility => $Conf::Conf{'log_facility'});
124123

125124
## Set the User ID & Group ID for the process
126125
$GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2];

src/sbin/bulk.pl.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ unless (Conf::load()) {
8383
Conf::get_sympa_conf();
8484
}
8585

86-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
86+
$log->openlog;
8787

8888
my $mailer = Sympa::Mailer->instance;
8989

@@ -112,7 +112,7 @@ if ($main::options{log_level}) {
112112
unless ($main::options{'foreground'}) {
113113
$process->daemonize;
114114
}
115-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
115+
$log->openlog;
116116

117117
# Create and write the PID file.
118118
$process->write_pid(initial => 1);

src/sbin/sympa_automatic.pl.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ unless ($main::options{'foreground'}) {
8686
$process->daemonize;
8787
}
8888

89-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
89+
$log->openlog;
9090

9191
# Create and write the PID file.
9292
$process->write_pid(initial => 1);
@@ -203,7 +203,7 @@ sub _load {
203203
}
204204

205205
## Open the syslog and say we're read out stuff.
206-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
206+
$log->openlog;
207207

208208
# Enable SMTP logging if required
209209
$mailer->{log_smtp} = $main::options{'mail'}

src/sbin/sympa_msg.pl.in

+3-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ unless ($main::options{'foreground'}) {
113113
}
114114
}
115115

116-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
116+
$log->openlog;
117117

118118
# Create and write the PID file.
119119
$process->write_pid(initial => 1);
@@ -147,8 +147,7 @@ unless ($main::options{'foreground'}) {
147147
# We're in a child process
148148
close STDERR;
149149
$process->direct_stderr_to_file;
150-
$log->openlog($Conf::Conf{'syslog'},
151-
$Conf::Conf{'log_socket_type'});
150+
$log->openlog;
152151
$log->syslog('info', 'Slave daemon started with PID %s',
153152
$PID);
154153
last;
@@ -283,7 +282,7 @@ sub _load {
283282
}
284283

285284
## Open the syslog and say we're read out stuff.
286-
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
285+
$log->openlog;
287286

288287
# Enable SMTP logging if required
289288
$mailer->{log_smtp} = $main::options{'mail'}

src/sbin/sympa_newaliases.pl.in

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ unless (Conf::load()) {
6767
exit 1;
6868
}
6969

70-
$log->openlog(
71-
$Conf::Conf{'syslog'},
72-
$Conf::Conf{'log_socket_type'},
73-
database_backend => undef
74-
);
70+
$log->openlog(database_backend => undef);
7571

7672
# setting log_level using conf unless it is set by calling option
7773
$log->{level} = $Conf::Conf{'log_level'};

src/sbin/task_manager.pl.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ unless (Conf::load()) {
7979
Conf::get_sympa_conf();
8080
}
8181

82-
$log->openlog($Conf::Conf{'log_facility'}, $Conf::Conf{'log_socket_type'});
82+
$log->openlog(facility => $Conf::Conf{'log_facility'});
8383

8484
# setting log_level using conf unless it is set by calling option
8585
if ($main::options{'log_level'}) {

sympa.conf.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ db_name sympa
2727
########################################################################
2828

2929
#syslog LOCAL1
30-
#log_socket_type unix
30+
#syslog_socket.type
3131

3232
########################################################################
3333
# Configure mail server

0 commit comments

Comments
 (0)