Steve Lynn wrote:
> On Mar 2, 2:30 am, martin.ev...@easysoft.com (Martin Evans) wrote:
>> Lynn, Steve wrote:
>>> All - I'm under Solaris using perl v. 5.8.3 and DBI v. 1.48.  I can catch 
>>> signals w/o a problem before I connect to the database.
>>> However after I connect, I can't catch signals anymore.  If I comment out 
>>> the "DBI->connect" and press ctrl-c in a ReadLine(0), the signal is caught 
>>> fine.
>>> I found one other issue that seemed similar 
>>> (http://www.mail-archive.com/dbi-us...@perl.org/msg07747.html).
>>> Please help.
>>> ###########################
>>> #!/usr/local/perl -w
>>> use strict;
>>> use warnings;
>>> use Term:ReadKey;
>>> require DBI;
>>> use sigtrap 'handler', \&SigExit, qw/HUP INT KILL/;
>>> my $dbh;
>>> my $response;
>>> sub SigExit {
>>>     print STDOUT "\nTest\n";
>>>     die("\n");
>>> }
>>> $dbh = 
>>> DBI->connect("DBI:Oracle:host=dbserver;sid=mydb;port=1521","scott","tiger")­;
>>> print "\nEnter a response: ";
>>> $response = ReadLine(0);
>>> print ""\nEnter another response: ";
>>> $response = ReadLine(0);
>>> ###########################
>>> Thanks,
>>> Steve
>> Oracle client libraries can trap some signals (including HUP) depending
>> on which ones you use and how you are connecting. I believe you will
>> need to set up your handlers after connect for those signals but I
>> cannot remember the down side in Oracle.
>>
>> There have been various posts on dbi-users about this in the past so an
>> archive of dbi-users (some can be found at dbi.perl.org) would probably
>> list them.
>>
>> Martin
>> --
>> Martin J. Evans
>> Easysoft Limitedhttp://www.easysoft.com- Hide quoted text -
>>
>> - Show quoted text -
> 
> Thanks Martin.
> 
> I'm not sure whether I was clear enough on my goal.  I'm trying to
> trap INT signals so that when requesting input from the operator with
> ReadLine, they can press ctrl-c and exit.  I don't like the default
> signal handling so I'd like to just do a die("\n") when an INT is
> received.

I think I got that.

> When I comment out the DBI->connect, a ctrl-c will exit from the
> ReadLine as intended.  However, once the DBI->connect is completed,
> and the operator presses ctrl-c within the ReadLine, '^C' appears, but
> the signal handler isn't called.  It looks like the DBI->connect
> cancels, disables or overrides my sigtrap.

What I saying is that the Oracle client libraries sometimes add signal
handlers (especially SIGCHLD) and these would be setup when you connected.

> I'm not trying to handle any signals from within DBI.  I just trying
> to handle INT from within ReadLine.  It seems like DBI->connect is
> canceling my signal handler.
> 
> I tried to reload sigtrap immediately after the DBI->connect but that
> didn't work either:

Then I think you have a different issue to the one I thought you had but
I suggest you write a script with a simple connect in it and nothing
else then run truss on it to see what actions are performed on signals.

When I do this (on Linux with instant client 11) I see:

rt_sigaction(SIGQUIT, NULL, NULL, 8)    = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGILL, NULL, NULL, 8)     = 0
rt_sigaction(SIGILL, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGILL, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGABRT, NULL, NULL, 8)    = 0
rt_sigaction(SIGABRT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGABRT, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGFPE, NULL, NULL, 8)     = 0
rt_sigaction(SIGFPE, NULL, {0x1, [FPE], SA_RESTART}, 8) = 0
rt_sigaction(SIGSEGV, NULL, NULL, 8)    = 0
rt_sigaction(SIGSEGV, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSEGV, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGBUS, NULL, NULL, 8)     = 0
rt_sigaction(SIGBUS, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGBUS, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSYS, NULL, NULL, 8)     = 0
rt_sigaction(SIGSYS, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSYS, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTRAP, NULL, NULL, 8)    = 0
rt_sigaction(SIGTRAP, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTRAP, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXCPU, NULL, NULL, 8)    = 0
rt_sigaction(SIGXCPU, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXCPU, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXFSZ, NULL, NULL, 8)    = 0
rt_sigaction(SIGXFSZ, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXFSZ, {0x221fb9e, [], SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0

and later

rt_sigaction(SIGPIPE, {0x1, ~[ILL ABRT BUS FPE SEGV USR2 XCPU XFSZ SYS
RTMIN RT_1], SA_RESTART|SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0

rt_sigaction(SIGTSTP, {0x1, ~[ILL ABRT BUS FPE SEGV USR2 XCPU XFSZ SYS
RTMIN RT_1], SA_RESTART|SA_SIGINFO}, {SIG_DFL, [], 0}, 8) = 0

> #!/usr/local/perl -w
> 
> use strict;
> use warnings;
> use Term:ReadKey;
> require DBI;
> 
> use sigtrap 'handler', \&SigExit, qw/HUP INT KILL/;
> 
> my $dbh;
> my $response;
> 
> sub SigExit {
>     print STDOUT "\nTest\n";
>     die("\n");
> }
> 
> $dbh = DBI-
>> connect("DBI:Oracle:host=dbserver;sid=mydb;port=1521","scott","tiger")­;
> 
> use sigtrap 'handler', \&SigExit, qw/HUP INT KILL/;
> 
> print "\nEnter a response: ";
> $response = ReadLine(0);
> 
> print ""\nEnter another response: ";
> $response = ReadLine(0);
> 
> ##################################
> 
> Any help would be appreciated,
> 
> Steve Lynn
> 
> 

BTW, your example works fine for me on Linux with Oracle Instant Client
11 (even without the second sigtrap).

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to