]> pd.if.org Git - newsd/blobdiff - Net-Server-NNTP/lib/Net/Server/NNTP.pm
Improved robustness of server startup
[newsd] / Net-Server-NNTP / lib / Net / Server / NNTP.pm
index 54765487dc4a86ca06d192491670b618f8863a67..bcc881f09c0a25d33fa03c099e4c891db19bcb54 100644 (file)
@@ -491,7 +491,7 @@ sub ihave {
        my $ok = 0;
 
        return $s->response(501) unless $id =~ /($article_re)/;
-       return $s->response(430) if $s->fetch_stat($id);
+       return $s->response(435) if $s->fetch_stat($id);
        return $s->response(436) unless $s->permit_posting;
 
        $s->response(335);
@@ -548,6 +548,7 @@ our %capabilities = (
        'OVER MSGID'    => '',
        'LIST ACTIVE NEWSGROUPS OVERVIEW.FMT ACTIVE.TIMES HEADERS'      => '',
        STREAMING       => '',
+       IMPLEMENTATION  => 'if.org newsd',
 );
 
 our %hdrs = (
@@ -1107,10 +1108,20 @@ sub connect_to_storage {
 
        # TODO use a config parameter optionally here
        my $dsn = $ENV{'DBI_DSN'};
-       $dsn = 'dbi:Pg:dbname=news' unless defined $dsn;
+       $dsn = qq{dbi:Pg:dbname=news} unless defined $dsn;
        $s->log(4, "connecting to $dsn");
 
-       $s->{db} = DBI->connect($dsn,'','',{AutoCommit => 0,RaiseError=>1});
+       eval {
+               $s->{db} = DBI->connect($dsn,'','',{AutoCommit => 0,RaiseError=>1});
+               $s->log(4, "Can't connect to DB: $DBI::errstr") unless $s->{db};
+       };
+       if ($@) {
+               $s->log(4, "Can't connect to DB: $DBI::errstr");
+               die $@;
+       }
+       $s->log(4, "connected to $dsn");
+
+       # TODO abort if can't connect
        $s->{db}->{PrintError} = 0;
 
        $s->{db}->do("set CLIENT_ENCODING to 'SQL_ASCII'");