Commit Graph

1803 Commits

Author SHA1 Message Date
Lennart Poettering da9fc98ded tree-wide: port more code over to PATH_STARTSWITH_SET() 2018-11-26 14:08:46 +01:00
Lennart Poettering 0cbd293e12 tree-wide: port over more cases to STR_IN_SET() 2018-11-26 14:08:46 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Zbigniew Jędrzejewski-Szmek a03d43593c journal: fix sort order of header includes 2018-11-20 07:27:37 +01:00
Yu Watanabe 278939be7a
Merge pull request #10847 from evverx/journald-stream-fuzzer
tests: add a fuzzer for journald streams
2018-11-20 13:37:27 +09:00
Evgeny Vereshchagin 9541f5ff5c tests: add a fuzzer for journald streams 2018-11-20 03:03:32 +01:00
Lennart Poettering 5e332028f2 util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other
headers without this affecting everything which pulls in macro.h, which
is one of our most basic headers.

This is just refactoring, no change in behaviour, in prepartion for
later changes.
2018-11-19 21:14:34 +01:00
Lennart Poettering 2a44bf5099
Merge pull request #10811 from keszybz/define-main-through-macro
Define main through macro
2018-11-19 15:28:17 +01:00
Evgeny Vereshchagin 1dab14aba7 journald: check whether sscanf has changed the value corresponding to %n
It's possible for sscanf to receive strings containing all three fields
and not matching the template at the same time. When this happens the
value of k doesn't change, which basically means that process_audit_string
tries to access memory randomly. Sometimes it works and sometimes it doesn't :-)

See also https://bugzilla.redhat.com/show_bug.cgi?id=1059314.
2018-11-17 11:25:19 +01:00
Zbigniew Jędrzejewski-Szmek 634a0ad3e5 cat: define main through macro 2018-11-17 09:13:35 +01:00
Evgeny Vereshchagin 090a20cfaf tests: add a fuzzer for process_audit_string 2018-11-16 23:14:31 +01:00
Lennart Poettering 567e5d5549
Merge pull request #10791 from keszybz/sd-event-get-enabled
Some minor tweaks for sd_event_source_get_enabled
2018-11-16 12:46:30 +01:00
Zbigniew Jędrzejewski-Szmek b6cdfbe5c4 journal: simplify use of sd_event_source_get_enabled() 2018-11-16 09:03:41 +01:00
Zbigniew Jędrzejewski-Szmek ca5d90d4d9 journal-file: get rid of a helper variable
It doesn't really save much in code length. Having the event source named
explicitly makes it easier to understand the code at a glance.
2018-11-16 09:03:41 +01:00
Evgeny Vereshchagin 080d112caa journal: fix an off-by-one error in dev_kmsg_record 2018-11-16 08:45:16 +01:00
Evgeny Vereshchagin 8857fb9beb tests: add a fuzzer for dev_kmsg_record 2018-11-16 08:44:35 +01:00
Zbigniew Jędrzejewski-Szmek cd5a29ce98
Merge pull request #10742 from poettering/c-utf8
default to C.UTF-8 locale, and many improvements to env var file parsing/kernel cmdline parsing
2018-11-15 12:47:17 +01:00
Lennart Poettering 13df9c398d fileio: automatically add NULL sentinel to parse_env_file()
Let's modernize things a bit.
2018-11-14 17:01:55 +01:00
Lennart Poettering aa8fbc74e3 fileio: drop "newline" parameter for env file parsers
Now that we don't (mis-)use the env file parser to parse kernel command
lines there's no need anymore to override the used newline character
set. Let's hence drop the argument and just "\n\r" always. This nicely
simplifies our code.
2018-11-14 17:01:54 +01:00
Zbigniew Jędrzejewski-Szmek fde32028a4 Move LONG_LINE_MAX definition to fileio.h
All users of the macro (except for one, in serialize.c), use the macro in
connection with read_line(), so they must include fileio.h.  Let's not play
libc games and require multiple header file to be included for the most common
use of a function.

The removal of def.h includes is not exact. I mostly went over the commits that
switch over to use read_line() and add def.h at the same time and reverted the
addition of def.h in those files.
2018-11-14 16:25:32 +01:00
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Zbigniew Jędrzejewski-Szmek 8e143a1232 journalctl: do not treat EINTR as an error when waiting for events
Fixup for 2a1e0f2228. Fixes #10724.

Reproducer: start 'journalctl -f' in a terminal window, change window size.
2018-11-11 12:40:27 +01:00
Zbigniew Jędrzejewski-Szmek 2f5ed71556 Drop copyright for Marius Vollmer
Ack in #9320.
2018-10-31 09:34:38 +01:00
Lennart Poettering 8cb17a64c4
Merge pull request #10563 from keszybz/lz4-quickfix-quickfix
journal: adapt for new improved LZ4_decompress_safe_partial()
2018-10-30 14:51:55 +01:00
Zbigniew Jędrzejewski-Szmek e41ef6fd00 journal: adapt for new improved LZ4_decompress_safe_partial()
With lz4 1.8.3, this function can now decompress partial results into a smaller
buffer. The release news don't say anything interesting, but the test case that
was previously failing now works OK.

Fixes #10259.

A test is added. It shows that with *older* lz4, a partial decompression can
occur with the returned size smaller then the requested number of bytes _and_
smaller then the size of the compressed data:

(lz4-libs-1.8.2-1.fc29.x86_64)
Compressed 4194304 → 16464
Decompressed → 4194304
Decompressed partial 12/4194304 → 4194304
Decompressed partial 1/1 → -2 (bad)
Decompressed partial 2/2 → -2 (bad)
Decompressed partial 3/3 → -2 (bad)
Decompressed partial 4/4 → -2 (bad)
Decompressed partial 5/5 → -2 (bad)
Decompressed partial 6/6 → 6 (good)
Decompressed partial 7/7 → 6 (good)
Decompressed partial 8/8 → 6 (good)
Decompressed partial 9/9 → 6 (good)
Decompressed partial 10/10 → 6 (good)
Decompressed partial 11/11 → 6 (good)
Decompressed partial 12/12 → 6 (good)
Decompressed partial 13/13 → 6 (good)
Decompressed partial 14/14 → 6 (good)
Decompressed partial 15/15 → 6 (good)
Decompressed partial 16/16 → 6 (good)
Decompressed partial 17/17 → 6 (good)
Decompressed partial 18/18 → -16459 (bad)

(lz4-libs-1.8.3-1.fc29.x86_64)
Compressed 4194304 → 16464
Decompressed → 4194304
Decompressed partial 12/4194304 → 12
Decompressed partial 1/1 → 1 (good)
Decompressed partial 2/2 → 2 (good)
Decompressed partial 3/3 → 3 (good)
Decompressed partial 4/4 → 4 (good)
...

If we got such a short "successful" decompression in decompress_startswith() as
implemented before this patch, we could be confused and return a false negative
result. But it turns out that this only occurs with small output buffer
sizes. We use greedy_realloc() to manager the buffer, so it is always at least
64 bytes. I couldn't hit a case where decompress_startswith() would actually
return a bogus result. But since the lack of proof is not conclusive, the code
for *older* lz4 is changed too, just to be safe. We cannot rule out that on a
different architecture or with some unlucky compressed string we could hit this
corner case.

The fallback code is guarded by a version check. The check uses a function not
the compile-time define, because there was no soversion bump in lz4 or new
symbols, and we could be compiled against a newer lz4 and linked at runtime
with an older one. (This happens routinely e.g. when somebody upgrades a subset
of distro packages.)
2018-10-30 11:04:51 +01:00
Zbigniew Jędrzejewski-Szmek ba17efce44 test-compress: add test for short decompress_startswith calls
I thought this might fail with lz4 < 1.8.3, but it seems that because of
greedy_realloc, we always use a buffer that is large enough, and it always
passes.
2018-10-30 09:28:51 +01:00
Zbigniew Jędrzejewski-Szmek e0a1d4b049 Drop support for lz4 < 1.3.0
lz4-r130 was released on May 29th, 2015. Let's drop the work-around for older
versions. In particular, we won't test any new code against those ancient
releases, so we shouldn't pretend they are supported.
2018-10-29 21:54:42 +01:00
Evgeny Vereshchagin e0f768c356 journal: drop an unused variable clang is complaining about
../../src/systemd/src/journal/journal-file.c:3592:30: warning: unused variable 'p' [-Wunused-variable]
        _cleanup_free_ char *p = NULL;
                             ^
1 warning generated.

This is a follow-up to 6812765891.
2018-10-29 15:21:58 +00:00
Lennart Poettering 2a1e0f2228 journalctl: in --follow mode watch stdout for POLLHUP/POLLERR and exit
Fixes: #9374
2018-10-26 12:28:38 +02:00
Lennart Poettering 971b52c485 journal-file: structured initialization is your friend 2018-10-25 21:44:48 +02:00
Lennart Poettering a33687b792 journald: when we are asked to rotate all files, let's also look at closed files
Before this when asked for rotation we'd only rotate files we have open
anyway. However there might be a number of other files on disk that are
active (i.e. not archived yet) but not open. Let's take care of those
too, so that rotation is always comprehensive, and the user gets the
guarantee that afterthe rotation all stored data is in archived files.

Fixes: #1017
2018-10-25 21:44:48 +02:00
Lennart Poettering e5b2d45c1d journalctl: fix error number in error message 2018-10-25 21:44:48 +02:00
Lennart Poettering 8df64fd01d journalctl: add ability to vacuum and rotate in one step
journalctl --vacuum-*= only vacuums archived files. To archive all
active files the rotate operation is used. Let's add a new switch that
combines both, so that the user a single command to first move all
running journal files into archival and then vacuum them.

See: #1017
2018-10-25 21:44:48 +02:00
Lennart Poettering d03077759e journald: log about an OOM condition 2018-10-25 21:44:48 +02:00
Lennart Poettering e859154447 journald: debug log when we cannot read the machine ID 2018-10-25 21:44:48 +02:00
Lennart Poettering 6812765891 journal-file: refactor journal_file_open_reliably()
Let's split out the part that actually renames the file in case we can't
open it into a new function journal_file_dispose().

This way we can reuse the function in other cases where we want to open
a file but can't.
2018-10-25 21:43:09 +02:00
Lennart Poettering 7a4d21ad20 journal-file: refactor journal_file_rotate()
Let's split the function in three: the part where we archive the old
file into journal_file_archive(), and the part where we initiate the
deferred closing into journal_file_initiate_close().
journal_file_rotate() then simply becomes a wrapper around these two
calls, and the opening of the new journal file.

This useful so that we can archive journal files without having to open
new ones, i.e. to do only the archival part of the rotation, without the
rotation part.
2018-10-25 21:43:09 +02:00
Lennart Poettering f760d8a858 journal: refactor out loop that processes deferred closes into its own function 2018-10-25 21:43:09 +02:00
Lennart Poettering 180e7f4e62 journal: fix some type confusion in journal_directory_vacuum()
Let's store array sizes and indexes in size_t. And let's count numbers
of files in uint64_t (simply because that is the type of the input
parameter for this of the function)
2018-10-25 21:43:09 +02:00
Lennart Poettering ab41da087d journald: use structured initialization 2018-10-25 21:42:05 +02:00
Lennart Poettering 6761e0a2fd journald: use usec_sub_unsigned() where we can 2018-10-25 21:42:05 +02:00
Evgeny Vereshchagin c8758e726c journald: use the "driver" transport for logging a refused connection
Otherwise, these messages can end up in `/dev/null` when journald is run
in containers as was shown in https://github.com/systemd/systemd/pull/10444#issuecomment-430927793.
2018-10-23 19:36:52 +02:00
Evgeny Vereshchagin 9e8b1ec08e sd-journal: escape binary data in match_make_string()
Fixes: #10383
2018-10-23 19:33:01 +02:00
Lennart Poettering 490c5a37cb tree-wide: some automatic coccinelle fixes (#10463)
Nothing fancy, just coccinelle doing its work.
2018-10-20 00:07:46 +09:00
Yu Watanabe 218b4609d0
Merge pull request #10447 from poettering/fgets-excorcism
let's get rid of fgets()
2018-10-19 08:36:01 +09:00
Lennart Poettering 2ff48e981e tree-wide: introduce setsockopt_int() helper and make use of it everywhere
As suggested by @heftig:

6d5e65f645 (commitcomment-30938667)
2018-10-18 19:50:29 +02:00
Lennart Poettering df2b06d1c2 catalog: fgets() excorcism 2018-10-18 13:39:29 +02:00
Anita Zhang 90fc172e19 core: implement per unit journal rate limiting
Add LogRateLimitIntervalSec= and LogRateLimitBurst= options for
services. If provided, these values get passed to the journald
client context, and those values are used in the rate limiting
function in the journal over the the journald.conf values.

Part of #10230
2018-10-18 09:56:20 +02:00
Lennart Poettering 8aeb1d3176
Merge pull request #10244 from poettering/nofile-bump
bump RLIMIT_NOFILE
2018-10-17 17:59:36 +02:00