Hi,
I'm using syslog with perror flag in some perl script, and I recently
notice that there is an additional newline at the end of each message
on stderr output.
Would anyone know why someone added \n in the first place ?
#####################################################
# cat /tmp/syslog.pl
use Sys::Syslog;
openlog($0, 'cons,pid,perror', 'user');
syslog('info', 'first line');
syslog('info', 'second line');
closelog();
#####################################################
The bug:
# perl /tmp/syslog.pl
/tmp/syslog.pl[14219]: first line
/tmp/syslog.pl[14219]: second line
# tail -n 2 /var/log/all
Jul 14 16:28:49 bsd /tmp/syslog.pl[27039]: first line
Jul 14 16:28:49 bsd /tmp/syslog.pl[27039]: second line
#####################################################
With the "fix"
# perl /tmp/syslog.pl
/tmp/syslog.pl[5146]: first line
/tmp/syslog.pl[5146]: second line
# tail -n 2 /var/log/all
Jul 14 16:37:18 bsd /tmp/syslog.pl[5146]: first line
Jul 14 16:37:18 bsd /tmp/syslog.pl[5146]: second line
#####################################################
Fix:
--- /usr/src/gnu/usr.bin/perl/cpan/Sys-Syslog/Syslog.pm.orig Mon
Jul 14 13:33:49 2014
+++ /usr/libdata/perl5/amd64-openbsd/5.16.3/Sys/Syslog.pm Mon
Jul 14 13:50:05 2014
@@ -396,7 +396,7 @@
$mask =~ s/(?<!%)((?:%%)*)%m/$1$error/g;
}
- $mask .= "\n" unless $mask =~ /\n$/;
+ $mask .= "\n" if ( $mask !~ /\n$/ and $current_proto ne 'native');
$message = @_ ? sprintf($mask, @_) : $mask;
if ($current_proto eq 'native') {
--
Bertrand PROVOST