trace.c revision cee0fb94c0d4227de0a00efc162fb2739844b641
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <syslog.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <limits.h>
#include <ctype.h>
#include "mms_strapp.h"
#include "mms_trace.h"
static char mms_trace_filename[256];
static int mms_trace_fd = -1;
static mms_trace_id_t mms_trace_id;
static uint64_t mms_trace_size = 0;
static pthread_mutex_t mms_trace_mutex;
static int mms_conf = 1;
static int mms_aborting = 0;
static char *mms_trace_sevstr[] = {
"EMERG", "ALERT", "CRIT", "OPER", "ERROR", "WARN", "NOTICE",
};
static char *mms_trace_idstr[] = {
};
static char *mms_trace_level[] = {
"emergency", "alert", "critical", "operational", "error",
};
static int mms_trace_sig[] = {
0,
};
static void
{
char size[20];
"mms_trace_setup_logadm: fork failed");
return;
} else if (shpid == 0) { /* child */
int fd;
if (fd >= 0) {
}
"-f", MMS_LOGADM_CONF,
"-s", size,
"-w", mms_trace_filename,
(char *)0);
exit(1);
}
"mms_trace_setup_logadm: wait failed");
}
static void
{
/*
* Setup to catch signals
*/
/*
* Allow alarm signal to interrupt
*/
}
}
/*
* Catch the signals caused by programming error here and flush
* the mms_trace buffer before aborting.
*/
static void
mms_trace_sighandler(int sig)
{
"Aborting <<<<<", sig);
mms_aborting = 1;
abort();
}
/*
* Open mms_trace file with id prefix.
*/
/*
* function name:
* mms_trace_open
*
* Parameters:
* filename trace file name
* id id of the component
* severity severity above which will be traced
* rot_size rotation size
* sig 1 - if trace will cat abort signals
* 0 - if trace will not catch signals
* conf 1 - if dm_trace_close will remove trace entry from
* 0 - if dm_trace_close will not remove trace entry
* from logadm.conf
*
* Description:
* open a trace file
*
* Note:
*
*
*/
int
{
int i;
/* Make sure that mms_trace_open has not already been */
/* opened */
if (mms_trace_get_fd() != -1) {
return (1);
}
return (1);
}
if (severity != -1 &&
return (1);
}
if (sig != 0) {
for (i = 0; mms_trace_sig[i] != 0; i++) {
}
}
return (1);
}
char name[128];
char *p;
*p = '\0';
}
}
}
return (-1);
}
} else {
return (1);
}
mms_trace_id = id;
if (rot_size != -1)
if (severity != -1)
(void) mms_trace_filter(severity);
/* Save mms_trace's filename for when file rotation takes place */
/* Obtain initial size of mms_trace file for rotation */
/*
* Setup mms_logadm.conf for this file
*/
if (conf) {
}
return (0);
}
/*
* Return mms_trace file descriptor.
*/
int
mms_trace_get_fd(void)
{
return (mms_trace_fd);
}
/*
* Function name:
* mms_trace_close
*
*
* Parameters:
* none
*
*
* Description:
* close a trace file.
* if mms_conf is 1 (set in mms_trace_open) then entry in logadm.conf
* for this trace file will be removed.
* If mms_trace_close is called during an abort from
* mms_trace_sighandler don't call mms_strapp,
* the malloc maydead lock if another thread aborted
* inside of malloc
*
* Note:
*
*
*/
void
mms_trace_close(void)
{
if (!mms_aborting && mms_conf) {
"mms_trace_close: fork failed");
(void) close(mms_trace_fd);
mms_trace_fd = -1;
return;
} else if (shpid == 0) { /* child */
int fd;
if (fd >= 0) {
}
"-f", MMS_LOGADM_CONF,
"-r", mms_trace_filename,
(char *)0);
exit(1);
}
"mms_trace_close: wait failed");
}
(void) close(mms_trace_fd);
mms_trace_fd = -1;
}
/*
* Set mms_trace id prefix.
*/
void
{
return;
}
mms_trace_id = id;
}
/*
* Get mms_trace id prefix.
*/
mms_trace_get_id(void)
{
return (mms_trace_id);
}
/*
* Get mms_trace serverity setting.
*/
mms_trace_get_severity(void)
{
return (mms_trace_sev);
}
/*
* Write variable number of args to mms_trace file.
*/
void
{
}
/*
* Write arg list to mms_trace file.
*/
void
{
char date[100];
char *buf;
char *str;
int len;
int num_iov;
int off;
int i;
const char *newline = "\n";
char size[20];
return; /* invalid severity */
}
if (severity > mms_trace_sev) {
return; /* not tracing this severity level */
}
if (pthread_mutex_lock(&mms_trace_mutex) != 0)
return;
/*
* Put mms_trace info into a write buffer
*/
(void) pthread_mutex_unlock(&mms_trace_mutex);
return;
}
(void) pthread_mutex_unlock(&mms_trace_mutex);
return;
}
len--;
}
} else {
}
}
}
mms_trace_size += len;
if (mms_trace_size > mms_trace_rot_size) {
(void) close(mms_trace_fd);
"mms_trace_va: fork failed");
return;
} else if (shpid == 0) { /* child */
"-f", MMS_LOGADM_CONF,
"-s", size,
(char *)0);
exit(1);
}
"mms_trace_va: wait failed");
mms_trace_size = 0;
}
(void) pthread_mutex_unlock(&mms_trace_mutex);
}
/*
* Set tracing severity level.
*/
int
{
return (1); /* invalid severity */
}
if (severity < MMS_SEV_ERROR)
/* Cannot mask levels EMERG through OPER */
else
return (0);
}
/*
* Set tracing severity level.
*/
int
mms_trace_str_filter(char *level)
{
return (1);
} else {
return (1);
}
return (mms_trace_filter(severity));
}
int
{
int rc = 0;
rc = 1;
*severity = MMS_SEV_CRIT;
*severity = MMS_SEV_OPER;
*severity = MMS_SEV_WARN;
*severity = MMS_SEV_INFO;
*severity = MMS_SEV_DEVP;
} else {
rc = 1;
}
return (rc);
}
char *
{
char *level;
} else {
}
return (level);
}
/* This routine is used to obtain the severity level for the */
/* MMS internal message scheme. When MM sends a private command */
/* to set or change the message levels that a LM or DM will send, */
/* it sends it in a string. This routine converts that string into */
/* an enumeration associated with the string. By default it sets */
/* the the level to ERROR */
mms_msg_get_severity(char *level)
{
"mms_msg_get_severity: null string filter");
return (MMS_MSG_SEV_ERROR);
return (MMS_MSG_SEV_EMERG);
return (MMS_MSG_SEV_ALERT);
return (MMS_MSG_SEV_CRIT);
return (MMS_MSG_SEV_ERROR);
return (MMS_MSG_SEV_WARN);
return (MMS_MSG_SEV_NOTICE);
return (MMS_MSG_SEV_INFO);
return (MMS_MSG_SEV_DEBUG);
return (MMS_MSG_SEV_DEVP);
} else {
"mms_msg_get_severity, invalid string filter: "
"%s", level);
return (MMS_MSG_SEV_ERROR);
}
}
/*
* Dump content of memory into a bufer
*/
char *
{
int off = 0;
int off_start;
int bytes;
int i;
int j;
for (i = 0; i < bytes; ) {
for (j = 0; j < 4; j++, i++) {
}
}
for (i = 0; i < bytes; i++) {
}
}
return (out);
}
/*
* Flush the mms_trace buffer to disk
*/
void
mms_trace_flush(void)
{
(void) fsync(mms_trace_fd);
}
/*
* Parse string to get file size.
*/
int
char *string,
{
char *p;
double conv;
double frac;
*size = 0;
/*
*/
errno = 0;
return (0);
}
goto err;
}
errno = 0;
goto err;
}
if (*p == 'K') {
p++;
} else if (*p == 'M') {
p++;
} else if (*p == 'G') {
p++;
} else if (frac > .09) {
goto err;
}
if (*p != '\0') {
goto err;
}
return (0);
err:
if (errno == 0) {
}
return (-1);
}
/*
* Set mms_trace file rotation size.
*/
int
char *size)
{
"mms_trace_set_fsize: Invalid mms_trace size - %s\n",
size);
return (1);
} else {
"mms_trace_set_fsize: Set mms_trace rotation size to "
return (0);
}
}