SCCS-vsn: lib/libc/gen/syslog.c 5.15
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)syslog.c 5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)syslog.c 5.15 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
#define MAXLINE 1024 /* max message size */
#define NULL 0 /* manifest */
#define MAXLINE 1024 /* max message size */
#define NULL 0 /* manifest */
-#define PRIFAC(p) (((p) & LOG_FACMASK) >> 3)
- /* XXX should be in <syslog.h> */
#define IMPORTANT LOG_ERR
static char logname[] = "/dev/log";
static char ctty[] = "/dev/console";
static int LogFile = -1; /* fd for log */
#define IMPORTANT LOG_ERR
static char logname[] = "/dev/log";
static char ctty[] = "/dev/console";
static int LogFile = -1; /* fd for log */
+static int connected; /* have done connect */
static int LogStat = 0; /* status bits, set by openlog() */
static char *LogTag = "syslog"; /* string to tag the entry with */
static int LogMask = 0xff; /* mask of priorities to be logged */
static int LogStat = 0; /* status bits, set by openlog() */
static char *LogTag = "syslog"; /* string to tag the entry with */
static int LogMask = 0xff; /* mask of priorities to be logged */
int pid, olderrno = errno;
/* see if we should just throw out this message */
int pid, olderrno = errno;
/* see if we should just throw out this message */
- if ((unsigned) PRIFAC(pri) >= LOG_NFACILITIES ||
- (LOG_MASK(pri & LOG_PRIMASK) & LogMask) == 0 ||
+ if ((unsigned) LOG_FAC(pri) >= LOG_NFACILITIES ||
+ LOG_MASK(LOG_PRI(pri)) == 0 ||
(pri &~ (LOG_PRIMASK|LOG_FACMASK)) != 0)
return;
(pri &~ (LOG_PRIMASK|LOG_FACMASK)) != 0)
return;
+ if (LogFile < 0 || !connected)
openlog(LogTag, LogStat | LOG_NDELAY, 0);
/* set default facility if none specified */
openlog(LogTag, LogStat | LOG_NDELAY, 0);
/* set default facility if none specified */
c = MAXLINE;
/* output the message to the local logger */
c = MAXLINE;
/* output the message to the local logger */
- if (sendto(LogFile, outline, c, 0, &SyslogAddr, sizeof SyslogAddr) >= 0)
+ if (send(LogFile, outline, c, 0) >= 0)
return;
if (!(LogStat & LOG_CONS))
return;
return;
if (!(LogStat & LOG_CONS))
return;
LogStat = logstat;
if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
LogFacility = logfac;
LogStat = logstat;
if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
LogFacility = logfac;
- if (LogFile >= 0)
- return;
- SyslogAddr.sa_family = AF_UNIX;
- strncpy(SyslogAddr.sa_data, logname, sizeof SyslogAddr.sa_data);
- if (LogStat & LOG_NDELAY) {
- LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
- fcntl(LogFile, F_SETFD, 1);
+ if (LogFile == -1) {
+ SyslogAddr.sa_family = AF_UNIX;
+ strncpy(SyslogAddr.sa_data, logname, sizeof SyslogAddr.sa_data);
+ if (LogStat & LOG_NDELAY) {
+ LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
+ fcntl(LogFile, F_SETFD, 1);
+ }
+ if (LogFile != -1 && !connected &&
+ connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) != -1)
+ connected = 1;
(void) close(LogFile);
LogFile = -1;
(void) close(LogFile);
LogFile = -1;