Author: arekm                        Date: Fri Dec  8 14:03:04 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- new; timeout specified from configuration by Przemyslaw Plewa <pepe at [EMAIL 
PROTECTED]>

---- Files affected:
SOURCES:
   mon-msql-mysql-timeout.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/mon-msql-mysql-timeout.patch
diff -u /dev/null SOURCES/mon-msql-mysql-timeout.patch:1.1
--- /dev/null   Fri Dec  8 15:03:04 2006
+++ SOURCES/mon-msql-mysql-timeout.patch        Fri Dec  8 15:02:59 2006
@@ -0,0 +1,56 @@
+diff -ruN mon-1.1.0pre1.org/mon.d/msql-mysql.monitor 
mon-1.1.0pre1/mon.d/msql-mysql.monitor
+--- mon-1.1.0pre1.org/mon.d/msql-mysql.monitor 2004-06-09 07:18:04.000000000 
+0200
++++ mon-1.1.0pre1/mon.d/msql-mysql.monitor     2006-12-08 15:00:05.000000000 
+0100
+@@ -53,17 +53,27 @@
+ 
+ use DBI;
+ use Getopt::Long;
++use POSIX ':signal_h';
+ 
+ my @details=();
+ my @failures=();
+ 
+-GetOptions( \%options, "mode=s", "port=i", "username=s", "password=s", 
"database=s" );
++my $mask = POSIX::SigSet->new( SIGALRM );
++my $action = POSIX::SigAction->new( 
++       sub { die "connect timeout" },        # the handler code ref
++       $mask,
++       # not using (perl 5.8.2 and later) 'safe' switch or sa_flags
++);
++
++GetOptions( \%options, "mode=s", "port=i", "username=s", "password=s", 
"database=s", "timeout=i" );
+ 
+ # uncomment these two lines and provide suitable information if you don't
+ # want to pass sensitive information on the command line
+ #$options{username} ||= "username";
+ #$options{password} ||= "password";
+ 
++$options{timeout} = 60 if ! $options{timeout};
++
+ if( $0 =~ m/\/msql\.monitor$/ || $options{mode} =~ m/msql/i ) { 
+       $mode = "mSQL";
+       $options{port} = 1114 if ! $options{port};
+@@ -76,8 +86,21 @@
+ }
+ 
+ for $host( @ARGV ) {
+-      my( $dbh ) = DBI->connect( 
"DBI:$mode:$options{database}:$host:$options{port}", $options{username}, 
$options{password}, { PrintError => 0 } );
+-      if( ! $dbh ) {
++      my $dbh = 0;
++      my $oldaction = POSIX::SigAction->new();
++      sigaction( 'ALRM', $action, $oldaction );
++      eval {
++              alarm $options{timeout};
++              $dbh = DBI->connect( 
"DBI:$mode:$options{database}:$host:$options{port}", $options{username}, 
$options{password}, { PrintError => 0 } );
++              alarm 0;
++      };
++      alarm 0;
++        sigaction( 'ALRM', $oldaction );
++      if ($@) {
++              push( @failures, $host);
++              push( @details, "$host: Could not connect to $mode server on 
$options{port}: [EMAIL PROTECTED]");
++              next;
++      } elsif( ! $dbh ) {
+               push( @failures, $host);
+               push( @details, "$host: Could not connect to $mode server on 
$options{port}: " . $DBI::errstr . "\n");
+               next;
================================================================
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to