Search code examples
perlsyslog

Does Sys::Syslog call closelog() for you if your script die()s?


This is maybe a point of grammar, but anyhow, just to clarify... perldoc on Sys::Syslog states:

The Third Rule of Sys::Syslog is: The program crashes, dies, calls closelog , the log is over.

If 'the program' refers to the whole thing, my script and Sys::Syslog included, does that mean Sys::Syslog does the closelog() calling for me?

If not, does this mean I should put closelog() in an END block?


Solution

  • Sys::Syslog doesn't call closelog() on exit. Look at closelog() or disconnect_log() calls in https://metacpan.org/source/SAPER/Sys-Syslog-0.33/Syslog.pm.

    But in most cases it's safe to omit closelog() on exit/die in your script: descriptors will be closed on process exit anyway.

    most cases means cases with ordinary scripts when the Perl interpreter terminates on exit/die of your script. Exclusions are special environments like mod_perl for example: process doesn't exit if your script dies.