Commit Diff


commit - aa627c91fcd7b6d56b9a9864fa89f8fa615ff0d2
commit + 376a540764c3778330b4f744031bcdb5c6e73647
blob - 0d0247e5a8d267f9cc2fd7407490b29fe25b3fe5
blob + d14891ab6dfa1a4a68e79ee7c51da7fe78924c50
--- gmid.c
+++ gmid.c
@@ -29,8 +29,10 @@ volatile sig_atomic_t hupped;
 
 struct vhost hosts[HOSTSLEN];
 
-int exfd, sock4, sock6;
+int exfd, logfd, sock4, sock6;
 
+struct imsgbuf logpibuf, logcibuf;
+
 const char *config_path, *certs_dir, *hostname;
 
 struct conf conf;
@@ -331,6 +333,33 @@ usage(const char *me)
 	    me);
 }
 
+static void
+logger_init(void)
+{
+	int p[2];
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
+		err(1, "socketpair");
+
+	switch (fork()) {
+	case -1:
+		err(1, "fork");
+	case 0:
+		logfd = p[1];
+		close(p[0]);
+		setproctitle("logger");
+		imsg_init(&logcibuf, p[1]);
+		drop_priv();
+		_exit(logger_main(p[1], &logcibuf));
+	default:
+		logfd = p[0];
+		close(p[1]);
+		imsg_init(&logpibuf, p[0]);
+		return;
+	}
+}
+
+
 static int
 serve(int argc, char **argv, int *p)
 {
blob - 454ddd3c2f24e0fb14a12b84c93856b0e69f748a
blob + e926f9c5b69fa2e933874dbb5c5a69e6f6ea0a5d
--- gmid.h
+++ gmid.h
@@ -114,7 +114,9 @@ struct conf {
 
 extern const char *config_path;
 extern struct conf conf;
-extern int exfd;
+extern int exfd, logfd;
+
+extern struct imsgbuf logpibuf, logcibuf;
 
 extern volatile sig_atomic_t hupped;
 
@@ -219,7 +221,7 @@ void		 log_notice(struct client*, const char*, ...)	LO
 void		 log_info(struct client*, const char*, ...)	LOG_ATTR_FMT;
 void		 log_debug(struct client*, const char*, ...)	LOG_ATTR_FMT;
 void		 log_request(struct client*, char*, size_t);
-void		 logger_init(void);
+int		 logger_main(int, struct imsgbuf*);
 
 /* mime.c */
 void		 init_mime(struct mime*);
blob - 6bb84f131f85407de99c5dd8ce931ce60aa6ef37
blob + 19b72b9790045ccc1c901644026500c808a5124e
--- log.c
+++ log.c
@@ -28,12 +28,9 @@
 #include <string.h>
 #include <syslog.h>
 
-static struct imsgbuf parent_ibuf, child_ibuf;
 static struct event inlog;
-static int logfd;
 
 static void handle_log(int, short, void*);
-static int logger_main(int, struct imsgbuf*);
 
 void
 fatal(const char *fmt, ...)
@@ -74,9 +71,9 @@ should_log(int priority)
 static inline void
 send_log(const char *msg, size_t len)
 {
-	imsg_compose(&parent_ibuf, 0, 0, 0, -1, msg, len);
+	imsg_compose(&logpibuf, 0, 0, 0, -1, msg, len);
 	/* XXX: use event_once() */
-	imsg_flush(&parent_ibuf);
+	imsg_flush(&logpibuf);
 }
 
 static inline void
@@ -267,7 +264,7 @@ handle_log(int fd, short ev, void *d)
 	}
 }
 
-static int
+int
 logger_main(int fd, struct imsgbuf *ibuf)
 {
 	event_init();
@@ -284,29 +281,3 @@ logger_main(int fd, struct imsgbuf *ibuf)
 
 	return 0;
 }
-
-void
-logger_init(void)
-{
-	int p[2];
-
-	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
-		err(1, "socketpair");
-
-	switch (fork()) {
-	case -1:
-		err(1, "fork");
-	case 0:
-		logfd = p[1];
-		close(p[0]);
-		setproctitle("logger");
-		imsg_init(&child_ibuf, p[1]);
-		drop_priv();
-		_exit(logger_main(p[1], &child_ibuf));
-	default:
-		logfd = p[0];
-		close(p[1]);
-		imsg_init(&parent_ibuf, p[0]);
-		return;
-	}
-}