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