dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / smbsrv / smbd / smbd_syslog.c
blob85f2b2d888768083db6bb900ef984b7a1a065eb5
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", ctime_r(&ts, cbuf));
53 newfmt = smb_syslog_fmt_m(fbuf, sizeof (fbuf), fmt, save_errno);
55 flockfile(stdout);
56 (void) fprintf(stdout, "smbd.%s: ", pri_name[pri]);
57 /* LINTED E_SEC_PRINTF_VAR_FMT */
58 (void) vfprintf(stdout, newfmt, ap);
59 (void) fprintf(stdout, "\n");
60 funlockfile(stdout);
62 (void) fflush(stdout);
66 * Provide a replacement for libsmb:smb_vsyslog() that prints messages
67 * both to the normal sysloc(3c), and to stdout, which ends up in:
68 * /var/svc/log/network-smb-server:default.log
69 * It's much easier to follow debug messages in the service log.
71 void
72 smb_vsyslog(int pri, const char *fmt, va_list ap)
74 va_list tap;
76 va_copy(tap, ap);
77 smb_svc_log(pri, fmt, tap);
78 va_end(tap);
80 vsyslog(pri, fmt, ap);
84 * An override for libsmb:smb_trace(). As the comment there says:
86 * This function is designed to be used with dtrace, i.e. see:
87 * usr/src/cmd/smbsrv/dtrace/smbd-all.d
89 * Outside of dtrace, the messages passed to this function usually
90 * lack sufficient context to be useful, so don't log them.
91 * However, if you insist, set debug >= 3 and this will log them.
93 void
94 smb_trace(const char *s)
96 if (smbd.s_debug >= 3)
97 (void) fprintf(stdout, "smbd.trace: %s\n", s);