Hello Perl Monks

There is a mystery kind of thing, that when i do some database operation in a signal handler, then after doing this operation, process causes to terminate.

Situation is something like this 1.> Suppose process is in some infinite loop 2.> I had written a signal handler for signal 'URG', something like this..

$SIG{'URG'} = sub { # # Update the current status of Host from Database A.> my $curStatus = $host->fetchResyncStatus(); B.> $host->setResyncStatus($curStatus); print "\n Received CLD in :: ". $host->getIP(); } ;
Now when i do only operation "B", with some value of $curStatus set, then after handling the signal, process resumes in infinite loop and continue working...But when i do operation "A" alone or with "B", which calls function below, it causes to terminate my process after completing the signal routine..
sub fetchResyncStatus { my $self = shift; my $hostname = $self->getIP(); my $status; # # Connect to database, If unable to do so, log # an error and return my $dbh = DBI->connect( "dbi:Oracle:<DBNAME>", "<UserName>", "<Password>" ) || do { $self->error(__LINE__.":". DBI::errstr."\n"); return 0; }; # # Sql query to retrieve host status from the database my $sql_query = "SELECT STATUS FROM NMS_CONFIG WHERE IPADDRESS='". +$hostname. "'"; # # Prepare SQL query, If unable to do so, log an error and # return my $sth = $dbh->prepare($sql_query) || do { $self->error(__LINE__.": Could not prepare statement: ".$db +h->errstr. "\n"); return 0; }; # # Execute the SQL query. If unable to o so, log an error and # return $sth->execute() || do { $self->error(__LINE__.": Could not execute statement ".$sth- +>errstr."\n"); }; # # sql_query returns a reference to a hash with NMS_CONFIG # column name as keys and the column entries as their # corresponding values. while (my $hash_ref = $sth->fetchrow_hashref() ) { $status = $hash_ref->{'STATUS'}; } # # Disconnect from the database. $dbh->disconnect(); # # Return the value of the recieved status #return $status; print "\n\nStatus in DB :: " .$status."\n"; return 'NORMAL';

after going through this function. i found that when i call DBI->connect, it causes the problem, However it connects to database, fetch desired thing, returns what is desired. but after doing so, terminate the process...

Please have some pointer on it...it's like murder mystery for me.... :(

Thanks in Advance


In reply to Handling DB operations in signal handler by ajeet@perl

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.