From: Benjamin Cama Date: Sun, 21 Aug 2011 11:06:57 +0000 (+0200) Subject: Better error handling on CLI initialization. X-Git-Tag: debian/2.2.1-1fdn2~1^2~1 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/5382473b0e690398304eab989a3e2a5f1158bb68?ds=sidebyside Better error handling on CLI initialization. Signed-off-by: Benjamin Cama --- diff --git a/cli.c b/cli.c index 9433106..3a037fa 100644 --- a/cli.c +++ b/cli.c @@ -286,11 +286,19 @@ void init_cli(char *hostname) addr.sin_addr.s_addr = config->cli_bind_address; /* defaults to INADDR_ANY */ addr.sin_port = htons(23); if (bind(clifd, (void *) &addr, sizeof(addr)) < 0) + { + LOG(0, 0, 0, "Error binding cli on port 23: %s\n", strerror(errno)); + close(clifd); + clifd = -1; + return; + } + if (listen(clifd, 10) < 0) { LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno)); + close(clifd); + clifd = -1; return; } - listen(clifd, 10); } void cli_do(int sockfd)