in reply to Re^2: Debugging Windows Services created with Win32::Daemon (STDERR)
in thread Debugging Windows Services created with Win32::Daemon

Using Win32::EventLog in conjunction with a __DIE__ handler would perhaps be a better solution.

If you define "better" as "still throws away lots of possible sources of information". Eventually, I'd do both. As a first step in figuring out what is going wrong, I'd go with the much simpler approach that catches stuff other than just die cases. To illustrate just one case: I wouldn't be at all surprised if Perl, after reporting "panic: ...", might not survive long enough to make it all the way to the end of the non-trivial number of opcodes required to catch then get stuff into the event log.

Wouldn't a pucker *nix daemon also throw away any parting STDERR output? The done thing is to close all the standard filestreams isn't it?

A production-quality daemon usually redirects STDERR to /dev/null (closing is a bad idea). But a Unix daemon who doesn't do this could end up with its output automatically going to the system log (or, on some older Unixes, to "the console"). On some old Unix configurations, this could actually cause problems. My comment wasn't meant to be a dig against Win32. I still suspect that Win32 is just throwing away the information. And sometimes that has its advantages. No need to get defensive. (:

It's quite likely that (if enabled) any non-zero termination code or STDERR output would end up in the system or application portion of the event log

What does "if enabled" mean? If there is a Win32 option to redirect daemon output to the event log, then hackdaddy would probably appreciate a pointer to it. He reports that such isn't happening for him.

- tye        

  • Comment on Re^3: Debugging Windows Services created with Win32::Daemon (STDERR)

Replies are listed 'Best First'.
Re^4: Debugging Windows Services created with Win32::Daemon (STDERR)
by BrowserUk (Patriarch) on Nov 16, 2005 at 21:07 UTC

    I was thinking of the option on Settings->cotrolPanel->System->Advanced->Startup&Recovery->System failure->[X] Write an event to the system log.

    That logs messages like

    "Application popup: perl.exe - Application Error : The instruction at "0x280b1efe" referenced memory at "0x00000009". The memory could not be "read".


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Thank you.

      I suspect that won't catch output to STDERR nor non-zero exit status, but I have no proof [and so this node is mostly useless (except for the 'thank you') unless it prompts someone to discover such answers :) ]

      - tye        

        I suspect that won't catch output to STDERR nor non-zero exit status.

        You are correct, my memory was fuzzy. In order for the exit status of the service to raise an event message log, the service has to

        If a service calls SetServiceStatus with the dwCurrentState member set to SERVICE_STOPPED and the dwWin32ExitCode member set to a nonzero value, the following entry is written into the System event log:

        Event ID = 7023 Source = Service Control Manager Type = Error Description = <ServiceName> terminated with the following error: <ExitCode>.

        This is available via the Win32::Deamon function

        State( { state => SERVICE_STOPPED, waithint => 0, error => $exit_code +} );

        STDERR will only log to the eventlog if the programmer arranges for it to do so through a tied filehandle or signal handlers. Which would work for program generated errors, but probably not those coming from withn the Perl executable like panics.

        Though, if enabled, segfaults will be logged.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.