Bug 161331 - perl sys::syslog formatting bug
perl sys::syslog formatting bug
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: perl (Show other bugs)
3.0
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jason Vas Dias
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-06-22 10:39 EDT by Tru Huynh
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-11-02 19:08:12 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Tru Huynh 2005-06-22 10:39:31 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; NetBSD amd64; en-US; rv:1.7.8) Gecko/20050524

Description of problem:
the sys::syslog from perl en RHEL3 or 4 on x86_64 or x86 has a formatting bug.
perl-5.8.0-89.10/perl-5.8.5-12.1 have the same issue

Version-Release number of selected component (if applicable):
perl-5.8.0-89.10.x86_64

How reproducible:
Always

Steps to Reproduce:
1.perl -e 'use Sys::Syslog; openlog "", "", "whatever"; syslog "info", "::a"; closelog;'
2.tail /var/log/messages
3.logger(1) does not show this issue
  

Actual Results:  /var/log/messages:
...
Jun 22 16:33:14 sillage :: a 
(there is 2 additionnal spaces, one between last : and character a, and one at the end of the line) 

Expected Results:  /var/log/messages:
...
Jun 22 16:33:14 sillage ::a
(no spaces added) 


Additional info:

annoying bug for parsing timestamps (for instance in syslog generated files by perl programs).

Tru
Comment 1 Tru Huynh 2005-06-22 11:02:02 EDT

perldoc Sys::Syslog
...
           openlog $ident, $logopt, $facility;
...
       openlog $ident, $logopt, $facility
           $ident is prepended to every message.  $logopt contains zero or
           more of the words pid, ndelay, nowait.  The cons option is ignored,
           since the failover mechanism will drop down to the console automat-
           ically if all other media fail.  $facility specifies the part of
           the system

here $ident is DEFINED and set as en empty string ("") but tested as non-empty
instead of undefined...

upstream ?

Comment 2 Warren Togami 2005-07-03 22:53:30 EDT
You are saying this is an issue in RHEL4 perl too?
What about FC4?
Comment 3 Tru Huynh 2005-07-04 03:40:57 EDT
yes, RHEL4 has the same issue perl-5.8.5-12.1.x86_64

I don't have any FC4 installed to try on, sorry.
Comment 4 Jason Vas Dias 2005-11-02 19:08:12 EST
Yes, this happens in all currently shipped Red Hat perl versions .

I'm not sure this is really a bug - the 'man Sys::Syslog' man-page states:

"
       openlog $ident, $logopt, $facility
...
       syslog $priority, $format, @args
...
           If you didn’t use openlog() before using syslog(), syslog 
           will try to guess the $ident by extracting the shortest prefix 
           of $format that ends in a ":".
"

So what is happening is that since you specified no 'ident' for openlog,
Syslog.pm tries to extract the ident from the message, and thinks it is ':'.

The "ident" is then used to prefix the message, ie. is the message 'tag',
followed by ": " .

The 'tag' field is not optional, as shown by the prototype of the c
openlog call: 
    void openlog(const char *ident, int option, int facility);
The string pointed  to  by ident  is  prepended to every message, and is
typically set to the program name, and if the LOG_PID option is supplied,
it will be suffixed with the process id in brackets, to form the usual
syslog tag of 'program[pid]:' .

There are several ways to workaround this situation :

1. Provide an "ident" to openlog - eg., in your example:
  
$ perl -e 'use Sys::Syslog; openlog $0, "", ""; syslog "info", "::a"; closelog;'

This would emit the syslog line:
       <date> <host> -e: ::a

Usually $0 will be the name of the script, which is '-e' for perl command line
expressions .

2. Use a proper printf format as the second argument to syslog:

$ perl -e 'use Sys::Syslog;  syslog "info", "%s", "::a";'

logs the line:
       <date> <host> <user>: ::a

The openlog is optional, meaning that syslog will open a log socket for you.

Unless Sys::Syslog were to arbitrarily disallow an 'ident' value of ':', 
(which could be an executable file name), it cannot fix this bug and
still provide the feature of embedding the ident tag in the message.

So this is not a bug - use one of the workarounds given above.

Note You need to log in before you can comment on or make changes to this bug.