* shut down clean in case of not being able to bind.
authorWilfried Göesgens <willi@citadel.org>
Thu, 1 Oct 2009 19:29:08 +0000 (19:29 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 1 Oct 2009 19:29:08 +0000 (19:29 +0000)
webcit/tcp_sockets.c
webcit/webserver.c

index 45c07ee79aef137e6e78be391cb40a11fe649f4d..3e3194b341859ff8a729d0eb66a838c490f7dd75 100644 (file)
@@ -415,7 +415,7 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
 
        if (port_number == 0) {
                lprintf(1, "Cannot start: no port number specified.\n");
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
        sin.sin_port = htons((u_short) port_number);
 
@@ -424,7 +424,7 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
        s = socket(PF_INET, SOCK_STREAM, (p->p_proto));
        if (s < 0) {
                lprintf(1, "Can't create a socket: %s\n", strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
        /* Set some socket options that make sense. */
        i = 1;
@@ -439,11 +439,11 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
        
        if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
                lprintf(1, "Can't bind: %s\n", strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
        if (listen(s, queue_len) < 0) {
                lprintf(1, "Can't listen: %s\n", strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
        return (s);
 }
@@ -469,7 +469,7 @@ int ig_uds_server(char *sockpath, int queue_len)
        if ((i != 0) && (errno != ENOENT)) {
                lprintf(1, "webcit: can't unlink %s: %s\n",
                        sockpath, strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
 
        memset(&addr, 0, sizeof(addr));
@@ -480,19 +480,19 @@ int ig_uds_server(char *sockpath, int queue_len)
        if (s < 0) {
                lprintf(1, "webcit: Can't create a socket: %s\n",
                        strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
 
        if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                lprintf(1, "webcit: Can't bind: %s\n",
                        strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
 
        if (listen(s, actual_queue_len) < 0) {
                lprintf(1, "webcit: Can't listen: %s\n",
                        strerror(errno));
-               exit(WC_EXIT_BIND);
+               return (-WC_EXIT_BIND);
        }
 
        chmod(sockpath, 0777);
index a4fcdef03c28465e528abcafdb14571f5f074caa..c3263ecb7820fb1d4e5abbf4197087aa60021aeb 100644 (file)
@@ -552,6 +552,11 @@ int main(int argc, char **argv)
                lprintf(2, "Attempting to bind to port %d...\n", http_port);
                msock = ig_tcp_server(ip_addr, http_port, LISTEN_QUEUE_LENGTH);
        }
+       if (msock < 0)
+       {
+               ShutDownWebcit();
+               return -msock;
+       }
 
        lprintf(2, "Listening on socket %d\n", msock);
        signal(SIGPIPE, SIG_IGN);