[master] d9c3cdd Fix build when daemon() is not available

Federico G. Schwindt fgsch at lodoss.net
Sat Jan 21 21:58:04 CET 2017


commit d9c3cddae1b4b5ec15935500f824f9d90d411c5f
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Sat Jan 21 19:08:02 2017 +0000

    Fix build when daemon() is not available

diff --git a/lib/libvarnishapi/daemon.c b/lib/libvarnishapi/daemon.c
index 55fc613..93e3bef 100644
--- a/lib/libvarnishapi/daemon.c
+++ b/lib/libvarnishapi/daemon.c
@@ -39,7 +39,24 @@
 #include <unistd.h>
 
 #include "compat/daemon.h"
-#include "vfil.h"
+#include "vas.h"
+
+/*
+ * Copied from libvarnish/vfil.c to avoid pulling libvarnish or vfil.c
+ * directly when daemon() is not working/available (i.e. OSX).
+ *
+ */
+static void
+vfil_null_fd(int target)
+{
+	int fd;
+
+	assert(target >= 0);
+	fd = open("/dev/null", O_RDWR);
+	assert(fd >= 0);
+	assert(dup2(fd, target) == target);
+	AZ(close(fd));
+}
 
 int
 varnish_daemon(int nochdir, int noclose)
@@ -82,9 +99,9 @@ varnish_daemon(int nochdir, int noclose)
 		(void)chdir("/");
 
 	if (!noclose) {
-		VFIL_null_fd(STDIN_FILENO);
-		VFIL_null_fd(STDOUT_FILENO);
-		VFIL_null_fd(STDERR_FILENO);
+		vfil_null_fd(STDIN_FILENO);
+		vfil_null_fd(STDOUT_FILENO);
+		vfil_null_fd(STDERR_FILENO);
 	}
 	return (0);
 }



More information about the varnish-commit mailing list