#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <syslog.h>
#include <smbsrv/smbinfo.h>
#include <smbsrv/smb_ioctl.h>
#include "smbd.h"
#define CBUFSIZ 26
static const char *pri_name[LOG_DEBUG+1] = {
"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"
};
static void
smb_svc_log(int pri, const char *fmt, va_list ap)
{
static time_t prev_ts;
char fbuf[SMBD_LOG_MSGSIZE];
char cbuf[CBUFSIZ];
char *newfmt;
time_t ts;
int save_errno = errno;
pri &= LOG_PRIMASK;
if (smbd.s_debug == 0 && pri == LOG_DEBUG)
return;
ts = time(NULL);
if (prev_ts != ts) {
prev_ts = ts;
(void) fprintf(stdout, "@ %s",
ctime_r(&ts, cbuf, sizeof (cbuf)));
}
newfmt = smb_syslog_fmt_m(fbuf, sizeof (fbuf), fmt, save_errno);
flockfile(stdout);
(void) fprintf(stdout, "smbd.%s: ", pri_name[pri]);
(void) vfprintf(stdout, newfmt, ap);
(void) fprintf(stdout, "\n");
funlockfile(stdout);
(void) fflush(stdout);
}
void
smb_vsyslog(int pri, const char *fmt, va_list ap)
{
va_list tap;
va_copy(tap, ap);
smb_svc_log(pri, fmt, tap);
va_end(tap);
vsyslog(pri, fmt, ap);
}
void
smb_trace(const char *s)
{
if (smbd.s_debug >= 3)
(void) fprintf(stdout, "smbd.trace: %s\n", s);
}