109 Commits

Author SHA1 Message Date
alakatos
4abe60f526 imjournal: Add FileCreateMode module parameter
FileCreateMode allows to set the default file mode bits
when creating new files. As of now, it has only impact on the state file.
Add test suite as well.

Minor indentation fix in run_journal.yml
2023-06-08 12:18:02 +02:00
alakatos
fb5ae30e6a imjournal: add second fallback to _COMM
If SYSLOG_IDENTIFIER is not present in the journal message,
then lookup the _COMM field, which stands for the name
of the process the journal entry originates from. This is
needed in order to be in compliance with the journalctl
output.
2022-10-31 14:40:12 +01:00
t.feng
eab250be37
Fix Segmentation fault in close journal 2022-08-08 11:36:59 +08:00
Michael Biebl
6569133c75
Typo fixes (#4801)
* typo fix: ambigious -> ambiguous

* typo fix: aquire -> acquire

* typo fix: assgined -> assigned

* typo fix: cancelation -> cancellation

* typo fix: childs -> children

* typo fix: configuraton -> configuration

* typo fix: delemiter -> delimiter

* typo fix: forwardig -> forwarding

* typo fix: initializiation -> initialization

* typo fix: intializing -> initializing

* typo fix: lengh -> length

* typo fix: mesage -> message

* typo fix: occured -> occurred

* typo fix: occurence -> occurrence

* typo fix: paramter -> parameter

* typo fix: remaing -> remaining

* typo fix: resetted -> reset

* typo fix: suppored -> supported

* typo fix: Sytem -> System

* typo fix: uncommited -> uncommitted

* typo fix: depricated -> deprecated

* typo fix: stoping -> stopping

* type fix: allow to -> allow one to
2022-02-17 10:54:12 +01:00
alakatos
321fc76f0f Move rsyslog global parameters to rsconf_t struct 2022-01-13 12:43:21 +01:00
Gerd Rausch
6a1faa065a imjournal: flush buffer before fsync
Flush the FILE* buffer before rename & fsync in order
to not end up syncing an empty file.

Also, close WorkDir on fsync in order to prevent
file descriptor leakage.

Signed-off-by: Gerd Rausch <gerd.rausch@oracle.com>
Signed-off-by: Venu Busireddy <venu.busireddy@oracle.com>
2021-04-15 11:44:04 -07:00
Rainer Gerhards
201a491fab
cosmetic: fix dummy module name in debug output
When we have optional components (like imjournal) a dummy module
is used. It's sole purpose is to emit "this module is not available".
During init, the module emitted an invalid module name into the debug
log. This has now been replaced by the generic term "dummy".

Note: it is highly unlikely that someone will ever see that message
at all, as it is unlikely for the dummy modules to be build.

see also: 84a7e3d80b (r41782830)

Thanks to Thomas D. (whissi) for the patch.
2020-08-26 14:28:10 +02:00
Rainer Gerhards
84a7e3d80b
build system: add --enable-imjournal=optional configure param 2020-06-29 14:49:09 +02:00
Rainer Gerhards
9fd27029a3
imjournal: restore code style
Commit f604d5269bd31c09a661e9e4a20dd5044f4750da introduced strlen("Constant")
what we prefer not to do. This is now changed to sizeof("Constant") - 1,
what we usally use.
2020-05-12 12:56:40 +02:00
Jeff Marckel
f604d5269b imjournal: remove strcat call 2020-02-27 11:52:32 -06:00
Jiri Vymazal
38ef313f0e Make handleRotation() function bit easier to read 2019-12-04 11:57:09 +01:00
Rainer Gerhards
df17aee501
Merge pull request #3981 from 3chas3/normalize-rate-limits
ratelimit: increase rate limit interval parameter
2019-12-02 17:07:11 +01:00
Charles (Chas) Williams
e5eb85129f Handle journal invalidate
The journal API will sometimes issue an SD_JOURNAL_INVALIDATE
which results in a repositioning of the cursor. From the man page:

    Programs only interested in a strictly sequential stream
    of log data may treat SD_JOURNAL_INVALIDATE the same way as
    SD_JOURNAL_APPEND, thus ignoring any changes to the log view
    earlier than the old end of the log stream.

If we have configured IgnorePreviousMessages, we want to treat the
invalidate event as an append, and wind to the end of the message
stream.
2019-11-29 15:57:36 -05:00
Charles (Chas) Williams
9f0282c7b8 ratelimit: increase rate limit interval parameter
The burst parameter in the ratelimit was increased to an unsigned int
but the interval remained an unsigned short. While it may be unusual,
there is possibly a chance to need to represent an interval longer than
about 3/4 of a day.

While here, go through and normalize all the various incarnations of
rate limiting to be explicitly unsigned int for the burst and interval.
2019-11-20 18:05:12 -05:00
Rainer Gerhards
85a886602e
imjournal bugfix: do not wait too long on recovery try
When trying to recover journal errors, imjournal waited a hardcoded
period of 10s between tries. This was pretty long and could lead to
loss of journal data.

This commit adjust it to 100ms, which should still be fully sufficient
to prevent the journal from "hammering" the CPU.

It may be worth considering to make this setting configurable - but
let's first see if there is real demand to actually do that.

closes https://github.com/rsyslog/rsyslog/issues/3969
2019-11-16 14:04:06 +01:00
Winslow Dalpe
399fb1f9c0 #3784: set the journal data threshold to MaxMessageSize
When data is read from the journal using sd_journal_get_data it may be
truncated to a certain threshold (64K by default).

If the rsyslog MaxMessageSize is larger than the threshold, there's a
chance rsyslog will receive incomplete messages from the journal.
Empirically, this appears to happen reliably when XZ compression is
used by journald. Systems where journald uses LZ4 compression do not
appear to suffer this issue reliably--if at all.

This change sets the threshold to the MaxMessageSize when the
journal is opened.
2019-10-29 20:42:35 -07:00
Rainer Gerhards
47c658661a
imjournal: fix regression
commit 78976a9bc059 introduced a regression that caused writing
the journal state file to fail. This happens when the state file
is given as relative file name and the working directory is also
a relative path. This situation is very uncommon. So most deployments
will never experience it. We discovered the issue during CI runs
where the trigger condition is given. Note that it also takes
multiple times of loading the journal to actually see the bug.

see also https://github.com/rsyslog/rsyslog/pull/3878
2019-10-16 13:09:01 +02:00
Jiri Vymazal
78976a9bc0 plugin code restructuring, added remote option
Decomposed ReadJournal() a bit, also now coupling journald
variables in one struct, added few warning messages and debug
prints to help with bug hunts in future, also got rid of two
needless journald calls. WorkAroundJournalBug now deprecated.
Added option to pull journald records from outside local machine.
2019-10-14 11:33:29 +02:00
Jiri Vymazal
bfe6a76607 Fix state-file closing with fsync option 2019-08-09 16:02:04 +02:00
Jiri Vymazal
32414a4bf2 added mising modpdescr for fsync 2019-07-23 14:14:44 +02:00
Jiri Vymazal
628d791b26 Add "fsync" option for imjournal
The new option makes possible to force physical write of stateFile
to persistent storage, ensuring we do not lose/duplicate messages
in case of hard crash or power loss.
2019-07-23 11:28:31 +02:00
Jiri Vymazal
1f625ffc8b Advance cursor after reloading journal
This fixes situation when journal was preloaded from previously
saved cursor but was not advanced to next entry so reading begun
from last message which was therefore duplicated.
2019-05-17 16:12:37 +02:00
Jiri Vymazal
9c22b31cd6 Fetching journal cursor only for valid journal
The sd_journal_get_cursor() got called regradless of previous
retcodes from other jorunal calls which flooded logs with journald
errors. Now skipping the call in case of previous journal call
non-zero result. Fixed success checking of get_cursor() call
to eliminate double-free possibility.

Also, making WorkAroundJournalBug true by default, as there were no
confirmed performance regressions for a quite long time.
2019-03-26 16:25:34 +01:00
Jiri Vymazal
9123293a2f Added missing reset of journal cursor
In one case there was possibility of free()'d value of journal
cursor not being reset, causing double-free and crash later on.
2019-03-15 11:18:33 +01:00
Jiri Vymazal
920c28ff70 Added missing free() calls of received journal cursor 2019-01-25 11:13:21 +01:00
Jiri Vymazal
0a245ddb33 Fix journald excessive reloading behavior
This is workaround for possible imjournal interaction with systemd
where journal invalidate fix is not present. The code tries to
detect SD_JOURNAL_INVALIDATE loop and not reload after each call.
2018-10-26 14:52:32 +02:00
Jiri Vymazal
0b3cb3401b Fixed resource leak in persistJournalState()
If fputs() failed we aborted without closing opened handle
2018-08-01 09:49:39 +02:00
Jiri Vymazal
59e58b5ec8 Fetching cursor on readJournal() and simplified pollJournal()
Fetching journal cursor in persistJournal could cause us to save
invalid cursor leading to duplicating messages further on, when new
WorkAroundJournalBug option is set we are saving it on each
readJournal() where we now that the state is good.

pollJournal() is now cleaner and faster, correctly handles INVALIDATE
status from journald and is able to continue polling after journal
flush. Also reduced POLL_TIMEOUT a bit as it caused rsyslog to exit
with error in corner cases for some ppc when left at full second.

re-factored imjournal CI tests with journal_print tool to have more
detailed error reporting
2018-07-31 12:08:25 +02:00
PascalWithopf
19133327cc correct codestyle in rsyslog 2018-07-31 09:44:27 +02:00
Jiri Vymazal
534d79344b Added skip journal load on first run
When starting rsyslog with imjournal for first time it outputs
an error and plugin does not run because no state file exists yet.
Now it skips the loading and creates state file on first persist.
Also fixed imjournal tests to actually test plugin functionality.
2018-07-24 15:40:54 +02:00
Abdul Waheed
69f8e1d1f7 imjournal: add journal impstats
imjournal: journal visibility through additional impstats counters
2018-06-26 13:01:27 +02:00
PascalWithopf
a35152d1c4 add statistics counter to imjournal
following statistics counter are now supported by imjournal
- submitted = total number of messages submitted for processing

closes https://github.com/rsyslog/rsyslog/issues/2549
2018-05-15 12:57:02 +02:00
Peter Portante
34b2d73369 Proposed fix for handling journal correctly
The fix is to immediately setup the inotify file descriptor via
`sd_journal_get_fd()` right after a journal open, and then
periodically call `sd_journal_process()` to give the client API
library a chance to detect deleted journal files on disk that need to
be closed so they can be properly erased by the file system.

We remove the open/close dance and simplify that code as a result.

Fixes issue #2436.
2018-02-01 17:43:59 -05:00
PascalWithopf
29c9fb1f9a codestyle: reduce line length to 120
lines are still checked for a length of 125 because
these are just some of the lines
2017-12-21 17:09:32 +01:00
Rainer Gerhards
6a5ba5cce8 imjournal: refactor journal state file load
Remove "time of check time of use" Coverity scan warning by refactoring
the code to directly try out things prior to just checking if we could.
Ultimately, we need to handle the same error (and already did so), so
there was little point in doing a check first.

Coverity scan CID 185500
2017-11-21 08:19:35 +01:00
PascalWithopf
e485c5c5bc codestyle: shorten lines to max 130 chars 2017-11-15 09:04:42 +01:00
Rainer Gerhards
27f96c84d3 imjournal bugfix: do not disable itself on error
If some functions calls inside the main loop failed, imjournal exited
with an error code, actually disabling all logging from the journal.
This was probably never intended.

This patch makes imjournal recover the situation instead.

closes https://github.com/rsyslog/rsyslog/issues/1895
2017-11-05 14:41:48 +01:00
Rainer Gerhards
82f9c4486e imjournal: refactor module, add more error messages
Medium-Size refactoring. Could still need some more brush-up
but is in better shape than before.

closes https://github.com/rsyslog/rsyslog/issues/1868
2017-11-05 14:41:48 +01:00
Rainer Gerhards
60accc74a2 imjournal cosmetic: use new-style LogMsg/LogError interface 2017-11-05 14:41:48 +01:00
Rainer Gerhards
9564267b71 imjournal: fix error message
The return state was invalidly handled. Errno is not used by libjournal,
we need to use the return value to obtain error message.

see also https://github.com/rsyslog/rsyslog/issues/1867
2017-11-05 14:41:48 +01:00
Rainer Gerhards
4736e53d47 imjournal bugfix: module did not work at all
The open function was broken by commit 92ac801 (v8.30.0),
resulting in no data being ever read from the journal.

patch bases on the idea of Radovan Sroka given here:
https://github.com/rsyslog/rsyslog/issues/1895#issuecomment-339017357
but follows the current imjournal-paradigm of having the journal
handle inside a global variable.

see also https://github.com/rsyslog/rsyslog/issues/1895
closes https://github.com/rsyslog/rsyslog/issues/1897
2017-10-25 11:15:01 +02:00
Rainer Gerhards
7b33904153 Merge pull request #1757 from tammar96/master
Fixed possible segfault.
2017-09-07 13:59:28 +02:00
Jiri Vymazal
83388eabe9 enabling falback to older systemd version without restart-less
persistent journal switch
2017-09-07 12:19:18 +02:00
Marek Tamaskovic
a5b40bb57c fixed nullptr check 2017-09-06 17:10:24 +02:00
Jiri Vymazal
92ac8016e4 Made switching to persistent journal in runtime possible,
now you can continue logging after switch to persistent
journal without need to restart rsyslog service.
Bumped correspondidng systemd version dependency.
2017-09-05 14:12:31 +02:00
Radovan Sroka
89ce7cb535 _PID fallback
- added fallback for _PID proprety when SYSLOG_PID is not available
- introduced new option "usepid" which sets which property should
  rsyslog use, it has 3 states system|syslog|both, default is both
- deprecated "usepidfromsystem" option, still can be used
  and override the "usepid"
- it is possible to revert previous default with usepid="syslog"
2017-05-31 15:24:45 +02:00
Radovan Sroka
f2df6ed2f3 Fixed situation when time goes backwards
This is resolving the situation when system is after reboot and boot_id doesn't match
so cursor pointing into "future".
Usually sd_journal_next jump to head of journal due to journal aproximation,
but when system time goes backwards and cursor is still invalid, rsyslog stops logging.
We use sd_journal_get_cursor to validate our cursor.
When cursor is invalid we are trying to jump to the head of journal
This problem with time should not affect persistent journal,
but if cursor has been intentionally compromised it could stop logging even
with persistent journal.
2017-02-16 15:30:26 +01:00
Pascal Withopf
b63a6b9010 codestyle: line length adjusted 2017-01-17 08:54:37 +01:00
Tomas Sykora
5cc4d07409 Removed old config of ignorenonvalidstatefile 2016-12-22 04:50:41 -05:00
Tomas Sykora
6069d501ee Make state file handling in imjournal more robust 2016-12-08 10:32:55 -05:00