summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-event
Commit message (Collapse)AuthorAgeFilesLines
* libsystemd: add missing _public_ attributesYu Watanabe2023-04-291-1/+1
|
* sd-event: store and compare per-module static origin idLuca Boccassi2023-04-252-67/+129
| | | | | | | | | sd-event objects use hashmaps, which use module-global state, so it is not safe to pass a sd-event object created by a module instance to another module instance (e.g.: when two libraries static linking sd-event are pulled in a single process). Initialize a random per-module origin id and store it in the object, and compare it when entering a public API, and error out if they don't match, together with the PID.
* tree-wide: simplify x ? x : y to x ?: y where applicableFrantisek Sumsal2023-03-181-1/+1
|
* mempress: change default PSI window duration to 2sLennart Poettering2023-03-091-1/+3
| | | | | | | | | | This changes the PSI window duration we default to for watching memory pressure events from 1s to 2s. This is because apparently the kernel will soon disallow window durations other than 2s for unprivileged processes. Hence, we'll bump the threshold from 100m to 200ms, and the window from 1s to 2s.
* Include <threads.h> if possible to get thread_local definitionCristian Rodríguez2023-03-061-0/+1
| | | | | | | | | | | | IN C23, thread_local is a reserved keyword and we shall therefore do nothing to redefine it. glibc has it defined for older standard version with the right conditions. v2 by Yu Watanabe: Move the definition to missing_threads.h like the way we define e.g. missing syscalls or missing definitions, and include it by the users. Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
* sd-event: handle kernels that set CONFIG_PSI_DEFAULT_DISABLED more gracefullyLennart Poettering2023-02-281-2/+11
| | | | | | | If CONFIG_PSI_DEFAULT_DISABLED is set in the kernel, then the PSI files will be there, and you can open them, but read()/write() will fail. Which is terrible, since that happens so late. But anyway, handle this gracefully.
* tree-wide: initialize fds with -EBADFDavid Tardon2023-02-231-1/+1
|
* sd-event: fix error handlingYu Watanabe2023-02-231-1/+1
| | | | Follow-up for 6d2326e036ceed30f9ccdb0266713c10a44dcf6c.
* sd-event: fix error handlingYu Watanabe2023-02-231-3/+4
| | | | Follow-up for 158fe190afe37b222c9dc2c53bd7be426b92ef89.
* sd-event: fix use of uninitialized variableYu Watanabe2023-02-231-1/+1
| | | | | | Follow-up for 158fe190afe37b222c9dc2c53bd7be426b92ef89. Fixes CID#1505670.
* sd-event: always initialize sd_event.perturbYu Watanabe2023-02-231-11/+10
| | | | | | | | If the boot ID cannot be obtained, let's first fallback to the machine ID, and if still cannot, then let's use 0. Otherwise, no timer event source cannot be triggered. Fixes #26549.
* sd-event: add high-level sd_event_add_memory_pressure() event sourceLennart Poettering2023-02-222-1/+593
| | | | | | | | | | | | | | | | | | | | | | | | Typically, in reasonably complex programs we want to realease various caches (such as glibc allocation caches) in case of memory pressure. Let's add explicit infrastructure for that to sd-event, that can hook Linux' Pressure Stall Information (PSI) logic with our event loop. This adds sd_event_add_memory_pressure() as easy, one-step API to install an even source that is called under memory pressure. The parameters which file to watch (the per-cgroup PSI file, or the system-wide file /proc/pressure/memory) can be configured via env vars. The idea is that the service manager sooner or later gains controls for setting this up correctly. Alternatively to the PSI a similar logic is supported but instead of waiting for POLLPRI on a procfs/cgroupfs fd we'll wait for POLLIN on FIFO or AF_UNIX sockets. This is useful for testing, and possibly in other environments, for example to hook up this protocol directly with GNOME's low memory monitor. By default this watches on the cgroup-local PSI so that we aren't affected by pressure on cgroups we are not related to.
* sd-event: allocate event source objects with the actually needed sizeLennart Poettering2023-02-171-9/+33
| | | | | | | | | | Currently we allocate fixed-size memory for event sources: the largest any of the event source type needs. Discrepancy in the sizes needed for the various event sources is quite major however: it's 144 bytes on x86_64, i.e. more than two cache lines. hence, let's be a tiny bit more careful, and allocate exactly as much as we need, but not more.
* sd-event: don't mistake USEC_INFINITY passed in for overflowLennart Poettering2023-01-061-0/+3
| | | | | | | | | Let's pass USEC_INFINITY from sd_event_source_set_time_relative() to sd_event_source_set_time() instead of raising EOVERFLOW. We should raise EOVERFLOW only if your addition fails, but not if the input already is USEC_INFINITY, since it's an entirely valid operation to have an infinite time-out, and we should support that.
* prioq: make prioq_reshuffle() voidLennart Poettering2022-12-231-4/+1
| | | | | | | | | | | We never use the return value, and it's confusing and kinda pointless what we return there. Hence drop it. Originally noticed by: tristone13th <tristone13th@outlook.com> Alternative to: #25810
* tree-wide: use -EBADF moreYu Watanabe2022-12-211-1/+1
|
* tree-wide: introduce PIPE_EBADF macroYu Watanabe2022-12-201-3/+3
|
* tree-wide: use -EBADF also in pipe initializersZbigniew Jędrzejewski-Szmek2022-12-191-1/+2
| | | | In some places, initialization is dropped when unnecesary.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-193-16/+15
| | | | | | | | | | | | | | | | -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.
* sd-event: never pass negative errnos as signalfd to signalfdZbigniew Jędrzejewski-Szmek2022-12-191-1/+3
| | | | | We treat any negative value as "invalid fd", but signalfd only accepts -1.
* Fix typojcg2022-11-261-1/+1
|
* sd-event: reenable epoll_pwait2()Lennart Poettering2022-11-231-6/+9
| | | | | | | | | | | | | | | | This reenables epoll_pwait2() use, i.e. undoes the effect of 39f756d3ae4765b8bf017567a12b8a4b358eaaf5. Instead of just reverting that, this PR will change things so that we strictly rely on glibc's new epoll_pwait2() wrapper (which was added earlier this year), and drop our own manual fallback syscall wrapper. That should nicely side-step any issues with correct syscall wrapping definitions (which on some arch seem not to be easy, given the sigset_t size final argument), by making this a glibc problem, not ours. Given that the only benefit this delivers are time-outs more granular than msec, it shouldn't really matter that we'll miss out on support for this on systems with older glibcs.
* Merge pull request #25291 from keszybz/util-cleanupYu Watanabe2022-11-092-1/+1
|\ | | | | Split/rename util.c+h and def.h
| * basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-082-1/+1
| | | | | | | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* | sd-event: adjust indentationZbigniew Jędrzejewski-Szmek2022-11-071-3/+3
|/
* sd-event: add helper for exiting event loop on SIGTERM/SIGINTLennart Poettering2022-09-301-0/+57
| | | | | | In many (most?) of our event loops we want to exit once SIGTERM/SIGINT is seen. Add a common helper for that, that does the right things in a single call.
* sd-event: if signal nr has high bit set sd_event_add_signal() auto-block it ↵Lennart Poettering2022-09-302-8/+64
| | | | | | | | | via sigprocmask() So far we expected callers to block the signals manually. Which is usually a good idea, since they should do that before forking off threads and similar. But let's add a mode where we automatically block it for the caller, to simplify things.
* fix typo in logj005125452022-09-151-1/+1
|
* tree-wide: Use correct format specifiersJan Janssen2022-08-301-3/+3
| | | | gcc will complain about all these with -Wformat-signedness.
* tree-wide: fix typoYu Watanabe2022-08-281-2/+2
|
* sd-event: introduce PROTECT_EVENT() macroYu Watanabe2022-07-161-7/+10
|
* sd-event: drop redundant codeYu Watanabe2022-07-161-5/+2
| | | | | The function `source_io_unregister()` will be anyway called in `source_disconnect()`.
* Merge pull request #23855 from keszybz/drop-list-is-emptyLennart Poettering2022-07-051-26/+26
|\ | | | | basic/list: drop LIST_IS_EMPTY
| * sd-event: rename field to indicate that it's a listZbigniew Jędrzejewski-Szmek2022-07-021-6/+6
| |
| * sd-event: rename field to indicate that it's a listZbigniew Jędrzejewski-Szmek2022-07-021-7/+7
| |
| * sd-event: align tableZbigniew Jędrzejewski-Szmek2022-07-021-11/+11
| |
| * basic/list: drop LIST_IS_EMPTYZbigniew Jędrzejewski-Szmek2022-07-021-4/+4
| | | | | | | | | | | | | | | | | | | | This was a trivial wrapper that didn't provide any added value. With more complicated structures like strvs, hashmaps, sets, and arrays, it is possible to have an empty container. But in case of a list, the list is empty only when the head is missing. Also, we generally want the positive condition, so we replace many if (!LIST_IS_EMPTY(x)) with just if (x).
* | sd-event: let sd_event_source_set_enabled accept NULLZbigniew Jędrzejewski-Szmek2022-06-303-9/+9
| | | | | | | | | | | | Same story as before: disabling a non-existent event source shouldn't need to be guarded by an if. I retained the wrapper so that that we don't have to say SD_EVENT_OFF in the many places where this is called.
* | sd-event: allow sd_event_source_is_enabled() to return false for NULLZbigniew Jędrzejewski-Szmek2022-06-303-8/+4
| | | | | | | | | | | | | | | | | | | | | | This is a natural use case, and instead of defining a wrapper to do this for us, let's just make this part of the API. Calling with NULL was not allowed, so this is not a breaking change to the interface. (After sd_event_source_is_enabled was originally added, we introduced sd_event_source_disable_unref() and other similar functions which accept NULL. So not accepting NULL here is likely to confuse people. Let's just make the API usable with minimal fuss.)
* | Merge pull request #23821 from dtardon/ascii-loggingYu Watanabe2022-06-291-1/+3
|\ \ | |/ |/| Allow ASCII fallback for Unicode characters in logs
| * tree-wide: allow ASCII fallback for … in logsDavid Tardon2022-06-281-1/+3
| |
* | test: add another test for inotify event sourceYu Watanabe2022-06-281-0/+52
| | | | | | | | The test case is for issue #23826.
* | sd-event: make sd_event_prepare() return positive when buffered inotify data ↵Yu Watanabe2022-06-281-1/+1
| | | | | | | | | | | | | | | | | | exists Previously, even if there is buffered inotify data, sd_event_prepare() did not process the data when there is no pending event source. Fixes #23826.
* | sd-event: use LIST_IS_EMPTY()Yu Watanabe2022-06-281-3/+3
|/
* sd-event: make inotify event work after the process is forkedYu Watanabe2022-04-131-2/+3
|
* sd-event: do not kill a child process from another childYu Watanabe2022-04-131-0/+3
|
* sd-event: do not update signal fd after PID is changedYu Watanabe2022-04-131-0/+3
| | | | | Otherwise, child event source will not work after the process is forked and the event source is unref()ed on the child process.
* sd-event: set pid to event source after all setup processes finishedYu Watanabe2022-04-131-6/+7
| | | | Otherwise, the assertion in source_disconnect() may be triggered,
* sd-event: rebreak commentsYu Watanabe2022-04-131-31/+22
|
* time-util: assume CLOCK_BOOTTIME always existsLennart Poettering2022-03-282-14/+4
| | | | | | | | Let's raise our supported baseline a bit: CLOCK_BOOTTIME started to work with timerfd in kernel 3.15 (i.e. back in 2014), let's require support for it now. This will raise our baseline only modestly from 3.13 → 3.15.