summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
Commit message (Collapse)AuthorAgeFilesLines
* 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()).
* sd-journal: return SD_JOURNAL_INVALIDATE only if journal files were actually ↵Michal Sekletar2017-04-241-0/+1
| | | | | | | | | | | | | | | | | | deleted/moved (#5580) When caller invokes sd_journal_open() we usually open at least one directory with journal files. add_root_directory() function increments current_invalidate_counter. After sd_journal_open() returns current_invalidate_counter != last_invalidate_counter. After caller waits for journal events (e.g. waits for new messages in journal) then it usually calls sd_journal_process(). However, on first call to sd_journal_process(), function determine_change() returns SD_JOURNAL_INVALIDATE even though no journal files were deleted/moved. This is because current_invalidate_counter != last_invalidate_counter. After the fix we make sure counters has the same value before we begin processing inotify events.
* journalctl: add remote log dir to search path when --merge is passed (#4970)Marcin Bachry2016-12-241-0/+3
| | | | | | | | The journalctl man page says: "-m, --merge Show entries interleaved from all available journals, including remote ones.", but current version of journalctl doesn't live up to this promise. This patch simply adds "/var/log/journal/remote" to search path if --merge flag is used. Should fix issue #3618
* Rename formats-util.h to format-util.hZbigniew Jędrzejewski-Szmek2016-11-071-1/+1
| | | | | | We don't have plural in the name of any other -util files and this inconsistency trips me up every time I try to type this file name from memory. "formats-util" is even hard to pronounce.
* tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2016-10-231-3/+3
| | | | | | | | | | | | | This makes strjoin and strjoina more similar and avoids the useless final argument. spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c) git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/' This might have missed a few cases (spatch has a really hard time dealing with _cleanup_ macros), but that's no big issue, they can always be fixed later.
* tree-wide: use mfree moreZbigniew Jędrzejewski-Szmek2016-10-161-6/+3
|
* sd-journal: fix sd_journal_open_directory with SD_JOURNAL_OS_ROOTZbigniew Jędrzejewski-Szmek2016-08-121-6/+10
| | | | | | | | | | | | The directory argument that is given to sd_j_o_d was ignored when SD_JOURNAL_OS_ROOT was given, and directories relative to the root of the host file system were used. With that flag, sd_j_o_d should do the same as sd_j_open_container: use the path as "prefix", i.e. the directory relative to which everything happens. Instead of touching sd_j_o_d, journal_new is fixed to do what sd_j_o_c was doing, and treat the specified path as prefix when SD_JOURNAL_OS_ROOT is specified.
* sd-journal: allow SYSTEM and CURRENT_USER flags with sd_j_open_directory[_fd]Zbigniew Jędrzejewski-Szmek2016-08-121-2/+4
| | | | | There is no reason not to. This makes journalctl -D ... --system work, useful for example when viewing files from a deactivated container.
* sd-journal: split out flags into separate defines for legibilityZbigniew Jędrzejewski-Szmek2016-08-121-4/+18
| | | | … in preparation for future changes.
* sd-journal: watch logs below container's /{var,run}/log/journal (instead of ↵Evgeny Vereshchagin2016-08-091-0/+2
| | | | | the /) (#3934) Fixes #3927.
* treewide: fix typos and remove accidental repetition of wordsTorstein Husebø2016-07-111-1/+1
|
* treewide: fix typos (#3187)Torstein Husebø2016-05-041-1/+1
|