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

Sys::Syslog::syslog kills program if syslogd not running #8060

Closed
p5pRT opened this issue Aug 9, 2005 · 10 comments
Closed

Sys::Syslog::syslog kills program if syslogd not running #8060

p5pRT opened this issue Aug 9, 2005 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 9, 2005

Migrated from rt.perl.org#36848 (status was 'resolved')

Searchable as RT36848$

@p5pRT
Copy link
Author

p5pRT commented Aug 9, 2005

From eravin@panix.com

Created by eravin@panix.com

On our NetBSD 2.0 boxes with perl 5.6.1, we use Sys​::Syslog this way​:

  use strict;
  use Sys​::Syslog qw(​:DEFAULT setlogsock); # use Unix-domain socket

  openlog $progname, "cons,pid", "daemon" ||
  warn "$progname​: openlog() fails​: $!\n";

But when we send messages with syslog(), the program dies if syslogd
is not running, with this message​:

  connect​: No such file or directory (SOCK_DGRAM after trying SOCK_STREAM)
at perlprog line NNN

Where the offending line is something like​:

  syslog("notice", "SHUTDOWN​: $sig");

The offending line is in a signal handler. If I edit out the syslog()
call n the signal handler, it gets even worse - the program dies with
no error message. Here's what happens when I step through with the
debugger​:

  main​::(/usr/local/sbin/servicemon​:160)​:
  160​: syslog("notice", "STARTUP​: services= " . join("/", @​services) . ",
  startwait=$startwait, cyclewait=$cyclewait");
  DB<1>
  Debugged program terminated. Use q to quit or R to restart,
  use O inhibit_exit to avoid stopping after program termination,
  h q, h R or h O to get additional info.

Any suggestions?

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.0:

Configured by fn at Mon Jul 29 16:55:09 EDT 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=netbsd, osvers=1.5.2, archname=i386-netbsd
    uname='netbsd juggler.panix.com 1.5.2 netbsd 1.5.2 (panix-std) #0: wed oct 17 21:14:18 edt 2001 marcotte@trinity.nyc.access.net:develnetbsd1.5.2srcsysarchi386compilepanix-std i386 '
    config_args='-Dprefix=/pkg/perl-5.8.0'
    hint=previous, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
    optimize='-O',
    cppflags='-fno-strict-aliasing -I/usr/local/include -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='egcs-2.91.66 19990314 (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -Wl,-rpath,/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-lm -lc -lposix -lcrypt -lutil
    perllibs=-lm -lc -lposix -lcrypt -lutil
    libc=/usr/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-whole-archive -lgcc -Wl,-no-whole-archive 			-Wl,-E '
    cccdlflags='-DPIC -fPIC ', lddlflags='--whole-archive -shared  -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.0:
    /pkg/perl-5.8.0/lib/perl-5.8.0/i386-netbsd
    /pkg/perl-5.8.0/lib/perl-5.8.0
    /pkg/perl-5.8.0/lib/site_perl/5.8.0/i386-netbsd
    /pkg/perl-5.8.0/lib/site_perl/5.8.0
    /pkg/perl-5.8.0/lib/site_perl
    .


Environment for perl v5.8.0:
    HOME=/net/u/2/e/eravin
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/net/u/2/e/eravin/bin:/usr/local/bin:/bin:/usr/bin:/usr/etc:/sbin:/usr/local/contrib/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Aug 10, 2005

From @nwc10

On Tue, Aug 09, 2005 at 04​:30​:32PM -0700, eravin @​ panix. com wrote​:

connect​: No such file or directory (SOCK_DGRAM after trying SOCK_STREAM)
at perlprog line NNN

Where the offending line is something like​:

syslog("notice", "SHUTDOWN​: $sig");

The offending line is in a signal handler. If I edit out the syslog()
call n the signal handler, it gets even worse - the program dies with
no error message. Here's what happens when I step through with the
debugger​:

main​::(/usr/local/sbin/servicemon​:160)​:
160​: syslog("notice", "STARTUP​: services= " . join("/", @​services) . ",
startwait=$startwait, cyclewait=$cyclewait");
DB<1>
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.

Any suggestions?

I've checked the source for Syslog.pm in 5.6.1 and it's calling croak()
If you wrap the call to syslog() in an eval, you will catch the error.

As to what happens if you remove the call to syslog - given that your
source line says "SHUTDOWN", is your program shutting down normally in this
case? Otherwise I have no idea.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=medium
---
Site configuration information for perl v5.8.0​:

Configured by fn at Mon Jul 29 16​:55​:09 EDT 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration​:
Platform​:
osname=netbsd, osvers=1.5.2, archname=i386-netbsd

I don't know how NetBSD versions work. Is this an older NetBSD with a newer
version of perl? (One that happens to have reasonable internet connectivity,
hence why you used it for bug reporting)

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Aug 10, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 11, 2005

From eravin@panix.com

On Wed, Aug 10, 2005 at 01​:32​:04AM -0700, Nicholas Clark via RT wrote​:

On Tue, Aug 09, 2005 at 04​:30​:32PM -0700, eravin @​ panix. com wrote​:

connect​: No such file or directory (SOCK_DGRAM after trying SOCK_STREAM)
at perlprog line NNN

Where the offending line is something like​:

syslog("notice", "SHUTDOWN​: $sig");

The offending line is in a signal handler. If I edit out the syslog()
call n the signal handler, it gets even worse - the program dies with
no error message. Here's what happens when I step through with the
debugger​:

main​::(/usr/local/sbin/servicemon​:160)​:
160​: syslog("notice", "STARTUP​: services= " . join("/", @​services) . ",
startwait=$startwait, cyclewait=$cyclewait");
DB<1>
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.

Any suggestions?

I've checked the source for Syslog.pm in 5.6.1 and it's calling croak()
If you wrap the call to syslog() in an eval, you will catch the error.

I did that in one script to work around the problem, but I've got a lot
of scripts that use Syslog.pm. I'd rather see it fixed in the module.

I submit that this is a design bug - no other syslog() library behaves
this way, especially not the C library that Syslog.pm is based on.
Sys​::Syslog​::syslog() should return an error and let the user deal
with it (which would be an improvement over the C version, which has
no defined return values).

As to what happens if you remove the call to syslog - given that your
source line says "SHUTDOWN", is your program shutting down normally in this
case? Otherwise I have no idea.

That's just a side note - my point was that you only get an error message
if the Sys​::Syslog​:syslog() call is in an exit signal handler.

Site configuration information for perl v5.8.0​:

Configured by fn at Mon Jul 29 16​:55​:09 EDT 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration​:
Platform​:
osname=netbsd, osvers=1.5.2, archname=i386-netbsd

I don't know how NetBSD versions work. Is this an older NetBSD with a newer
version of perl? (One that happens to have reasonable internet connectivity,
hence why you used it for bug reporting)

Nicholas Clark

Sorry, I'm using a NetBSD 2.0 machine whose default version of Perl was
apparently compiled a few years ago on a NetBSD 1.5.2 machine. It's a
public shell machine, and the default Perl version is deliberately kept
ancient to avoid breaking customer scripts.

  -- Ed

@p5pRT
Copy link
Author

p5pRT commented Aug 11, 2005

From @nwc10

On Wed, Aug 10, 2005 at 12​:21​:49PM -0400, Ed Ravin wrote​:

I submit that this is a design bug - no other syslog() library behaves
this way, especially not the C library that Syslog.pm is based on.
Sys​::Syslog​::syslog() should return an error and let the user deal
with it (which would be an improvement over the C version, which has
no defined return values).

One way of implementing in error return in perl is throwing an exception.

We may not agree whether this is the most appropriate design paradigm in
this case, but it's definitely a perlish way of doing things, even if it's
not a syslogish way.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2005

From eravin@panix.com

On Thu, Aug 11, 2005 at 01​:52​:35AM -0700, Nicholas Clark via RT wrote​:

On Wed, Aug 10, 2005 at 12​:21​:49PM -0400, Ed Ravin wrote​:

I submit that this is a design bug - no other syslog() library behaves
this way, especially not the C library that Syslog.pm is based on.
Sys​::Syslog​::syslog() should return an error and let the user deal
with it (which would be an improvement over the C version, which has
no defined return values).

One way of implementing in error return in perl is throwing an exception.

We may not agree whether this is the most appropriate design paradigm in
this case, but it's definitely a perlish way of doing things, even if it's
not a syslogish way.

In that case, we have a documentation bug - the fact that Sys​::Syslog might
crash the calling program with croak() is not mentioned in its man page.

Would you accept patches for a "nocroak" or "nofatal" option to be used
in Sys​::Syslog​::openlog() to disable the fatal exit behavior?

  -- Ed

@p5pRT p5pRT closed this as completed Aug 31, 2005
@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2005

@rgs - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2005

From @rgs

Ed Ravin wrote​:

In that case, we have a documentation bug - the fact that Sys​::Syslog might
crash the calling program with croak() is not mentioned in its man page.

Would you accept patches for a "nocroak" or "nofatal" option to be used
in Sys​::Syslog​::openlog() to disable the fatal exit behavior?

I applied the following to bleadperl :

Change 25342 by rgs@​bloom on 2005/08/31 15​:14​:28

  Document that Sys​::Syslog​::openlog might die.
  Fixes [perl #36848] Sys​::Syslog​::syslog kills program if syslogd not running

Affected files ...

... //depot/perl/ext/Sys/Syslog/Syslog.pm#29 edit

Differences ...

==== //depot/perl/ext/Sys/Syslog/Syslog.pm#29 (text) ====

@​@​ -53,13 +53,15 @​@​

=item openlog $ident, $logopt, $facility

+Opens the syslog.
I<$ident> is prepended to every message. I<$logopt> contains zero or
more of the words I<pid>, I<ndelay>, I<nowait>. The cons option is
ignored, since the failover mechanism will drop down to the console
automatically if all other media fail. I<$facility> specifies the
part of the system to report about, for example LOG_USER or LOG_LOCAL0​:
see your C<syslog(3)> documentation for the facilities available in
-your system.
+your system. This function will croak if it can't connect to the syslog
+daemon.

B<You should use openlog() before calling syslog().>

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2005

From eravin@panix.com

On Wed, Aug 31, 2005 at 08​:42​:04AM -0700, Rafael Garcia-Suarez via RT wrote​:

According to our records, your request regarding
"Sys​::Syslog​::syslog kills program if syslogd not running"
has been resolved.

If you have any further questions or concerns, please respond to this message.

It looks like no action was taken. I think at the very least, the behavior
that I complained about should be documented in the Syslog.pm man page.

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2005

From eravin@panix.com

On Wed, Aug 31, 2005 at 09​:01​:57AM -0700, Rafael Garcia-Suarez via RT wrote​:

Ed Ravin wrote​:

In that case, we have a documentation bug - the fact that Sys​::Syslog might
crash the calling program with croak() is not mentioned in its man page.

Would you accept patches for a "nocroak" or "nofatal" option to be used
in Sys​::Syslog​::openlog() to disable the fatal exit behavior?

I applied the following to bleadperl :

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant