chuckleberryfinn has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using Win32 and running perl version 5.6.1 build 638. I am using Net::Dns::Nameserver to make a simple dns server, I use the nameserver's main_loop function but trap the ctrl-c signal using $SIG{'INT'} (to perform cleanup). Everything works as expected but at the end of the cleanup subroutine, when i call exit 0, I receive "Perl Command Line Interpreter has encountered a problem and needs to close.". I don't think I should be seeing this but I'm not sure what's wrong. Do any of the monks have any insight? I've also tried using die but I get the same results.

Replies are listed 'Best First'.
Re: Nameserver exit problem
by jethro (Monsignor) on Jul 21, 2008 at 02:11 UTC
    A really wild guess: Signal handling had some issues with non-POSIX systems. See the section about signals in chapter 6 of the camel book. Maybe you can avoid the error with something like this:
    $SIG{INT}= 'DEFAULT'; exit;
    Is the error still there when you remove the cleanup code from your signal handler?

    Could you try out a minimal script like

    $SIG{INT}= 'handler'; sub handler { print "Got ctrl-Cd\n"; exit(0); } while (1) { sleep 1; }
    If this shows the problematic behaviour, perl or your OS is the culprit. Otherwise you might search the source of Net::DNS::Nameserver whether it defines signal handlers.

      FWIW, your snippet worked with me without issues in WinXP with 5.6.0, 5.6.1, 5.8.0, 5.8.8 and 5.10.0.

Re: Nameserver exit problem
by quester (Vicar) on Jul 21, 2008 at 02:17 UTC

    I assume by "build 638" you mean that you are using ActivePerl, but Win32 could mean any of several versions of Windows; it would really help if you specified the exact versions.

    Incidentally... Perl 5.6.1 was released in April 2001, and Windows XP (which is currently the last fully supported version of Windows) was released after that, sometime in October 2001. You might want to try a later version of Perl, partly to see if the bug is fixed, and partly because you are running without quite a few subsequent security patches.

Re: Nameserver exit problem
by ikegami (Patriarch) on Jul 21, 2008 at 03:21 UTC
    Before Perl 5.8, signals could interrupt Perl in an unsafe manner. (See "Safe Signals" in perlipc.) Have you tried using a more recent version of Perl? Yours is rather old.