From 5382473b0e690398304eab989a3e2a5f1158bb68 Mon Sep 17 00:00:00 2001 From: Benjamin Cama Date: Sun, 21 Aug 2011 13:06:57 +0200 Subject: [PATCH] Better error handling on CLI initialization. Signed-off-by: Benjamin Cama --- cli.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli.c b/cli.c index 9433106..3a037fa 100644 --- a/cli.c +++ b/cli.c @@ -287,10 +287,18 @@ void init_cli(char *hostname) addr.sin_port = htons(23); if (bind(clifd, (void *) &addr, sizeof(addr)) < 0) { - LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno)); + 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)