9 date 93.08.25.17.23.42; author jromine; state Exp;
14 date 92.12.15.00.20.22; author jromine; state Exp;
19 date 92.11.19.00.24.36; author jromine; state Exp;
24 date 92.11.13.00.04.36; author jromine; state Exp;
29 date 90.04.05.15.34.53; author sources; state Exp;
34 date 90.04.05.14.54.30; author sources; state Exp;
39 date 90.02.05.14.11.20; author sources; state Exp;
44 date 90.02.01.14.14.35; author sources; state Exp;
49 date 90.02.01.14.09.03; author sources; state Exp;
60 @off_t fixes for BSD44
63 @#if !defined (BSD43) && !defined(hpux)
65 static char SccsId[] = "@@(#)syslog.c 4.1 (Berkeley) 5/27/83";
68 static char ident[] = "@@(#)$Id: syslog.c,v 1.8 1992/12/15 00:20:22 jromine Exp jromine $";
72 * SYSLOG -- print message on log file
74 * This routine looks a lot like printf, except that it
75 * outputs to the log file instead of the standard output.
76 * Also, it prints the module name in front of lines,
77 * and has some other formatting types (or will sometime).
78 * Also, it adds a newline on the end of messages.
80 * The output of this routine is intended to be read by
81 * /etc/syslog, which will add timestamps.
83 #include <sys/types.h>
84 #include <sys/socket.h>
85 #include <netinet/in.h>
90 #define MAXLINE 1024 /* max message size */
91 #define BUFSLOP 20 /* space to allow for "extra stuff" */
93 #define NULL 0 /* manifest */
96 #define LOG_COOLIT LOG_LOCAL0 /* local syslog code */
97 #define LOG_DGRAM LOG_LOCAL1 /* idem */
100 #define LOG_HOST "localhost" /* host where syslogd is running */
101 #endif /* LOG_HOST */
103 int LogFile = -1; /* fd for log */
104 int LogStat = 0; /* status bits, set by initlog */
105 char *LogTag = (char *)NULL; /* string to tag the entry with */
106 int LogMask = LOG_DEBUG; /* lowest priority to be logged */
108 struct sockaddr_in SyslogAddr;
109 static char *SyslogHost = LOG_HOST;
114 extern char *sys_errlist[];
117 syslog(pri, fmt, p0, p1, p2, p3, p4)
121 char buf[MAXLINE+BUFSLOP], outline[MAXLINE + 1];
122 register char *b, *f;
126 /* see if we should just throw out this message */
129 for (b = buf, f = fmt; f && *f; b = buf) {
132 if (pri > 0 && (LogStat & LOG_COOLIT) == 0) {
133 sprintf(b, "<%d>", pri);
136 if (LogStat & LOG_PID) {
137 sprintf(b, "%d ", getpid());
141 sprintf(b, "%s: ", LogTag);
144 while ((c = *f++) != '\0' && c != '\n' && b < buf + MAXLINE) {
152 *b++ = '%', *b++ = c, *b++ = '\0';
154 *b++ = '%', *b++ = c;
158 if ((unsigned)errno > sys_nerr)
159 sprintf(b, "error %d", errno);
161 strcat(b, sys_errlist[errno]);
166 *b++ = '\n', *b = '\0';
167 sprintf(outline, buf, p0, p1, p2, p3, p4);
169 if (LogStat & LOG_DGRAM)
170 (void) sendto(LogFile, outline, strlen(outline), 0,
171 &SyslogAddr, sizeof SyslogAddr);
173 (void) write(LogFile, outline, strlen(outline));
175 perror("syslog: sendto");
180 * OPENLOG -- open system log
182 openlog(ident, logstat)
193 sp = getservbyname("syslog", "udp");
194 hp = gethostbyname(SyslogHost);
195 if (sp == NULL || hp == NULL)
197 LogFile = socket(AF_INET, SOCK_DGRAM, 0);
199 perror("syslog: socket");
202 bzero(&SyslogAddr, sizeof SyslogAddr);
203 SyslogAddr.sin_family = hp->h_addrtype;
204 bcopy(hp->h_addr, (char *)&SyslogAddr.sin_addr, hp->h_length);
205 SyslogAddr.sin_port = sp->s_port;
206 LogStat |= LOG_DGRAM;
209 LogStat |= LOG_COOLIT;
210 LogStat &= ~LOG_DGRAM;
212 LogFile = open("/dev/console", 1);
214 perror("syslog: /dev/console");
220 * CLOSELOG -- close the system log
225 (void) close(LogFile);
228 #endif /* not BSD43 */
239 static char ident[] = "@@(#)$Id: syslog.c,v 1.7 1992/11/19 00:24:36 jromine Exp jromine $";
242 extern int errno, sys_nerr;
249 @define NULL only if not defined
254 static char ident[] = "@@(#)$Id: syslog.c,v 1.6 1992/11/13 00:04:36 jromine Exp jromine $";
272 static char ident[] = "@@(#)$Id: syslog.c,v 1.5 1990/04/05 15:34:53 sources Exp jromine $";
277 char *LogTag = NULL; /* string to tag the entry with */
288 static char ident[] = "@@(#)$Id:$";
308 static char ident[] = "@@(#)$Id:";
323 @HPUX systems evidently have syslog now