2
* (c) Copyright 1992 by Panagiotis Tsirigotis
3
* (c) Copyright 1998-2001 by Rob Braun
4
* All rights reserved. The file named COPYRIGHT specifies the terms
5
* and conditions for redistribution.
10
#include <sys/types.h>
22
static xlog_h start_filelog( const char *id, struct filelog *flp )
26
int log_file_mode = ( debug.on ) ? 0644 : LOG_FILE_MODE ;
27
const char *func = "start_filelog" ;
29
xh = xlog_create( XLOG_FILELOG, id, XLOG_NOFLAGS,
30
flp->fl_filename, LOG_OPEN_FLAGS, log_file_mode ) ;
33
msg( LOG_ERR, func, "creation of %s log failed", id ) ;
37
if ( xlog_control( xh, XLOG_GETFD, &fd ) != XLOG_ENOERROR ||
38
fcntl( fd, F_SETFD, FD_CLOEXEC ) == -1 )
40
msg( LOG_ERR, func, "Failed to set close-on-exec flag for log file" ) ;
45
ps.rws.descriptors_free-- ;
47
if ( FILELOG_SIZE_CONTROL( flp ) )
48
(void) xlog_control( xh,
49
XLOG_LIMITS, flp->fl_soft_limit, flp->fl_hard_limit ) ;
56
* This function is invoked when a xlog detects an error (for example,
57
* exceeding the file size limit).
58
* The function just enters a log message.
60
* NOTE: We could destroy the xlog at this point but we choose not to.
62
static void log_in_error( xlog_h xh, int error_code, void *arg )
64
struct service *sp = SP( arg ) ;
65
const char *log_id = ( sp == NULL ) ? "common" : SVC_ID( sp ) ;
66
const char *func = "log_in_error" ;
71
if ( error_code == XLOG_ESIZE )
72
msg( LOG_ERR, func, "Size of %s log exceeded hard limit", log_id ) ;
74
msg( LOG_ERR, func, "Error in %s log: %d", log_id, error_code ) ;
78
* Start logging for the specified service.
79
* The current configuration is used to determine the common log file.
81
status_e log_start( struct service *sp, xlog_h *xhp )
84
const char *sid = SVC_ID( sp ) ;
85
struct log *lp = SC_LOG( SVC_CONF( sp ) ) ;
86
const char *func = "log_start" ;
95
xh = xlog_create( XLOG_SYSLOG, sid, XLOG_NOFLAGS,
96
LOG_GET_SYSLOG( lp )->sl_facility,
97
LOG_GET_SYSLOG( lp )->sl_level ) ;
100
msg( LOG_ERR, func, "failed to create a log for service %s", sid ) ;
103
xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
108
* NOTE: if the same file is specified for more than one service,
109
* it will be opened as many times.
110
* Furthermore, size control will not be accurate.
112
xh = start_filelog( sid, LOG_GET_FILELOG( lp ) ) ;
115
(void) xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ;
119
if ( DEFAULT_LOG( ps ) == NULL )
120
if ( DEFAULT_LOG_ERROR( ps ) )
124
xh = start_filelog( "default",
125
LOG_GET_FILELOG( SC_LOG( DEFAULTS( ps ) ) ) ) ;
128
DEFAULT_LOG_ERROR( ps ) = TRUE ;
131
DEFAULT_LOG( ps ) = xh ;
132
(void) xlog_control( xh,
133
XLOG_CALLBACK, log_in_error, VOID_NULL ) ;
136
xh = DEFAULT_LOG( ps ) ;
139
default: /* SHOULDN'T HAPPEN */
140
msg( LOG_ERR, func, "bad log type (%d) for service %s",
141
(int) LOG_GET_TYPE( lp ), sid ) ;
149
void log_end( struct log *lp, xlog_h xh )
151
const char *func = "log_end" ;
153
if ( xh == NULL ) /* shouldn't be NULL but just in case */
155
msg( LOG_NOTICE, func, "called with NULL handle" ) ;
159
switch ( LOG_GET_TYPE( lp ) )
162
ps.rws.descriptors_free++ ;