From: Wilfried Göesgens Date: Thu, 1 Oct 2009 19:29:08 +0000 (+0000) Subject: * shut down clean in case of not being able to bind. X-Git-Tag: v7.86~818 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=e7923ad2e2db07d95b5d127f12f17d89dd9fe279 * shut down clean in case of not being able to bind. --- diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index 45c07ee79..3e3194b34 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -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); diff --git a/webcit/webserver.c b/webcit/webserver.c index a4fcdef03..c3263ecb7 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -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);