From owner-freebsd-arch Sat Mar 23 14:52:51 2002 Delivered-To: freebsd-arch@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id 19F2737B417 for ; Sat, 23 Mar 2002 14:52:46 -0800 (PST) Received: by flood.ping.uio.no (Postfix, from userid 2602) id C5B5A5346; Sat, 23 Mar 2002 23:52:43 +0100 (CET) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: Mikhail Teterin Cc: arch@FreeBSD.org Subject: Re: review request for bin/11294 References: <200203231928.g2NJSasb063343@aldan.algebra.com> From: Dag-Erling Smorgrav Date: 23 Mar 2002 23:52:42 +0100 In-Reply-To: Message-ID: Lines: 9 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --=-=-= Here's a patch. To log to a remote host, make /etc/loghost a symlink to its name or IP address ('ln -fs 10.0.5.14 /etc/loghost'). DES -- Dag-Erling Smorgrav - des@ofug.org --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=syslog.diff Index: lib/libc/gen/syslog.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.25 diff -u -r1.25 syslog.c --- lib/libc/gen/syslog.c 9 Mar 2002 11:38:01 -0000 1.25 +++ lib/libc/gen/syslog.c 23 Mar 2002 22:49:07 -0000 @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/syslog.c,v 1.25 2002/03/09 11:38:01 dwmalone Exp $"); #include "namespace.h" -#include +#include #include #include #include @@ -71,6 +71,8 @@ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ +static void connectlog_remote(const char *); +static void connectlog_local(void); /* * Format of the magic cookie passed through the stdio hook @@ -274,6 +276,7 @@ (void)_close(fd); } } + static void disconnectlog() { @@ -289,8 +292,61 @@ connected = 0; /* retry connect */ } +#define _PATH_LOGHOST "/etc/loghost" static void connectlog() +{ + char loghost[MAXHOSTNAMELEN]; + int len; + + if (LogFile != -1 && connected) + return; + if (LogFile != -1) { + _close(LogFile); + LogFile = -1; + } + connected = 0; + len = _readlink(_PATH_LOGHOST, loghost, sizeof loghost); + if (len > 0 && len < sizeof loghost) { + loghost[len] = '\0'; + connectlog_remote(loghost); + } + if (!connected) + connectlog_local(); +} + +#define SYSLOG_SERVICE "syslog" +static void +connectlog_remote(const char *host) +{ + struct addrinfo hints, *res = NULL; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = PF_UNSPEC; + if (getaddrinfo(host, SYSLOG_SERVICE, &hints, &res) != 0) + goto fail; + LogFile = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (LogFile == -1) + goto fail; + if (connect(LogFile, res->ai_addr, res->ai_addrlen) == -1) + goto fail; + (void)_fcntl(LogFile, F_SETFD, 1); + freeaddrinfo(res); + connected = 1; + return; + fail: + if (res != NULL) + freeaddrinfo(res); + if (LogFile != -1) { + _close(LogFile); + LogFile = 1; + } +} + +static void +connectlog_local() { struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ --=-=-=-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message