/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2011 Nexenta Systems. All rights reserved.
*/
/*
* log.c - debugging and logging functions
*
* Logging destinations
* svc.startd(1M) supports three logging destinations: the system log, a
* standard output (redirected to the /var/svc/log/svc.startd.log file by
* default). Any or all of these destinations may be used to
* communicate a specific message; the audiences for each destination differ.
*
* Generic messages associated with svc.startd(1M) are made by the
* log_framework() and log_error() functions. For these messages, svc.startd
* logs under its own name and under the LOG_DAEMON facility when issuing
* events to the system log. By design, severities below LOG_NOTICE are never
* issued to the system log.
*
* Messages associated with a specific service instance are logged using the
* log_instance() or log_instance_fmri() functions. These messages are always
* sent to the appropriate per-instance log file.
*
* In the case of verbose or debug boot, the log_transition() function
* displays messages regarding instance transitions to the system console,
* until the expected login services are available.
*
* Finally, log_console() displays messages to the system consoles and
* the master restarter log file. This is used when booting to a milestone
* other than 'all'.
*
* Logging detail
* The constants for severity from <syslog.h> are reused, with a specific
* convention here. (It is worth noting that the #define values for the LOG_
* levels are such that more important severities have lower values.) The
* severity determines the importance of the event, and its addressibility by
* the administrator. Each severity level's use is defined below, along with
* an illustrative example.
*
* LOG_EMERG Not used presently.
*
* LOG_ALERT An unrecoverable operation requiring external
* intervention has occurred. Includes an inability to
* write to the smf(5) repository (due to svc.configd(1M)
* absence, due to permissions failures, etc.). Message
* should identify component at fault.
*
* LOG_CRIT An unrecoverable operation internal to svc.startd(1M)
* has occurred. Failure should be recoverable by restart
* of svc.startd(1M).
*
* LOG_ERR An smf(5) event requiring administrative intervention
* has occurred. Includes instance being moved to the
* maintenance state.
*
* LOG_WARNING A potentially destabilizing smf(5) event not requiring
* administrative intervention has occurred.
*
* LOG_NOTICE A noteworthy smf(5) event has occurred. Includes
* individual instance failures.
*
* LOG_INFO A noteworthy operation internal to svc.startd(1M) has
* occurred. Includes recoverable failures or otherwise
* unexpected outcomes.
*
* LOG_DEBUG An internal operation only of interest to a
* svc.startd(1M) developer has occurred.
*
* Logging configuration
* The preferred approach is to set the logging property values
* in the options property group of the svc.startd default instance. The
* valid values are "quiet", "verbose", and "debug". "quiet" is the default;
* "verbose" and "debug" allow LOG_INFO and LOG_DEBUG logging requests to
* reach the svc.startd.log file, respectively.
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <kstat.h>
#include <libgen.h>
#include <libintl.h>
#include <libuutil.h>
#include <locale.h>
#include <malloc.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <strings.h>
#include <syslog.h>
#include <unistd.h>
#include <zone.h>
#include "startd.h"
/*
* This parameter can be modified using mdb to turn on & off extended
* internal debug logging. Although a performance loss can be expected.
*/
#ifndef NDEBUG
/*
* This is a circular buffer for all (even those not emitted externally)
* logging messages. To read it properly you should start after the first
* null, go until the second, and then go back to the beginning until the
* first null. Or use ::startd_log in mdb.
*/
#endif
static void
{
if (usec < 0) {
sec -= 1;
usec += 1000000;
}
}
static void
{
#ifdef NDEBUG
return;
#endif
if (st->st_log_timezone_known)
else
prefix);
#ifndef NDEBUG
/* Copy into logbuf. */
(void) pthread_mutex_lock(&logbuf_mutex);
else
(void) pthread_mutex_unlock(&logbuf_mutex);
return;
#endif
}
}
/*PRINTFLIKE2*/
void
{
}
/*PRINTFLIKE2*/
void
{
}
/*
* log_framework2() differs from log_framework() by the fact that
* some checking are done before logging the messages in the internal
* buffer for performance reasons.
* The messages aren't logged if:
* - severity >= LOG_DEBUG and
* - st_log_level_min < LOG_DEBUG and
* - internal_debug_flags is not set for 'flags'
*/
void
{
(internal_debug_flags & flags) ||
}
}
/*
* void log_preexec()
*
* log_preexec() should be invoked prior to any exec(2) calls, to prevent the
* logfile and syslogd file descriptors from being leaked to child processes.
* Why openlog(3C) lacks a close-on-exec option is a minor mystery.
*/
void
{
closelog();
}
/*
* void setlog()
* Close file descriptors and redirect output.
*/
void
{
int fd;
closefrom(0);
if (fd == -1)
return;
}
static int
{
int fd;
return (-1);
return (-1);
fd = -1;
}
return (fd);
}
static void
{
char *message;
logstem);
if (fd == -1) {
if (canlog)
return;
}
if (st->st_log_timezone_known)
else
if (canlog)
} else {
}
}
/*
* void log_instance(const restarter_inst_t *, boolean_t, const char *, ...)
*
* The log_instance() format is "[ month day time message ]". (The
* brackets distinguish svc.startd messages from method output.) We avoid
* calling log_*() functions on error when canlog is not set, since we may
* be called from a child process.
*
* When adding new calls to this function, consider: If this is called before
* any instances have started, then it should be called with canlog clear,
* lest we spew errors to the console when booted on the miniroot.
*/
/*PRINTFLIKE3*/
void
const char *format, ...)
{
args);
}
/*
* void log_instance_fmri(const char *, const char *,boolean_t, const char *,
* ...)
*
* The log_instance_fmri() format is "[ month day time message ]". (The
* brackets distinguish svc.startd messages from method output.) We avoid
* calling log_*() functions on error when canlog is not set, since we may
* be called from a child process.
*
* For new calls to this function, see the warning in log_instance()'s
* comment.
*/
/*PRINTFLIKE4*/
void
const char *format, ...)
{
}
/*
* void log_transition(const restarter_inst_t *, start_outcome_t)
*
* The log_transition() format is
*
* [ _service_fmri_ _participle_ (_common_name_) ]
*
* Again, brackets separate messages from specific service instance output to
* the console.
*/
void
{
char *message;
char *action;
int severity;
if (outcome == START_REQUESTED) {
return;
return;
if (cname)
cname);
else
*omessage = '\0';
omessage);
} else {
switch (outcome) {
case MAINT_REQUESTED:
"request (see 'svcs -xv' for details)");
break;
case START_FAILED_REPEATEDLY:
"maintenance (see 'svcs -xv' for details)");
break;
"maintenance (see 'svcs -xv' for details)");
break;
case START_FAILED_FATAL:
"maintenance (see 'svcs -xv' for details)");
break;
"maintenance (see 'svcs -xv' for details)");
break;
case START_FAILED_OTHER:
"maintenance (see 'svcs -xv' for details)");
break;
case START_REQUESTED:
/*FALLTHROUGH*/
default:
}
}
"Could not log boot message for %s: %s.\n",
} else {
/*
* All significant errors should to go to syslog to
* communicate appropriate information even for systems
* without a console connected during boot. Send the
* message to stderr only if the severity is lower than
* (indicated by >) LOG_ERR.
*/
/*LINTED*/
"fprintf() failed with %s.\n",
} else {
}
}
}
/*
* log_console - log a message to the consoles and to syslog
*
* This logs a message as-is to the console (and auxiliary consoles),
* as well as to the master restarter log.
*/
/*PRINTFLIKE2*/
void
{
}
/*
* void log_init()
*
* Set up the log files, if necessary, for the current invocation. This
* function should be called before any other functions in this file. Set the
* syslog(3C) logging mask such that severities of the importance of
* LOG_NOTICE and above are passed through, but lower severity messages are
* masked out.
*
* It may be called multiple times to change the logging configuration due to
* administrative request.
*/
void
log_init()
{
char *dir;
if (getzoneid() != GLOBAL_ZONEID) {
} else {
/*
* We need to special-case the BOOT_TIME utmp entry, and
* drag that value out of the kernel if it's there.
*/
if (((kc = kstat_open()) != 0) &&
!= NULL) &&
NULL)) {
/*
* If we're here, then we've successfully found
* the boot_time kstat... use its value.
*/
} else {
}
if (kc)
(void) kstat_close(kc);
}
}
/*
* Establish our timezone if the appropriate directory is available.
*/
tzset();
}
/*
* Establish our locale if the appropriate directory is available. Set
* the locale string from the environment so we can extract template
* information correctly, if the locale directories aren't yet
* available.
*/
(void) textdomain(TEXT_DOMAIN);
}
}
if (logfile) {
}
/*
* Set syslog(3C) behaviour in all cases.
*/
closelog();
return;
else
} else {
}
return;
}
if (logfile &&
"couldn't mark logfile close-on-exec: %s\n",
}