]> err.no Git - yubikey-server-c/commitdiff
Move db connection later
authorTollef Fog Heen <tfheen@err.no>
Wed, 21 Oct 2009 15:19:43 +0000 (17:19 +0200)
committerTollef Fog Heen <tfheen@err.no>
Wed, 21 Oct 2009 15:19:43 +0000 (17:19 +0200)
Do as little as possible while we are still running as root.  This
also makes ident connections work.

src/main.c

index d21c60f0cc7796381ec71bfd27aca2159bd70440..43bd7c3428ab936059db8cdd2e241e175ffc9b99 100644 (file)
@@ -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);