65 Commits

Author SHA1 Message Date
Rainer Gerhards
b326c76f45 style: normalize C source formatting via clang-format (PoC)
This commit applies the new canonical formatting style using `clang-format` with custom settings (notably 4-space indentation), as part of our shift toward automated formatting normalization.

⚠️ No functional changes are included — only whitespace and layout modifications as produced by `clang-format`.

This change is part of the formatting modernization strategy discussed in:
https://github.com/rsyslog/rsyslog/issues/5747

Key context:
- Formatting is now treated as a disposable view, normalized via tooling.
- The `.clang-format` file defines the canonical style.
- A fixup script (`devtools/format-code.sh`) handles remaining edge cases.
- Formatting commits are added to `.git-blame-ignore-revs` to reduce noise.
- Developers remain free to format code however they prefer locally.
2025-07-16 13:56:21 +02:00
Rainer Gerhards
5520373959
imfile bugfix: message loss/duplication when monitored file is rotated
When a to-be-monitored file is being rotated, some messages may be lost or
duplicated. In case of duplication, many file lines may be duplicated
depending on actual timing. The whole bug was primarily timing depenedent
in general. It most often was visible in practice when the monitored
file was very frequently rotated (we had some report with every few
seconds).

Note that while we try hard to not lose any messages, input file
rotation always has some loss potential. This is inevitable if
the monitored file is being truncated.

Also note that this bugfix affects imfile, only. It has nothing to do
and no relation to rsyslog output files being rotated on HUP.

closes: https://github.com/rsyslog/rsyslog/issues/4797
2022-08-04 12:54:07 +02:00
Rainer Gerhards
90feae08e6
omfile: support for zstd compression
The zstd library provides better and faster compression than zlib.
This patch integrates zstd as a dynamically-loadable functionality.
As such, no further dependencies need to be added to the rsyslog
base package.

Due to the increased performance, usage of zstd is highly recommended
for high-volume use cases.

This patch also refactor zlib compression in order to unify handling
in both compression cases.
2022-07-13 14:31:51 +02:00
Rainer Gerhards
370b86133b
imfile: add new input parameter escapeLF.replacement
The new parameter permits to specify a replacement to be configured
when "escapeLF" is set to "on". Previously, a fixed replacement string
was used ("#012"/"\n") depending on circumstances. If the parameter is
set to an empty string, the LF is simply discarded.

closes https://github.com/rsyslog/rsyslog/issues/3889
2019-11-14 14:31:24 +01:00
Rainer Gerhards
7d2a3b9e5d
cleanup and small testbench plumbing improvement 2018-10-22 18:01:44 +02:00
Rainer Gerhards
f85ef7aabc
bugfix imfile: file change was not reliably detected
A change in the inode was not detected under all circumstances,
most importantly not in some logrotate cases.

Includes new tests made by Andre Lorbach. They now use the
logrotate tool natively to reproduce the issue.
2018-09-27 10:00:57 +02:00
Rainer Gerhards
2d15cbc822 imfile: improve truncation detection
previously, truncation was only detected at end of file. Especially with
busy files that could cause loss of data and possibly also stall imfile
reading. The new code now also checks during each read. Obviously, there
is some additional overhead associated with that, but this is unavoidable.

It still is highly recommended NOT to turn on "reopenOnTruncate" in imfile.
Note that there are also inherant reliability issues. There is no way to
"fix" these, as they are caused by races between the process(es) who truncate
and rsyslog reading the file. But with the new code, the "problem window"
should be much smaller and, more importantly, imfile should not stall.

see also https://github.com/rsyslog/rsyslog/issues/2659
see also https://github.com/rsyslog/rsyslog/issues/1605
2018-09-22 15:52:38 +02:00
Rich Megginson
c902a0938f imfile: support for endmsg.regex
This adds support for endmsg.regex.  It is similar to
startmsg.regex except that it matches the line that denotes
the end of the message, rather than the start of the next message.
This is primarily for container log file use cases such as this:

    date stdout P start of message
    date stdout P  middle of message
    date stdout F  end of message

The `F` means this is the line which contains the final part of
the message.  The fully assembled message should be
`start of message middle of message end of message`.
`startmsg.regex="^[^ ]+ stdout F "` will match.
2018-09-11 20:01:47 -06:00
PascalWithopf
19133327cc correct codestyle in rsyslog 2018-07-31 09:44:27 +02:00
Rainer Gerhards
d5cadd26d4 imfile: refactor state file format
We change it to json and also change the way it is stored and loaded.
This sets base to additional improvements in imfile.

closes https://github.com/rsyslog/rsyslog/issues/2529
2018-03-29 09:15:27 +02:00
Rainer Gerhards
0858209381 imfile: adjust offset metadata to give begin offset of file 2017-09-07 17:08:21 +02:00
PascalWithopf
2f40554acb codestyle: correct too long lines 2017-06-29 09:28:21 +02:00
PascalWithopf
8ceaddde35 imfile: add posibility to truncate msg
closes https://github.com/rsyslog/rsyslog/issues/1552
2017-05-19 12:04:02 +02:00
PascalWithopf
a0a6e5bbba imfile: fix problem that fileNotFoundError was reported repeatedly in polling mode
fix https://github.com/rsyslog/rsyslog/issues/1534
2017-05-03 10:00:28 +02:00
PascalWithopf
3f789a4458 imfile: add error message when file is not found and parameter to disable this message 2017-05-02 10:54:56 +02:00
Pascal Withopf
b63a6b9010 codestyle: line length adjusted 2017-01-17 08:54:37 +01:00
kordex
ed37e8b6de core: fix potential negative file numbers for queue files 2016-10-18 13:04:23 +02:00
Rainer Gerhards
8eea909367 imfile: add "readTimeout" parameter
closes https://github.com/rsyslog/rsyslog/issues/1133
2016-10-10 15:45:45 +02:00
Rainer Gerhards
51c03c66e0 make inline functions C99-compliant
As it seems, different C compilers have different rules/interpretations
on inline functions. The current code base did not properly obey all C99
rules. We fix this by converting some functions to macros and others to
include the necessary C99 plumbing. We also remove some inline attributes
for functions where this seems to be to agressive (aka "function to big").

This fixes build problems in some environments and is a general code
cleanup measure.
2016-09-05 16:47:14 +02:00
Rainer Gerhards
6a387869fa queue subsystem: improve debug messages 2016-08-22 16:20:02 +02:00
Rainer Gerhards
3b0222c284 bugfix omfile: async output file writing does not respect flushing
neither parameter flushInterval nor flushOnTXEnd="on" was respected.

closes https://github.com/rsyslog/rsyslog/issues/1054
2016-05-27 14:49:01 +02:00
Rainer Gerhards
42155cd5b4 Merge branch 'trim-line-over-bytes' of https://github.com/JindongChen/rsyslog into merge-664
Conflicts:
	runtime/stream.h
2016-02-15 15:45:40 +01:00
Chen Jindong
7da93520ca Trim line when length of line over specified bytes 2015-12-11 13:58:37 +08:00
Matthew Wang
ca79a68f04 Reopen truncated file with opt-in flag 'reopenOnTruncate'
Attempt to fix #511.  This is an enhanced version based on
https://github.com/rsyslog/rsyslog/pull/514, works fine for us so far.
As discussed before, I added an opt-in flag 'reopenOnTruncate' and
default is "off".
2015-12-03 20:24:35 +08:00
Rainer Gerhards
483522a117 imfile: add support for multi-line msg termination via regex 2015-05-19 09:32:35 +02:00
Rainer Gerhards
6e511e8e8b imfile: preliminary patch for msg loss in readmode != 0
This is a preliminary patch, which needs to undergo further testing
in cases where rsyslogd is shut down with partial messages read.

see also https://github.com/rsyslog/rsyslog/issues/144
2015-03-29 14:38:59 +02:00
Rainer Gerhards
4bcccb64fd refactor: another round of qualifiers... 2013-12-04 12:10:07 +01:00
Rainer Gerhards
ea9c81ce3c imfile: support LF escaping in read mode 1 2013-09-10 11:34:31 +02:00
Rainer Gerhards
c3784aab3c Merge branch 'v6-stable' into tmp 2013-07-19 14:59:49 +02:00
Rainer Gerhards
ea4625e8a4 Merge branch 'v5-stable' into tmp 2013-07-19 14:59:09 +02:00
Tomas Heinrich
cbf7ab6f35 bugfix: correction to the interface of stream obj
The datatype of the argument to SetiMaxFileSize() was too small and
could overflow.
The SetMaxFileSize() interface wasn't used at all (possibly confused
with SetiMaxFileSize()) and was dropped.
2013-07-19 14:53:00 +02:00
Rainer Gerhards
0cee769fcd log encryption: initial PoC implementation
rough baseline, needs to be extended for actual use.
2013-04-05 12:08:49 +02:00
Rainer Gerhards
35bafbef04 imfile: now detects file change when rsyslog was inactive
Previosly, this case could not be detected, so if a file was overwritten
or rotated away while rsyslog was stopped, some data was missing. This
is now detected and the new file being forwarded right from the
beginning.
closes: http://bugzilla.adiscon.com/show_bug.cgi?id=228
2013-03-20 17:05:18 +01:00
Rainer Gerhards
42cd1fa7d7 Merge branch 'v7-stable'
Conflicts:
	configure.ac
	doc/manual.html
	plugins/imfile/imfile.c
	plugins/imklog/bsd.c
	plugins/imklog/imklog.c
	plugins/imklog/imklog.h
2012-11-22 11:05:45 +01:00
Rainer Gerhards
c563914d6f queue: file delete stream does no longer do real io
This stream is primarily used for state tracking, and has been
modified to do just that. This results in considerable less io
being done and the respective speedup.
2012-11-19 16:46:41 +01:00
Rainer Gerhards
3475caa394 refactor stream.h; fix some issues with last patch
Most importantly, the last patch for imfile contained a number
of glitches, which are fixed by this commit (a memory leak under
unusual conditions, partial message loss when rsyslog was
terminated in the interim & mixing file data to the wrong files
when multiple monitors were used [due to static variable]). The
commit is actually a re-write of the patch, based on its core
idea.

Also some other minor cleanup was done.
2012-11-15 10:08:26 +01:00
Rainer Gerhards
5a59687119 Merge branch 'c1-streamzip' into master-streamzip
Conflicts:
	ChangeLog
	configure.ac
	doc/rsyslog_conf_global.html
	runtime/stream.c
	tools/omfile.c
2012-10-05 12:45:14 +02:00
Rainer Gerhards
5df935249e improved omfile zip writer to increase compression
This was achieved by somewhat reducing the robustness of the zip
archive. This is controlled by the new setting $OMFileVeryReliableZip.
2012-09-14 18:41:30 +02:00
Rainer Gerhards
46605923a2 refactor: removing dead apc code
another concept that did not prove valuable enough to be kept active. For
the last couple of releases, the dead code was kept inside the project as
we thought we could probably reuse it. Doesn't look so...
2012-01-19 15:37:56 +01:00
David Lang
9813a12789 enhanced imfile to support multi-line messages
Signed-off-by: Rainer Gerhards <rgerhards@adiscon.com>
2011-01-25 14:24:50 +01:00
Rainer Gerhards
8f0a8076cc Merge branch 'beta' into master
Conflicts:
	ChangeLog
	configure.ac
	plugins/imudp/imudp.c
	runtime/stream.h
	tests/Makefile.am
	tests/diag.sh
	tools/omfile.c
2010-04-09 13:00:56 +02:00
Rainer Gerhards
8b9cef552d Merge branch 'v4-stable' into v5-stable
Conflicts:
	ChangeLog
	configure.ac
	doc/manual.html
	runtime/debug.c
	runtime/stream.c
	tests/Makefile.am
	tests/diskqueue.sh
	tests/nettester.c
	tools/omfile.c
2010-03-29 11:07:15 +02:00
Rainer Gerhards
6c43f93022 fixed regression introduced with previous commit
disk queue mode did no longer work correctly. A side-effect of
this commit here is slightly cleaned-up (and more elegant) code
for circular files.
2010-03-10 09:52:49 +01:00
Rainer Gerhards
38cb392672 replaced data type "bool" by "sbool" because this created some portability issues 2010-02-02 15:51:01 +01:00
Rainer Gerhards
9901996b5b Merge branch 'v4-beta' into beta
Conflicts:
	ChangeLog
2010-01-15 17:03:51 +01:00
Rainer Gerhards
5b4e06fc28 bugfix: rsyslog hangs when writing to a named pipe which nobody was reading.
Thanks to Michael Biebl for reporting this bug.
2010-01-15 17:01:10 +01:00
Rainer Gerhards
7d9ad61884 Merge branch 'beta' 2009-08-19 13:04:35 +02:00
Rainer Gerhards
bfc3eaf23c bugfix: potential segfault in output file writer (omfile)
In async write mode, we use modular arithmetic to index the output
buffer array. However, the counter variables accidently were signed,
thus resulting in negative indizes after integer overflow. That in turn
could lead to segfaults, but was depending on the memory layout of
the instance in question (which in turn depended on a number of
variables, like compile settings but also configuration). The counters
are now unsigned (as they always should have been) and so the dangling
mis-indexing does no longer happen. This bug potentially affected all
installations, even if only some may actually have seen a segfault.
2009-08-18 18:48:18 +02:00
Rainer Gerhards
cf906392c3 Merge branch 'v4-devel'
Conflicts:
	runtime/debug.h
	runtime/stream.c
2009-07-08 15:23:25 +02:00
Rainer Gerhards
5221a1e42e added capability to write incomplete buffers after an inactivity timeout
for the stream class and thus finally activating omfile's timeout
capability in a useful way without polling and too-high performance
overhead.
2009-07-07 18:33:00 +02:00