1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-03 06:45:37 -08:00

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@
This commit is contained in:
sthen 2011-07-12 11:28:31 +00:00
parent 30df58edb6
commit 2cb6e4c655
3 changed files with 27 additions and 10 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;