From dec256c6f49d01cd4bcecbc2582525a629cc9f31 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 31 Dec 2010 16:30:39 +0100 Subject: [PATCH] Moved gethostname() before fork() --- nwhod.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nwhod.c b/nwhod.c index 9447d6a..872a68d 100644 --- a/nwhod.c +++ b/nwhod.c @@ -34,6 +34,7 @@ struct hostrec { static int sock, port; static struct hostrec *first_host; static time_t now, last_local_scan; +static char hostname[64]; static void die(char *msg, ...) __attribute__((noreturn)); @@ -79,6 +80,9 @@ net_init(char *name) if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) die("Cannot connect socket: %m"); } + + if (gethostname(hostname, sizeof(hostname)) < 0) + die("Unable to get my own host name: %m"); } static void @@ -275,11 +279,8 @@ static void local_scan(void) { struct nwho_pkt pkt; - static char hostname[64]; make_pkt(&pkt); - if (!hostname[0] && gethostname(hostname, sizeof(hostname)) < 0) - die("gethostname: %m"); save_pkt(hostname, &pkt); } -- 2.39.2