Fix #61: add support for -c and -cc to disable log compression

This patch imports the FreeBSD meaning to the `-c` command line option.
It disables "last message repeated" style log compression for repeated
log messages.  A single `-c` disables compression for pipes, another
`-c` (-cc works) also disables compression for all other log targets.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2023-04-22 08:48:32 +02:00
parent b3d0a9b638
commit 218a032557
2 changed files with 15 additions and 3 deletions

View File

@ -38,7 +38,7 @@
.Nd log systems messages
.Sh SYNOPSIS
.Nm
.Op Fl ?468AdFHKknsTtv
.Op Fl ?468AcdFHKknsTtv
.Op Fl a Ar addr[/len][:port]
.Op Fl a Ar name[:port]
.Op Fl b Ar addr[:port]
@ -245,6 +245,12 @@ relies on this file being removed at system reboot. The default
location depends on the system and how
.Nm
was configured.
.It Fl c
Disable the compression of repeated instances of the same line into a
single line of the form
.Dq Li "last message repeated N times"
when the output is a pipe to another program. If specified twice,
disable this compression in all cases.
.It Fl d
Put
.Nm

View File

@ -144,6 +144,7 @@ static int MarkInterval = 20 * 60; /* interval between marks in seconds */
static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */
static int mask_C1 = 1; /* mask characters from 0x80 - 0x9F */
static int send_to_all; /* send message to all IPv4/IPv6 addresses */
static int no_compress; /* don't compress messages (1=pipes, 2=all) */
static int secure_opt; /* sink for others, log to remote, or only unix domain socks */
static int secure_mode; /* same as above but from syslog.conf, only if cmdline unset */
@ -396,7 +397,7 @@ int main(int argc, char *argv[])
char *ptr;
int ch;
while ((ch = getopt(argc, argv, "468Aa:b:C:dHFf:Kkm:nP:p:r:sTtv?")) != EOF) {
while ((ch = getopt(argc, argv, "468Aa:b:C:cdHFf:Kkm:nP:p:r:sTtv?")) != EOF) {
switch ((char)ch) {
case '4':
family = PF_INET;
@ -434,6 +435,10 @@ int main(int argc, char *argv[])
CacheFile = optarg;
break;
case 'c':
no_compress++;
break;
case 'd': /* debug */
Debug = 1;
Foreground = 1;
@ -1680,7 +1685,8 @@ static void logmsg(struct buf_msg *buffer)
/*
* suppress duplicate lines to this file
*/
if ((buffer->flags & MARK) == 0 && savedlen == f->f_prevlen &&
if (no_compress - (f->f_type != F_PIPE) < 1 &&
(buffer->flags & MARK) == 0 && savedlen == f->f_prevlen &&
!strcmp(saved, f->f_prevline)) {
f->f_lasttime = buffer->timestamp;
f->f_prevcount++;