Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've used the Net::DNS::Nameserver module to run a local nameserver on my windows workstation. After teaching it a few tricks and getting it to do what I want, I thought I would get fancy and have it register itself as my dns server. Win32::Ipconfig does this very nicely.

I store my current dns servers in a hash then set my adapter to use my local nameserver. When my server stops, I set the adapter back to the servers I saved. I put this step in the END block, but it doesn't seem to get called when I CTRL-C. In fact, nothing happens when I hit CTRL-C when I set my own signal handler.

After much gnashing of teeth and blaming signal handling on windows, I realized that Net::DNS::Nameserver must be handling signals in its own loop. I was hoping that the END in my code would execute after the modules cleanup, but it doesn't seem to be.

My question is simply, can I catch CTRL-C and cleanup, or somehow make sure my end code always runs? I have put together a small example below to illustrate the problem.

TIA
#!/usr/bin/perl use warnings; use strict; use Net::DNS; use Net::DNS::Nameserver; sub replyhandler { 1 } sub gotint { my $sig = shift; die "die because I caught: SIG<$sig>\n"; } #$SIG{'INT'} = \&gotint; my $ns = Net::DNS::Nameserver->new( LocalAddr => '127.0.0.1', ReplyHan +dler => \&replyhandler); $ns->main_loop; while ( 1 ) { sleep 1 } END { print "oh no this is the END\n" }

In reply to Cleaning up after CTRL-C when using Net::DNS::Nameserver on Windows? by elwarren

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found