summaryrefslogtreecommitdiff
path: root/src/journal-remote
Commit message (Collapse)AuthorAgeFilesLines
...
* journal: stop using JournalFile.mmap everywhereVito Caputo2021-12-071-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Preparatory commit; before JournalFile can stop hanging onto its copy of MMapCache, all these users need to find another way. Most of the time these callers already have the MMapCache onhand, so it's no big deal for them to just supply it. journal_file_rotate() in particular needed to change, and it seemed wise to not use the mmap_cache_fd_cache() accessor on f->cache_fd, instead requiring the caller supply the cache to use. This was done with an eye towards a potential future where the journal_file_archive() isolates the cache_fd to a private cache, which the newly rotated-to file wouldn't be allowed to use. It's no biggie for the existing callers to just provide the appropriate surviving cache. Basically the mmap_cache_fd_cache() accessor was added just for journal-verify.c's (ab)use of the mmap-cache. Which, if the ugly singleton MMapCache assumption ever goes away, can be cleaned up to simply use a separate MMapCache for those search arrays.
* journal: Introduce journald-file.c for journal file write related logicDaan De Meyer2021-12-064-22/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, all the logic related to writing journal files lives in journal-file.c which is part of libsystemd (sd-journal). Because it's part of libsystemd, we can't depend on any code from src/shared. To allow using code from src/shared when writing journal files, let's gradually move the write related logic from journal-file.c to journald-file.c in src/journal. This directory is not part of libsystemd and as such can use code from src/shared. We can safely remove any journal write related logic from libsystemd as it's not used by any public APIs in libsystemd. This commit introduces the new file along with the JournaldFile struct which wraps an instance of JournalFile. The goal is to gradually move more functions from journal-file.c and fields from JournalFile to journald-file.c and JournaldFile respectively. This commit also modifies all call sites that write journal files to use JournaldFile instead of JournalFile. All sd-journal tests that write journal files are moved to src/journal so they can make use of journald-file.c. Because the deferred closes logic is only used by journald, we move it out of journal-file.c as well. In journal_file_open(), we would wait for any remaining deferred closes for the file we're about to open to complete before continuing if the file was not newly created. In journald_file_open(), we call this logic unconditionally since it stands that if a file is newly created, it can't have any outstanding deferred closes. No changes in behavior are introduced aside from the earlier execution of waiting for any deferred closes to complete when opening a new journal file.
* journal-remote: more handling of sd_event_source_set_enabled failuresLuca Boccassi2021-11-131-4/+14
| | | | | | | But avoid clobbering the return value if it works CID#1465793 CID#1465794
* tree-wide: don't ignore return code from sd_event_source_set_enabled()Luca Boccassi2021-11-121-2/+2
| | | | | | CID#1465793 CID#1465794 CID#1465795
* build: preserve correct mode when generating files via jinja2Christian Brauner2021-11-081-2/+1
| | | | | | | | | When using "capture : true" in custom_target()s the mode of the source file is not preserved when the generated file is not installed and so needs to be tweaked manually. Switch from output capture to creating the target file and copy the permissions from the input file. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
* tree-wide: always use TAKE_FD() when calling rearrange_stdio()Lennart Poettering2021-11-031-2/+2
| | | | | | | | | | | | rearrange_stdio() invalidates specified fds even on failure, which means we should always invalidate the fds we pass in no matter what. Let's make this explicit by using TAKE_FD() for that everywhere. Note that in many places we such invalidation doesnt get us much behaviour-wise, since we don't use the variables anymore later. But TAKE_FD() in a way is also documentation, it encodes explicitly that the fds are invalidated here, so I think it's a good thing to always make this explicit here.
* Merge pull request #20988 from DaanDeMeyer/rotate-reasonZbigniew Jędrzejewski-Szmek2021-10-191-1/+1
|\ | | | | journal: Improve rotation logging
| * journal: Add log level argument to journal_file_rotate_suggested()Daan De Meyer2021-10-181-1/+1
| | | | | | | | | | | | | | | | When journald is rotating a file, we'd like to log the reason at LOG_INFO or higher instead of LOG_DEBUG. For journalctl --header, logging the reason at a level higher than LOG_DEBUG doesn't really make sense. To accomodate both use cases, make the log level used by journal_file_rotate_suggested() configurable.
* | alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhereLennart Poettering2021-10-142-3/+3
|/ | | | | | | | | | | | | Let's define two helpers strdupa_safe() + strndupa_safe() which do the same as their non-safe counterparts, except that they abort if called with allocations larger than ALLOCA_MAX. This should ensure that all our alloca() based allocations are subject to this limit. afaics glibc offers three alloca() based APIs: alloca() itself, strndupa() + strdupa(). With this we have now replacements for all of them, that take the limit into account.
* variuos: add missing includesZbigniew Jędrzejewski-Szmek2021-09-221-0/+1
|
* tree-wide: mark set-but-not-used variables as unused to make LLVM happyFrantisek Sumsal2021-09-153-3/+3
| | | | | | | | | | | | | | LLVM 13 introduced `-Wunused-but-set-variable` diagnostic flag, which trips over some intentionally set-but-not-used variables or variables attached to cleanup handlers with side effects (`_cleanup_umask_`, `_cleanup_(notify_on_cleanup)`, `_cleanup_(restore_sigsetp)`, etc.): ``` ../src/basic/process-util.c:1257:46: error: variable 'saved_ssp' set but not used [-Werror,-Wunused-but-set-variable] _cleanup_(restore_sigsetp) sigset_t *saved_ssp = NULL; ^ 1 error generated. ```
* tree-wide: port everything over to new sd-id128 compund literal blissLennart Poettering2021-08-201-2/+1
|
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-035-8/+8
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* meson: use a/b instead of join_paths(a,b)Zbigniew Jędrzejewski-Szmek2021-07-271-1/+1
| | | | It is nicer and shorter.
* log-generator: count arguments as offset from an iteratormonosans2021-07-191-12/+4
|
* Add a network timeout option to journal-uploadJayanth Ananthapadmanaban2021-06-141-4/+12
|
* fuzz-journal-remote: print some kinds of errorsZbigniew Jędrzejewski-Szmek2021-05-311-1/+2
| | | | | | | | | | | In https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34803, we fail with: Assertion 'IN_SET(r, -ENOMEM, -EMFILE, -ENFILE)' failed at src/journal-remote/fuzz-journal-remote.c:69, function int LLVMFuzzerTestOneInput(const uint8_t *, size_t)(). Aborting. AddressSanitizer:DEADLYSIGNAL Let's try to print the error, so maybe we can see what is going on. With the previous commit we shouldn't print out anything.
* journal-remote: downgrade messages about input data to warningsZbigniew Jędrzejewski-Szmek2021-05-311-1/+1
| | | | | | Those are unexpected, so a user-visible message seems appropriate. But they are not our errors, and to some extent we can recover from them, so "warning" seems more appropriate than "error".
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-192-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
* meson: use jinja2 in src/journal-remoteZbigniew Jędrzejewski-Szmek2021-05-193-25/+23
| | | | | | One stanza had "if install_sysconfdir_samples", while the other "if install_sysconfdir", which looks like a mistake. install_sysconfdir_samples is now used for both.
* tree-wide: use af_to_ipv4_ipv6() + af_from_ipv4_ipv6() helpers at various placesLennart Poettering2021-05-111-1/+2
|
* Wider range of options for selecting entries for systemd-journal-gatewaydSamuel BF2021-05-102-3/+40
| | | | | Introducing --user, --system, --merge and --file flags, like for journalctl and systemd-journal-upload.
* fix: point to the correct drop-ins subdirectory for confsJóhann B. Guðmundsson2021-04-222-2/+2
|
* meson: simplify the BUILD_MODE conditionalZbigniew Jędrzejewski-Szmek2021-04-141-1/+1
| | | | | | | Using a enum is all nice and generic, but at this point it seems unlikely that we'll add further build modes. But having an enum means that we need to include the header file with the enumeration whenerever the conditional is used. I want to use the conditional in log.h, which makes it hard to avoid circular imports.
* tree-wide: avoid uninitialized warning on _cleanup_ variablesLuca Boccassi2021-04-142-2/+2
| | | | | | | With some versions of the compiler, the _cleanup_ attr makes it think the variable might be freed/closed when uninitialized, even though it cannot happen. The added cost is small enough to be worth the benefit, and optimized builds will help reduce it even further.
* journal-upload: use _cleanup_ for curl_slistDavid Tardon2021-03-181-8/+6
|
* journal-upload: make the curl_slist cleanup actually workDavid Tardon2021-03-181-5/+7
| | | | If h is NULL, it is pointless to call curl_slist_free_all() on it...
* journal-upload: cleanup CURL* on errorDavid Tardon2021-03-181-2/+4
|
* journal-gatewayd: use automatic cleanupDavid Tardon2021-03-181-4/+3
|
* journal-remote: check return value from MHD_add_response_headerZbigniew Jędrzejewski-Szmek2021-03-072-7/+18
| | | | | | | Sadly, the API does not allow us to distinguish oom from invalid settings. If the call fails, let's assume oom happened. Coverity CID#1444714.
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-054-4/+4
|
* Merge pull request #18704 from keszybz/fallback-hostame-overrideZbigniew Jędrzejewski-Szmek2021-02-231-1/+1
|\ | | | | Allow overriding of fallback hostname through envvar and os-release field
| * basic/os-util: make the sentinel implicitZbigniew Jędrzejewski-Szmek2021-02-221-1/+1
| |
* | Recommend drop-ins over modifications to the main config fileZbigniew Jędrzejewski-Szmek2021-02-192-16/+18
|/ | | | As discussed in https://github.com/systemd/systemd/pull/18347.
* Merge pull request #18596 from keszybz/systemctl-quiet-legendLennart Poettering2021-02-172-37/+18
|\ | | | | systemctl: hide legends with --quiet, allow overriding
| * journal-remote: inline one more iterator variable declarationZbigniew Jędrzejewski-Szmek2021-02-171-4/+2
| |
| * journal-remote: convert to parse_boolean_argument() and fix type confusionZbigniew Jędrzejewski-Szmek2021-02-172-33/+16
| | | | | | | | | | | | | | | | | | We were passing a reference to 'int arg_seal' to config_parse_bool(), which expects a 'bool *'. Luckily, this would work, because 'bool' is smaller than 'int', so config_parse_bool() would set the least-significant byte of arg_seal. At least I think so. But let's use consistent types ;) Also, modernize style a bit and don't use integers in boolean context.
* | tree-wide: reset the cleaned-up variable in cleanup functionsZbigniew Jędrzejewski-Szmek2021-02-161-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the cleanup function returns the appropriate type, use that to reset the variable. For other functions (usually the foreign ones which return void), add an explicit value to reset to. This causes a bit of code churn, but I think it might be worth it. In a following patch static destructors will be called from a fuzzer, and this change allows them to be called multiple times. But I think such a change might help with detecting unitialized code reuse too. We hit various bugs like this, and things are more obvious when a pointer has been set to NULL. I was worried whether this change increases text size, but it doesn't seem to: -Dbuildtype=debug: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494520 Feb 16 15:06 build/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494576 Feb 16 15:10 build/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494640 Feb 16 15:15 build/systemd* -Dbuildtype=release: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:09 build-rawhide/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:10 build-rawhide/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:16 build-rawhide/systemd* I would expect that the compiler would be able to elide the setting of a variable if the variable is never used again. And this seems to be the case: in optimized builds there is no change in size whatsoever. And the change in size in unoptimized build is negligible. Something strange is happening with size of libsystemd: it's bigger in optimized builds. Something to figure out, but unrelated to this patch.
* tree-wide: propagate error code from _from_string() functionsZbigniew Jędrzejewski-Szmek2021-02-101-4/+2
| | | | Now that we know we have something useful, no need to make an answer up.
* tree-wide: use -EINVAL for enum invalid valuesZbigniew Jędrzejewski-Szmek2021-02-101-1/+1
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617. This does not touch anything exposed in src/systemd. Changing the defines there would be a compatibility break. Note that tests are broken after this commit. They will be fixed in the next one.
* Add comma in structured initialization in a few placesZbigniew Jędrzejewski-Szmek2021-02-101-1/+1
| | | | It just looks nicer…
* fuzz-journal-remote: do not assert on resource conditionsZbigniew Jędrzejewski-Szmek2021-02-091-21/+34
| | | | | | | | | | | | | | We have a number of issues where oss-fuzz reports input-independent crashes of fuzz-journal-remote. Instead of asserting that stuff that allocated fds and memory never fails, let's instead just return an error. https://oss-fuzz.com/testcase-detail/4791099424112640 https://oss-fuzz.com/testcase-detail/4531912477638656 I don't see any docs as to whether LLVMFuzzerTestOneInput() is allowed to return non-zero. Propagating the error code is easiest, so let's just do that. If it turns out that this causes oss-fuzz to still report a failure, we can suppress that later.
* tree-wide: enable colorized logging for daemons when run in consoleYu Watanabe2021-02-011-1/+1
| | | | It may be useful when debugging daemons.
* log: make tools also read the kernel command line when run as a serviceYu Watanabe2021-02-012-2/+2
| | | | | | | | This effectively reverts 41d1f469cf10f5f3e9cb4f4853ace9b0cfe5beae. Before this, e.g., `networkctl reload` invoked by `systemctl reload systemd-networkd.service` does not produce debugging logs even if systemd.log-level=debug is set. This fixes the issue.
* tree-wide: Drop custom formatting for print() help messagesDaan De Meyer2021-01-313-12/+9
| | | | | | | | | | | | I think this formatting was originally used because it simplified adding new options to the help messages. However, these days, most tools their help message end with "\nSee the %s for details.\n" so the final line almost never has to be edited which eliminates the benefit of the custom formatting used for printf() help messages. Let's make things more consistent and use the same formatting for printf() help messages that we use everywhere else. Prompted by https://github.com/systemd/systemd/pull/18355#discussion_r567241580
* tree-wide: add spdx header on source filesZbigniew Jędrzejewski-Szmek2021-01-281-0/+1
| | | | version.h is tiny, but the other two certainly deserve a license header.
* tree-wide: add spdx header on all scripts and helpersZbigniew Jędrzejewski-Szmek2021-01-281-0/+2
| | | | | | Even though many of those scripts are very simple, it is easier to include the header than to try to say whether each of those files is trivial enough not to require one.
* meson: move test or fuzzer definitions to relevant meson.build in subdirectoriesYu Watanabe2021-01-191-0/+8
|
* meson: slightly disentangle code dependenciesYu Watanabe2021-01-191-1/+1
| | | | But, still sd-id128 is used in src/basic.
* fuzzers: move several fuzzersYu Watanabe2021-01-192-0/+80
|