xref: /titanic_41/usr/src/cmd/smbsrv/fksmbd/fksmbd_log.c (revision 7206bf49b1fe641544165ee97f63856da95e0868)
1*7206bf49SGordon Ross /*
2*7206bf49SGordon Ross  * This file and its contents are supplied under the terms of the
3*7206bf49SGordon Ross  * Common Development and Distribution License ("CDDL"), version 1.0.
4*7206bf49SGordon Ross  * You may only use this file in accordance with the terms of version
5*7206bf49SGordon Ross  * 1.0 of the CDDL.
6*7206bf49SGordon Ross  *
7*7206bf49SGordon Ross  * A full copy of the text of the CDDL should have accompanied this
8*7206bf49SGordon Ross  * source.  A copy of the CDDL is also available via the Internet at
9*7206bf49SGordon Ross  * http://www.illumos.org/license/CDDL.
10*7206bf49SGordon Ross  */
11*7206bf49SGordon Ross 
12*7206bf49SGordon Ross /*
13*7206bf49SGordon Ross  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
14*7206bf49SGordon Ross  */
15*7206bf49SGordon Ross 
16*7206bf49SGordon Ross #include <stdio.h>
17*7206bf49SGordon Ross #include <stdarg.h>
18*7206bf49SGordon Ross #include <errno.h>
19*7206bf49SGordon Ross #include <string.h>
20*7206bf49SGordon Ross #include <syslog.h>
21*7206bf49SGordon Ross #include <sys/strlog.h>
22*7206bf49SGordon Ross 
23*7206bf49SGordon Ross #include <smbsrv/smbinfo.h>
24*7206bf49SGordon Ross #include <smbsrv/smb_ioctl.h>
25*7206bf49SGordon Ross #include "smbd.h"
26*7206bf49SGordon Ross 
27*7206bf49SGordon Ross #include <libfakekernel/fakekernel.h>
28*7206bf49SGordon Ross 
29*7206bf49SGordon Ross static const char *pri_name[LOG_DEBUG+1] = {
30*7206bf49SGordon Ross 	"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"
31*7206bf49SGordon Ross };
32*7206bf49SGordon Ross 
33*7206bf49SGordon Ross 
34*7206bf49SGordon Ross /*
35*7206bf49SGordon Ross  * Provide a replacement for libsmb:smb_vsyslog() that just
36*7206bf49SGordon Ross  * prints the messages to stdout for "fksmbd" debugging.
37*7206bf49SGordon Ross  */
38*7206bf49SGordon Ross void
smb_vsyslog(int pri,const char * fmt,va_list ap)39*7206bf49SGordon Ross smb_vsyslog(int pri, const char *fmt, va_list ap)
40*7206bf49SGordon Ross {
41*7206bf49SGordon Ross 	int save_errno = errno;
42*7206bf49SGordon Ross 	char buf[SMBD_LOG_MSGSIZE];
43*7206bf49SGordon Ross 	char *newfmt;
44*7206bf49SGordon Ross 
45*7206bf49SGordon Ross 	pri &= LOG_PRIMASK;
46*7206bf49SGordon Ross 
47*7206bf49SGordon Ross 	if (smbd.s_debug == 0 && pri > LOG_INFO)
48*7206bf49SGordon Ross 		return;
49*7206bf49SGordon Ross 
50*7206bf49SGordon Ross 	newfmt = smb_syslog_fmt_m(buf, sizeof (buf), fmt, save_errno);
51*7206bf49SGordon Ross 
52*7206bf49SGordon Ross 	flockfile(stdout);
53*7206bf49SGordon Ross 	(void) fprintf(stdout, "fksmbd.%s: ", pri_name[pri]);
54*7206bf49SGordon Ross 	/* LINTED E_SEC_PRINTF_VAR_FMT */
55*7206bf49SGordon Ross 	(void) vfprintf(stdout, newfmt, ap);
56*7206bf49SGordon Ross 	(void) fprintf(stdout, "\n");
57*7206bf49SGordon Ross 	funlockfile(stdout);
58*7206bf49SGordon Ross 
59*7206bf49SGordon Ross 	(void) fflush(stdout);
60*7206bf49SGordon Ross }
61*7206bf49SGordon Ross 
62*7206bf49SGordon Ross /*
63*7206bf49SGordon Ross  * Provide a real function (one that prints something) to replace
64*7206bf49SGordon Ross  * the stub in libfakekernel.  This prints cmn_err() messages.
65*7206bf49SGordon Ross  */
66*7206bf49SGordon Ross void
fakekernel_putlog(char * msg,size_t len,int flags)67*7206bf49SGordon Ross fakekernel_putlog(char *msg, size_t len, int flags)
68*7206bf49SGordon Ross {
69*7206bf49SGordon Ross 
70*7206bf49SGordon Ross 	/*
71*7206bf49SGordon Ross 	 * [CE_CONT, CE_NOTE, CE_WARN, CE_PANIC] maps to
72*7206bf49SGordon Ross 	 * [SL_NOTE, SL_NOTE, SL_WARN, SL_FATAL]
73*7206bf49SGordon Ross 	 */
74*7206bf49SGordon Ross 	if (smbd.s_debug == 0 && (flags & SL_NOTE))
75*7206bf49SGordon Ross 		return;
76*7206bf49SGordon Ross 	(void) fwrite(msg, 1, len, stdout);
77*7206bf49SGordon Ross 	(void) fflush(stdout);
78*7206bf49SGordon Ross }
79*7206bf49SGordon Ross 
80*7206bf49SGordon Ross /*
81*7206bf49SGordon Ross  * Initialization function called at the start of fksmbd:main().
82*7206bf49SGordon Ross  * Call an empty function in both of libfksmbsrv, libfakekernel,
83*7206bf49SGordon Ross  * just to force them to load so we can set breakpoints in them
84*7206bf49SGordon Ross  * without debugger forceload tricks.  This also avoids elfchk
85*7206bf49SGordon Ross  * complaints from libfakekernel, which we don't call directly
86*7206bf49SGordon Ross  * except for here.
87*7206bf49SGordon Ross  */
88*7206bf49SGordon Ross void
fksmbd_init(void)89*7206bf49SGordon Ross fksmbd_init(void)
90*7206bf49SGordon Ross {
91*7206bf49SGordon Ross 	fksmbsrv_drv_load();
92*7206bf49SGordon Ross 	fakekernel_init();
93*7206bf49SGordon Ross }
94