/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Daemon log message. This can direct log messages to either stdout,
* an error log file or syslog (or any combination).
*/
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
static int syslog_opened = 0;
static int error_log_flags;
static int syslog_log_flags;
static int daemon_log_flag;
static int log_to_stdout(int);
static int log_to_error_log(int);
static int log_to_syslog(int);
static int msg_level_to_syslog(int);
/*
* Complicated by not wanting to do any emit processing if no one's actually
* going to see it.
*/
void
log_emit(char c)
{
/*
* No one has set the do_emit_flag, go ahead and figure it out.
*/
if (do_emit_flag < 0) {
}
if (!do_emit_flag)
return;
/*
* Check for buffer overflow.
*/
*emit_p = '\0';
lastnl = 1;
}
/*
* ones in succession.
*/
if (c == '\n' || c == '\r') {
if (!lastnl) {
*emit_p = '\0';
}
lastnl = 1;
} else {
lastnl = 0;
*emit_p++ = c;
}
}
/*
* If stdout is a tty and this is MSG_EMIT, we should have alredy output it.
* If running as daemon, output to stdout is a waste of time.
*/
static int
{
return (0);
return (daemon_log_flag == 0);
}
/*
* Can't turn off FATAL or ERROR messages to error log file.
*/
static int
{
if (!error_log_fp)
return (0);
return (1);
return (msg_level & error_log_flags);
}
/*
* Can't turn off FATAL or ERROR messages to syslog.
*/
static int
{
if (!syslog_opened)
return (0);
return (1);
return (msg_level & syslog_log_flags);
}
/*
* Turn internal MSG level to syslog msg level. Don't return a msg level
* lower priority than min_syslog_level.
*/
static int
{
if (min_syslog_level <= LOG_ERR)
return (min_syslog_level);
return (LOG_ERR);
if (min_syslog_level <= LOG_WARNING)
return (min_syslog_level);
return (LOG_WARNING);
if (min_syslog_level <= LOG_NOTICE)
return (min_syslog_level);
return (LOG_NOTICE);
if (min_syslog_level <= LOG_INFO)
return (min_syslog_level);
return (LOG_INFO);
}
/*
* Log a message to the appropriate places.
*/
void
{
if (log_to_stdout(msg_level)) {
}
if (log_to_error_log(msg_level)) {
}
if (log_to_syslog(msg_level)) {
log_msg[0] = '\0';
}
*p = '\0';
log_msg[0] = '\0';
}
}
}
/*
* Output debug message
*/
void
{
if ((debug_level & get_interpreter_debug_level()) == 0)
return;
}
/*
* Log a perror message to the appropriate places.
*/
void
{
}
void
{
}
char *error_log_name;
void
{
exit(1);
}
}
void
{
syslog_opened = 1;
}
/*
* outputting to stdout, which is a waste of time when we're running as a
* daemon.
*/
void
{
if (flag)
else
daemon_log_flag = 0;
}
int
{
int msgflags = 0;
char c;
while ((c = *flags++) != '\0') {
switch (c) {
default:
break;
}
}
return (msgflags);
}
static void
{
}
static void
{
char *fname;
return;
}
if (error_log_fp)
if (error_log_name)
error_log_fp = fp;
} else if (error_log_name)
else
}
static void
_init(void)
{
}