]> mj.ucw.cz Git - nwho.git/commitdiff
Moved gethostname() before fork()
authorMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:30:39 +0000 (16:30 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:30:39 +0000 (16:30 +0100)
nwhod.c

diff --git a/nwhod.c b/nwhod.c
index 9447d6a93bf7d129766c577bda3a7931797f5ee7..872a68d5e72b8d5cfb10623a2cd02f13b2e5e5da 100644 (file)
--- 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);
 }