summaryrefslogtreecommitdiff
path: root/src/journal
Commit message (Collapse)AuthorAgeFilesLines
* test-journal-syslog: Add some valid priority casesJan Janssen2022-03-161-11/+18
|
* test: Use TEST macros in more placesJan Janssen2022-03-164-67/+55
|
* Merge pull request #22739 from mrc0mmand/list-boot-followupYu Watanabe2022-03-151-1/+11
|\ | | | | A couple of follow-ups for #22721
| * journal: make --reverse affect --list-bootsFrantisek Sumsal2022-03-141-0/+3
| | | | | | | | Fixes: #16274
| * journal: use table_set_json_field_name() to override a column nameFrantisek Sumsal2022-03-141-1/+5
| | | | | | | | | | Pointed out in: https://github.com/systemd/systemd/pull/22721#discussion_r826014227 Follow-up for: 5a1355d848a0f6564a04c6d8268e72bc93d173de
| * journal: reset previously set JSON flagsFrantisek Sumsal2022-03-141-0/+3
| | | | | | | | | | | | | | | | Make sure we reset the JSON format flags if the format option is used multiple times, e.g. `journalctl -o json-format -o export`. Pointed out in: https://github.com/systemd/systemd/pull/22721#discussion_r826018985 Follow-up for: 5a1355d848a0f6564a04c6d8268e72bc93d173de
* | journal: preserve acls when rotating user journals with NOCOW attribute setFranck Bui2022-03-141-1/+4
|/ | | | | | | When restoring the COW flag for journals on BTRFS, the full journal contents are copied into new files. But during these operations, the acls of the previous files were lost and users were not able to access to their old journal contents anymore.
* journal: convert --list-boots to a tableFrantisek Sumsal2022-03-131-11/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | so it can be output as JSON as well. ``` $ build-san/journalctl --list-boots --file boot-test.journal IDX BOOT ID FIRST ENTRY LAST ENTRY -3 39d66eb1925f4d01b8464d502650a714 Sat 2022-03-05 15:20:33 CET Sat 2022-03-05 16:19:21 CET -2 5dffeb08a27344d5ae9e2fc244bbcbc5 Fri 2022-03-11 17:23:57 CET Fri 2022-03-11 17:38:31 CET -1 c8ebd52915b642c39eda4bf00f864f79 Fri 2022-03-11 17:38:41 CET Fri 2022-03-11 20:03:46 CET 0 00bcba97c7094fa88cc5d1cf2a389057 Sat 2022-03-12 20:39:08 CET Sat 2022-03-12 20:40:18 CET $ build-san/journalctl --list-boots --file boot-test.journal -q -3 39d66eb1925f4d01b8464d502650a714 Sat 2022-03-05 15:20:33 CET Sat 2022-03-05 16:19:21 CET -2 5dffeb08a27344d5ae9e2fc244bbcbc5 Fri 2022-03-11 17:23:57 CET Fri 2022-03-11 17:38:31 CET -1 c8ebd52915b642c39eda4bf00f864f79 Fri 2022-03-11 17:38:41 CET Fri 2022-03-11 20:03:46 CET 0 00bcba97c7094fa88cc5d1cf2a389057 Sat 2022-03-12 20:39:08 CET Sat 2022-03-12 20:40:18 CET $ build-san/journalctl --list-boots --file boot-test.journal -o json-pretty [ { "index" : -3, "boot_id" : "39d66eb1925f4d01b8464d502650a714", "first_entry" : 1646490033438495, "last_entry" : 1646493561047353 }, { "index" : -2, "boot_id" : "5dffeb08a27344d5ae9e2fc244bbcbc5", "first_entry" : 1647015837289036, "last_entry" : 1647016711595489 }, { "index" : -1, "boot_id" : "c8ebd52915b642c39eda4bf00f864f79", "first_entry" : 1647016721056382, "last_entry" : 1647025426397414 }, { "index" : 0, "boot_id" : "00bcba97c7094fa88cc5d1cf2a389057", "first_entry" : 1647113948506002, "last_entry" : 1647114018943637 } ] ``` Resolves: #14625
* meson: move files' closing brace to separate lineZbigniew Jędrzejewski-Szmek2022-03-031-2/+4
|
* meson: do not use split() in file listsZbigniew Jędrzejewski-Szmek2022-03-021-31/+27
| | | | | | | | | | | The approach to use '''…'''.split() instead of a list of strings was initially used when converting from automake because it allowed identical blocks of lines to be used for both, making the conversion easier. But over the years we have been using normal lists more and more, especially when there were just a few filenames listed. This converts the rest. No functional change.
* shared: Add more dlopen() testsDaan De Meyer2022-03-013-64/+0
| | | | | | Add dlopen_dw(), dlopen_elf() and dlopen_pcre2() to the dlopen test. To enable adding dlopen_pcre2(), we move pcre2-dlopen.h/c from src/journal to src/shared.
* journal-file: explicitly handle file systems that do not support hole punchingLennart Poettering2022-02-041-3/+14
| | | | | | | | Apparently the error code fallocate() returns if hole punching is not supported is not too well defined (man page just says "an error is returned"), hence let's accept the usual set of errors, and the normalize it to EOPNOTSUPP, and generate a clear error message in this case.
* journal-file: fix error handling of pread() in journald_file_punch_holes()Lennart Poettering2022-02-041-3/+10
|
* journal: when copying journal file to undo NOCOW flag, go via fdLennart Poettering2022-02-031-1/+1
| | | | | | | | | | | | We have the journal file open already, hence reference it via the fd insted of the file name. After all, some other tool might have renamed/deleted it already. Let's not actually reuse the fd though, since we want a separate file offset for the copying, hence just make it simply and reopen via /proc/self/fd/. Follow-up for d71ece3f0b85c7a3decc50143b68ac07fc5831ae
* journal: Rename JournaldFile to ManagedJournalFileDaan De Meyer2022-02-0211-174/+173
| | | | | JournalFile and JournaldFile are hard to distinguish from each other. Let's use ManagedJournalFile instead to make the distinction more clear.
* journal-file: don't use pread() when determining where to append, use mmap ↵Lennart Poettering2022-02-021-1/+1
| | | | | | | | | | | | | | as before This partially undoes the effect of ab6e257b3e4e5b95f3750ed019bed6e89989e41b. Originally, we always used the mmap logic to determine the current end of the file. ab6e257b3e4e5b95f3750ed019bed6e89989e41b changed this so that we always used pread(). With this change we'll use pread() from the synchronization thread and mmap otherwise.
* journal: various fixes to journal_file_read_object()Lennart Poettering2022-02-011-2/+2
| | | | | | | | | | | | | | | This fixes a bunch of issues: pread() returns ssize_t, and returns errors in 'errno', handle that correctly. More importantly: it might incompletely read data in case we hit EOF. Check for that, and handle it. Finally, rename the function to journal_file_read_object_header(), since it really doesn't read full objects, but only their headers. Follow-up for: 117e21121e857b4b7d81949542e8dd257265970a
* journal: Truncate file instead of punching hole in final objectDaan De Meyer2022-01-271-0/+13
| | | | | Instead of punching a hole in the final object if it's an entry array, let's just truncate the file instead.
* journal: stat journal file after truncatingDaan De Meyer2022-01-271-2/+2
| | | | | Let's make sure the data stored in last_stat is up-to-date after truncating the journal file.
* journal: Pass data objects to journal_file_move_to_entry_..._for_data() ↵Daan De Meyer2022-01-261-8/+8
| | | | | | | | functions This reduces the number of calls to journal_file_move_to_object() which are heavy. All call sites have easy access to the data object so this change doesn't end up complicating things.
* Fix journald audit logging with fields > N_IOVEC_AUDIT_FIELDS.YmrDtnJu2022-01-211-1/+1
| | | | | | | | ELEMENTSOF(iovec) is not the correct value for the newly introduced parameter m to function map_all_fields because it is the maximum number of elements in the iovec array, including those reserved for N_IOVEC_META_FIELDS. The correct value is the current number of already used elements in the array plus the maximum number to use for fields decoded from the kernel audit message.
* journal: Copy holes when archiving BTRFS journal filesDaan De Meyer2022-01-171-1/+1
| | | | | | | | | | | Previously, the holes we punched earlier would get removed when copying the file. Let's enable the new COPY_HOLES flag to make sure this doesn't happen. In my test, this drops a 800MB btrfs journal (without compression) to 720 MB. Fixes #22087
* Merge pull request #22098 from DaanDeMeyer/journal-corrupt-2Yu Watanabe2022-01-141-4/+4
|\ | | | | journal: Fixes for handling of corrupt entry objects
| * journal: Remove unused arguments from journal_file_next_entry_for_data()Daan De Meyer2022-01-121-4/+4
| |
* | journal: Don't discard -b arg when followed by -eDaan De Meyer2022-01-141-2/+0
| | | | | | | | | | | | | | | | Allowing -e to be used to view the last logs of a previous boot seems like a useful feature so let's not discard -b options anymore when followed by -e. Fixes #22107
* | meson: Use files() for fuzzersJan Janssen2022-01-111-12/+12
| | | | | | | | | | | | Not having to provide the full path in the source tree is much nicer and the produced lists can also be used anywhere in the source tree.
* | meson: Use files() for testsJan Janssen2022-01-111-7/+7
|/ | | | | | Not having to provide the full path in the source tree is much nicer and the produced lists can also be used anywhere in the source tree.
* journal: Log filename when we fail to write an entryDaan De Meyer2022-01-051-2/+2
|
* journal: Log a better message when we're rotating because a file is fullDaan De Meyer2022-01-051-1/+4
| | | | | | | The previous message was confusing errors. When we're rotating because we've reached the file size limit, let's log a better message. Fixes #22007.
* journal: Handle partially read HashItem's when punching holesDaan De Meyer2021-12-211-2/+5
|
* Merge pull request #21786 from keszybz/dirent-workYu Watanabe2021-12-173-3/+1
|\ | | | | Make FOREACH_DIRENT and FOREACH_DIRENT_ALL declare the iterator variables
| * meson: stop building out convenience libraries by defaultZbigniew Jędrzejewski-Szmek2021-12-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The meson default for static_library() are: build_by_default=true, install=false. We never interact with the static libraries, and we only care about them as a stepping-stone towards the installable executables or libraries. Thus let's only build them if they are a dependency of something else we are building. While at it, let's drop install:false, since this appears to be the default. This change would have fixed the issue with lib_import_common failing to build too: we wouldn't attempt to build it. In practice this changes very little, because we generally only declare static libraries where there's something in the default target that will make use of them. But it seems to be a better pattern to set build_by_default to false.
| * Define FOREACH_DIRENT through FOREACH_DIRENT_ALLZbigniew Jędrzejewski-Szmek2021-12-151-1/+0
| | | | | | | | As in the previous commit, 'de' is used as the iterator variable name.
| * tree-wide: make FOREACH_DIRENT_ALL define the iterator variableZbigniew Jędrzejewski-Szmek2021-12-151-1/+0
| | | | | | | | | | | | | | | | | | The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
* | Merge pull request #21784 from DaanDeMeyer/issue-21675Luca Boccassi2021-12-151-10/+13
|\ \ | | | | | | journal: Hole punching improvements
| * | journal: Stop reading in increments of block size during hole punchingDaan De Meyer2021-12-151-3/+1
| | | | | | | | | | | | | | | | | | Let's not try to be overly clever here. This code path is not overly performance sensitive and we should avoid trying to outsmart the kernel without proper benchmarking.
| * | journal: Use 16kb buffer during hole punchingDaan De Meyer2021-12-151-1/+2
| | | | | | | | | | | | Let's use the same buffer size as used in as copy.h.
| * | journal: Correctly advance offset when iterating hash table entriesDaan De Meyer2021-12-151-7/+6
| | | | | | | | | | | | | | | | | | pread() is not guaranteed to completely fill up the given buffer with data which we assumed until now. Instead, only increment the offset by the number of bytes that were actually read.
| * | journal: Add a minimum hole size for hole punchingDaan De Meyer2021-12-151-0/+5
| |/ | | | | | | | | Let's not bother punching extremely small holes to avoid unnecessary file fragmentation.
* | journactl: show info about journal range only at debug level (#21775)Zbigniew Jędrzejewski-Szmek2021-12-151-1/+1
|/ | | | | | | | | | | | | | | | | | | The message that the "journal begins … ends …" has been always confusing to users. (Before b91ae210e62 it was "logs begin … end …" which was arguably even more confusing, but really the change in b91ae210e62 didn't substantially change this.) When the range shown is limited (by -e, -f, --since, or other options), it doesn't really matter to the user what the oldest entries are, since they are purposefully limiting the range. In fact, if we are showing the last few entries with -e or -f, knowing that many months the oldest entries have is completely useless. And when such options are *not* used, the first entry generally corresponds to the beginning of the range shown, and the last entry corresponds to the end of that range. So again, it's not particularly useful, except when debugging journalctl or such. Let's just treat it as a debug message. Fixes #21491.
* journalctl: have -f and -e imply no-value -bнаб2021-12-101-0/+9
| | | | | Both of these take multiple seconds, best-case, to get the last few entries, but do so instantly with -b
* journal: succes[s]fully typoнаб2021-12-081-1/+1
| | | | | As found by fossies codespell: https://fossies.org/linux/test/systemd-main.bb916f3.211208.tar.gz/codespell.html
* journal-file: require MMapCache* for journal_file_open()Vito Caputo2021-12-075-19/+56
| | | | | | | | | | | | | | | Previously the MMapCache* was optionally NULL, which open would handle by creating a new MMapCache* for the occasion. This produced some slightly circuitous refcount-handling code in the function, as well as arguably creating opportunities for weirdness where an MMapCache* was intended to be supplied but happened to be NULL, which this magic would then paper over. In any case, this was basically only being utilized by tests, apparently just to avoid having to create an MMapCache. So update the relevant tests to supply an MMapCache and make journal_file_open() treat a NULL MMapCache* as fatal w/assert.
* journal: stop using JournalFile.mmap everywhereVito Caputo2021-12-074-5/+6
| | | | | | | | | | | | | | | | | | | | | | | 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: Fix disabling NO_COW on btrfs filesystemsDaan De Meyer2021-12-061-0/+26
| | | | | | | | | | | | | | Disabling NOCOW when data has been written to a file doesn't work. Instead, when we're done writing to a journal file (after archiving), let's rewrite the file with COW enabled. This also takes care of properly defragmenting the file. With zstd compression level 3, journal files are compressed to 12% of their original size with default journal settings. As rewriting the file might take a while since we also do an fsync() after the rewrite, this work is done in the offline thread to avoid blocking the journald event loop.
* journal: Update the JournalFile path when archivingDaan De Meyer2021-12-062-3/+4
| | | | | | | | | | When we archive a path, we rename the file to indicate this. However, until now, we didn't actually update the path member of the corresponding JournalFile instance. Let's make sure we also update this to avoid misuse of the old path later on. This change also requires we save the previous path in journal_file_rotate() since we need to open a new file at the previous path.
* journal: Move offlining logic to journald-file.cDaan De Meyer2021-12-064-4/+312
| | | | | | | | | | | | | | With this change, the logic to write the final tag, emit the final change notification and to offline the file moves from journal_file_close() to journald_file_close(). Since all this logic is only executed when the journal file is writable and all code that writes journal files already uses journald_file_close() instead of journal_file_close(), this change should not introduce any changes in behaviour. Moving the offline related logic to journald-file.c allows us to use code from src/shared in the offlining logic, more specifically, we can use the file copying logic from copy.h to fix BTRFS filesystem compression for journal files when archiving.
* journal: Introduce journald-file.c for journal file write related logicDaan De Meyer2021-12-0611-68/+1240
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* tree-wide: use ERRNO_IS_TRANSIENT()Yu Watanabe2021-11-303-9/+10
|
* basic/util: rename u64log2 to log2u64Zbigniew Jędrzejewski-Szmek2021-11-261-1/+1
| | | | | u64log2 was strangely named. We even have log2i and log2u right below in that file.