diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2011-07-12 11:28:32 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2011-07-12 11:28:32 +0000 |
commit | 05243c6f66a5234bfa91c181715631f297522bea (patch) | |
tree | 51bd56ac28826ec4b60bc62b2672b8a04b4fc879 /usr.sbin | |
parent | e5e2aedcbb8ace7ea6fee83762905d18f32f9776 (diff) |
Allow syslogc -n XX to display less than the whole file, and -n XX -f to
display more/less than the default of 10. ok mpf@ jmc@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/syslogc/syslogc.8 | 9 | ||||
-rw-r--r-- | usr.sbin/syslogc/syslogc.c | 18 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 10 |
3 files changed, 27 insertions, 10 deletions
diff --git a/usr.sbin/syslogc/syslogc.8 b/usr.sbin/syslogc/syslogc.8 index fbf525f717b..821aef01661 100644 --- a/usr.sbin/syslogc/syslogc.8 +++ b/usr.sbin/syslogc/syslogc.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: syslogc.8,v 1.8 2008/09/10 22:17:33 sobrado Exp $ +.\" $OpenBSD: syslogc.8,v 1.9 2011/07/12 11:28:31 sthen Exp $ .\" .\" Copyright (c) 2004 Damien Miller .\" @@ -13,7 +13,7 @@ .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.Dd $Mdocdate: September 10 2008 $ +.Dd $Mdocdate: July 12 2011 $ .Dt SYSLOGC 8 .Os .Sh NAME @@ -22,6 +22,7 @@ .Sh SYNOPSIS .Nm syslogc .Op Fl Ccfo +.Op Fl n Ar lines .Op Fl s Ar reporting_socket .Ar logname .Nm syslogc @@ -48,7 +49,7 @@ option to .Pp By default, .Nm -will query the specified log and return it to standard output. +will query the specified log and return all entries to standard output. .Pp The options are as follows: .Bl -tag -width Ds @@ -62,6 +63,8 @@ Like the .Fl f option in .Xr tail 1 . +.It Fl n Ar lines +Print the specified number of lines from the end of the buffer. .It Fl o Check whether the specified log has overflowed. If the log has overflowed, then a message will be printed to diff --git a/usr.sbin/syslogc/syslogc.c b/usr.sbin/syslogc/syslogc.c index a6a30b46c91..dedf82b78d9 100644 --- a/usr.sbin/syslogc/syslogc.c +++ b/usr.sbin/syslogc/syslogc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogc.c,v 1.15 2011/07/04 20:23:09 mpf Exp $ */ +/* $OpenBSD: syslogc.c,v 1.16 2011/07/12 11:28:31 sthen Exp $ */ /* * Copyright (c) 2004 Damien Miller @@ -22,6 +22,7 @@ #include <err.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -33,7 +34,7 @@ /* * Client protocol NB. all numeric fields in network byte order */ -#define CTL_VERSION 1 +#define CTL_VERSION 2 /* Request */ struct ctl_cmd { @@ -45,6 +46,7 @@ struct ctl_cmd { #define CMD_FLAGS 5 /* Query flags only */ #define CMD_READ_CONT 6 /* Read out log continuously */ u_int32_t cmd; + u_int32_t lines; char logname[MAX_MEMBUF_NAME]; }; @@ -61,7 +63,8 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-Ccfo] [-s reporting_socket] logname\n" + fprintf(stderr, + "usage: %s [-Ccfo] [-n lines] [-s reporting_socket] logname\n" " %s -q\n", __progname, __progname); exit(1); } @@ -78,12 +81,13 @@ main(int argc, char **argv) extern int optind; struct ctl_cmd cc; struct ctl_reply_hdr rr; + const char *errstr; memset(&cc, '\0', sizeof(cc)); ctlsock_path = DEFAULT_CTLSOCK; rval = oflag = 0; - while ((ch = getopt(argc, argv, "Ccfhoqs:")) != -1) { + while ((ch = getopt(argc, argv, "Ccfhon:qs:")) != -1) { switch (ch) { case 'C': cc.cmd = CMD_CLEAR; @@ -97,6 +101,12 @@ main(int argc, char **argv) case 'f': cc.cmd = CMD_READ_CONT; break; + case 'n': + cc.lines = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr) + errx(1, "number of lines is %s: %s", + errstr, optarg); + break; case 'o': cc.cmd = CMD_FLAGS; oflag = 1; diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index cc9782b75df..d092abf6b3f 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.103 2009/10/27 23:59:54 deraadt Exp $ */ +/* $OpenBSD: syslogd.c,v 1.104 2011/07/12 11:28:31 sthen Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -207,7 +207,7 @@ int membuf_drop = 0; /* logs were dropped in continuous membuf read */ /* * Client protocol NB. all numeric fields in network byte order */ -#define CTL_VERSION 1 +#define CTL_VERSION 2 /* Request */ struct { @@ -219,6 +219,7 @@ struct { #define CMD_FLAGS 5 /* Query flags only */ #define CMD_READ_CONT 6 /* Read out log continuously */ u_int32_t cmd; + u_int32_t lines; char logname[MAX_MEMBUF_NAME]; } ctl_cmd; @@ -1910,7 +1911,10 @@ ctlconn_read_handler(void) } if (ctl_cmd.cmd == CMD_READ_CONT) { f->f_un.f_mb.f_attached = 1; - tailify_replytext(reply_text, 10); + tailify_replytext(reply_text, + ctl_cmd.lines > 0 ? ctl_cmd.lines : 10); + } else if (ctl_cmd.lines > 0) { + tailify_replytext(reply_text, ctl_cmd.lines); } } break; |