/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 2007, The Storage Networking Industry Association. */
/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <pthread.h>
#include <errno.h>
#include "ndmpd_log.h"
#include "ndmpd.h"
#include "ndmpd_common.h"
/*
* Since we use buffered file I/O for log file, the thread may lose CPU.
* At this time, another thread can destroy the contents of the buffer
* that must be written to the log file. The following mutex is used
* to allow only one thread to write into the log file.
*/
static char *priority_str[] = {
"EMERGENCY",
"ALERT",
"CRITICAL",
"ERROR",
"WARNING",
"NOTICE",
"INFO",
"DEBUG",
};
/*
* mk_pathname
*
* Append the NDMP working directory path to the specified file
*/
static char *
{
char *fmt;
int len;
/* LINTED variable format specifier */
/* LINTED variable format specifier */
return (buf);
}
/*
* openlogfile
*
* Open the NDMP log file
*/
static int
{
perror("Error opening logfile");
return (-1);
}
return (0);
}
/*
* log_write_cur_time
*
* Add the current time for each log entry
*/
static void
log_write_cur_time(void)
{
}
/*
* add_newline
*
* The new line at the end of each log
*/
static void
{
}
/*
* log_append
*
* Append the message to the end of the log
*/
static void
{
if (ndmp_synclog)
}
/*
* ndmp_log_openfile
*
* Open the log file either for append or write mode. This function should
* be called while ndmpd is still running single-threaded and in foreground.
*/
int
{
int i;
/* read debug property if it isn't overriden by cmd line option */
if (override_debug)
else
/* Create the debug path if it doesn't exist */
"Could not create log path %s: %s\n",
lpath = "/var";
}
}
/*
* NDMP log file name will be {logfilename}.0 to {logfilename}.5, where
* {logfilename}.0 will always be the latest and the {logfilename}.5
* will be the oldest available file on the system. We keep maximum of 5
* log files. With the new session the files are shifted to next number
* and if the last file {logfilename}.5 exist, it will be overwritten
* with {logfilename}.4.
*/
if (debug) {
i = LOG_FILE_CNT - 1;
while (i >= 0) {
i--;
continue;
}
"Could not rename %s to %s: %s\n",
i--;
}
}
/*
* Append only if debug is not enable.
*/
if (debug)
mode = "w";
else
mode = "a";
}
/*
* ndmp_log_close_file
*
* Close the log file
*/
void
ndmp_log_close_file(void)
{
}
(void) mutex_destroy(&log_lock);
}
void
{
int c;
char *f, *b;
char *errstr;
return;
(void) mutex_lock(&log_lock);
if (priority > 7)
/* Replace text error messages if fmt contains %m */
b = buf;
f = fmt;
while (((c = *f++) != '\0') && (c != '\n') &&
if (c != '%') {
*b++ = c;
continue;
}
if ((c = *f++) != 'm') {
*b++ = '%';
*b++ = c;
continue;
}
"error %d", errno);
} else {
while ((*errstr != '\0') &&
if (*errstr == '%') {
b += 2;
} else {
*b++ = *errstr;
}
errstr++;
}
*b = '\0';
}
b += strlen(b);
}
*b = '\0';
/* LINTED variable format specifier */
/* Send all logs other than debug, to syslog log file. */
/* ndmp_log_buf will have priority string and log info also */
/* if ndmpd is running in foreground print log message to stderr */
if (log_to_stderr)
(void) mutex_unlock(&log_lock);
}