summaryrefslogtreecommitdiff
path: root/src/journal/journald-stream.c
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-2/+2
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* journal: filter log based on LogFilterPatternsQuentin Deslandes2022-12-151-0/+5
| | | | | | | | | | | Use LogFilterPatterns from the unit's cgroup xattr in order to keep or discard log messages before writing them to the journal. When a log message is discarded, it won't be written to syslog, console... either. When a native, syslog, or standard output log message is received, systemd-journald will process it if it matches against at least one allowed pattern (if any) and none of the denied patterns (if any).
* journal: Use shared log ratelimit constantDaan De Meyer2022-12-051-17/+18
| | | | | Instead of maintaining two different constants, move the constant to journal-internal.h and share it between files.
* journal: Ratelimit more journald log messagesDaan De Meyer2022-11-101-18/+26
| | | | | | systemd-journald is prone to spamming logs if the system gets into a messy state. Let's improve the situation by ratelimiting logs on the hot code paths to 3 times per minute.
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-6/+2
|
* 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: use ERRNO_IS_TRANSIENT()Yu Watanabe2021-11-301-1/+1
|
* tree-wide: use sd_event_source_disable_unref() where we canLennart Poettering2021-11-091-6/+1
|
* util: define initializer for 'struct ucred' that properly invalidates all fieldsLennart Poettering2021-10-111-3/+5
| | | | | i.e. let's make sure to invalid uid/gid to UID_INVAID + GID_INVALID instead of zero.
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-1/+1
| | | | | | | | | | | | | | | | | 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.
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-191-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | 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.)
* journald: enforce longer line length limit during "setup" phase of stream ↵Yangyang Shen2021-04-211-7/+28
| | | | | | | | protocol This PR made modification on Lennart Poettering's basis. Fix the LineMax's function failure problem. Signed-off-by: Yangyang Shen <shenyangyang4@huawei.com>
* tree-wide: avoid uninitialized warning on _cleanup_ variablesLuca Boccassi2021-04-141-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.
* journald: restore syslog priority *with* facility bits for stream ↵Lennart Poettering2021-03-161-7/+25
| | | | | | connections when restarting journald Fixes: #19019
* journald: use log_warning_errno() where appropriateLennart Poettering2021-03-161-16/+8
|
* tree-wide: return NULL from freeing functionsZbigniew Jędrzejewski-Szmek2021-02-161-3/+3
| | | | | | I started working on this because I wanted to change how DEFINE_TRIVIAL_CLEANUP_FUNC is defined. Even independently of that change, it's nice to make make things more consistent and predictable.
* 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.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: define iterator inside of the macroZbigniew Jędrzejewski-Szmek2020-09-081-2/+1
|
* journald: rework pid change handlingLennart Poettering2020-05-131-35/+68
| | | | | | | | | Let's introduce an explicit line ending marker for line endings due to pid change. Let's also make sure we don't get confused with buffer management. Fixes: #15654
* journald: use the fact that client_context_release() returns NULLLennart Poettering2020-05-131-2/+1
|
* journald: rework end of line marker handling to use a field tableLennart Poettering2020-05-131-9/+20
|
* journald: use log_warning_errno() where appropriateLennart Poettering2020-05-131-5/+4
|
* journald: Increase stdout buffer size sooner, when almost fullBenjamin Robin2020-05-131-2/+2
| | | | | | If the previous received buffer length is almost equal to the allocated buffer size, before this change the next read can only receive a couple of bytes (in the worst case only 1 byte), which is not efficient.
* tree-wide: make sure our control buffers are properly alignedLennart Poettering2020-05-071-3/+3
| | | | | | | | | | | | | We always need to make them unions with a "struct cmsghdr" in them, so that things properly aligned. Otherwise we might end up at an unaligned address and the counting goes all wrong, possibly making the kernel refuse our buffers. Also, let's make sure we initialize the control buffers to zero when sending, but leave them uninitialized when reading. Both the alignment and the initialization thing is mentioned in the cmsg(3) man page.
* socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA ↵Lennart Poettering2020-04-231-19/+7
| | | | | | | around cmsg_find() let's take this once step further, and add type-safety to cmsg_find(), and imply the CMSG_DATA() macro for finding the cmsg payload.
* tree-wide: use recvmsg_safe() at various placesLennart Poettering2020-04-231-0/+1
| | | | | | | | | | | | | | | | | Let's be extra careful whenever we return from recvmsg() and see MSG_CTRUNC set. This generally means we ran into a programming error, as we didn't size the control buffer large enough. It's an error condition we should at least log about, or propagate up. Hence do that. This is particularly important when receiving fds, since for those the control data can be of any size. In particular on stream sockets that's nasty, because if we miss an fd because of control data truncation we cannot recover, we might not even realize that we are one off. (Also, when failing early, if there's any chance the socket might be AF_UNIX let's close all received fds, all the time. We got this right most of the time, but there were a few cases missing. God, UNIX is hard to use)
* tree-wide: use the return value from sockaddr_un_set_path()Zbigniew Jędrzejewski-Szmek2020-03-021-4/+4
| | | | | | | | | It fully initializes the address structure, so no need for pre-initialization, and also returns the length of the address, so no need to recalculate using SOCKADDR_UN_LEN(). socklen_t is unsigned, so let's not use an int for it. (It doesn't matter, but seems cleaner and more portable to not assume anything about the type.)
* journal: fix log messageYu Watanabe2020-02-071-1/+1
|
* journald: add exit on idleLennart Poettering2020-01-311-0/+4
|
* journald: use structured initializationLennart Poettering2020-01-311-3/+5
|
* journald: allow running multiple instances of journaldLennart Poettering2020-01-311-12/+19
| | | | | | | | | | | | | | If we do, we operate on a separate set of logs and runtime objects The namespace is configured via argv[1]. Fixes: #12123 Fixes: #10230 #9519 (These latter two issues ask for slightly different stuff, but the usecases generally can be solved by running separate instances of journald now, hence also declaring that as "Fixes:")
* journald: let's use TAKE_PTR() and TAKE_FD() where appropriateLennart Poettering2020-01-311-3/+2
|
* journald: let's use unlink_and_free() where we canLennart Poettering2020-01-311-5/+4
|
* journal: refresh cached credentials of stdout streamsLorenz Bauer2019-11-051-2/+47
| | | | | | | | | | | | | | | | | | | | journald assumes that getsockopt(SO_PEERCRED) correctly identifies the process on the remote end of the socket. However, this is incorrect according to man 7 socket: The returned credentials are those that were in effect at the time of the call to connect(2) or socketpair(2). This becomes a problem when a new process inherits the stdout stream from a parent. First, log messages from the child process will be attributed to the parent. Second, the struct ucred used by journald becomes invalid as soon as the parent exits. Further sendmsg calls then fail with ENOENT. Logs for the child process then vanish from the journal. Fix this by using recvmsg on the stdout stream, and refreshing the cached struct ucred if SCM_CREDENTIALS indicate a new process. Fixes #13708
* tree-wide: get rid of strappend()Lennart Poettering2019-07-121-3/+3
| | | | | It's a special case of strjoin(), so no need to keep both. In particular as typing strjoin() is even shoert than strappend().
* tree-wide: port users over to use new ERRNO_IS_ACCEPT_AGAIN() callLennart Poettering2019-04-101-1/+2
|
* Voidify more mkdir_p callsZbigniew Jędrzejewski-Szmek2019-03-271-1/+1
|
* 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.
* util-lib: split out all temporary file related calls into tmpfiles-util.cLennart Poettering2018-12-021-0/+1
| | | | | | | | This splits out a bunch of functions from fileio.c that have to do with temporary files. Simply to make the header files a bit shorter, and to group things more nicely. No code changes, just some rearranging of source files.
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-221-4/+4
| | | | | | | | | | | 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.
* tests: add a fuzzer for journald streamsEvgeny Vereshchagin2018-11-201-2/+2
|
* fileio: automatically add NULL sentinel to parse_env_file()Lennart Poettering2018-11-141-2/+1
| | | | 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.
* journald: use the "driver" transport for logging a refused connectionEvgeny Vereshchagin2018-10-231-1/+11
| | | | | Otherwise, these messages can end up in `/dev/null` when journald is run in containers as was shown in https://github.com/systemd/systemd/pull/10444#issuecomment-430927793.
* tree-wide: use sockaddr_un_unlink() whereever appropriateLennart Poettering2018-10-151-1/+1
| | | | Let's port everything over.
* journal: voidify fd_nonblock()Lennart Poettering2018-10-131-1/+1
| | | | | | | CID #1396098 CID #1396096 CID #1396091 CID #1396086
* 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.
* tree-wide: drop !! casts to booleansZbigniew Jędrzejewski-Szmek2018-06-131-4/+4
| | | | | | | | | | | They are not needed, because anything that is non-zero is converted to true. C11: > 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the > value compares equal to 0; otherwise, the result is 1. https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c