Hi List,
A couple of days ago, I received a bug report relating to my
Unix::Syslog module (see CPAN for details).
The user noticed that the following code
openlog( basename($0), LOG_PID, LOG_DAEMON );
syslog( LOG_DEBUG, 'this is test %d', 1 );
closelog();
would result in
Nov 27 12:37:13 <his machine> 8�^P^H^C[17913]: this is test 1
, whereas
my $ident = basename($0);
openlog( $ident, LOG_PID, LOG_DAEMON );
syslog( LOG_DEBUG, 'this is test %d', 1 );
closelog();
Nov 27 12:44:27 <his machine> writelog[17913]: this is test 1
I tracked that bug down to the return value/argument handling and
found that if I copied the ident-string in my openlog() wrapper,
everything worked fine.
There are three questions now:
1. Why is the return value (the pointer) of a function being reused?
2. Can this be considered a bug in Perl. Has it been fixed in recent
versions, I am using 5.005_02?
3. To work around that issue, I strdup() the ident-argument before
calling openlog(). Is this The Right Thing(tm)?
Best regards,
Marcus