From 5a1a3d1fcb3c6b7b7a67ecaad99baa03065cc171 Mon Sep 17 00:00:00 2001 From: "tim.schubert@tu-bs.de" <tim.schubert@tu-bs.de> Date: Sun, 30 Oct 2016 02:37:19 +0200 Subject: [PATCH] Register the signal handler before opening the socket that is closed by it. --- netcalc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/netcalc.c b/netcalc.c index 5db7360..344055c 100644 --- a/netcalc.c +++ b/netcalc.c @@ -275,6 +275,12 @@ int client() int main(int argc, char *argv[]) { + SOCKFD = 0; + struct sigaction action; + memset(&action, 0, sizeof(struct sigaction)); + action.sa_handler = cleanup; + sigaction(SIGTERM, &action, NULL); + char* host = NULL; char* port = "5000"; int afamiliy = AF_UNSPEC; @@ -310,11 +316,6 @@ int main(int argc, char *argv[]) return 1; } - struct sigaction action; - memset(&action, 0, sizeof(struct sigaction)); - action.sa_handler = cleanup; - sigaction(SIGTERM, &action, NULL); - if (CLIENT) { connectclient(ainfo); if (client() == -1) {