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