syslog.c revision 9120:fe1f7d8cd967
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/fm/protocol.h>
27#include <sys/strlog.h>
28#include <sys/log.h>
29#include <fm/fmd_api.h>
30#include <fm/fmd_msg.h>
31
32#include <stropts.h>
33#include <syslog.h>
34#include <locale.h>
35#include <strings.h>
36#include <stdlib.h>
37#include <unistd.h>
38#include <limits.h>
39#include <alloca.h>
40#include <errno.h>
41#include <fcntl.h>
42#include <time.h>
43
44/*
45 * SYSLOG_DOMAIN and SYSLOG_TEMPLATE define the dgettext() parameters the agent
46 * can use to retrieve the localized format string for diagnosis messages.
47 * The format string retrieved from SYSLOG_DOMAIN is the default format
48 * string, but when processing each suspect list, dgettext() is also called
49 * for the domain that matches the diagcode dictname and if SYSLOG_TEMPLATE
50 * is defined, it overrides the default for that suspect list only.
51 *
52 * Similarly, SYSLOG_URL is also checked to see if syslog_url
53 * should be overridden for each suspect list.
54 *
55 * The net effect of all this is that for a given diagcode DICT-1234-56:
56 *
57 *	- If DICT.mo defines syslog-msgs-message-template, it is used
58 *	  as the format string for the diagnosis message.
59 *
60 *	- Otherwise, syslog-msgs-message-template from FMD.mo is used.
61 *
62 *	- If DICT.mo defines syslog-url, it is used when filling
63 *	  in the %s in the "description" message.
64 *
65 *	- Otherwise, if syslog-msgs.conf defines a "url" property, that
66 *	  value is used.
67 *
68 *	- Otherwise, the default "http://sun.com/msg/" is used (via the
69 *	  fmd_props[] table defined in this file).
70 */
71static const char SYSLOG_DOMAIN[] = "FMD";
72static const char SYSLOG_TEMPLATE[] = "syslog-msgs-message-template";
73static const char SYSLOG_URL[] = "syslog-url";
74static const char SYSLOG_POINTER[] = "syslog-msgs-pointer";
75
76static struct stats {
77	fmd_stat_t bad_vers;
78	fmd_stat_t bad_fmri;
79	fmd_stat_t bad_code;
80	fmd_stat_t bad_time;
81	fmd_stat_t log_err;
82	fmd_stat_t msg_err;
83	fmd_stat_t no_msg;
84} syslog_stats = {
85	{ "bad_vers", FMD_TYPE_UINT64, "event version is missing or invalid" },
86	{ "bad_fmri", FMD_TYPE_UINT64, "event fmri is missing or invalid" },
87	{ "bad_code", FMD_TYPE_UINT64, "event code has no dictionary name" },
88	{ "bad_time", FMD_TYPE_UINT64, "event time is not properly encoded" },
89	{ "log_err", FMD_TYPE_UINT64, "failed to log message to log(7D)" },
90	{ "msg_err", FMD_TYPE_UINT64, "failed to log message to sysmsg(7D)" },
91	{ "no_msg", FMD_TYPE_UINT64, "message logging suppressed" }
92};
93
94static const struct facility {
95	const char *fac_name;
96	int fac_value;
97} syslog_facs[] = {
98	{ "LOG_DAEMON", LOG_DAEMON },
99	{ "LOG_LOCAL0", LOG_LOCAL0 },
100	{ "LOG_LOCAL1", LOG_LOCAL1 },
101	{ "LOG_LOCAL2", LOG_LOCAL2 },
102	{ "LOG_LOCAL3", LOG_LOCAL3 },
103	{ "LOG_LOCAL4", LOG_LOCAL4 },
104	{ "LOG_LOCAL5", LOG_LOCAL5 },
105	{ "LOG_LOCAL6", LOG_LOCAL6 },
106	{ "LOG_LOCAL7", LOG_LOCAL7 },
107	{ NULL, 0 }
108};
109
110static char *syslog_locdir;	/* l10n messages directory (if alternate) */
111static char *syslog_url;	/* current value of "url" property */
112static char *syslog_pointer;	/* info to point user to the full message */
113static int syslog_msgall;	/* set to message all faults */
114static log_ctl_t syslog_ctl;	/* log(7D) meta-data for each msg */
115static int syslog_logfd = -1;	/* log(7D) file descriptor */
116static int syslog_msgfd = -1;	/* sysmsg(7D) file descriptor */
117static int syslog_file;		/* log to syslog_logfd */
118static int syslog_cons;		/* log to syslog_msgfd */
119
120/*
121 * Ideally we would just use syslog(3C) for outputting our messages, but our
122 * messaging standard defines a nice multi-line format and syslogd(1M) is very
123 * inflexible and stupid when it comes to multi-line messages.  It pulls data
124 * out of log(7D) and splits it up by \n, printing each line to the console
125 * with its usual prefix of date and sender; it uses the same behavior for the
126 * messages file as well.  Further, syslog(3C) provides no CE_CONT equivalent
127 * for userland callers (which at least works around repeated file prefixing).
128 * So with a multi-line message format, your file and console end up like this:
129 *
130 * Dec 02 18:08:40 hostname this is my nicely formatted
131 * Dec 02 18:08:40 hostname message designed for 80 cols
132 * ...
133 *
134 * To resolve these issues, we use our own syslog_emit() wrapper to emit
135 * messages and some knowledge of how the Solaris log drivers work.  We first
136 * construct an enlarged format string containing the appropriate msgid(1).
137 * We then format the caller's message using the provided format and buffer.
138 * We send this message to log(7D) using putmsg() with SL_CONSOLE | SL_LOGONLY
139 * set in the log_ctl_t.  The log driver allows us to set SL_LOGONLY when we
140 * construct messages ourself, indicating that syslogd should only emit the
141 * message to /var/adm/messages and any remote hosts, and skip the console.
142 * Note: the log driver packet size limit for output via putmsg is LOGMAX_PS.
143 * Then we emit the message a second time, without the special prefix, to the
144 * sysmsg(7D) device, which handles console redirection and also permits us
145 * to output any characters we like to the console, including \n and \r.
146 */
147/*PRINTFLIKE2*/
148static void
149syslog_emit(fmd_hdl_t *hdl, const char *msgformat, ...)
150{
151	struct strbuf ctl, dat;
152	uint32_t msgid;
153
154	char *format, *p, c;
155	char *buf = NULL;
156	size_t formatlen, logmsglen;
157	int len, plen;
158	va_list ap;
159
160	formatlen = strlen(msgformat) + 64; /* +64 for prefix and \0 */
161	format = alloca(formatlen);
162
163	STRLOG_MAKE_MSGID(msgformat, msgid);
164	(void) snprintf(format, formatlen,
165	    "fmd: [ID %u FACILITY_AND_PRIORITY] %s", msgid, msgformat);
166
167	/*
168	 * Figure out the length of the message then allocate a buffer
169	 * of adequate size.
170	 */
171	va_start(ap, msgformat);
172	if ((len = vsnprintf(&c, 1, format, ap)) >= 0 &&
173	    (buf = fmd_hdl_alloc(hdl, len + 1, FMD_SLEEP)) != NULL)
174		(void) vsnprintf(buf, len + 1, format, ap);
175	va_end(ap);
176
177	if (buf == NULL)
178		return;
179
180	ctl.buf = (void *)&syslog_ctl;
181	ctl.len = sizeof (syslog_ctl);
182
183	dat.buf = buf;
184	logmsglen = strlen(buf) + 1;
185
186	/*
187	 * The underlying log driver won't accept (ERANGE) messages
188	 * longer than LOG_MAXPS bytes.  The long message will be truncated
189	 * and appended with a pointer to the full message.
190	 */
191	if (logmsglen <= LOG_MAXPS) {
192		dat.len = logmsglen;
193	} else {
194		plen = strlen(syslog_pointer) + 1;
195		buf[LOG_MAXPS - plen] = '\0';
196		/*
197		 * If possible, the pointer is appended after a newline
198		 */
199		if ((p = strrchr(buf, '\n')) == NULL)
200			p = &buf[LOG_MAXPS - plen];
201
202		(void) strcpy(p, syslog_pointer);
203		dat.len = strlen(buf) + 1;
204	}
205
206	if (syslog_file && putmsg(syslog_logfd, &ctl, &dat, 0) != 0) {
207		fmd_hdl_debug(hdl, "putmsg failed: %s\n", strerror(errno));
208		syslog_stats.log_err.fmds_value.ui64++;
209	}
210
211	dat.buf = strchr(buf, ']');
212	dat.len = (size_t)(logmsglen - (dat.buf - buf));
213
214	dat.buf[0] = '\r'; /* overwrite ']' with carriage return */
215	dat.buf[1] = '\n'; /* overwrite ' ' with newline */
216
217	if (syslog_cons && write(syslog_msgfd, dat.buf, dat.len) != dat.len) {
218		fmd_hdl_debug(hdl, "write failed: %s\n", strerror(errno));
219		syslog_stats.msg_err.fmds_value.ui64++;
220	}
221
222	fmd_hdl_free(hdl, buf, len + 1);
223}
224
225/*ARGSUSED*/
226static void
227syslog_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
228{
229	char *uuid, *code, *dict, *url, *urlcode, *template, *p;
230	char *src_name, *src_vers, *platform, *chassis, *server;
231	char *typ, *sev, *fmt, *trfmt, *rsp, *imp, *act, *locdir;
232	char desc[1024], date[64];
233	boolean_t domsg;
234
235	nvlist_t *fmri, *auth;
236	uint8_t version;
237	struct tm tm, *tmp;
238	int64_t *tv;
239	time_t sec;
240	uint_t tn = 0;
241	char *olang = NULL;
242	int locale_c = 0;
243	size_t len;
244
245	/*
246	 * don't log updated and isolated events (for now)
247	 */
248	if (strcmp(class, FM_LIST_ISOLATED_CLASS) == 0 ||
249	    strcmp(class, FM_LIST_UPDATED_CLASS) == 0)
250		return;
251
252	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
253	    version > FM_SUSPECT_VERSION) {
254		fmd_hdl_debug(hdl, "invalid event version: %u\n", version);
255		syslog_stats.bad_vers.fmds_value.ui64++;
256		return; /* invalid event version */
257	}
258
259	if (!syslog_msgall && nvlist_lookup_boolean_value(nvl,
260	    FM_SUSPECT_MESSAGE, &domsg) == 0 && !domsg) {
261		fmd_hdl_debug(hdl, "%s requested no message\n", class);
262		syslog_stats.no_msg.fmds_value.ui64++;
263		return; /* event is not to be messaged */
264	}
265
266	/*
267	 * Extract the DE element, which is an FMRI for the diagnosis engine
268	 * that made this event, and validate its meta-data before continuing.
269	 */
270	if (nvlist_lookup_nvlist(nvl, FM_SUSPECT_DE, &fmri) != 0 ||
271	    nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &p) != 0 ||
272	    strcmp(p, FM_FMRI_SCHEME_FMD) != 0 ||
273	    nvlist_lookup_uint8(fmri, FM_VERSION, &version) != 0 ||
274	    version > FM_FMD_SCHEME_VERSION ||
275	    nvlist_lookup_nvlist(fmri, FM_FMRI_AUTHORITY, &auth) != 0 ||
276	    nvlist_lookup_uint8(auth, FM_VERSION, &version) != 0 ||
277	    version > FM_FMRI_AUTH_VERSION) {
278		syslog_stats.bad_fmri.fmds_value.ui64++;
279		return; /* invalid de fmri */
280	}
281
282	/*
283	 * Extract the relevant identifying elements of the FMRI and authority.
284	 * Note: for now, we ignore FM_FMRI_AUTH_DOMAIN (only for SPs).
285	 */
286	(void) nvlist_lookup_string(fmri, FM_FMRI_FMD_NAME, &src_name);
287	(void) nvlist_lookup_string(fmri, FM_FMRI_FMD_VERSION, &src_vers);
288	(void) nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &platform);
289	(void) nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server);
290
291	if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &chassis) != 0)
292		chassis = "-"; /* chassis serial number may not be present */
293
294	/*
295	 * Extract the uuid and diagcode dictionary from the event code.  The
296	 * dictionary name is the text preceding the first "-" in the code.
297	 */
298	(void) nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid);
299	(void) nvlist_lookup_string(nvl, FM_SUSPECT_DIAG_CODE, &code);
300
301	if ((p = strchr(code, '-')) == NULL || p == code) {
302		fmd_hdl_debug(hdl, "invalid diagnosis code: %s\n", code);
303		syslog_stats.bad_code.fmds_value.ui64++;
304		return; /* invalid diagnosis code */
305	}
306
307	dict = alloca((size_t)(p - code) + 1);
308	(void) strncpy(dict, code, (size_t)(p - code));
309	dict[(size_t)(p - code)] = '\0';
310
311	/*
312	 * Alloca a hunk of memory and use it to create the msgid strings
313	 * <code>.type, <code>.severity, <code>.description, and so forth.
314	 * These form the msgids we will use to look up the localized text.
315	 * Since we've allocated things to be of the right size, we know
316	 * than snprintf() can't overflow: INT_MAX is used shut lint up and
317	 * avoid code to needlessly recompute the remaining buffer space.
318	 */
319	typ = alloca(6 * (strlen(code) + 16));
320	sev = typ + snprintf(typ, INT_MAX, "%s.type", code) + 1;
321	fmt = sev + snprintf(sev, INT_MAX, "%s.severity", code) + 1;
322	rsp = fmt + snprintf(fmt, INT_MAX, "%s.description", code) + 1;
323	imp = rsp + snprintf(rsp, INT_MAX, "%s.response", code) + 1;
324	act = imp + snprintf(imp, INT_MAX, "%s.impact", code) + 1;
325	(void) snprintf(act, INT_MAX, "%s.action", code);
326
327	fmd_msg_lock();
328
329	if (syslog_locdir != NULL)
330		locdir =  bindtextdomain(dict, syslog_locdir);
331
332	if ((trfmt = dgettext(dict, fmt)) == fmt) {
333		/*
334		 * We didn't find a translation in the dictionary for the
335		 * current language.  The string we passed to gettext is merely
336		 * an index - it isn't sufficient, on its own, to be used as the
337		 * message.  Fall back to C and try again.
338		 */
339		olang = setlocale(LC_MESSAGES, NULL);
340		if (olang) {
341			p = alloca(strlen(olang) + 1);
342			olang = strcpy(p, olang);
343		}
344		locale_c = 1;
345		(void) setlocale(LC_MESSAGES, "C");
346		trfmt = dgettext(dict, fmt);
347	}
348
349	if ((url = dgettext(dict, SYSLOG_URL)) == SYSLOG_URL)
350		url = syslog_url;
351
352	/*
353	 * If the URL ends with a slash, that indicates the code should be
354	 * appended to it.  After formatting the URL, reformat the DESC
355	 * text using the URL as an snprintf argument.
356	 */
357	len = strlen(url);
358	if (url[len - 1] == '/') {
359		urlcode = alloca(len + strlen(code) + 1);
360		(void) snprintf(urlcode, INT_MAX, "%s%s", url, code);
361	} else {
362		urlcode = url;
363	}
364	/* LINTED - variable format specifier to snprintf() */
365	(void) snprintf(desc, sizeof (desc), trfmt, urlcode);
366
367	/*
368	 * Extract the diagnosis time and format it using the locale's default.
369	 * strftime() will use GMT or local time based on our "gmt" setting.
370	 */
371	if (nvlist_lookup_int64_array(nvl, FM_SUSPECT_DIAG_TIME,
372	    &tv, &tn) == 0 && tn == 2 && (sec = (time_t)tv[0]) != (time_t)-1 &&
373	    (tmp = localtime_r(&sec, &tm)) != NULL)
374		(void) strftime(date, sizeof (date), "%C", tmp);
375	else {
376		syslog_stats.bad_time.fmds_value.ui64++;
377		(void) strcpy(date, "-");
378	}
379
380	/*
381	 * Create and log the final string by filling in the template with the
382	 * strings we've created and the strings from the message dictionary.
383	 * If a template is provided for this dictionary, use it, otherwise
384	 * fall back to the default template.
385	 */
386	if ((template = dgettext(dict, SYSLOG_TEMPLATE)) == SYSLOG_TEMPLATE)
387		template = dgettext(SYSLOG_DOMAIN, SYSLOG_TEMPLATE);
388	/*
389	 * Do samely for the message pointer.  If the message is too long
390	 * to be handled by the underlying log drvier, the message will be
391	 * truncated and the pointer will be added to point user to the
392	 * full message.
393	 */
394	if ((syslog_pointer = dgettext(dict, SYSLOG_POINTER)) == SYSLOG_POINTER)
395		syslog_pointer = dgettext(SYSLOG_DOMAIN, SYSLOG_POINTER);
396
397	syslog_ctl.pri &= LOG_FACMASK;
398	if (strcmp(class, FM_LIST_RESOLVED_CLASS) == 0 ||
399	    strcmp(class, FM_LIST_REPAIRED_CLASS) == 0)
400		syslog_ctl.pri |= LOG_NOTICE;
401	else
402		syslog_ctl.pri |= LOG_ERR;
403	syslog_emit(hdl, template, code, dgettext(dict, typ),
404	    dgettext(dict, sev), date, platform, chassis, server, src_name,
405	    src_vers, uuid, desc, dgettext(dict, rsp), dgettext(dict, imp),
406	    dgettext(dict, act));
407
408	/*
409	 * Switch back to our original language if we had to fall back to C.
410	 */
411	if (olang != NULL)
412		(void) setlocale(LC_MESSAGES, olang);
413
414	if (syslog_locdir != NULL)
415		(void) bindtextdomain(dict, locdir);
416
417	fmd_msg_unlock();
418
419	if (locale_c) {
420		fmd_hdl_debug(hdl,
421		    trfmt == fmt ?
422		    "dgettext(%s, %s) in %s and C failed\n" :
423		    "dgettext(%s, %s) in %s failed; C used\n",
424		    dict, fmt, olang ? olang : "<null>");
425	}
426}
427
428static const fmd_prop_t fmd_props[] = {
429	{ "console", FMD_TYPE_BOOL, "true" },
430	{ "facility", FMD_TYPE_STRING, "LOG_DAEMON" },
431	{ "gmt", FMD_TYPE_BOOL, "false" },
432	{ "syslogd", FMD_TYPE_BOOL, "true" },
433	{ "url", FMD_TYPE_STRING, "http://sun.com/msg/" },
434	{ "message_all", FMD_TYPE_BOOL, "false" },
435	{ NULL, 0, NULL }
436};
437
438static const fmd_hdl_ops_t fmd_ops = {
439	syslog_recv,	/* fmdo_recv */
440	NULL,		/* fmdo_timeout */
441	NULL,		/* fmdo_close */
442	NULL,		/* fmdo_stats */
443	NULL,		/* fmdo_gc */
444};
445
446static const fmd_hdl_info_t fmd_info = {
447	"Syslog Messaging Agent", "1.0", &fmd_ops, fmd_props
448};
449
450void
451_fmd_init(fmd_hdl_t *hdl)
452{
453	const struct facility *fp;
454	char *facname, *tz, *rootdir, *locdir, *locale, *p;
455
456	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
457		return; /* invalid data in configuration file */
458
459	(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, sizeof (syslog_stats) /
460	    sizeof (fmd_stat_t), (fmd_stat_t *)&syslog_stats);
461
462	if ((syslog_logfd = open("/dev/conslog", O_WRONLY | O_NOCTTY)) == -1)
463		fmd_hdl_abort(hdl, "syslog-msgs failed to open /dev/conslog");
464
465	if ((syslog_msgfd = open("/dev/sysmsg", O_WRONLY | O_NOCTTY)) == -1)
466		fmd_hdl_abort(hdl, "syslog-msgs failed to open /dev/sysmsg");
467
468	/*
469	 * All FMA event dictionaries use msgfmt(1) message objects to produce
470	 * messages, even for the C locale.  We therefore want to use dgettext
471	 * for all message lookups, but its defined behavior in the C locale is
472	 * to return the input string.  Since our input strings are event codes
473	 * and not format strings, this doesn't help us.  We resolve this nit
474	 * by setting NLSPATH to a non-existent file: the presence of NLSPATH
475	 * is defined to force dgettext(3C) to do a full lookup even for C.
476	 */
477	if (getenv("NLSPATH") == NULL && putenv(fmd_hdl_strdup(hdl,
478	    "NLSPATH=/usr/lib/fm/fmd/fmd.cat", FMD_SLEEP)) != 0)
479		fmd_hdl_abort(hdl, "syslog-msgs failed to set NLSPATH");
480
481	fmd_msg_lock();
482	(void) setlocale(LC_MESSAGES, "");
483	locale = setlocale(LC_MESSAGES, NULL);
484	if (locale) {
485		p = alloca(strlen(locale) + 1);
486		locale = strcpy(p, locale);
487	} else {
488		locale = "<null>";
489	}
490	fmd_msg_unlock();
491	fmd_hdl_debug(hdl, "locale=%s\n", locale);
492
493	/*
494	 * If the "gmt" property is set to true, force our EVENT-TIME to be
495	 * reported in GMT time; otherwise we use localtime.  tzset() affects
496	 * the results of subsequent calls to strftime(3C) above.
497	 */
498	if (fmd_prop_get_int32(hdl, "gmt") == FMD_B_TRUE &&
499	    ((tz = getenv("TZ")) == NULL || strcmp(tz, "GMT") != 0)) {
500		(void) putenv(fmd_hdl_strdup(hdl, "TZ=GMT", FMD_SLEEP));
501		tzset(); /* reload env */
502	}
503
504	/*
505	 * Look up the value of the "facility" property and use it to determine
506	 * what syslog LOG_* facility value we use to fill in our log_ctl_t.
507	 * The details of our logging method are described above syslog_emit().
508	 */
509	facname = fmd_prop_get_string(hdl, "facility");
510
511	for (fp = syslog_facs; fp->fac_name != NULL; fp++) {
512		if (strcmp(fp->fac_name, facname) == 0)
513			break;
514	}
515
516	if (fp->fac_name == NULL)
517		fmd_hdl_abort(hdl, "invalid 'facility' setting: %s\n", facname);
518
519	fmd_prop_free_string(hdl, facname);
520	syslog_ctl.pri = fp->fac_value;
521	syslog_ctl.flags = SL_CONSOLE | SL_LOGONLY;
522
523	/*
524	 * Cache any properties we use every time we receive an event and
525	 * subscribe to list.suspect events regardless of the .conf file.
526	 */
527	syslog_file = fmd_prop_get_int32(hdl, "syslogd");
528	syslog_cons = fmd_prop_get_int32(hdl, "console");
529	syslog_url = fmd_prop_get_string(hdl, "url");
530	syslog_msgall = fmd_prop_get_int32(hdl, "message_all");
531
532	/*
533	 * If fmd's rootdir property is set to a non-default root, then we are
534	 * going to need to rebind the text domains we use for dgettext() as
535	 * we go.  Look up the default l10n messages directory and make
536	 * syslog_locdir be this path with fmd.rootdir prepended to it.
537	 */
538	rootdir = fmd_prop_get_string(hdl, "fmd.rootdir");
539
540	if (*rootdir != '\0' && strcmp(rootdir, "/") != 0) {
541		fmd_msg_lock();
542		locdir = bindtextdomain(SYSLOG_DOMAIN, NULL);
543		fmd_msg_unlock();
544		if (locdir != NULL) {
545			size_t len = strlen(rootdir) + strlen(locdir) + 1;
546			syslog_locdir = fmd_hdl_alloc(hdl, len, FMD_SLEEP);
547			(void) snprintf(syslog_locdir, len, "%s%s", rootdir,
548			    locdir);
549			fmd_hdl_debug(hdl,
550			    "binding textdomain to %s for syslog\n",
551			    syslog_locdir);
552		}
553	}
554
555	fmd_prop_free_string(hdl, rootdir);
556	fmd_hdl_subscribe(hdl, FM_LIST_SUSPECT_CLASS);
557	fmd_hdl_subscribe(hdl, FM_LIST_UPDATED_CLASS);
558	fmd_hdl_subscribe(hdl, FM_LIST_ISOLATED_CLASS);
559	fmd_hdl_subscribe(hdl, FM_LIST_REPAIRED_CLASS);
560	fmd_hdl_subscribe(hdl, FM_LIST_RESOLVED_CLASS);
561}
562
563void
564_fmd_fini(fmd_hdl_t *hdl)
565{
566	fmd_hdl_strfree(hdl, syslog_locdir);
567	fmd_prop_free_string(hdl, syslog_url);
568
569	(void) close(syslog_logfd);
570	(void) close(syslog_msgfd);
571}
572