xref: /freebsd/lib/libc/gen/syslog.c (revision 857b57eae13f201c6c0f7017cc41559c985403e1)
158f0484fSRodney W. Grimes /*
258f0484fSRodney W. Grimes  * Copyright (c) 1983, 1988, 1993
358f0484fSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
458f0484fSRodney W. Grimes  *
558f0484fSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
658f0484fSRodney W. Grimes  * modification, are permitted provided that the following conditions
758f0484fSRodney W. Grimes  * are met:
858f0484fSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
958f0484fSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1058f0484fSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1158f0484fSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1258f0484fSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
1358f0484fSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
1458f0484fSRodney W. Grimes  *    must display the following acknowledgement:
1558f0484fSRodney W. Grimes  *	This product includes software developed by the University of
1658f0484fSRodney W. Grimes  *	California, Berkeley and its contributors.
1758f0484fSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
1858f0484fSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1958f0484fSRodney W. Grimes  *    without specific prior written permission.
2058f0484fSRodney W. Grimes  *
2158f0484fSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2258f0484fSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2358f0484fSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2458f0484fSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2558f0484fSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2658f0484fSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2758f0484fSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2858f0484fSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2958f0484fSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3058f0484fSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3158f0484fSRodney W. Grimes  * SUCH DAMAGE.
3258f0484fSRodney W. Grimes  */
3358f0484fSRodney W. Grimes 
3458f0484fSRodney W. Grimes #if defined(LIBC_SCCS) && !defined(lint)
35adf6ad9eSPeter Wemm static char sccsid[] = "@(#)syslog.c	8.5 (Berkeley) 4/29/95";
3658f0484fSRodney W. Grimes #endif /* LIBC_SCCS and not lint */
37b231cb39SDavid E. O'Brien #include <sys/cdefs.h>
38b231cb39SDavid E. O'Brien __FBSDID("$FreeBSD$");
3958f0484fSRodney W. Grimes 
40d201fe46SDaniel Eischen #include "namespace.h"
4158f0484fSRodney W. Grimes #include <sys/types.h>
4258f0484fSRodney W. Grimes #include <sys/socket.h>
4358f0484fSRodney W. Grimes #include <sys/syslog.h>
4458f0484fSRodney W. Grimes #include <sys/uio.h>
45d584948eSBrian Somers #include <sys/un.h>
4658f0484fSRodney W. Grimes #include <netdb.h>
4758f0484fSRodney W. Grimes 
4858f0484fSRodney W. Grimes #include <errno.h>
4958f0484fSRodney W. Grimes #include <fcntl.h>
5058f0484fSRodney W. Grimes #include <paths.h>
5158f0484fSRodney W. Grimes #include <stdio.h>
524cd01193SMark Murray #include <stdlib.h>
5358f0484fSRodney W. Grimes #include <string.h>
5458f0484fSRodney W. Grimes #include <time.h>
5558f0484fSRodney W. Grimes #include <unistd.h>
5658f0484fSRodney W. Grimes 
5758f0484fSRodney W. Grimes #include <stdarg.h>
58d201fe46SDaniel Eischen #include "un-namespace.h"
5958f0484fSRodney W. Grimes 
604cd01193SMark Murray #include "libc_private.h"
614cd01193SMark Murray 
6258f0484fSRodney W. Grimes static int	LogFile = -1;		/* fd for log */
638d41a9efSBrian Somers static int	connected;		/* have done connect */
647e6ace85SPeter Wemm static int	opened;			/* have done openlog() */
6558f0484fSRodney W. Grimes static int	LogStat = 0;		/* status bits, set by openlog() */
6658f0484fSRodney W. Grimes static const char *LogTag = NULL;	/* string to tag the entry with */
6758f0484fSRodney W. Grimes static int	LogFacility = LOG_USER;	/* default facility code */
6858f0484fSRodney W. Grimes static int	LogMask = 0xff;		/* mask of priorities to be logged */
6958f0484fSRodney W. Grimes 
70b231cb39SDavid E. O'Brien static void	disconnectlog(void); /* disconnect from syslogd */
71b231cb39SDavid E. O'Brien static void	connectlog(void);	/* (re)connect to syslogd */
727e6ace85SPeter Wemm 
7358f0484fSRodney W. Grimes /*
747c8e2aa4SPeter Wemm  * Format of the magic cookie passed through the stdio hook
757c8e2aa4SPeter Wemm  */
767c8e2aa4SPeter Wemm struct bufcookie {
777c8e2aa4SPeter Wemm 	char	*base;	/* start of buffer */
787c8e2aa4SPeter Wemm 	int	left;
797c8e2aa4SPeter Wemm };
807c8e2aa4SPeter Wemm 
817c8e2aa4SPeter Wemm /*
827c8e2aa4SPeter Wemm  * stdio write hook for writing to a static string buffer
837c8e2aa4SPeter Wemm  * XXX: Maybe one day, dynamically allocate it so that the line length
847c8e2aa4SPeter Wemm  *      is `unlimited'.
857c8e2aa4SPeter Wemm  */
867e6ace85SPeter Wemm static
877e6ace85SPeter Wemm int writehook(cookie, buf, len)
887c8e2aa4SPeter Wemm 	void	*cookie;	/* really [struct bufcookie *] */
897c8e2aa4SPeter Wemm 	char	*buf;		/* characters to copy */
907c8e2aa4SPeter Wemm 	int	len;		/* length to copy */
917c8e2aa4SPeter Wemm {
927c8e2aa4SPeter Wemm 	struct bufcookie *h;	/* private `handle' */
937c8e2aa4SPeter Wemm 
947c8e2aa4SPeter Wemm 	h = (struct bufcookie *)cookie;
957c8e2aa4SPeter Wemm 	if (len > h->left) {
967c8e2aa4SPeter Wemm 		/* clip in case of wraparound */
977c8e2aa4SPeter Wemm 		len = h->left;
987c8e2aa4SPeter Wemm 	}
997c8e2aa4SPeter Wemm 	if (len > 0) {
1007c8e2aa4SPeter Wemm 		(void)memcpy(h->base, buf, len); /* `write' it. */
1017c8e2aa4SPeter Wemm 		h->base += len;
1027c8e2aa4SPeter Wemm 		h->left -= len;
1037c8e2aa4SPeter Wemm 	}
1047c8e2aa4SPeter Wemm 	return 0;
1057c8e2aa4SPeter Wemm }
1067c8e2aa4SPeter Wemm 
1077c8e2aa4SPeter Wemm /*
10858f0484fSRodney W. Grimes  * syslog, vsyslog --
10958f0484fSRodney W. Grimes  *	print message on log file; output is intended for syslogd(8).
11058f0484fSRodney W. Grimes  */
11158f0484fSRodney W. Grimes void
11258f0484fSRodney W. Grimes syslog(int pri, const char *fmt, ...)
11358f0484fSRodney W. Grimes {
11458f0484fSRodney W. Grimes 	va_list ap;
11558f0484fSRodney W. Grimes 
11658f0484fSRodney W. Grimes 	va_start(ap, fmt);
11758f0484fSRodney W. Grimes 	vsyslog(pri, fmt, ap);
11858f0484fSRodney W. Grimes 	va_end(ap);
11958f0484fSRodney W. Grimes }
12058f0484fSRodney W. Grimes 
12158f0484fSRodney W. Grimes void
12258f0484fSRodney W. Grimes vsyslog(pri, fmt, ap)
12358f0484fSRodney W. Grimes 	int pri;
124b231cb39SDavid E. O'Brien 	const char *fmt;
12558f0484fSRodney W. Grimes 	va_list ap;
12658f0484fSRodney W. Grimes {
127b231cb39SDavid E. O'Brien 	int cnt;
128b231cb39SDavid E. O'Brien 	char ch, *p;
12958f0484fSRodney W. Grimes 	time_t now;
13058f0484fSRodney W. Grimes 	int fd, saved_errno;
131ab09ef00SDavid Malone 	char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26];
1327c8e2aa4SPeter Wemm 	FILE *fp, *fmt_fp;
1337c8e2aa4SPeter Wemm 	struct bufcookie tbuf_cookie;
1347c8e2aa4SPeter Wemm 	struct bufcookie fmt_cookie;
13558f0484fSRodney W. Grimes 
13658f0484fSRodney W. Grimes #define	INTERNALLOG	LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
13758f0484fSRodney W. Grimes 	/* Check for invalid bits. */
13858f0484fSRodney W. Grimes 	if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
13958f0484fSRodney W. Grimes 		syslog(INTERNALLOG,
14058f0484fSRodney W. Grimes 		    "syslog: unknown facility/priority: %x", pri);
14158f0484fSRodney W. Grimes 		pri &= LOG_PRIMASK|LOG_FACMASK;
14258f0484fSRodney W. Grimes 	}
14358f0484fSRodney W. Grimes 
14458f0484fSRodney W. Grimes 	/* Check priority against setlogmask values. */
145ff17906bSAndrey A. Chernov 	if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
14658f0484fSRodney W. Grimes 		return;
14758f0484fSRodney W. Grimes 
14858f0484fSRodney W. Grimes 	saved_errno = errno;
14958f0484fSRodney W. Grimes 
15058f0484fSRodney W. Grimes 	/* Set default facility if none specified. */
15158f0484fSRodney W. Grimes 	if ((pri & LOG_FACMASK) == 0)
15258f0484fSRodney W. Grimes 		pri |= LogFacility;
15358f0484fSRodney W. Grimes 
1547c8e2aa4SPeter Wemm 	/* Create the primary stdio hook */
1557c8e2aa4SPeter Wemm 	tbuf_cookie.base = tbuf;
1567c8e2aa4SPeter Wemm 	tbuf_cookie.left = sizeof(tbuf);
1577c8e2aa4SPeter Wemm 	fp = fwopen(&tbuf_cookie, writehook);
1587c8e2aa4SPeter Wemm 	if (fp == NULL)
1597c8e2aa4SPeter Wemm 		return;
1607c8e2aa4SPeter Wemm 
16158f0484fSRodney W. Grimes 	/* Build the message. */
16258f0484fSRodney W. Grimes 	(void)time(&now);
1637c8e2aa4SPeter Wemm 	(void)fprintf(fp, "<%d>", pri);
164ab09ef00SDavid Malone 	(void)fprintf(fp, "%.15s ", ctime_r(&now, timbuf) + 4);
1657c8e2aa4SPeter Wemm 	if (LogStat & LOG_PERROR) {
1667c8e2aa4SPeter Wemm 		/* Transfer to string buffer */
1677c8e2aa4SPeter Wemm 		(void)fflush(fp);
1687c8e2aa4SPeter Wemm 		stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left);
1697c8e2aa4SPeter Wemm 	}
17058f0484fSRodney W. Grimes 	if (LogTag == NULL)
1714cd01193SMark Murray 		LogTag = _getprogname();
17258f0484fSRodney W. Grimes 	if (LogTag != NULL)
1737c8e2aa4SPeter Wemm 		(void)fprintf(fp, "%s", LogTag);
17458f0484fSRodney W. Grimes 	if (LogStat & LOG_PID)
1757c8e2aa4SPeter Wemm 		(void)fprintf(fp, "[%d]", getpid());
17658f0484fSRodney W. Grimes 	if (LogTag != NULL) {
1777c8e2aa4SPeter Wemm 		(void)fprintf(fp, ": ");
1787c8e2aa4SPeter Wemm 	}
1797c8e2aa4SPeter Wemm 
1807c8e2aa4SPeter Wemm 	/* Check to see if we can skip expanding the %m */
1817c8e2aa4SPeter Wemm 	if (strstr(fmt, "%m")) {
1827c8e2aa4SPeter Wemm 
1837c8e2aa4SPeter Wemm 		/* Create the second stdio hook */
1847c8e2aa4SPeter Wemm 		fmt_cookie.base = fmt_cpy;
1857c8e2aa4SPeter Wemm 		fmt_cookie.left = sizeof(fmt_cpy) - 1;
1867c8e2aa4SPeter Wemm 		fmt_fp = fwopen(&fmt_cookie, writehook);
1877c8e2aa4SPeter Wemm 		if (fmt_fp == NULL) {
1887c8e2aa4SPeter Wemm 			fclose(fp);
1897c8e2aa4SPeter Wemm 			return;
19058f0484fSRodney W. Grimes 		}
19158f0484fSRodney W. Grimes 
192e6cfb1ccSAlfred Perlstein 		/*
193e6cfb1ccSAlfred Perlstein 		 * Substitute error message for %m.  Be careful not to
194e6cfb1ccSAlfred Perlstein 		 * molest an escaped percent "%%m".  We want to pass it
195e6cfb1ccSAlfred Perlstein 		 * on untouched as the format is later parsed by vfprintf.
196e6cfb1ccSAlfred Perlstein 		 */
197e6cfb1ccSAlfred Perlstein 		for ( ; (ch = *fmt); ++fmt) {
19858f0484fSRodney W. Grimes 			if (ch == '%' && fmt[1] == 'm') {
19958f0484fSRodney W. Grimes 				++fmt;
2007c8e2aa4SPeter Wemm 				fputs(strerror(saved_errno), fmt_fp);
201e6cfb1ccSAlfred Perlstein 			} else if (ch == '%' && fmt[1] == '%') {
202e6cfb1ccSAlfred Perlstein 				++fmt;
2037c8e2aa4SPeter Wemm 				fputc(ch, fmt_fp);
204e6cfb1ccSAlfred Perlstein 				fputc(ch, fmt_fp);
205e6cfb1ccSAlfred Perlstein 			} else {
206e6cfb1ccSAlfred Perlstein 				fputc(ch, fmt_fp);
207e6cfb1ccSAlfred Perlstein 			}
208e6cfb1ccSAlfred Perlstein 		}
20958f0484fSRodney W. Grimes 
2107c8e2aa4SPeter Wemm 		/* Null terminate if room */
2117c8e2aa4SPeter Wemm 		fputc(0, fmt_fp);
2127c8e2aa4SPeter Wemm 		fclose(fmt_fp);
2137c8e2aa4SPeter Wemm 
2147c8e2aa4SPeter Wemm 		/* Guarantee null termination */
2157c8e2aa4SPeter Wemm 		fmt_cpy[sizeof(fmt_cpy) - 1] = '\0';
2167c8e2aa4SPeter Wemm 
2177c8e2aa4SPeter Wemm 		fmt = fmt_cpy;
2187c8e2aa4SPeter Wemm 	}
2197c8e2aa4SPeter Wemm 
2207c8e2aa4SPeter Wemm 	(void)vfprintf(fp, fmt, ap);
2217c8e2aa4SPeter Wemm 	(void)fclose(fp);
2227c8e2aa4SPeter Wemm 
2237c8e2aa4SPeter Wemm 	cnt = sizeof(tbuf) - tbuf_cookie.left;
22458f0484fSRodney W. Grimes 
225857b57eaSDiomidis Spinellis 	/* Remove a trailing newline */
226857b57eaSDiomidis Spinellis 	if (tbuf[cnt - 1] == '\n')
227857b57eaSDiomidis Spinellis 		cnt--;
228857b57eaSDiomidis Spinellis 
22958f0484fSRodney W. Grimes 	/* Output to stderr if requested. */
23058f0484fSRodney W. Grimes 	if (LogStat & LOG_PERROR) {
23158f0484fSRodney W. Grimes 		struct iovec iov[2];
232b231cb39SDavid E. O'Brien 		struct iovec *v = iov;
23358f0484fSRodney W. Grimes 
23458f0484fSRodney W. Grimes 		v->iov_base = stdp;
23558f0484fSRodney W. Grimes 		v->iov_len = cnt - (stdp - tbuf);
23658f0484fSRodney W. Grimes 		++v;
23758f0484fSRodney W. Grimes 		v->iov_base = "\n";
23858f0484fSRodney W. Grimes 		v->iov_len = 1;
239d201fe46SDaniel Eischen 		(void)_writev(STDERR_FILENO, iov, 2);
24058f0484fSRodney W. Grimes 	}
24158f0484fSRodney W. Grimes 
24258f0484fSRodney W. Grimes 	/* Get connected, output the message to the local logger. */
2437e6ace85SPeter Wemm 	if (!opened)
24458f0484fSRodney W. Grimes 		openlog(LogTag, LogStat | LOG_NDELAY, 0);
2457e6ace85SPeter Wemm 	connectlog();
2467e6ace85SPeter Wemm 	if (send(LogFile, tbuf, cnt, 0) >= 0)
2477e6ace85SPeter Wemm 		return;
2487e6ace85SPeter Wemm 
2497e6ace85SPeter Wemm 	/*
2507e6ace85SPeter Wemm 	 * If the send() failed, the odds are syslogd was restarted.
2517e6ace85SPeter Wemm 	 * Make one (only) attempt to reconnect to /dev/log.
2527e6ace85SPeter Wemm 	 */
2537e6ace85SPeter Wemm 	disconnectlog();
2547e6ace85SPeter Wemm 	connectlog();
25558f0484fSRodney W. Grimes 	if (send(LogFile, tbuf, cnt, 0) >= 0)
25658f0484fSRodney W. Grimes 		return;
25758f0484fSRodney W. Grimes 
25858f0484fSRodney W. Grimes 	/*
25994998878SDavid Malone 	 * Output the message to the console; try not to block
26094998878SDavid Malone 	 * as a blocking console should not stop other processes.
26194998878SDavid Malone 	 * Make sure the error reported is the one from the syslogd failure.
26258f0484fSRodney W. Grimes 	 */
26358f0484fSRodney W. Grimes 	if (LogStat & LOG_CONS &&
26494998878SDavid Malone 	    (fd = _open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) {
26511e67a9fSPeter Wemm 		struct iovec iov[2];
266b231cb39SDavid E. O'Brien 		struct iovec *v = iov;
26711e67a9fSPeter Wemm 
26811e67a9fSPeter Wemm 		p = strchr(tbuf, '>') + 1;
26911e67a9fSPeter Wemm 		v->iov_base = p;
27011e67a9fSPeter Wemm 		v->iov_len = cnt - (p - tbuf);
27111e67a9fSPeter Wemm 		++v;
27211e67a9fSPeter Wemm 		v->iov_base = "\r\n";
27311e67a9fSPeter Wemm 		v->iov_len = 2;
274d201fe46SDaniel Eischen 		(void)_writev(fd, iov, 2);
2759233c4d9SJason Evans 		(void)_close(fd);
27658f0484fSRodney W. Grimes 	}
27758f0484fSRodney W. Grimes }
2787e6ace85SPeter Wemm static void
2797e6ace85SPeter Wemm disconnectlog()
2807e6ace85SPeter Wemm {
2817e6ace85SPeter Wemm 	/*
2827e6ace85SPeter Wemm 	 * If the user closed the FD and opened another in the same slot,
2837e6ace85SPeter Wemm 	 * that's their problem.  They should close it before calling on
2847e6ace85SPeter Wemm 	 * system services.
2857e6ace85SPeter Wemm 	 */
2867e6ace85SPeter Wemm 	if (LogFile != -1) {
2879233c4d9SJason Evans 		_close(LogFile);
2887e6ace85SPeter Wemm 		LogFile = -1;
2897e6ace85SPeter Wemm 	}
2908d41a9efSBrian Somers 	connected = 0;			/* retry connect */
2917e6ace85SPeter Wemm }
2927e6ace85SPeter Wemm 
2937e6ace85SPeter Wemm static void
2947e6ace85SPeter Wemm connectlog()
2957e6ace85SPeter Wemm {
296d584948eSBrian Somers 	struct sockaddr_un SyslogAddr;	/* AF_UNIX address of local logger */
297cf49f439SJohn Polstra 
2987e6ace85SPeter Wemm 	if (LogFile == -1) {
299d201fe46SDaniel Eischen 		if ((LogFile = _socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
3007e6ace85SPeter Wemm 			return;
3019233c4d9SJason Evans 		(void)_fcntl(LogFile, F_SETFD, 1);
3027e6ace85SPeter Wemm 	}
3038d41a9efSBrian Somers 	if (LogFile != -1 && !connected) {
304d584948eSBrian Somers 		SyslogAddr.sun_len = sizeof(SyslogAddr);
305d584948eSBrian Somers 		SyslogAddr.sun_family = AF_UNIX;
306d584948eSBrian Somers 		(void)strncpy(SyslogAddr.sun_path, _PATH_LOG,
3070b3b961eSBrian Somers 		    sizeof SyslogAddr.sun_path);
308d201fe46SDaniel Eischen 		connected = _connect(LogFile, (struct sockaddr *)&SyslogAddr,
309cf49f439SJohn Polstra 			sizeof(SyslogAddr)) != -1;
310cf49f439SJohn Polstra 
3118d41a9efSBrian Somers 		if (!connected) {
312cf49f439SJohn Polstra 			/*
313cf49f439SJohn Polstra 			 * Try the old "/dev/log" path, for backward
314cf49f439SJohn Polstra 			 * compatibility.
315cf49f439SJohn Polstra 			 */
316d584948eSBrian Somers 			(void)strncpy(SyslogAddr.sun_path, _PATH_OLDLOG,
3170b3b961eSBrian Somers 			    sizeof SyslogAddr.sun_path);
318d201fe46SDaniel Eischen 			connected = _connect(LogFile,
319d584948eSBrian Somers 				(struct sockaddr *)&SyslogAddr,
320cf49f439SJohn Polstra 				sizeof(SyslogAddr)) != -1;
321cf49f439SJohn Polstra 		}
322cf49f439SJohn Polstra 
3238d41a9efSBrian Somers 		if (!connected) {
3249233c4d9SJason Evans 			(void)_close(LogFile);
3257e6ace85SPeter Wemm 			LogFile = -1;
326cf49f439SJohn Polstra 		}
3277e6ace85SPeter Wemm 	}
3287e6ace85SPeter Wemm }
3297e6ace85SPeter Wemm 
33058f0484fSRodney W. Grimes void
33158f0484fSRodney W. Grimes openlog(ident, logstat, logfac)
33258f0484fSRodney W. Grimes 	const char *ident;
33358f0484fSRodney W. Grimes 	int logstat, logfac;
33458f0484fSRodney W. Grimes {
33558f0484fSRodney W. Grimes 	if (ident != NULL)
33658f0484fSRodney W. Grimes 		LogTag = ident;
33758f0484fSRodney W. Grimes 	LogStat = logstat;
33858f0484fSRodney W. Grimes 	if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
33958f0484fSRodney W. Grimes 		LogFacility = logfac;
34058f0484fSRodney W. Grimes 
3417e6ace85SPeter Wemm 	if (LogStat & LOG_NDELAY)	/* open immediately */
3427e6ace85SPeter Wemm 		connectlog();
3437e6ace85SPeter Wemm 
3447e6ace85SPeter Wemm 	opened = 1;	/* ident and facility has been set */
34558f0484fSRodney W. Grimes }
34658f0484fSRodney W. Grimes 
34758f0484fSRodney W. Grimes void
34858f0484fSRodney W. Grimes closelog()
34958f0484fSRodney W. Grimes {
3509233c4d9SJason Evans 	(void)_close(LogFile);
35158f0484fSRodney W. Grimes 	LogFile = -1;
352bedff4e8SRuslan Ermilov 	LogTag = NULL;
3538d41a9efSBrian Somers 	connected = 0;
35458f0484fSRodney W. Grimes }
35558f0484fSRodney W. Grimes 
35658f0484fSRodney W. Grimes /* setlogmask -- set the log mask level */
35758f0484fSRodney W. Grimes int
35858f0484fSRodney W. Grimes setlogmask(pmask)
35958f0484fSRodney W. Grimes 	int pmask;
36058f0484fSRodney W. Grimes {
36158f0484fSRodney W. Grimes 	int omask;
36258f0484fSRodney W. Grimes 
36358f0484fSRodney W. Grimes 	omask = LogMask;
36458f0484fSRodney W. Grimes 	if (pmask != 0)
36558f0484fSRodney W. Grimes 		LogMask = pmask;
36658f0484fSRodney W. Grimes 	return (omask);
36758f0484fSRodney W. Grimes }
368