2 * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3 * All rights reserved. The file named COPYRIGHT specifies the terms
4 * and conditions for redistribution.
19 #define MSGBUFSIZE 2048
22 static int syslog_init(xlog_s *, va_list) ;
23 static void syslog_fini(xlog_s *) ;
24 static int syslog_control(xlog_s *, xlog_cmd_e, va_list ) ;
25 static int syslog_write(xlog_s *, const char buf[], int , int , va_list ) ;
26 static int syslog_parms(xlog_e, va_list) ;
28 static struct syslog_parms parms =
42 struct xlog_ops __xlog_syslog_ops =
54 * Notice that the following functions will never be invoked since
55 * the xlog_* functions will not call them. However, we need to define
56 * them so that we don't have any unresolved references; and we define
57 * them without any arguments.
67 static void closelog()
71 #endif /* NO_SYSLOG */
78 static int syslog_init( xlog_s *xp, va_list ap )
80 struct syslog_parms *slp = &parms ;
83 sp = NEW( struct syslog_s ) ;
85 return( XLOG_ENOMEM ) ;
86 sp->sl_facility = va_arg( ap, int ) ;
87 sp->sl_default_level = va_arg( ap, int ) ;
88 if ( slp->slp_n_xlogs++ == 0 )
89 openlog( slp->slp_ident, slp->slp_logopts, slp->slp_facility ) ;
91 return( XLOG_ENOERROR ) ;
95 static void syslog_fini( xlog_s *xp )
97 if ( --parms.slp_n_xlogs == 0 )
99 free( SYSLOG( xp ) ) ;
104 static int syslog_control( xlog_s *xp, xlog_cmd_e cmd, va_list ap )
109 SYSLOG( xp )->sl_default_level = va_arg( ap, int ) ;
113 SYSLOG( xp )->sl_facility = va_arg( ap, int ) ;
121 if ( parms.slp_n_xlogs )
122 openlog( parms.slp_ident, parms.slp_logopts, parms.slp_facility ) ;
125 /* These fall through ? */
135 return( XLOG_ENOERROR ) ;
139 static int syslog_write( xlog_s *xp, const char buf[], int len, int flags, va_list ap )
143 char prefix[ MSGBUFSIZE ] ;
144 int prefix_size = sizeof( prefix ) ;
148 int action_flags = ( flags | xp->xl_flags ) ;
150 if ( flags & XLOG_SET_LEVEL )
151 level = va_arg( ap, int ) ;
153 level = SYSLOG( xp )->sl_default_level ;
154 syslog_arg = SYSLOG( xp )->sl_facility + level ;
156 if ( action_flags & XLOG_PRINT_ID )
158 cc = strx_nprint( &prefix[ prefix_len ], prefix_size, "%s: ",
164 if ( ( action_flags & XLOG_NO_ERRNO ) ||
165 ( percent_m_pos = __xlog_add_errno( buf, len ) ) == -1 )
166 syslog( syslog_arg, "%.*s%.*s", prefix_len, prefix, len, buf ) ;
170 char errno_buf[ 100 ] ;
171 unsigned size = sizeof( errno_buf ) ;
173 ep = __xlog_explain_errno( errno_buf, &size ) ;
174 syslog( syslog_arg, "%.*s%.*s%.*s%.*s",
178 len - percent_m_pos - 2, buf + percent_m_pos + 2 ) ;
180 return( XLOG_ENOERROR ) ;
184 static int syslog_parms( xlog_e type, va_list ap )
188 id = __xlog_new_string( va_arg( ap, char * ) );
190 return( XLOG_ENOMEM ) ;
191 parms.slp_ident = id ;
192 parms.slp_logopts = va_arg( ap, int ) ;
193 parms.slp_facility = va_arg( ap, int ) ;
194 return( XLOG_ENOERROR ) ;