$OpenBSD: patch-hgd-netd_c,v 1.3 2011/12/04 12:57:09 edd Exp $

Fix for bug #139 (Wrong PID file written away).

--- hgd-netd.c.orig	Sun Dec  4 12:42:41 2011
+++ hgd-netd.c	Sun Dec  4 12:43:29 2011
@@ -1622,16 +1622,14 @@ main(int argc, char **argv)
 		hgd_exit_nicely();
 	}
 
-	/* Do this before daemonising so we can see its output if it fails. */
-	if (hgd_write_pid_file() != HGD_OK) {
-		DPRINTF(HGD_D_ERROR, "Can't write PID away");
-		return (HGD_FAIL);
-	}
-
 	/* alright, everything looks good, lets be a daemon and background */
 	if (background)
 		hgd_daemonise();
 
+	if (hgd_write_pid_file() != HGD_OK) {
+		DPRINTF(HGD_D_ERROR, "Can't write PID away");
+		return (HGD_FAIL);
+	}
 
 	hgd_listen_loop();
 
