Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/syslog.c
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "libc_private.h" | #include "libc_private.h" | ||||
/* Maximum number of characters of syslog message */ | |||||
#define MAXLINE 8192 | |||||
static int LogFile = -1; /* fd for log */ | static int LogFile = -1; /* fd for log */ | ||||
static int status; /* connection status */ | static int status; /* connection status */ | ||||
static int opened; /* have done openlog() */ | static int opened; /* have done openlog() */ | ||||
static int LogStat = 0; /* status bits, set by openlog() */ | static int LogStat = 0; /* status bits, set by openlog() */ | ||||
static const char *LogTag = NULL; /* string to tag the entry with */ | static const char *LogTag = NULL; /* string to tag the entry with */ | ||||
static int LogFacility = LOG_USER; /* default facility code */ | static int LogFacility = LOG_USER; /* default facility code */ | ||||
static int LogMask = 0xff; /* mask of priorities to be logged */ | static int LogMask = 0xff; /* mask of priorities to be logged */ | ||||
static pthread_mutex_t syslog_mutex = PTHREAD_MUTEX_INITIALIZER; | static pthread_mutex_t syslog_mutex = PTHREAD_MUTEX_INITIALIZER; | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
vsyslog1(int pri, const char *fmt, va_list ap) | vsyslog1(int pri, const char *fmt, va_list ap) | ||||
{ | { | ||||
struct timeval now; | struct timeval now; | ||||
struct tm tm; | struct tm tm; | ||||
char ch, *p; | char ch, *p; | ||||
long tz_offset; | long tz_offset; | ||||
int cnt, fd, saved_errno; | int cnt, fd, saved_errno; | ||||
char hostname[MAXHOSTNAMELEN], *stdp, tbuf[MAXLINE], fmt_cpy[MAXLINE], | char hostname[MAXHOSTNAMELEN], *stdp, tbuf[2048], fmt_cpy[1024], | ||||
errstr[64], tz_sign; | errstr[64], tz_sign; | ||||
FILE *fp, *fmt_fp; | FILE *fp, *fmt_fp; | ||||
struct bufcookie tbuf_cookie; | struct bufcookie tbuf_cookie; | ||||
struct bufcookie fmt_cookie; | struct bufcookie fmt_cookie; | ||||
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID | #define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID | ||||
/* Check for invalid bits. */ | /* Check for invalid bits. */ | ||||
if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) { | if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) { | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | |||||
/* Should be called with mutex acquired */ | /* Should be called with mutex acquired */ | ||||
static void | static void | ||||
connectlog(void) | connectlog(void) | ||||
{ | { | ||||
struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ | struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ | ||||
if (LogFile == -1) { | if (LogFile == -1) { | ||||
socklen_t len; | |||||
if ((LogFile = _socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, | if ((LogFile = _socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, | ||||
0)) == -1) | 0)) == -1) | ||||
return; | return; | ||||
if (_getsockopt(LogFile, SOL_SOCKET, SO_SNDBUF, &len, | |||||
&(socklen_t){sizeof(len)}) == 0) { | |||||
if (len < MAXLINE) { | |||||
len = MAXLINE; | |||||
(void)_setsockopt(LogFile, SOL_SOCKET, SO_SNDBUF, | |||||
&len, sizeof(len)); | |||||
} | |||||
} | |||||
} | } | ||||
if (LogFile != -1 && status == NOCONN) { | if (LogFile != -1 && status == NOCONN) { | ||||
SyslogAddr.sun_len = sizeof(SyslogAddr); | SyslogAddr.sun_len = sizeof(SyslogAddr); | ||||
SyslogAddr.sun_family = AF_UNIX; | SyslogAddr.sun_family = AF_UNIX; | ||||
/* | /* | ||||
* First try privileged socket. If no success, | * First try privileged socket. If no success, | ||||
* then try default socket. | * then try default socket. | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |