From: Tollef Fog Heen Date: Wed, 21 Oct 2009 15:19:43 +0000 (+0200) Subject: Move db connection later X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0750b18588db1867364fb3ff64faca60bdcc0a4;p=yubikey-server-c Move db connection later Do as little as possible while we are still running as root. This also makes ident connections work. --- diff --git a/src/main.c b/src/main.c index d21c60f..43bd7c3 100644 --- a/src/main.c +++ b/src/main.c @@ -575,12 +575,6 @@ int main(int argc, char ** argv) /* XXX return value */ parse_config(config, &conf); - db_conn = PQconnectdb(conf.dbdef); - if (PQstatus(db_conn) != CONNECTION_OK) { - syslog(LOG_ERR, "connection to database failed: %s", - PQerrorMessage(db_conn)); - exit(1); - } d = MHD_start_daemon(MHD_USE_DEBUG, conf.port, NULL, /* Access policy handler */ @@ -604,6 +598,13 @@ int main(int argc, char ** argv) exit(1); } + db_conn = PQconnectdb(conf.dbdef); + if (PQstatus(db_conn) != CONNECTION_OK) { + syslog(LOG_ERR, "connection to database failed: %s", + PQerrorMessage(db_conn)); + exit(1); + } + if (!foreground) daemon(0, 0);