(core) catch connect croack error for database plugin (#3477)
This commit is contained in:
parent
75b52633ba
commit
629c7d5ad6
|
@ -224,18 +224,29 @@ sub connect {
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->set_signal_handlers();
|
$self->set_signal_handlers();
|
||||||
alarm($self->{timeout}) if (defined($self->{timeout}));
|
my $connect_error;
|
||||||
$self->{instance} = DBI->connect(
|
eval {
|
||||||
"DBI:". $self->{data_source},
|
alarm($self->{timeout}) if (defined($self->{timeout}));
|
||||||
$self->{username},
|
$self->{instance} = DBI->connect(
|
||||||
$self->{password},
|
"DBI:". $self->{data_source},
|
||||||
{ RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} }
|
$self->{username},
|
||||||
);
|
$self->{password},
|
||||||
alarm(0) if (defined($self->{timeout}));
|
{ RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} }
|
||||||
|
);
|
||||||
|
alarm(0) if (defined($self->{timeout}));
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$connect_error = $@;
|
||||||
|
}
|
||||||
|
|
||||||
$self->prepare_destroy();
|
$self->prepare_destroy();
|
||||||
|
|
||||||
if (!defined($self->{instance})) {
|
if (!defined($self->{instance})) {
|
||||||
my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)');
|
my $err_msg = sprintf(
|
||||||
|
'Cannot connect: %s',
|
||||||
|
defined($DBI::errstr) ? $DBI::errstr :
|
||||||
|
(defined($connect_error) ? $connect_error : '(no error string)')
|
||||||
|
);
|
||||||
if ($dontquit == 0) {
|
if ($dontquit == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => $err_msg);
|
$self->{output}->add_option_msg(short_msg => $err_msg);
|
||||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
|
|
|
@ -55,6 +55,7 @@ sub connect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $connect_error;
|
||||||
if (defined($self->{timeout})) {
|
if (defined($self->{timeout})) {
|
||||||
my $mask = POSIX::SigSet->new(SIGALRM);
|
my $mask = POSIX::SigSet->new(SIGALRM);
|
||||||
my $action = POSIX::SigAction->new(
|
my $action = POSIX::SigAction->new(
|
||||||
|
@ -69,14 +70,26 @@ sub connect {
|
||||||
$self->connect_db2();
|
$self->connect_db2();
|
||||||
};
|
};
|
||||||
alarm(0);
|
alarm(0);
|
||||||
|
if ($@) {
|
||||||
|
$connect_error = $@;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
sigaction(SIGALRM, $oldaction);
|
sigaction(SIGALRM, $oldaction);
|
||||||
} else {
|
} else {
|
||||||
$self->connect_db2();
|
eval {
|
||||||
|
$self->connect_db2();
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$connect_error = $@;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($self->{instance})) {
|
if (!defined($self->{instance})) {
|
||||||
my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)');
|
my $err_msg = sprintf(
|
||||||
|
'Cannot connect: %s',
|
||||||
|
defined($DBI::errstr) ? $DBI::errstr :
|
||||||
|
(defined($connect_error) ? $connect_error : '(no error string)')
|
||||||
|
);
|
||||||
if ($dontquit == 0) {
|
if ($dontquit == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => $err_msg);
|
$self->{output}->add_option_msg(short_msg => $err_msg);
|
||||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
|
|
|
@ -28,7 +28,7 @@ use POSIX qw(:signal_h);
|
||||||
|
|
||||||
sub connect_oracle {
|
sub connect_oracle {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{instance} = DBI->connect(
|
$self->{instance} = DBI->connect(
|
||||||
'DBI:' . $self->{data_source},
|
'DBI:' . $self->{data_source},
|
||||||
$self->{username},
|
$self->{username},
|
||||||
|
@ -55,6 +55,7 @@ sub connect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $connect_error;
|
||||||
if (defined($self->{timeout})) {
|
if (defined($self->{timeout})) {
|
||||||
my $mask = POSIX::SigSet->new(SIGALRM);
|
my $mask = POSIX::SigSet->new(SIGALRM);
|
||||||
my $action = POSIX::SigAction->new(
|
my $action = POSIX::SigAction->new(
|
||||||
|
@ -69,14 +70,26 @@ sub connect {
|
||||||
$self->connect_oracle();
|
$self->connect_oracle();
|
||||||
};
|
};
|
||||||
alarm(0);
|
alarm(0);
|
||||||
|
if ($@) {
|
||||||
|
$connect_error = $@;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
sigaction(SIGALRM, $oldaction);
|
sigaction(SIGALRM, $oldaction);
|
||||||
} else {
|
} else {
|
||||||
$self->connect_oracle();
|
eval {
|
||||||
|
$self->connect_oracle();
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$connect_error = $@;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($self->{instance})) {
|
if (!defined($self->{instance})) {
|
||||||
my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)');
|
my $err_msg = sprintf(
|
||||||
|
'Cannot connect: %s',
|
||||||
|
defined($DBI::errstr) ? $DBI::errstr :
|
||||||
|
(defined($connect_error) ? $connect_error : '(no error string)')
|
||||||
|
);
|
||||||
if ($dontquit == 0) {
|
if ($dontquit == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => $err_msg);
|
$self->{output}->add_option_msg(short_msg => $err_msg);
|
||||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
|
|
Loading…
Reference in New Issue