5917 User-mode SMB server
[unleashed.git] / usr / src / cmd / smbsrv / smbd / smbd_syslog.c
blob46389ce226fee35de08640669f763368b5300230
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>
22 #include <smbsrv/smbinfo.h>
23 #include <smbsrv/smb_ioctl.h>
24 #include "smbd.h"
26 #define CBUFSIZ 26 /* ctime(3c) */
28 static const char *pri_name[LOG_DEBUG+1] = {
29 "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"
32 static void
33 smb_svc_log(int pri, const char *fmt, va_list ap)
35 static time_t prev_ts;
36 char fbuf[SMBD_LOG_MSGSIZE];
37 char cbuf[CBUFSIZ];
38 char *newfmt;
39 time_t ts;
40 int save_errno = errno;
42 pri &= LOG_PRIMASK;
43 if (smbd.s_debug == 0 && pri == LOG_DEBUG)
44 return;
46 ts = time(NULL);
47 if (prev_ts != ts) {
48 prev_ts = ts;
49 /* NB: cbuf has \n */
50 (void) fprintf(stdout, "@ %s",
51 ctime_r(&ts, cbuf, sizeof (cbuf)));
54 newfmt = smb_syslog_fmt_m(fbuf, sizeof (fbuf), fmt, save_errno);
56 flockfile(stdout);
57 (void) fprintf(stdout, "smbd.%s: ", pri_name[pri]);
58 /* LINTED E_SEC_PRINTF_VAR_FMT */
59 (void) vfprintf(stdout, newfmt, ap);
60 (void) fprintf(stdout, "\n");
61 funlockfile(stdout);
63 (void) fflush(stdout);
67 * Provide a replacement for libsmb:smb_vsyslog() that prints messages
68 * both to the normal sysloc(3c), and to stdout, which ends up in:
69 * /var/svc/log/network-smb-server:default.log
70 * It's much easier to follow debug messages in the service log.
72 void
73 smb_vsyslog(int pri, const char *fmt, va_list ap)
75 va_list tap;
77 va_copy(tap, ap);
78 smb_svc_log(pri, fmt, tap);
79 va_end(tap);
81 vsyslog(pri, fmt, ap);
85 * An override for libsmb:smb_trace(). As the comment there says:
87 * This function is designed to be used with dtrace, i.e. see:
88 * usr/src/cmd/smbsrv/dtrace/smbd-all.d
90 * Outside of dtrace, the messages passed to this function usually
91 * lack sufficient context to be useful, so don't log them.
92 * However, if you insist, set debug >= 3 and this will log them.
94 void
95 smb_trace(const char *s)
97 if (smbd.s_debug >= 3)
98 (void) fprintf(stdout, "smbd.trace: %s\n", s);