summaryrefslogtreecommitdiff
path: root/src/journal/journal-file.c
AgeCommit message (Collapse)Author
2017-02-24Fix missing space in comments (#5439)AsciiWolf
2017-02-02Merge pull request #5204 from keszybz/masked-warning-cleanupLennart Poettering
Cleanup of error code mismatch for masked units
2017-02-01Consistently use ERFKILL for masked unitsZbigniew Jędrzejewski-Szmek
76ec966f0e33685f833 changed the code from ESHUTDOWN to ERFKILL, but missed one spot in bus-common-errors.c. Fix that. The code in transaction.c was checking for ERFKILL, but I'm not sure if this mismatch had any effect, i.e. if there were any code paths in which the wrong code actually made difference. Also add comments when ESHUTDOWN is used in the journal code, so it's easy to distinguish those cases when grepping. Standarize on the same capitalization. (There's also a bunch of uses in sd-bus.c, but that's clearly different.)
2017-02-02Merge pull request #5151 from keszybz/journal-flagsLennart Poettering
More information about unsupported journal file flags
2017-02-01Merge pull request #5191 from keszybz/tweaksZbigniew Jędrzejewski-Szmek
2017-02-01Revert "Trivial typo fixes and code refactorings (#5191)"Zbigniew Jędrzejewski-Szmek
Let's do a merge to preserve all the commit messages. This reverts commit 785d345145bbd06c8f1c75c6a0b119c4e8f411db.
2017-02-01Trivial typo fixes and code refactorings (#5191)Zbigniew Jędrzejewski-Szmek
* logind: trivial simplification free_and_strdup() handles NULL arg, so make use of that. * boot: fix two typos * pid1: rewrite check in ignore_proc() to not check condition twice It's harmless, but it seems nicer to evaluate a condition just a single time. * core/execute: reformat exec_context_named_iofds() for legibility * core/execute.c: check asprintf return value in the usual fashion This is unlikely to fail, but we cannot rely on asprintf return value on failure, so let's just be correct here. CID #1368227. * core/timer: use (void) CID #1368234. * journal-file: check asprintf return value in the usual fashion This is unlikely to fail, but we cannot rely on asprintf return value on failure, so let's just be correct here. CID #1368236. * shared/cgroup-show: use (void) CID #1368243. * cryptsetup: do not return uninitialized value on error CID #1368416.
2017-01-31tree-wide: adjust fall through comments so that gcc is happyZbigniew Jędrzejewski-Szmek
gcc 7 adds -Wimplicit-fallthrough=3 to -Wextra. There are a few ways we could deal with that. After we take into account the need to stay compatible with older versions of the compiler (and other compilers), I don't think adding __attribute__((fallthrough)), even as a macro, is worth the trouble. It sticks out too much, a comment is just as good. But gcc has some very specific requiremnts how the comment should look. Adjust it the specific form that it likes. I don't think the extra stuff we had in those comments was adding much value. (Note: the documentation seems to be wrong, and seems to describe a different pattern from the one that is actually used. I guess either the docs or the code will have to change before gcc 7 is finalized.)
2017-01-31journal-file: check asprintf return value in the usual fashionZbigniew Jędrzejewski-Szmek
This is unlikely to fail, but we cannot rely on asprintf return value on failure, so let's just be correct here. CID #1368236.
2017-01-24journal-file, journalctl: provide better hint about unsupported featuresZbigniew Jędrzejewski-Szmek
https://bugzilla.redhat.com/show_bug.cgi?id=1416201 $ journalctl -b Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses an unsupported feature, ignoring file. Use SYSTEMD_LOG_LEVEL=debug journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ to see the details. -- No entries -- $ journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses incompatible flag lz4-compressed disabled at compilation time. Failed to open journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~: Protocol not supported mmap cache statistics: 0 hit, 1 miss Failed to open files: Protocol not supported
2017-01-24journal-file: factor out helper functionZbigniew Jędrzejewski-Szmek
In preparation for later changes.
2016-10-16tree-wide: use mfree moreZbigniew Jędrzejewski-Szmek
2016-10-12journal: refuse opening journal files from the future for writingLennart Poettering
Never permit that we write to journal files that have newer timestamps than our local wallclock has. If we'd accept that, then the entries in the file might end up not being ordered strictly. Let's refuse this with ETXTBSY, and then immediately rotate to use a new file, so that each file remains strictly ordered also be wallclock internally.
2016-10-12journal: when iterating through entry arrays and we hit an invalid one keep ↵Lennart Poettering
going When iterating through partially synced journal files we need to be prepared for hitting with invalid entries (specifically: non-initialized). Instead of generated an error and giving up, let's simply try to preceed with the next one that is valid (and debug log about this). This reworks the logic introduced with caeab8f626e709569cc492b75eb7e119076059e7 to iteration in both directions, and tries to look for valid entries located after the invalid one. It also extends the behaviour to both iterating through the global entry array and per-data object entry arrays. Fixes: #4088
2016-10-12journal: add an explicit check for uninitialized objectsLennart Poettering
Let's make dissecting of borked journal files more expressive: if we encounter an object whose first 8 bytes are all zeroes, then let's assume the object was simply never initialized, and say so. Previously, this would be detected as "overly short object", which is true too in a away, but it's a lot more helpful printing different debug options for the case where the size is not initialized at all and where the size is initialized to some bogus value. No function behaviour change, only a different log messages for both cases.
2016-10-12journal: also check that our entry arrays are properly orderedLennart Poettering
Let's and extra check, reusing check_properly_ordered() also for journal_file_next_entry_for_data().
2016-10-12journal: split out check for properly ordered arrays into its own functionLennart Poettering
This adds a new call check_properly_ordered(), which we can reuse later, and makes the code a bit more readable.
2016-10-12journal: split out array index inc/dec code into a new call bump_array_index()Lennart Poettering
This allows us to share a bit more code between journal_file_next_entry() and journal_file_next_entry_for_data().
2016-10-12journal: when we encounter a broken journal file, add some debug loggingLennart Poettering
Let's make it easier to figure out when we see an invalid journal file, why we consider it invalid, and add some minimal debug logging for it. This log output is normally not seen (after all, this all is library code), unless debug logging is exlicitly turned on.
2016-09-23journal: fix HMAC calculation when appending a data objectFranck Bui
Since commit 5996c7c295e073ce21d41305169132c8aa993ad0 (v190 !), the calculation of the HMAC is broken because the hash for a data object including a field is done in the wrong order: the field object is hashed before the data object is. However during verification, the hash is done in the opposite order as objects are scanned sequentially.
2016-09-23journal: warn when we fail to append a tag to a journalFranck Bui
We shouldn't silently fail when appending the tag to a journal file since FSS protection will simply be disabled in this case.
2016-05-04treewide: fix typos (#3187)Torstein Husebø
2016-05-02tree-wide: fix invocations of chattr_path()Lennart Poettering
chattr_path() takes two bitmasks, and no booleans. Fix the various invocations to do this properly.
2016-04-29journal-file: when rotating a journal file, fsync directory tooLennart Poettering
As suggested by: https://github.com/systemd/systemd/pull/3126#discussion_r61125474
2016-04-29journal: when creating a new journal file, fsync() the directory it is ↵Lennart Poettering
created in too Fixes: #2831
2016-04-27journal: set STATE_ARCHIVED as part of offlining (#2740)Vito Caputo
The only code path which makes a journal durable is via journal_file_set_offline(). When we perform a rotate the journal's header->state is being set to STATE_ARCHIVED prior to journal_file_set_offline() being called. In journal_file_set_offline(), we short-circuit the entire offline when f->header->state != STATE_ONLINE. This all results in none of the journal_file_set_offline() fsync() calls being reached when rotate archives a journal, so archived journals are never explicitly made durable. What we do now is instead of setting the f->header->state to STATE_ARCHIVED directly in journal_file_rotate() prior to journal_file_close(), we set an archive flag in f->archive for the journal_file_set_offline() machinery to honor by committing STATE_ARCHIVED instead of STATE_OFFLINE when set. Prior to this, rotated journals were never getting fsync() explicitly performed on them, since journal_file_set_offline() short-circuited. Obviously this is undesirable, and depends entirely on the underlying filesystem as to how much durability was achieved when simply closing the file. Note that this problem existed prior to the recent asynchronous fsync changes, but those changes do facilitate our performing this durable offline on rotate without blocking, regardless of the underlying filesystem sync-on-close semantics.
2016-04-26journal-file: make seeking in corrupted files workLennart Poettering
Previously, when we used a bisection table for seeking through a corrupted file, and the end of the bisection table was corrupted we'd most likely fail the entire seek operation. Improve the situation: if we encounter invalid entries in a bisection table, linearly go backwards until we find a working entry again.
2016-04-26journal-file: when iterating through a partly corruped journal file, treat ↵Lennart Poettering
error like EOF When we linearly iterate through a corrupted journal file, and we encounter a read error, don't consider this fatal, but merely as EOF condition (and log about it).
2016-04-26journal-file: always generate the same error when encountering corrupted filesLennart Poettering
Let's make sure EBADMSG is the one error we throw when we encounter corrupted data, so that we can neatly test for it.
2016-04-26sd-journal: detect earlier if we try to read an object from an invalid offsetLennart Poettering
Specifically, detect early if we try to read from offset 0, i.e. are using uninitialized offset data.
2016-04-25Merge pull request #3109 from poettering/journal-by-fdZbigniew Jędrzejewski-Szmek
rework "journalctl -M"
2016-04-25Merge pull request #3114 from poettering/journalctl-bZbigniew Jędrzejewski-Szmek
Fix endless loops in journalctl --list-boots (closes #617).
2016-04-25journal: fix already offline check and thread leak (#2810)Vito Caputo
Early in journal_file_set_offline() f->header->state is tested to see if it's != STATE_ONLINE, and since there's no need to do anything if the journal isn't online, the function simply returned here. Since moving part of the offlining process to a separate thread, there are two problems here: 1. We can't simply check f->header->state, because if there is an offline thread active it may modify f->header->state. 2. Even if the journal is deemed offline, the thread responsible may still need joining, so a bare return may leak the thread's resources like its stack. To address #1, the helper journal_file_is_offlining() is called prior to accessing f->header->state. If journal_file_is_offlining() returns true, f->header->state isn't even checked, because an offlining journal is obviously online, and we'll just continue with the normal set offline code path. If journal_file_is_offlining() returns false, then it's safe to check f->header->state, because the offline_state is beyond the point of modifying f->header->state, and there's a memory barrier in the helper. If we find f->header->state is != STATE_ONLINE, then we call the idempotent journal_file_set_offline_thread_join() on the way out of the function, to join a potential lingering offline thread.
2016-04-25journalctl: improve output of --header a bitLennart Poettering
Show the various timestamps in hexadecimal too. This is useful for matching the timestamps included in cursor strings (which are encoded in hex, too), with the references in the journal header.
2016-04-25sd-journal: add API for opening journal files or directories by fdLennart Poettering
Also, expose this via the "journalctl --file=-" syntax for STDIN. This feature remains undocumented though, as it is probably not too useful in real-life as this still requires fds that support mmaping and seeking, i.e. does not work for pipes, for which reading from STDIN is most commonly used.
2016-02-23Merge pull request #2708 from vcaputo/journal-restore-offline-state-on-errorLennart Poettering
journal: restore offline state on error
2016-02-22tree-wide: make ++/-- usage consistent WRT spacingVito Caputo
Throughout the tree there's spurious use of spaces separating ++ and -- operators from their respective operands. Make ++ and -- operator consistent with the majority of existing uses; discard the spaces.
2016-02-22journal: restore offline state on errorVito Caputo
If we fail to create the thread, technically we should leave the offline_state as OFFLINE_JOINED, not OFFLINE_SYNCING.
2016-02-19journal: defer journal closes on rotateVito Caputo
When we rotate journals, we must set offline and close the current one, but don't generally need to wait for this to complete. Instead, we'll initiate an asynchronous offline via journal_file_set_offline(oldfile, false), and add the file to a per-server set of deferred closes to be closed later when they won't block. There's one complication however; journal_file_open() via journal_file_verify_header() assumes that any writable journal in the online state is the product of an unclean shutdown or other form of corruption. Thus there's a need for journal_file_open() to be aware of deferred closes and synchronize with their completion when opening preexisting journals for writing. To facilitate this the deferred closes set is supplied to the journal_file_open() function where the deferred closes may be closed synchronously before verifying the header in such circumstances.
2016-02-19journal: asynchronous journal_file_set_offline()Vito Caputo
This adds a wait flag to journal_file_set_offline(), when false the offline is performed asynchronously in a separate thread. When wait is true, if an asynchronous offline is already in-progress it is restarted and waited for. Otherwise the offline is performed synchronously without the use of a thread. journal_file_set_online() cancels or waits for the asynchronous offline to complete if in-flight, depending on where in the offline process the thread happens to be. If the thread is in the fsync() phase, it is cancelled and waiting is unnecessary. Otherwise, the thread is joined before proceeding. A new offline_state member is added to JournalFile which is used via atomic operations for communicating between the offline thread and the journal_file_set_{offline,online}() functions.
2016-02-19journal: add void cast to journal_file_close() callsVito Caputo
2016-02-19journal: add void cast to fsync() callsVito Caputo
2016-02-13Merge pull request #2589 from keszybz/resolve-tool-2Lennart Poettering
Better support of OPENPGPKEY, CAA, TLSA packets and tests
2016-02-11Add memcpy_safeZbigniew Jędrzejewski-Szmek
ISO/IEC 9899:1999 §7.21.1/2 says: Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. In base64_append_width memcpy was called as memcpy(x, NULL, 0). GCC 4.9 started making use of this and assumes This worked fine under -O0, but does something strange under -O3. This patch fixes a bug in base64_append_width(), fixes a possible bug in journal_file_append_entry_internal(), and makes use of the new function to simplify the code in other places.
2016-02-10tree-wide: remove Emacs lines from all filesDaniel Mack
This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
2016-02-09journal: Drop monotonicity check when appending to journal fileKlearchos Chaloulos
Remove the check that triggers rotation of the journal file when the arriving log entry had a monotonic timestamp smaller that the previous log entry. This check causes unnecessary rotations when journal-remote was receiving from multiple senders, therefore monotonicity can not be guaranteed. Also, it does not offer any useful functionality for systemd-journald.
2016-02-06journal: add missing space to switch statementVito Caputo
2016-02-05journal: add asserts on f->(data|field)_hash_tableVito Caputo
Functions dereferencing these members should assert their non-NULL state.
2016-02-05journal: add asserts for f->headerVito Caputo
Just some additional asserts in functions dereferencing f->header.
2016-01-26journald: minor fixesLennart Poettering
This primarily contains some minor coding style fixups for 7a24f3bf2fb181243a1957a0cdd54cd919396793 and earlier changes. Specifically: * Don't log at log levels above LOG_DEBUG from "library" code like journal-file.c * Don't negate errno values before passing them to log_debug_errno(), as the call can handle this fine anyway * Cast some calls we knowingly ignore the return values of to (void) * Don't clobber function call-by-ref return values on failure * Don't mix function calls and variable declarations in one line There's also one more relevant change: when failing to enqueue a journal change fs event, we'll run it immediately.