syslog.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* SYSLOG -- print message on log file
*
* This routine looks a lot like printf, except that it
* outputs to the log file instead of the standard output.
* Also:
* adds a timestamp,
* prints the module name in front of the message,
* has some other formatting types (or will sometime),
* adds a newline on the end of the message.
*
*
* Author: Eric Allman
* Modified to use UNIX domain IPC by Ralph Campbell
*/
#include <netdb.h>
#include <strings.h>
#include <varargs.h>
#include <vfork.h>
#include <stdio.h>
#define NULL 0 /* manifest */
static struct _syslog {
int _LogFile;
int _LogStat;
char *_LogTag;
int _LogMask;
struct sockaddr _SyslogAddr;
char *_SyslogHost;
int _LogFacility;
} *_syslog;
extern int errno;
extern char *calloc();
extern char *strerror(int);
extern unsigned int alarm();
static int
{
if (_syslog == 0)
return (0); /* can't do it */
LogStat = 0; /* status bits, set by openlog() */
return (1);
}
/*VARARGS2*/
int pri;
char *fmt;
{
}
int pri;
char *fmt;
{
register char *b, *f, *o;
register int c;
long now;
int taglen;
/*
* Maximum tag length is 256 (the pad in outline) minus the size of the
* other things that can go in the pad.
*/
#define MAX_TAG 230
if (_syslog == 0 && !allocstatic())
return;
/* see if we should just throw out this message */
return;
if (LogFile < 0)
/* set default facility if none specified */
if ((pri & LOG_FACMASK) == 0)
pri |= LogFacility;
/* build the message */
o = outline;
o += strlen(o);
if (LogTag) {
o[taglen] = '\0';
o += strlen(o);
}
o += strlen(o);
}
if (LogTag) {
(void) strcpy(o, ": ");
o += 2;
}
b = buf;
f = fmt;
char *errstr;
if (c != '%') {
*b++ = c;
continue;
}
if ((c = *f++) != 'm') {
*b++ = '%';
*b++ = c;
continue;
}
olderrno);
else {
if (*errstr == '%') {
strcpy(b, "%%");
b += 2;
}
else
*b++ = *errstr;
errstr++;
}
*b = '\0';
}
b += strlen(b);
}
*b++ = '\n';
*b = '\0';
if (c > MAXLINE) {
c = MAXLINE;
}
/* output the message to the local logger */
sizeof (SyslogAddr)) >= 0)
return;
return;
/* output the message to the console */
if (pid == -1)
return;
if (pid == 0) {
int fd;
(void) alarm(5);
(void) alarm(0);
(void) strcat(o, "\r\n");
c += 2;
}
} else
(void) alarm(0);
_exit(0);
}
if (!(LogStat & LOG_NOWAIT))
;
}
/*
* OPENLOG -- open system log
*/
char *ident;
{
if (_syslog == 0 && !allocstatic())
return;
if (ident != NULL)
LogTag = ident;
if (logfac != 0)
if (LogFile >= 0)
return;
sizeof (SyslogAddr.sa_data));
if (LogStat & LOG_NDELAY) {
}
}
/*
* CLOSELOG -- close the system log
*/
closelog()
{
if (_syslog == 0)
return;
LogFile = -1;
}
/*
* SETLOGMASK -- set the log mask level
*/
int pmask;
{
int omask;
if (_syslog == 0 && !allocstatic())
return (-1);
if (pmask != 0)
return (omask);
}
/*
* temporarily to solve bugid 1220257. Perhaps
* they could become a public interface at some
* point but not for now.
*/
extern int _doprnt();
/*VARARGS3*/
static int
size_t n;
{
register int count;
if (n == 0)
return (0);
return (count);
}
/*VARARGS3*/
static int
size_t n;
{
register int count;
if (n == 0)
return (0);
return (count);
}