From 920f5a61b9ccb37fcc307d69cc3b5a4def2f8f09 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 14 Jul 2014 04:02:33 +0000 Subject: [PATCH] Create a socketpair() and tie one end to /dev/klog using ioctl LIOCSFD. This allows us to receive messages direct from programs using the fd-safe sendsyslog(2), aka. syslog_r(3). Thanks to guenther for this part of the solution. ok beck tedu miod guenther --- usr.sbin/syslogd/syslogd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 165100ef9a8..9d50ff51dee 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.110 2014/02/04 23:28:05 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.111 2014/07/14 04:02:33 deraadt Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -286,7 +286,7 @@ main(int argc, char *argv[]) socklen_t len; char *p, *line; char resolve[MAXHOSTNAMELEN]; - int lockpipe[2] = { -1, -1}, nullfd; + int lockpipe[2] = { -1, -1}, pair[2], nullfd; struct addrinfo hints, *res, *res0; FILE *fp; @@ -436,6 +436,14 @@ main(int argc, char *argv[]) pfd[PFD_UNIX_0 + i].events = POLLIN; } + nfunix++; + if (socketpair(AF_UNIX, SOCK_DGRAM, PF_UNSPEC, pair) == -1) + die(0); + fd = pair[0]; + double_rbuf(fd); + pfd[PFD_UNIX_0 + i].fd = fd; + pfd[PFD_UNIX_0 + i].events = POLLIN; + if (ctlsock_path != NULL) { fd = unix_socket(ctlsock_path, SOCK_STREAM, 0600); if (fd != -1) { @@ -456,6 +464,10 @@ main(int argc, char *argv[]) pfd[PFD_KLOG].events = POLLIN; } + if (ioctl(fd, LIOCSFD, &pair[1]) == -1) + dprintf("LIOCSFD errno %d\n", errno); + close(pair[1]); + dprintf("off & running....\n"); chdir("/"); -- 2.20.1