From 0ca6c19419752b9af0608f3cda107fecebd2df6a Mon Sep 17 00:00:00 2001 From: dms Date: Sun, 14 Oct 2001 13:03:14 +0000 Subject: [PATCH] - basically fix up openDB to allow unix sockets. -lear. - forgot fixDist for one DebianDownload line. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@524 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/Modules/Debian.pl | 2 +- src/db_mysql.pl | 22 +++++++++++++++++----- src/db_pgsql.pl | 24 ++++++++++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/Modules/Debian.pl b/src/Modules/Debian.pl index bbe2847..1c438fc 100644 --- a/src/Modules/Debian.pl +++ b/src/Modules/Debian.pl @@ -871,7 +871,7 @@ sub generateIndex { } &::DEBUG("deb: gIndex: calling DebianDownload($dist, ...)."); - &DebianDownload($dist, %urlpackages); + &DebianDownload($dist, &fixDist($dist, %urlpackages) ); &::status("Debian: generating index for '$dist'."); if (!open(OUT,">$idx")) { diff --git a/src/db_mysql.pl b/src/db_mysql.pl index 1b3f3dc..266dd69 100644 --- a/src/db_mysql.pl +++ b/src/db_mysql.pl @@ -9,20 +9,29 @@ package main; if (&IsParam("useStrict")) { use strict; } +##### +# &openDB($dbname, $sqluser, $sqlpass, $nofail); sub openDB { - my ($db, $user, $pass) = @_; - my $dsn = "DBI:mysql:$db:$param{'SQLHost'}"; + my ($db, $user, $pass, $no_fail) = @_; + my $dsn = "DBI:mysql:$db"; + my $hoststr = ""; + if (exists $param{'SQLHost'} and $param{'SQLHost'}) { + $dsn .= ":$param{SQLHost}"; + $hoststr = " to $param{'SQLHost'}"; + } $dbh = DBI->connect($dsn, $user, $pass); if ($dbh) { - &status("Opened MySQL connection to $param{'SQLHost'}"); + &status("Opened MySQL connection$hoststr"); } else { - &ERROR("cannot connect to $param{'SQLHost'}."); + &ERROR("cannot connect$hoststr."); &ERROR("since mysql is not available, shutting down bot!"); &closePID(); &closeSHM($shm); &closeLog(); + return if ($no_fail); + exit 1; } } @@ -30,7 +39,10 @@ sub openDB { sub closeDB { return 0 unless ($dbh); - &status("Closed MySQL connection to $param{'SQLHost'}."); + my $hoststr = ""; + $hoststr = " to $param{'SQLHost'}" if (exists $param{'SQLHost'}); + + &status("Closed MySQL connection$hoststr."); $dbh->disconnect(); return 1; diff --git a/src/db_pgsql.pl b/src/db_pgsql.pl index 7d025f9..f7d91ae 100644 --- a/src/db_pgsql.pl +++ b/src/db_pgsql.pl @@ -7,22 +7,30 @@ if (&IsParam("useStrict")) { use strict; } +##### +# openDB($dbname, $sqluser, $sqlpass, $nofail); sub openDB { - my $connectstr="dbi:Pg:dbname=$param{DBName};"; - $connectstr.=";host=$param{SQLHost}" if(defined $param{'SQLHost'}); - $dbh = DBI->connect($connectstr, $param{'SQLUser'}, $param{'SQLPass'}); + my($dbname, $sqluser, $sqlpass, $nofail) = @_; + my $connectstr = "dbi:Pg:dbname=$dbname;"; + my $hoststr = ""; + if (exists $param{'SQLHost'} and $param{'SQLHost'}) { + $hoststr = " to $param{'SQLHost'}"; + $connectstr .= ";host=$param{SQLHost}"; + } + $dbh = DBI->connect($connectstr, $sqluser, $sqlpass); - if (!$dbh->err) { - &status("Opened pgSQL connection". - (exists $param{'SQLHost'} ? " to ".$param{'SQLHost'} : "")); + if ($dbh and !$dbh->err) { + &status("Opened pgSQL connection$hoststr"); } else { - &ERROR("cannot connect to $param{'SQLHost'}."); - &ERROR("pgSQL: ".$dbh->errstr); + &ERROR("cannot connect$hoststr."); + &ERROR("pgSQL: ".$dbh->errstr) if ($dbh); &closePID(); &closeSHM($shm); &closeLog(); + return 0 if ($nofail); + exit 1; } } -- 2.39.2