1
|
diff --git a/usr.sbin/syslogd/clog.h b/usr.sbin/syslogd/clog.h
|
2
|
new file mode 100644
|
3
|
index 0000000..093bdb0
|
4
|
--- /dev/null
|
5
|
+++ b/usr.sbin/syslogd/clog.h
|
6
|
@@ -0,0 +1,104 @@
|
7
|
+/*-
|
8
|
+ * Copyright (c) 2001
|
9
|
+ * Jeff Wheelhouse (jdw@wwwi.com)
|
10
|
+ *
|
11
|
+ * This code was originally developed by Jeff Wheelhouse (jdw@wwwi.com).
|
12
|
+ *
|
13
|
+ * Redistribution and use in source and binary forms, with or without
|
14
|
+ * modification, are permitted provided that the following conditions
|
15
|
+ * are met:
|
16
|
+ * 1. Redistribution of source code must retail the above copyright
|
17
|
+ * notice, this list of conditions and the following disclaimer.
|
18
|
+ * 2. Redistributions in binary form must reproduce the above copyright
|
19
|
+ * notice, this list of conditions and the following disclaimer in the
|
20
|
+ * documentation and/or other materials provided with the distribution.
|
21
|
+ *
|
22
|
+ * THIS SOFTWARE IS PROVIDED BY JEFF WHEELHOUSE ``AS IS'' AND ANY EXPRESS OR
|
23
|
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
24
|
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
25
|
+ * NO EVENT SHALL JEFF WHEELHOUSE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
26
|
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT
|
27
|
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
28
|
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
31
|
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+ *
|
33
|
+ * $Id: clog.h,v 1.2 2001/10/02 04:43:52 jdw Exp $
|
34
|
+ * $DragonFly: src/usr.sbin/clog/clog.h,v 1.1 2004/10/30 20:26:46 dillon Exp $
|
35
|
+ */
|
36
|
+
|
37
|
+
|
38
|
+#ifndef _CLOG_H_
|
39
|
+#define _CLOG_H_
|
40
|
+
|
41
|
+/*
|
42
|
+ * This magic constant is used to identify a valid circular log file.
|
43
|
+ * syslogd will ignore any circular log file that doesn't have this constant.
|
44
|
+ */
|
45
|
+
|
46
|
+const char MAGIC_CONST[4] = "CLOG";
|
47
|
+
|
48
|
+
|
49
|
+struct clog_footer {
|
50
|
+ uint32_t cf_magic;
|
51
|
+ uint32_t cf_wrap;
|
52
|
+ uint32_t cf_next;
|
53
|
+ uint32_t cf_max;
|
54
|
+ uint32_t cf_lock;
|
55
|
+};
|
56
|
+
|
57
|
+
|
58
|
+#endif /* _CLOG_H_ */
|
59
|
+/*-
|
60
|
+ * Copyright (c) 2001
|
61
|
+ * Jeff Wheelhouse (jdw@wwwi.com)
|
62
|
+ *
|
63
|
+ * This code was originally developed by Jeff Wheelhouse (jdw@wwwi.com).
|
64
|
+ *
|
65
|
+ * Redistribution and use in source and binary forms, with or without
|
66
|
+ * modification, are permitted provided that the following conditions
|
67
|
+ * are met:
|
68
|
+ * 1. Redistribution of source code must retail the above copyright
|
69
|
+ * notice, this list of conditions and the following disclaimer.
|
70
|
+ * 2. Redistributions in binary form must reproduce the above copyright
|
71
|
+ * notice, this list of conditions and the following disclaimer in the
|
72
|
+ * documentation and/or other materials provided with the distribution.
|
73
|
+ *
|
74
|
+ * THIS SOFTWARE IS PROVIDED BY JEFF WHEELHOUSE ``AS IS'' AND ANY EXPRESS OR
|
75
|
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
76
|
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
77
|
+ * NO EVENT SHALL JEFF WHEELHOUSE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
78
|
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT
|
79
|
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
80
|
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
81
|
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
82
|
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
83
|
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
84
|
+ *
|
85
|
+ * $Id: clog.h,v 1.2 2001/10/02 04:43:52 jdw Exp $
|
86
|
+ * $DragonFly: src/usr.sbin/clog/clog.h,v 1.1 2004/10/30 20:26:46 dillon Exp $
|
87
|
+ */
|
88
|
+
|
89
|
+
|
90
|
+#ifndef _CLOG_H_
|
91
|
+#define _CLOG_H_
|
92
|
+
|
93
|
+/*
|
94
|
+ * This magic constant is used to identify a valid circular log file.
|
95
|
+ * syslogd will ignore any circular log file that doesn't have this constant.
|
96
|
+ */
|
97
|
+
|
98
|
+const char MAGIC_CONST[4] = "CLOG";
|
99
|
+
|
100
|
+
|
101
|
+struct clog_footer {
|
102
|
+ uint32_t cf_magic;
|
103
|
+ uint32_t cf_wrap;
|
104
|
+ uint32_t cf_next;
|
105
|
+ uint32_t cf_max;
|
106
|
+ uint32_t cf_lock;
|
107
|
+};
|
108
|
+
|
109
|
+
|
110
|
+#endif /* _CLOG_H_ */
|
111
|
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
|
112
|
index 60c74d1..606fbd5 100644
|
113
|
--- a/usr.sbin/syslogd/syslogd.c
|
114
|
+++ b/usr.sbin/syslogd/syslogd.c
|
115
|
@@ -89,6 +89,7 @@ __FBSDID("$FreeBSD$");
|
116
|
#include <sys/resource.h>
|
117
|
#include <sys/syslimits.h>
|
118
|
#include <sys/types.h>
|
119
|
+#include <sys/mman.h>
|
120
|
|
121
|
#include <netinet/in.h>
|
122
|
#include <netdb.h>
|
123
|
@@ -110,6 +111,8 @@ __FBSDID("$FreeBSD$");
|
124
|
#include <utmpx.h>
|
125
|
|
126
|
#include "pathnames.h"
|
127
|
+#include "clog.h"
|
128
|
+
|
129
|
#include "ttymsg.h"
|
130
|
|
131
|
#define SYSLOG_NAMES
|
132
|
@@ -118,6 +121,7 @@ __FBSDID("$FreeBSD$");
|
133
|
const char *ConfFile = _PATH_LOGCONF;
|
134
|
const char *PidFile = _PATH_LOGPID;
|
135
|
const char ctty[] = _PATH_CONSOLE;
|
136
|
+const char ring_magic[] = "CLOG";
|
137
|
|
138
|
#define dprintf if (Debug) printf
|
139
|
|
140
|
@@ -183,6 +187,11 @@ struct filed {
|
141
|
char f_pname[MAXPATHLEN];
|
142
|
pid_t f_pid;
|
143
|
} f_pipe;
|
144
|
+ struct {
|
145
|
+ char f_rname[MAXPATHLEN];
|
146
|
+ struct clog_footer *f_footer;
|
147
|
+ size_t f_size;
|
148
|
+ } f_ring;
|
149
|
} f_un;
|
150
|
char f_prevline[MAXSVLINE]; /* last message logged */
|
151
|
char f_lasttime[16]; /* time of last occurrence */
|
152
|
@@ -261,10 +270,12 @@ int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */
|
153
|
#define F_USERS 5 /* list of users */
|
154
|
#define F_WALL 6 /* everyone logged on */
|
155
|
#define F_PIPE 7 /* pipe to program */
|
156
|
+#define F_RING 8 /* ring buffer (circular log) */
|
157
|
|
158
|
-const char *TypeNames[8] = {
|
159
|
+const char *TypeNames[9] = {
|
160
|
"UNUSED", "FILE", "TTY", "CONSOLE",
|
161
|
- "FORW", "USERS", "WALL", "PIPE"
|
162
|
+ "FORW", "USERS", "WALL", "PIPE",
|
163
|
+ "RING"
|
164
|
};
|
165
|
|
166
|
static struct filed *Files; /* Log files that we write to */
|
167
|
@@ -329,6 +340,8 @@ static int skip_message(const char *, const char *, int);
|
168
|
static void printline(const char *, char *, int);
|
169
|
static void printsys(char *);
|
170
|
static int p_open(const char *, pid_t *);
|
171
|
+ssize_t rbwrite __P((struct filed *, char *, size_t));
|
172
|
+ssize_t rbwritev __P((struct filed *, struct iovec *, int));
|
173
|
static void readklog(void);
|
174
|
static void reapchild(int);
|
175
|
static void usage(void);
|
176
|
@@ -1286,7 +1299,21 @@ fprintlog(struct filed *f, int flags, const char *msg)
|
177
|
needdofsync = 1;
|
178
|
}
|
179
|
break;
|
180
|
-
|
181
|
+ case F_RING:
|
182
|
+ dprintf(" %s\n", f->f_un.f_ring.f_rname);
|
183
|
+ v->iov_base = "\n";
|
184
|
+ v->iov_len = 1;
|
185
|
+ if (rbwritev(f, iov, 7)==-1) {
|
186
|
+ int e = errno;
|
187
|
+ (void)munmap(f->f_un.f_ring.f_footer,sizeof(struct clog_footer));
|
188
|
+ (void)close(f->f_file);
|
189
|
+ f->f_type = F_UNUSED;
|
190
|
+ errno = e;
|
191
|
+ logerror(f->f_un.f_fname);
|
192
|
+ }
|
193
|
+
|
194
|
+ break;
|
195
|
+
|
196
|
case F_PIPE:
|
197
|
dprintf(" %s\n", f->f_un.f_pipe.f_pname);
|
198
|
v->iov_base = lf;
|
199
|
@@ -1589,6 +1616,10 @@ init(int signo)
|
200
|
}
|
201
|
f->f_un.f_pipe.f_pid = 0;
|
202
|
break;
|
203
|
+ case F_RING:
|
204
|
+ (void)munmap(f->f_un.f_ring.f_footer,sizeof(struct clog_footer));
|
205
|
+ (void)close(f->f_file);
|
206
|
+ break;
|
207
|
}
|
208
|
next = f->f_next;
|
209
|
if (f->f_program) free(f->f_program);
|
210
|
@@ -1730,6 +1761,10 @@ init(int signo)
|
211
|
}
|
212
|
break;
|
213
|
|
214
|
+ case F_RING:
|
215
|
+ printf("%s", f->f_un.f_ring.f_rname);
|
216
|
+ break;
|
217
|
+
|
218
|
case F_PIPE:
|
219
|
printf("%s", f->f_un.f_pipe.f_pname);
|
220
|
break;
|
221
|
@@ -1780,6 +1815,7 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host)
|
222
|
const char *p, *q;
|
223
|
char *bp;
|
224
|
char buf[MAXLINE], ebuf[100];
|
225
|
+ struct stat sb;
|
226
|
|
227
|
dprintf("cfline(\"%s\", f, \"%s\", \"%s\")\n", line, prog, host);
|
228
|
|
229
|
@@ -1953,9 +1989,16 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host)
|
230
|
p++;
|
231
|
endkey = ']';
|
232
|
}
|
233
|
- while (*p && (*p != endkey) && (i-- > 0)) {
|
234
|
+ while (*p && (*p != endkey) && (*p != '[') && (i-- > 0)) {
|
235
|
*tp++ = *p++;
|
236
|
}
|
237
|
+ if (*p == '[') {
|
238
|
+ p++;
|
239
|
+ while (*p && (*p != ']') && (i-- > 0)) {
|
240
|
+ *tp++ = *p++;
|
241
|
+ }
|
242
|
+ p++;
|
243
|
+ }
|
244
|
if (endkey == ']' && *p == endkey)
|
245
|
p++;
|
246
|
*tp = '\0';
|
247
|
@@ -2000,6 +2043,38 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host)
|
248
|
}
|
249
|
break;
|
250
|
|
251
|
+ case '%':
|
252
|
+ if ((f->f_file = open(p+1, O_RDWR, 0 )) < 0) {
|
253
|
+ f->f_type = F_UNUSED;
|
254
|
+ logerror(p+1);
|
255
|
+ break;
|
256
|
+ }
|
257
|
+ if (fstat(f->f_file,&sb)<0) {
|
258
|
+ (void)close(f->f_file);
|
259
|
+ f->f_type = F_UNUSED;
|
260
|
+ logerror(p+1);
|
261
|
+ break;
|
262
|
+ }
|
263
|
+ f->f_un.f_ring.f_footer = mmap(NULL,sizeof(struct clog_footer),PROT_READ|PROT_WRITE,MAP_SHARED,f->f_file,sb.st_size-sizeof(struct clog_footer));
|
264
|
+ if (f->f_un.f_ring.f_footer==NULL) {
|
265
|
+ (void)close(f->f_file);
|
266
|
+ f->f_type = F_UNUSED;
|
267
|
+ logerror(p+1);
|
268
|
+ break;
|
269
|
+ }
|
270
|
+ if (memcmp(&(f->f_un.f_ring.f_footer->cf_magic),MAGIC_CONST,4)!=0) {
|
271
|
+ (void)munmap(f->f_un.f_ring.f_footer,sizeof(struct clog_footer));
|
272
|
+ (void)close(f->f_file);
|
273
|
+ f->f_type = F_UNUSED;
|
274
|
+ errno = ENODEV;
|
275
|
+ logerror(p+1);
|
276
|
+ break;
|
277
|
+ }
|
278
|
+ f->f_un.f_ring.f_size = sb.st_size;
|
279
|
+ (void)strcpy(f->f_un.f_ring.f_rname, p + 1);
|
280
|
+ f->f_type = F_RING;
|
281
|
+ break;
|
282
|
+
|
283
|
case '|':
|
284
|
f->f_un.f_pipe.f_pid = 0;
|
285
|
(void)strlcpy(f->f_un.f_pipe.f_pname, p + 1,
|
286
|
@@ -2743,6 +2818,49 @@ socksetup(int af, char *bindhostname)
|
287
|
return (socks);
|
288
|
}
|
289
|
|
290
|
+ ssize_t rbwritev(struct filed *f, struct iovec *iov, int iovcnt) {
|
291
|
+ int i;
|
292
|
+ ssize_t out = 0;
|
293
|
+ ssize_t err;
|
294
|
+
|
295
|
+ for(i=0;i<iovcnt;i++) {
|
296
|
+ err = rbwrite(f,iov[i].iov_base,iov[i].iov_len);
|
297
|
+ if (err==-1) return -1;
|
298
|
+ out += err;
|
299
|
+ }
|
300
|
+ return out;
|
301
|
+ }
|
302
|
+
|
303
|
+
|
304
|
+ ssize_t rbwrite(struct filed *f, char *buf, size_t nbytes) {
|
305
|
+ size_t maxwrite = f->f_un.f_ring.f_footer->cf_max - f->f_un.f_ring.f_footer->cf_next;
|
306
|
+ ssize_t err;
|
307
|
+ ssize_t out = 0;
|
308
|
+
|
309
|
+ f->f_un.f_ring.f_footer->cf_lock = 1;
|
310
|
+ while (nbytes>0) {
|
311
|
+ maxwrite = f->f_un.f_ring.f_footer->cf_max - f->f_un.f_ring.f_footer->cf_next;
|
312
|
+ if (maxwrite>nbytes) maxwrite = nbytes;
|
313
|
+ err = pwrite(f->f_file,buf,maxwrite,f->f_un.f_ring.f_footer->cf_next);
|
314
|
+ if (err==-1) {
|
315
|
+ f->f_un.f_ring.f_footer->cf_lock = 0;
|
316
|
+ return -1;
|
317
|
+ }
|
318
|
+ nbytes -= err;
|
319
|
+ out += err;
|
320
|
+ buf += err;
|
321
|
+ f->f_un.f_ring.f_footer->cf_next += err;
|
322
|
+ if (f->f_un.f_ring.f_footer->cf_next==f->f_un.f_ring.f_footer->cf_max) {
|
323
|
+ f->f_un.f_ring.f_footer->cf_next = 0;
|
324
|
+ f->f_un.f_ring.f_footer->cf_wrap = 1;
|
325
|
+ }
|
326
|
+
|
327
|
+ }
|
328
|
+
|
329
|
+ f->f_un.f_ring.f_footer->cf_lock = 0;
|
330
|
+ return out;
|
331
|
+ }
|
332
|
+
|
333
|
static void
|
334
|
increase_rcvbuf(int fd)
|
335
|
{
|