syslogd.c (88dd0550920c3dd378b2b761bda52339b5d860ec) syslogd.c (964687879a38034d3f0221d3c73b9add6cadb567)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1983, 1988, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 53 unchanged lines hidden (view full) ---

62 * This program implements a system log. It takes a series of lines.
63 * Each line may have a priority, signified as "<n>" as
64 * the first characters of the line. If this is
65 * not present, a default priority is used.
66 *
67 * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will
68 * cause it to reread its configuration file.
69 *
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1983, 1988, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 53 unchanged lines hidden (view full) ---

62 * This program implements a system log. It takes a series of lines.
63 * Each line may have a priority, signified as "<n>" as
64 * the first characters of the line. If this is
65 * not present, a default priority is used.
66 *
67 * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will
68 * cause it to reread its configuration file.
69 *
70 * Defined Constants:
71 *
72 * MAXLINE -- the maximum line length that can be handled.
73 * DEFUPRI -- the default priority for user messages
74 * DEFSPRI -- the default priority for kernel messages
75 *
76 * Author: Eric Allman
77 * extensive changes by Ralph Campbell
78 * more extensive changes by Eric Allman (again)
79 * Extension to log by program name as well as facility and priority
80 * by Peter da Silva.
81 * -u and -v by Harlan Stenn.
82 * Priority comparison code by Harlan Stenn.
83 */
84
70 * Author: Eric Allman
71 * extensive changes by Ralph Campbell
72 * more extensive changes by Eric Allman (again)
73 * Extension to log by program name as well as facility and priority
74 * by Peter da Silva.
75 * -u and -v by Harlan Stenn.
76 * Priority comparison code by Harlan Stenn.
77 */
78
85#define MAXLINE 8192 /* maximum line length */
86#define MAXSVLINE MAXLINE /* maximum saved line length */
87#define DEFUPRI (LOG_USER|LOG_NOTICE)
88#define DEFSPRI (LOG_KERN|LOG_CRIT)
89#define TIMERINTVL 30 /* interval for checking flush, mark */
90#define TTYMSGTIME 1 /* timeout passed to ttymsg */
91#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */
92
93#include <sys/param.h>
94#include <sys/event.h>

--- 35 unchanged lines hidden (view full) ---

130#include <stdio.h>
131#include <stdlib.h>
132#include <string.h>
133#include <sysexits.h>
134#include <unistd.h>
135#include <utmpx.h>
136
137#include "pathnames.h"
79#define DEFUPRI (LOG_USER|LOG_NOTICE)
80#define DEFSPRI (LOG_KERN|LOG_CRIT)
81#define TIMERINTVL 30 /* interval for checking flush, mark */
82#define TTYMSGTIME 1 /* timeout passed to ttymsg */
83#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */
84
85#include <sys/param.h>
86#include <sys/event.h>

--- 35 unchanged lines hidden (view full) ---

122#include <stdio.h>
123#include <stdlib.h>
124#include <string.h>
125#include <sysexits.h>
126#include <unistd.h>
127#include <utmpx.h>
128
129#include "pathnames.h"
130#include "syslogd.h"
131#include "syslogd_cap.h"
138#include "ttymsg.h"
139
132#include "ttymsg.h"
133
140#define SYSLOG_NAMES
141#include <sys/syslog.h>
142
143static const char *ConfFile = _PATH_LOGCONF;
144static const char *PidFile = _PATH_LOGPID;
145static const char include_str[] = "include";
146static const char include_ext[] = ".conf";
147
148#define dprintf if (Debug) printf
149
134static const char *ConfFile = _PATH_LOGCONF;
135static const char *PidFile = _PATH_LOGPID;
136static const char include_str[] = "include";
137static const char include_ext[] = ".conf";
138
139#define dprintf if (Debug) printf
140
150#define MAXUNAMES 20 /* maximum number of user names */
151
152#define sstosa(ss) ((struct sockaddr *)(ss))
153#ifdef INET
154#define sstosin(ss) ((struct sockaddr_in *)(void *)(ss))
155#define satosin(sa) ((struct sockaddr_in *)(void *)(sa))
156#endif
157#ifdef INET6
158#define sstosin6(ss) ((struct sockaddr_in6 *)(void *)(ss))
159#define satosin6(sa) ((struct sockaddr_in6 *)(void *)(sa))

--- 37 unchanged lines hidden (view full) ---

197 * Flags to logmsg().
198 */
199
200#define IGN_CONS 0x001 /* don't print on console */
201#define SYNC_FILE 0x002 /* do fsync on file after printing */
202#define MARK 0x008 /* this message is a mark */
203#define ISKERNEL 0x010 /* kernel generated message */
204
141#define sstosa(ss) ((struct sockaddr *)(ss))
142#ifdef INET
143#define sstosin(ss) ((struct sockaddr_in *)(void *)(ss))
144#define satosin(sa) ((struct sockaddr_in *)(void *)(sa))
145#endif
146#ifdef INET6
147#define sstosin6(ss) ((struct sockaddr_in6 *)(void *)(ss))
148#define satosin6(sa) ((struct sockaddr_in6 *)(void *)(sa))

--- 37 unchanged lines hidden (view full) ---

186 * Flags to logmsg().
187 */
188
189#define IGN_CONS 0x001 /* don't print on console */
190#define SYNC_FILE 0x002 /* do fsync on file after printing */
191#define MARK 0x008 /* this message is a mark */
192#define ISKERNEL 0x010 /* kernel generated message */
193
205/* Timestamps of log entries. */
206struct logtime {
207 struct tm tm;
208 suseconds_t usec;
209};
210
211/* Traditional syslog timestamp format. */
212#define RFC3164_DATELEN 15
213#define RFC3164_DATEFMT "%b %e %H:%M:%S"
214
194/* Traditional syslog timestamp format. */
195#define RFC3164_DATELEN 15
196#define RFC3164_DATEFMT "%b %e %H:%M:%S"
197
215enum filt_proptype {
216 FILT_PROP_NOOP,
217 FILT_PROP_MSG,
218 FILT_PROP_HOSTNAME,
219 FILT_PROP_PROGNAME,
220};
221
222enum filt_cmptype {
223 FILT_CMP_CONTAINS,
224 FILT_CMP_EQUAL,
225 FILT_CMP_STARTS,
226 FILT_CMP_REGEX,
227};
228
229/*
230 * This structure holds a property-based filter
231 */
232struct prop_filter {
233 enum filt_proptype prop_type;
234 enum filt_cmptype cmp_type;
235 uint8_t cmp_flags;
236#define FILT_FLAG_EXCLUDE (1 << 0)
237#define FILT_FLAG_ICASE (1 << 1)
238 union {
239 char *p_strval;
240 regex_t *p_re;
241 } pflt_uniptr;
242#define pflt_strval pflt_uniptr.p_strval
243#define pflt_re pflt_uniptr.p_re
244 size_t pflt_strlen;
245};
246
247enum f_type {
248 F_UNUSED, /* unused entry */
249 F_FILE, /* regular file */
250 F_TTY, /* terminal */
251 F_CONSOLE, /* console terminal */
252 F_FORW, /* remote machine */
253 F_USERS, /* list of users */
254 F_WALL, /* everyone logged on */
255 F_PIPE, /* pipe to program */
256};
257
258/*
259 * This structure represents the files that will have log
260 * copies printed.
261 * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY
262 * or if f_type is F_PIPE and f_pid > 0.
263 */
264struct filed {
265 enum f_type f_type;
266
267 /* Used for filtering. */
268 char *f_host; /* host from which to recd. */
269 char *f_program; /* program this applies to */
270 struct prop_filter *f_prop_filter; /* property-based filter */
271 u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */
272 u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */
273#define PRI_LT 0x1
274#define PRI_EQ 0x2
275#define PRI_GT 0x4
276
277 /* Logging destinations. */
278 int f_file; /* file descriptor */
279 int f_flags; /* file-specific flags */
280#define FFLAG_SYNC 0x01
281#define FFLAG_NEEDSYNC 0x02
282 union {
283 char f_uname[MAXUNAMES][MAXLOGNAME]; /* F_WALL, F_USERS */
284 char f_fname[MAXPATHLEN]; /* F_FILE, F_CONSOLE, F_TTY */
285 struct {
286 char f_hname[MAXHOSTNAMELEN];
287 struct addrinfo *f_addr;
288 } f_forw; /* F_FORW */
289 struct {
290 char f_pname[MAXPATHLEN];
291 int f_procdesc;
292 } f_pipe; /* F_PIPE */
293 } f_un;
294#define fu_uname f_un.f_uname
295#define fu_fname f_un.f_fname
296#define fu_forw_hname f_un.f_forw.f_hname
297#define fu_forw_addr f_un.f_forw.f_addr
298#define fu_pipe_pname f_un.f_pipe.f_pname
299#define fu_pipe_pd f_un.f_pipe.f_procdesc
300
301 /* Book-keeping. */
302 char f_prevline[MAXSVLINE]; /* last message logged */
303 time_t f_time; /* time this was last written */
304 struct logtime f_lasttime; /* time of last occurrence */
305 int f_prevpri; /* pri of f_prevline */
306 size_t f_prevlen; /* length of f_prevline */
307 int f_prevcount; /* repetition cnt of prevline */
308 u_int f_repeatcount; /* number of "repeated" msgs */
309 STAILQ_ENTRY(filed) next; /* next in linked list */
310};
311static STAILQ_HEAD(, filed) fhead =
312 STAILQ_HEAD_INITIALIZER(fhead); /* Log files that we write to */
313static struct filed consfile; /* Console */
314
198static STAILQ_HEAD(, filed) fhead =
199 STAILQ_HEAD_INITIALIZER(fhead); /* Log files that we write to */
200static struct filed consfile; /* Console */
201
315
316/*
317 * Queue of about-to-be dead processes we should watch out for.
318 */
319struct deadq_entry {
320 int dq_procdesc;
321 int dq_timeout;
322 TAILQ_ENTRY(deadq_entry) dq_entries;
323};

--- 3481 unchanged lines hidden ---
202/*
203 * Queue of about-to-be dead processes we should watch out for.
204 */
205struct deadq_entry {
206 int dq_procdesc;
207 int dq_timeout;
208 TAILQ_ENTRY(deadq_entry) dq_entries;
209};

--- 3481 unchanged lines hidden ---