xref: /illumos-gate/usr/src/cmd/fm/modules/common/syslog-msgs/syslog.c (revision 3ca4d65123c517bcba59dbc2e8a0d5f327972c51)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e1c679faSaf  * Common Development and Distribution License (the "License").
6e1c679faSaf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21b6955755SRobert Johnston 
227c478bd9Sstevel@tonic-gate /*
23cbf75e67SStephen Hanson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h>
287c478bd9Sstevel@tonic-gate #include <sys/strlog.h>
29072c378dSmb #include <sys/log.h>
30b6955755SRobert Johnston 
317c478bd9Sstevel@tonic-gate #include <fm/fmd_api.h>
32e1c679faSaf #include <fm/fmd_msg.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <stropts.h>
357c478bd9Sstevel@tonic-gate #include <strings.h>
36b6955755SRobert Johnston #include <syslog.h>
377c478bd9Sstevel@tonic-gate #include <alloca.h>
38b6955755SRobert Johnston #include <unistd.h>
39b6955755SRobert Johnston #include <stdlib.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <fcntl.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate static struct stats {
447c478bd9Sstevel@tonic-gate 	fmd_stat_t bad_vers;
457c478bd9Sstevel@tonic-gate 	fmd_stat_t bad_code;
467c478bd9Sstevel@tonic-gate 	fmd_stat_t log_err;
477c478bd9Sstevel@tonic-gate 	fmd_stat_t msg_err;
487c478bd9Sstevel@tonic-gate 	fmd_stat_t no_msg;
497c478bd9Sstevel@tonic-gate } syslog_stats = {
507c478bd9Sstevel@tonic-gate 	{ "bad_vers", FMD_TYPE_UINT64, "event version is missing or invalid" },
517c478bd9Sstevel@tonic-gate 	{ "bad_code", FMD_TYPE_UINT64, "event code has no dictionary name" },
527c478bd9Sstevel@tonic-gate 	{ "log_err", FMD_TYPE_UINT64, "failed to log message to log(7D)" },
537c478bd9Sstevel@tonic-gate 	{ "msg_err", FMD_TYPE_UINT64, "failed to log message to sysmsg(7D)" },
547c478bd9Sstevel@tonic-gate 	{ "no_msg", FMD_TYPE_UINT64, "message logging suppressed" }
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate static const struct facility {
587c478bd9Sstevel@tonic-gate 	const char *fac_name;
597c478bd9Sstevel@tonic-gate 	int fac_value;
607c478bd9Sstevel@tonic-gate } syslog_facs[] = {
617c478bd9Sstevel@tonic-gate 	{ "LOG_DAEMON", LOG_DAEMON },
627c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL0", LOG_LOCAL0 },
637c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL1", LOG_LOCAL1 },
647c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL2", LOG_LOCAL2 },
657c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL3", LOG_LOCAL3 },
667c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL4", LOG_LOCAL4 },
677c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL5", LOG_LOCAL5 },
687c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL6", LOG_LOCAL6 },
697c478bd9Sstevel@tonic-gate 	{ "LOG_LOCAL7", LOG_LOCAL7 },
707c478bd9Sstevel@tonic-gate 	{ NULL, 0 }
717c478bd9Sstevel@tonic-gate };
727c478bd9Sstevel@tonic-gate 
73b6955755SRobert Johnston static fmd_msg_hdl_t *syslog_msghdl; /* handle for libfmd_msg calls */
747c478bd9Sstevel@tonic-gate static int syslog_msgall;	/* set to message all faults */
757c478bd9Sstevel@tonic-gate static log_ctl_t syslog_ctl;	/* log(7D) meta-data for each msg */
767c478bd9Sstevel@tonic-gate static int syslog_logfd = -1;	/* log(7D) file descriptor */
777c478bd9Sstevel@tonic-gate static int syslog_msgfd = -1;	/* sysmsg(7D) file descriptor */
787c478bd9Sstevel@tonic-gate static int syslog_file;		/* log to syslog_logfd */
797c478bd9Sstevel@tonic-gate static int syslog_cons;		/* log to syslog_msgfd */
80b6955755SRobert Johnston static const char SYSLOG_POINTER[] = "syslog-msgs-pointer";
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Ideally we would just use syslog(3C) for outputting our messages, but our
847c478bd9Sstevel@tonic-gate  * messaging standard defines a nice multi-line format and syslogd(1M) is very
857c478bd9Sstevel@tonic-gate  * inflexible and stupid when it comes to multi-line messages.  It pulls data
867c478bd9Sstevel@tonic-gate  * out of log(7D) and splits it up by \n, printing each line to the console
877c478bd9Sstevel@tonic-gate  * with its usual prefix of date and sender; it uses the same behavior for the
887c478bd9Sstevel@tonic-gate  * messages file as well.  Further, syslog(3C) provides no CE_CONT equivalent
897c478bd9Sstevel@tonic-gate  * for userland callers (which at least works around repeated file prefixing).
907c478bd9Sstevel@tonic-gate  * So with a multi-line message format, your file and console end up like this:
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * Dec 02 18:08:40 hostname this is my nicely formatted
937c478bd9Sstevel@tonic-gate  * Dec 02 18:08:40 hostname message designed for 80 cols
947c478bd9Sstevel@tonic-gate  * ...
957c478bd9Sstevel@tonic-gate  *
967c478bd9Sstevel@tonic-gate  * To resolve these issues, we use our own syslog_emit() wrapper to emit
977c478bd9Sstevel@tonic-gate  * messages and some knowledge of how the Solaris log drivers work.  We first
987c478bd9Sstevel@tonic-gate  * construct an enlarged format string containing the appropriate msgid(1).
997c478bd9Sstevel@tonic-gate  * We then format the caller's message using the provided format and buffer.
1007c478bd9Sstevel@tonic-gate  * We send this message to log(7D) using putmsg() with SL_CONSOLE | SL_LOGONLY
1017c478bd9Sstevel@tonic-gate  * set in the log_ctl_t.  The log driver allows us to set SL_LOGONLY when we
1027c478bd9Sstevel@tonic-gate  * construct messages ourself, indicating that syslogd should only emit the
1037c478bd9Sstevel@tonic-gate  * message to /var/adm/messages and any remote hosts, and skip the console.
1047c478bd9Sstevel@tonic-gate  * Then we emit the message a second time, without the special prefix, to the
1057c478bd9Sstevel@tonic-gate  * sysmsg(7D) device, which handles console redirection and also permits us
1067c478bd9Sstevel@tonic-gate  * to output any characters we like to the console, including \n and \r.
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate static void
109b6955755SRobert Johnston syslog_emit(fmd_hdl_t *hdl, const char *msg)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	struct strbuf ctl, dat;
1127c478bd9Sstevel@tonic-gate 	uint32_t msgid;
1137c478bd9Sstevel@tonic-gate 
114b6955755SRobert Johnston 	char *buf;
115b6955755SRobert Johnston 	size_t buflen;
1167c478bd9Sstevel@tonic-gate 
117b6955755SRobert Johnston 	const char *format = "fmd: [ID %u FACILITY_AND_PRIORITY] %s";
118b6955755SRobert Johnston 	STRLOG_MAKE_MSGID(format, msgid);
1197c478bd9Sstevel@tonic-gate 
120b6955755SRobert Johnston 	buflen = snprintf(NULL, 0, format, msgid, msg);
121b6955755SRobert Johnston 	buf = alloca(buflen + 1);
122b6955755SRobert Johnston 	(void) snprintf(buf, buflen + 1, format, msgid, msg);
12378432d5eScy 
1247c478bd9Sstevel@tonic-gate 	ctl.buf = (void *)&syslog_ctl;
1257c478bd9Sstevel@tonic-gate 	ctl.len = sizeof (syslog_ctl);
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	dat.buf = buf;
128b6955755SRobert Johnston 	dat.len = buflen + 1;
129072c378dSmb 
130072c378dSmb 	/*
131b6955755SRobert Johnston 	 * The underlying log driver won't accept messages longer than
132b6955755SRobert Johnston 	 * LOG_MAXPS bytes.  Therefore, messages which exceed this limit will
133b6955755SRobert Johnston 	 * be truncated and appended with a pointer to the full message.
134072c378dSmb 	 */
135b6955755SRobert Johnston 	if (dat.len > LOG_MAXPS) {
136b6955755SRobert Johnston 		char *syslog_pointer, *p;
137b6955755SRobert Johnston 		size_t plen;
138b6955755SRobert Johnston 
139b6955755SRobert Johnston 		if ((syslog_pointer = fmd_msg_gettext_id(syslog_msghdl, NULL,
140b6955755SRobert Johnston 		    SYSLOG_POINTER)) == NULL) {
141b6955755SRobert Johnston 			/*
142b6955755SRobert Johnston 			 * This shouldn't happen, but if it does we'll just
143b6955755SRobert Johnston 			 * truncate the message.
144b6955755SRobert Johnston 			 */
145b6955755SRobert Johnston 			buf[LOG_MAXPS - 1] = '\0';
146b6955755SRobert Johnston 			dat.len = LOG_MAXPS;
147b6955755SRobert Johnston 		} else {
148b6955755SRobert Johnston 			plen = strlen(syslog_pointer) + 1;
149b6955755SRobert Johnston 			buf[LOG_MAXPS - plen] = '\0';
150b6955755SRobert Johnston 			/*
151b6955755SRobert Johnston 			 * If possible, the pointer is appended after a newline
152b6955755SRobert Johnston 			 */
153b6955755SRobert Johnston 			if ((p = strrchr(buf, '\n')) == NULL)
154b6955755SRobert Johnston 				p = &buf[LOG_MAXPS - plen];
155b6955755SRobert Johnston 
156b6955755SRobert Johnston 			(void) strcpy(p, syslog_pointer);
157b6955755SRobert Johnston 			free(syslog_pointer);
158b6955755SRobert Johnston 			dat.len = strlen(buf) + 1;
159b6955755SRobert Johnston 		}
16019e1255fScy 	}
1617c478bd9Sstevel@tonic-gate 	if (syslog_file && putmsg(syslog_logfd, &ctl, &dat, 0) != 0) {
1627c478bd9Sstevel@tonic-gate 		fmd_hdl_debug(hdl, "putmsg failed: %s\n", strerror(errno));
1637c478bd9Sstevel@tonic-gate 		syslog_stats.log_err.fmds_value.ui64++;
1647c478bd9Sstevel@tonic-gate 	}
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	dat.buf = strchr(buf, ']');
167b6955755SRobert Johnston 	dat.len -= (size_t)(dat.buf - buf);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	dat.buf[0] = '\r'; /* overwrite ']' with carriage return */
1707c478bd9Sstevel@tonic-gate 	dat.buf[1] = '\n'; /* overwrite ' ' with newline */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	if (syslog_cons && write(syslog_msgfd, dat.buf, dat.len) != dat.len) {
1737c478bd9Sstevel@tonic-gate 		fmd_hdl_debug(hdl, "write failed: %s\n", strerror(errno));
1747c478bd9Sstevel@tonic-gate 		syslog_stats.msg_err.fmds_value.ui64++;
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1797c478bd9Sstevel@tonic-gate static void
1807c478bd9Sstevel@tonic-gate syslog_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	uint8_t version;
183b6955755SRobert Johnston 	boolean_t domsg;
184b6955755SRobert Johnston 	char *msg;
185cbf75e67SStephen Hanson 
1867c478bd9Sstevel@tonic-gate 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
1877c478bd9Sstevel@tonic-gate 	    version > FM_SUSPECT_VERSION) {
1887c478bd9Sstevel@tonic-gate 		fmd_hdl_debug(hdl, "invalid event version: %u\n", version);
1897c478bd9Sstevel@tonic-gate 		syslog_stats.bad_vers.fmds_value.ui64++;
1907c478bd9Sstevel@tonic-gate 		return; /* invalid event version */
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	if (!syslog_msgall && nvlist_lookup_boolean_value(nvl,
1947c478bd9Sstevel@tonic-gate 	    FM_SUSPECT_MESSAGE, &domsg) == 0 && !domsg) {
1957c478bd9Sstevel@tonic-gate 		fmd_hdl_debug(hdl, "%s requested no message\n", class);
1967c478bd9Sstevel@tonic-gate 		syslog_stats.no_msg.fmds_value.ui64++;
1977c478bd9Sstevel@tonic-gate 		return; /* event is not to be messaged */
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 
200b6955755SRobert Johnston 	if ((msg = fmd_msg_gettext_nv(syslog_msghdl, NULL, nvl)) == NULL) {
201b6955755SRobert Johnston 		fmd_hdl_debug(hdl, "failed to format message");
2027c478bd9Sstevel@tonic-gate 		syslog_stats.bad_code.fmds_value.ui64++;
203b6955755SRobert Johnston 		return; /* libfmd_msg error */
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
206*3ca4d651SRobert Johnston 	syslog_ctl.pri &= LOG_FACMASK;
207*3ca4d651SRobert Johnston 	if (strcmp(class, FM_LIST_RESOLVED_CLASS) == 0 ||
208*3ca4d651SRobert Johnston 	    strcmp(class, FM_LIST_REPAIRED_CLASS) == 0)
209*3ca4d651SRobert Johnston 		syslog_ctl.pri |= LOG_NOTICE;
210*3ca4d651SRobert Johnston 	else
211*3ca4d651SRobert Johnston 		syslog_ctl.pri |= LOG_ERR;
212*3ca4d651SRobert Johnston 
213b6955755SRobert Johnston 	syslog_emit(hdl, msg);
214b6955755SRobert Johnston 	free(msg);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate static const fmd_prop_t fmd_props[] = {
2187c478bd9Sstevel@tonic-gate 	{ "console", FMD_TYPE_BOOL, "true" },
2197c478bd9Sstevel@tonic-gate 	{ "facility", FMD_TYPE_STRING, "LOG_DAEMON" },
2207c478bd9Sstevel@tonic-gate 	{ "gmt", FMD_TYPE_BOOL, "false" },
2217c478bd9Sstevel@tonic-gate 	{ "syslogd", FMD_TYPE_BOOL, "true" },
2227c478bd9Sstevel@tonic-gate 	{ "url", FMD_TYPE_STRING, "http://sun.com/msg/" },
2237c478bd9Sstevel@tonic-gate 	{ "message_all", FMD_TYPE_BOOL, "false" },
2247c478bd9Sstevel@tonic-gate 	{ NULL, 0, NULL }
2257c478bd9Sstevel@tonic-gate };
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate static const fmd_hdl_ops_t fmd_ops = {
2287c478bd9Sstevel@tonic-gate 	syslog_recv,	/* fmdo_recv */
2297c478bd9Sstevel@tonic-gate 	NULL,		/* fmdo_timeout */
2307c478bd9Sstevel@tonic-gate 	NULL,		/* fmdo_close */
2317c478bd9Sstevel@tonic-gate 	NULL,		/* fmdo_stats */
2327c478bd9Sstevel@tonic-gate 	NULL,		/* fmdo_gc */
2337c478bd9Sstevel@tonic-gate };
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate static const fmd_hdl_info_t fmd_info = {
2367c478bd9Sstevel@tonic-gate 	"Syslog Messaging Agent", "1.0", &fmd_ops, fmd_props
2377c478bd9Sstevel@tonic-gate };
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate void
2407c478bd9Sstevel@tonic-gate _fmd_init(fmd_hdl_t *hdl)
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 	const struct facility *fp;
243b6955755SRobert Johnston 	char *facname, *tz, *rootdir, *urlbase;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
2467c478bd9Sstevel@tonic-gate 		return; /* invalid data in configuration file */
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, sizeof (syslog_stats) /
2497c478bd9Sstevel@tonic-gate 	    sizeof (fmd_stat_t), (fmd_stat_t *)&syslog_stats);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if ((syslog_logfd = open("/dev/conslog", O_WRONLY | O_NOCTTY)) == -1)
2527c478bd9Sstevel@tonic-gate 		fmd_hdl_abort(hdl, "syslog-msgs failed to open /dev/conslog");
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if ((syslog_msgfd = open("/dev/sysmsg", O_WRONLY | O_NOCTTY)) == -1)
2557c478bd9Sstevel@tonic-gate 		fmd_hdl_abort(hdl, "syslog-msgs failed to open /dev/sysmsg");
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	/*
2587c478bd9Sstevel@tonic-gate 	 * If the "gmt" property is set to true, force our EVENT-TIME to be
2597c478bd9Sstevel@tonic-gate 	 * reported in GMT time; otherwise we use localtime.  tzset() affects
2607c478bd9Sstevel@tonic-gate 	 * the results of subsequent calls to strftime(3C) above.
2617c478bd9Sstevel@tonic-gate 	 */
2627c478bd9Sstevel@tonic-gate 	if (fmd_prop_get_int32(hdl, "gmt") == FMD_B_TRUE &&
2637c478bd9Sstevel@tonic-gate 	    ((tz = getenv("TZ")) == NULL || strcmp(tz, "GMT") != 0)) {
2647c478bd9Sstevel@tonic-gate 		(void) putenv(fmd_hdl_strdup(hdl, "TZ=GMT", FMD_SLEEP));
2657c478bd9Sstevel@tonic-gate 		tzset(); /* reload env */
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	/*
2697c478bd9Sstevel@tonic-gate 	 * Look up the value of the "facility" property and use it to determine
2707c478bd9Sstevel@tonic-gate 	 * what syslog LOG_* facility value we use to fill in our log_ctl_t.
2717c478bd9Sstevel@tonic-gate 	 * The details of our logging method are described above syslog_emit().
2727c478bd9Sstevel@tonic-gate 	 */
2737c478bd9Sstevel@tonic-gate 	facname = fmd_prop_get_string(hdl, "facility");
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	for (fp = syslog_facs; fp->fac_name != NULL; fp++) {
2767c478bd9Sstevel@tonic-gate 		if (strcmp(fp->fac_name, facname) == 0)
2777c478bd9Sstevel@tonic-gate 			break;
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	if (fp->fac_name == NULL)
2817c478bd9Sstevel@tonic-gate 		fmd_hdl_abort(hdl, "invalid 'facility' setting: %s\n", facname);
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	fmd_prop_free_string(hdl, facname);
284627351e3Scy 	syslog_ctl.pri = fp->fac_value;
2857c478bd9Sstevel@tonic-gate 	syslog_ctl.flags = SL_CONSOLE | SL_LOGONLY;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/*
2887c478bd9Sstevel@tonic-gate 	 * Cache any properties we use every time we receive an event and
2897c478bd9Sstevel@tonic-gate 	 * subscribe to list.suspect events regardless of the .conf file.
2907c478bd9Sstevel@tonic-gate 	 */
2917c478bd9Sstevel@tonic-gate 	syslog_file = fmd_prop_get_int32(hdl, "syslogd");
2927c478bd9Sstevel@tonic-gate 	syslog_cons = fmd_prop_get_int32(hdl, "console");
2937c478bd9Sstevel@tonic-gate 	syslog_msgall = fmd_prop_get_int32(hdl, "message_all");
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	rootdir = fmd_prop_get_string(hdl, "fmd.rootdir");
296b6955755SRobert Johnston 	syslog_msghdl = fmd_msg_init(rootdir, FMD_MSG_VERSION);
297b6955755SRobert Johnston 	fmd_prop_free_string(hdl, rootdir);
2987c478bd9Sstevel@tonic-gate 
299b6955755SRobert Johnston 	if (syslog_msghdl == NULL)
300b6955755SRobert Johnston 		fmd_hdl_abort(hdl, "failed to initialize libfmd_msg");
301b6955755SRobert Johnston 
302b6955755SRobert Johnston 	urlbase = fmd_prop_get_string(hdl, "url");
303b6955755SRobert Johnston 	(void) fmd_msg_url_set(syslog_msghdl, urlbase);
304b6955755SRobert Johnston 	fmd_prop_free_string(hdl, urlbase);
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	fmd_hdl_subscribe(hdl, FM_LIST_SUSPECT_CLASS);
307627351e3Scy 	fmd_hdl_subscribe(hdl, FM_LIST_REPAIRED_CLASS);
30825c6ff4bSstephh 	fmd_hdl_subscribe(hdl, FM_LIST_RESOLVED_CLASS);
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate 
311b6955755SRobert Johnston /*ARGSUSED*/
3127c478bd9Sstevel@tonic-gate void
3137c478bd9Sstevel@tonic-gate _fmd_fini(fmd_hdl_t *hdl)
3147c478bd9Sstevel@tonic-gate {
315b6955755SRobert Johnston 	fmd_msg_fini(syslog_msghdl);
3167c478bd9Sstevel@tonic-gate 	(void) close(syslog_logfd);
3177c478bd9Sstevel@tonic-gate 	(void) close(syslog_msgfd);
3187c478bd9Sstevel@tonic-gate }
319