ndmpd_log.c revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6
/*
* Copyright 2008 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 */
#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 <pthread.h>
#include <errno.h>
#include "ndmpd_log.h"
#include "ndmpd.h"
#include "ndmpd_common.h"
#define LOG_FNAME "ndmplog.%d"
#define LOG_FILE_CNT 5
#define LOG_SIZE_INT 256
static boolean_t debug_level = 0;
static int ndmp_synclog = 1;
/*
* 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 *
{
int len;
return (NULL);
/* LINTED variable format specifier */
/* LINTED variable format specifier */
return (buf);
}
/*
* openlogfile
*
* Open the NDMP log file
*/
static int
{
int rv;
return (-1);
(void) mutex_lock(&log_lock);
rv = 0;
rv = -1;
rv = -1;
}
(void) mutex_unlock(&log_lock);
return (rv);
}
/*
* 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
add_newline(char *fmt)
{
}
/*
* log_append
*
* Append the message to the end of the log
*/
static void
log_append(char *msg)
{
if (ndmp_synclog)
}
/*
* ndmp_log_openfile
*
* Open the log file either for append or write mode.
*/
int
ndmp_log_open_file(void)
{
int i;
/*
* 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 (get_debug_level()) {
i = LOG_FILE_CNT - 1;
while (i >= 0) {
i--;
continue;
}
"Could not rename from %s to %s",
i--;
}
}
/*
* Append only if debug is not enable.
*/
if (get_debug_level())
mode = "w";
else
mode = "a";
}
/*
* ndmp_log_close_file
*
* Close the log file
*/
void
ndmp_log_close_file(void)
{
(void) mutex_lock(&log_lock);
}
(void) mutex_unlock(&log_lock);
}
/*
* set_debug_level
*
* Sets the current debug level.
* Parameters:
* level (input) - new debug level.
*
* Returns:
* old debug level.
*/
{
debug_level = level;
return (old);
}
/*
* get_debug_level
*
* Returns the current debug level.
*
* Parameters:
* None.
*
* Returns:
* debug level.
*/
get_debug_level(void)
{
return (debug_level);
}
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 */
(void) mutex_unlock(&log_lock);
}