summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
Commit message (Collapse)AuthorAgeFilesLines
* sd-journal: remove the dead code and actually fix #14695Michal Sekletár2020-03-281-4/+3
| | | | | | | | | | | journal_file_fstat() returns an error if we call it on already unlinked journal file and hence we never reach remove_file_real() which is the entire point. I must have made some mistake while testing the fix that got me thinking the issue is gone while opposite was true. Fixes #14695
* fix journalctl regression (#15099)Georg Müller2020-03-131-1/+0
| | | | | | | | | | | | | This regression was introduced in #14913. The current_file variable can be NULL, as, for example, with the following commands: * journalctl --list-boots * journalctl -b -1 --no-pager Since current_file is only checked for pointer equality with f, removing the assertion is safe here.
* journalctl: show duplicate entries if they are from the same file (#14898)Georg Müller2020-03-111-3/+5
| | | | | | | | | | When having a service which intentionally outputs multiple equal lines, all these messages might be inserted with the same timestamp. journalctl has a mechanism to avoid duplicate lines, which might be in different journal files. This patch allows duplicate lines, if they are from the same file.
* sd-journal: close journal files that were deleted by journald before we've ↵Michal Sekletár2020-02-051-0/+15
| | | | | | setup inotify watch Fixes #14695
* journal: make constant argument actually 'const'Lennart Poettering2020-01-311-1/+1
|
* journal: allow opening journal files specific to some namespaceLennart Poettering2020-01-311-14/+92
|
* journal: use structured initializationLennart Poettering2020-01-311-8/+11
|
* journal: properly mark two definitions that are deprecated with GCC ↵Lennart Poettering2020-01-311-1/+1
| | | | attributes for that
* journal: don't use startswith() on something that is not a NUL-terminated stringLennart Poettering2020-01-211-1/+1
| | | | | | | Otherwise we might access memory coming after it that is not valid or allocated. Fixes: #14114
* tree-wide: use SD_ID128_STRING_MAX where appropriateLennart Poettering2019-12-101-1/+1
|
* tree-wide: drop missing.hYu Watanabe2019-10-311-1/+0
|
* tree-wide: replace strjoina() with prefix_roota()Yu Watanabe2019-06-251-2/+2
|
* tree-wide: replace strjoin() with path_join()Yu Watanabe2019-06-211-4/+1
|
* sd-journal: voidify callZbigniew Jędrzejewski-Szmek2019-05-301-1/+1
| | | | To appease coverity, CID#1400674.
* util: split out nulstr related stuff to nulstr-util.[ch]Lennart Poettering2019-03-141-0/+1
|
* Delete duplicate linesTopi Miettinen2019-01-121-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Found by inspecting results of running this small program: int main(int argc, const char **argv) { for (int i = 1; i < argc; i++) { FILE *f; char line[1024], prev[1024], *r; int lineno; prev[0] = '\0'; lineno = 1; f = fopen(argv[i], "r"); if (!f) exit(1); do { r = fgets(line, sizeof(line), f); if (!r) break; if (strcmp(line, prev) == 0) printf("%s:%d: error: dup %s", argv[i], lineno, line); lineno++; strcpy(prev, line); } while (!feof(f)); fclose(f); } }
* util-lib: split out env file parsing code into env-file.cLennart Poettering2018-12-021-0/+1
| | | | | | It's quite complex, let's split this out. No code changes, just some file rearranging.
* tree-wide: port over more cases to STR_IN_SET()Lennart Poettering2018-11-261-2/+1
|
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-221-23/+23
| | | | | | | | | | | 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.
* fileio: automatically add NULL sentinel to parse_env_file()Lennart Poettering2018-11-141-1/+3
| | | | Let's modernize things a bit.
* fileio: drop "newline" parameter for env file parsersLennart Poettering2018-11-141-1/+1
| | | | | | | 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.
* sd-journal: escape binary data in match_make_string()Evgeny Vereshchagin2018-10-231-1/+2
| | | | Fixes: #10383
* tree-wide: use CMP() macro where applicableYu Watanabe2018-10-161-16/+14
| | | | Follow-up for 6dd91b368298e3b3b264a5f2cb5647b2c5cb692b.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* fileio: accept FILE* in addition to path in parse_env_file()Lennart Poettering2018-05-241-1/+1
| | | | | | | Most our other parsing functions do this, let's do this here too, internally we accept that anyway. Also, the closely related load_env_file() and load_env_file_pairs() also do this, so let's be systematic.
* journal: use automatic cleanup moreDavid Tardon2018-05-101-48/+22
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* journal: provide compress_threshold_bytes parameterAlex Gartrell2018-03-201-1/+1
| | | | | | Previously the compression threshold was hardcoded to 512, which meant that smaller values wouldn't be compressed. This left some storage savings on the table, so instead, we make that number tunable.
* stat-util: unify code that checks whether something is a regular fileLennart Poettering2018-02-201-15/+6
| | | | | | Let's add a common implementation for regular file checks, that are careful to return the right error code (EISDIR/EISLNK/EBADFD) when we are encountering a wrong file node.
* sd-journal: when picking up a new file, compare inode/device info with ↵Lennart Poettering2018-02-201-39/+88
| | | | | | | | | | | previous open file by same name Let's make sure we aren't confused if a journal file is replaced by a different one (for example due to rotation) if we are in a q overflow: let's compare the inode/device information, and if it changed replace any open file object as needed. Fixes: #8198
* sd-journal: rename add_file() → add_file_by_name()Lennart Poettering2018-02-201-6/+15
| | | | | | Let's be more careful with the naming, and indicate that the function is about *named* journal files, and will validate the name as needed. (in opposition to add_any_file() which doesn't care about names)
* journal-file: refuse opening non-regular journal filesLennart Poettering2018-02-201-0/+4
| | | | | Let's check the file node type when we open/stat journal files: refuse anything that is not a regular file...
* sd-journal: make sure it's safe to call sd_journal_process() before the ↵Lennart Poettering2018-02-121-0/+3
| | | | | | | | | | first sd_journal_wait() In that case we have no inotify fd yet, and there's nothing to process hence. Let's make the call a NOP. (Previously, without this change we'd end up trying to read off inotify fd -1, which is quite a problem... 😢)
* sd-journal: properly handle inotify queue overflowLennart Poettering2018-02-121-77/+196
| | | | | | | | | | | | | | | | | This adds proper handling of IN_Q_OVERFLOW: when the inotify queue runs over we'll reiterate all directories we are looking at. At the same time we'll mark all files and directories we encounter that way with a generation counter we first increased. All files and directories not marked like this are then unloaded. With this logic we do the best when the inotify queue overflows: we synchronize our in-memory state again with what's on disk. This contains some refactoring of the directory logic, to share more code between uuid directories and "root" directories and generally make things a bit more readable by splitting things up into smaller bits. See: #7998 #8032
* sd-journal: use more appropriate API to validate 128bit idsLennart Poettering2018-02-121-5/+3
| | | | We have id128_is_valid(), let's use it.
* tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-02-121-2/+2
| | | | | | path Let's make use of our new hash_ops!
* journal: move code that checks for network fs to stat-util.[ch]Lennart Poettering2018-02-121-11/+2
| | | | | We have similar code in stat-util.[ch] and managing this at a central place almost definitely is the better choice.
* Merge pull request #7042 from vcaputo/iteratedcacheLennart Poettering2018-02-011-4/+15
|\ | | | | RFC: Optionally cache hashmap iterated results
| * journal: use IteratedCache in sd-journalVito Caputo2018-01-271-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes real_journal_next() to leverage the IteratedCache for accelerating iteration across the open journal files. journalctl timing comparisons with 100 journal files of 8MiB size party to this boot: Pre (~v235): # time ./journalctl -b --no-pager > /dev/null real 0m9.613s user 0m9.560s sys 0m0.053s # time ./journalctl -b --no-pager > /dev/null real 0m9.548s user 0m9.525s sys 0m0.023s # time ./journalctl -b --no-pager > /dev/null real 0m9.612s user 0m9.582s sys 0m0.030s Post-IteratedCache: # time ./journalctl -b --no-pager > /dev/null real 0m8.449s user 0m8.425s sys 0m0.024s # time ./journalctl -b --no-pager > /dev/null real 0m8.409s user 0m8.382s sys 0m0.027s # time ./journalctl -b --no-pager > /dev/null real 0m8.410s user 0m8.350s sys 0m0.061s ~12.5% improvement, the benefit increases the more log files there are.
* | log: minimize includes in log.hLennart Poettering2018-01-111-0/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | log.h really should only include the bare minimum of other headers, as it is really pulled into pretty much everything else and already in itself one of the most basic pieces of code we have. Let's hence drop inclusion of: 1. sd-id128.h because it's entirely unneeded in current log.h 2. errno.h, dito. 3. sys/signalfd.h which we can replace by a simple struct forward declaration 4. process-util.h which was needed for getpid_cached() which we now hide in a funciton log_emergency_level() instead, which nicely abstracts the details away. 5. sys/socket.h which was needed for struct iovec, but a simple struct forward declaration suffices for that too. Ultimately this actually makes our source tree larger (since users of the functionality above must now include it themselves, log.h won't do that for them), but I think it helps to untangle our web of includes a tiny bit. (Background: I'd like to isolate the generic bits of src/basic/ enough so that we can do a git submodule import into casync for it)
* journal: use new helpers with journal_file_closeZbigniew Jędrzejewski-Szmek2017-11-281-5/+1
| | | | journal_file_close_set() is not necessary anymore.
* Use hashmap_free_free where appropriateZbigniew Jędrzejewski-Szmek2017-11-281-4/+1
|
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* Merge pull request #6974 from keszybz/clean-up-definesLennart Poettering2017-10-041-2/+2
|\ | | | | Clean up define definitions
| * build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-10-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* | tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|/
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-10-021-2/+2
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* tree-wide: make use of getpid_cached() wherever we canLennart Poettering2017-07-201-2/+2
| | | | | | | This moves pretty much all uses of getpid() over to getpid_raw(). I didn't specifically check whether the optimization is worth it for each replacement, but in order to keep things simple and systematic I switched over everything at once.
* journal: return 0 from _skip() when it didn't skipLars Karlitski2017-05-111-2/+5
| | | | | Seeking to the tail and calling `sd_journal_previous_skip(journal, 0)` was equivalent to calling it with skip == 1 (same for head and next()).