Menu

#8 Trace alarm() calls

closed
nobody
None
5
2005-02-22
2003-08-12
Ed Avis
No

I recently spent a while tracking down a bug related to
alarm() in yasql. The bug turned out to be in Solaris
and I will post a separate patch with workaround
details. But while debugging I found the following
extra trace statements useful.

This patch does not change any functionality, it just
adds some log messages which can be seen if the debug
level is set to 2 or higher.

diff -Naur yasql-1.81/yasql.in yasql-1.81-dev/yasql.in
--- yasql-1.81/yasql.in 2002-03-06 22:27:57.000000000 +0000
+++ yasql-1.81-dev/yasql.in 2003-08-12
15:54:03.788400000 +0100
@@ -679,6 +679,7 @@
# install alarm signal handle
$SIG{ALRM} = \&sighandle;
alarm($conf{connection_timeout});
+ debugmsg(2, "Set alarm for external connection
($conf{connection_timeout} seconds)");

print "Attempting connection to local database\n";
$dbhandle =
DBI->connect('dbi:Oracle:',undef,undef,$attributes)
@@ -689,7 +690,8 @@

$this_prompt_host = $ENV{ORACLE_SID};
$this_prompt_user = $ENV{LOGNAME};
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
} elsif($connect_string) {
# We were provided with a connect string, so we
can use the TNS method

@@ -706,6 +708,7 @@
# install alarm signal handle
$SIG{ALRM} = \&sighandle;
alarm($conf{connection_timeout});
+ debugmsg(2, "Set alarm for connect-string
connection ($conf{connection_timeout} seconds)");

print "Attempting connection to $userstring\n";
$dbhandle =
DBI->connect('dbi:Oracle:',$userstring,$password,$attributes)
@@ -713,10 +716,11 @@
$dberr = $DBI::err;
$dberrstr = $DBI::errstr;
};
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");

$this_prompt_host = $connect_string;
$this_prompt_user = $username;
- alarm(0); # cancel alarm
} elsif($opt_host) {
# attempt a connection to $opt_host
my $dsn;
@@ -729,6 +733,7 @@
# install alarm signal handle
$SIG{ALRM} = \&sighandle;
alarm($conf{connection_timeout});
+ debugmsg(2, "Set alarm for host connection
($conf{connection_timeout} seconds)");

print "Attempting connection to $opt_host\n";
debugmsg(1,"dsn: [$dsn]");
@@ -742,7 +747,8 @@
$this_prompt_host = $opt_host;
$this_prompt_host = "$opt_sid!" .
$this_prompt_host if $opt_sid;
$prompt{user} = $username;
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
} else {
# attempt a connection without specifying a
hostname or anything

@@ -752,6 +758,7 @@
# install alarm signal handle
$SIG{ALRM} = \&sighandle;
alarm($conf{connection_timeout});
+ debugmsg(2, "Set alarm for default connection
($conf{connection_timeout} seconds)");

print "Attempting connection to local database\n";
$dbhandle =
DBI->connect('dbi:Oracle:',$username,$password,$attributes)
@@ -762,7 +769,8 @@

$this_prompt_host = $ENV{ORACLE_SID};
$this_prompt_user = $username;
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
}

if($dbhandle) {
@@ -3152,22 +3160,25 @@
} else {
# install alarm signal handle
$SIG{ALRM} = \&sighandle;
- debugmsg(2, "Setting alarm for ping
($conf{connection_timeout} seconds)");
alarm($conf{connection_timeout});
+ debugmsg(2, "Set alarm for ping
($conf{connection_timeout} seconds)");

debugmsg(2, "Pinging...");
if($dbh->ping()) {
debugmsg(2, "Ping successfull");
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
return(1);
} else {
debugmsg(2, "Ping failed");
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
db_reconnect();
return(0);
}
}
- alarm(0); # cancel alarm
+ alarm(0);
+ debugmsg(2, "Cancelled alarm");
}

sub query_err {

Discussion

  • Kozman Bálint

    Kozman Bálint - 2005-02-22
    • status: open --> closed
     
  • Kozman Bálint

    Kozman Bálint - 2005-02-22

    Logged In: YES
    user_id=1209168

    This seems to only be useful in really particular testing
    circumstances. Probably we should make a development fork. :-)

     

Log in to post a comment.