summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-event
Commit message (Collapse)AuthorAge
* sd-event: add destroy callback logic to sd-event tooLennart Poettering2018-08-24
| | | | | This adds what has been added to sd_bus_slot and sd_bus_track to sd_event too.
* sd-event: use structure initialization instead of new0() where possibleLennart Poettering2018-08-24
|
* sd-event: add test for the new sd_event_add_inotify() APILennart Poettering2018-08-24
| | | | | | This tests a couple of corner cases of the sd-event API including changing priorities of existing event sources, as well as overflow conditions of the inotify queue.
* sd-event: add new API for subscribing to inotify eventsLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new call sd_event_add_inotify() which allows watching for inotify events on specified paths. sd-event will try to minimize the number of inotify fds allocated, and will try to add file watches to the same inotify fd objects as far as that's possible. Doing this kind of inotify object should optimize behaviour in programs that watch a limited set of mostly independent files as in most cases a single inotify object will suffice for watching all files. Traditionally, this kind of coalescing logic (i.e. that multiple event sources are implemented on top of a single inotify object) was very hard to do, as the inotify API had serious limitations: it only allowed adding watches by path, and would implicitly merge watches installed on the same node via different path, without letting the caller know about whether such merging took place or not. With the advent of O_PATH this issue can be dealt with to some point: instead of adding a path to watch to an inotify object with inotify_add_watch() right away, we can open the path with O_PATH first, call fstat() on the fd, and check the .st_dev/.st_ino fields of that against a list of watches we already have in place. If we find one we know that the inotify_add_watch() will update the watch mask of the existing watch, otherwise it will create a new watch. To make this race-free we use inotify_add_watch() on the /proc/self/fd/ path of the O_PATH fd, instead of the original path, so that we do the checking and watch updating with guaranteed the same inode. This approach let's us deal safely with inodes that may appear under various different paths (due to symlinks, hardlinks, bind mounts, fs namespaces). However it's not a perfect solution: currently the kernel has no API for changing the watch mask of an existing watch -- unless you have a path or fd to the original inode. This means we can "merge" the watches of the same inode of multiple event sources correctly, but we cannot "unmerge" it again correctly in many cases, as access to the original inode might have been lost, due to renames, mount/unmount, or deletions. We could in theory always keep open an O_PATH fd of the inode to watch so that we can change the mask anytime we want, but this is highly problematics, as it would consume too many fds (and in fact the scarcity of fds is the reason why watch descriptors are a separate concepts from fds) and would keep the backing mounts busy (wds do not keep mounts busy, fds do). The current implemented approach to all this: filter in userspace and accept that the watch mask on some inode might be higher than necessary due to earlier installed event sources that might have ceased to exist. This approach while ugly shouldn't be too bad for most cases as the same inodes are probably wacthed for the same masks in most implementations. In order to implement priorities correctly a seperate inotify object is allocated for each priority that is used. This way we get separate per-priority event queues, of which we never dequeue more than a few events at a time. Fixes: #3982
* sd-event: voidify more thingsLennart Poettering2018-08-24
|
* sd-event: propagate errors from source_set_pending() in all casesLennart Poettering2018-08-24
|
* sd-event: drop pending events when we turn off/on an event sourceLennart Poettering2018-08-24
|
* sd-event: use symbolic name for normal priorityLennart Poettering2018-08-24
|
* sd-event: use structure initialization for epoll_eventLennart Poettering2018-08-24
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | 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.
* sd-event: use _cleanup_ to manage temporary referencesZbigniew Jędrzejewski-Szmek2018-08-24
|
* fd-util: move certain fds above fd #2 (#8129)Lennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds some paranoia code that moves some of the fds we allocate for longer periods of times to fds > 2 if they are allocated below this boundary. This is a paranoid safety thing, in order to avoid that external code might end up erroneously use our fds under the assumption they were valid stdin/stdout/stderr. Think: some app closes stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes writes on our fds. This both adds the helper to do the moving as well as ports over a number of users to this new logic. Since we don't want to litter all our code with invocations of this I tried to strictly focus on fds we keep open for long periods of times only and only in code that is frequently loaded into foreign programs (under the assumptions that in our own codebase we are smart enough to always keep stdin/stdout/stderr allocated to avoid this pitfall). Specifically this means all code used by NSS and our sd-xyz API: 1. our logging APIs 2. sd-event 3. sd-bus 4. sd-resolve 5. sd-netlink This changed was inspired by this: https://github.com/systemd/systemd/issues/8075#issuecomment-363689755 This shows that apparently IRL there are programs that do close stdin/stdout/stderr, and we should accomodate for that. Note that this won't fix any bugs, this just makes sure that buggy programs are less likely to interfere with out own code.
* Add fd close support to sd_event_sourceNathaniel McCallum2018-05-30
| | | | | | | | | | | | | | It is often the case that a file descriptor and its corresponding IO sd_event_source share a life span. When this is the case, developers will have to unref the event source and close the file descriptor. Instead, we can just have the event source take ownership of the file descriptor and close it when the event source is freed. This is especially useful when combined with cleanup attributes and sd_event_source_unrefp(). This patch adds two new public functions: sd_event_source_get_io_fd_own() sd_event_source_set_io_fd_own()
* Add support for SD_EVENT_DEFAULTNathaniel McCallum2018-05-30
| | | | | | | | | | | | | | | | | | | | | Currently, sd-event supports the ability to have a thread-local default event loop. However, this is less useful than it can be since all functions which require an sd_event* as input require the caller to pass it. This patch adds a new macro which allows the developer to pass a constant SD_EVENT_DEFAULT instead. This reduces work for the caller. For example: r = sd_event_default(&e); r = sd_event_add_io(e, ...); sd_event_unref(e); Becomes: r = sd_event_add_io(SD_EVENT_DEFAULT, ...); If no thread-local default event loop exists, the function calls will return -ENOPKG. No event loop will ever be implicitly created.
* tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we canLennart Poettering2018-05-30
|
* Prep v236 : Add missing SPDX-License-Identifier (4/9) src/libelogindSven Eden2018-03-26
|
* tree-wide: do not work in assert()Yu Watanabe2017-11-09
| | | | Follow-up for 85e55d14dea66f5fe412ca8128487d5ea828b7b1.
* Prep 229.9: Make all supportable API functions visible.Sven Eden2017-12-12
| | | | | | | | | | The process of cleaning up elogind, meaning to mask all bits that are unneeded by elogind, has been finished a while ago. It is therefore time to re-enable all previously masked API functions that elogind can support. This will make it easier for future developers to integrate elogind into their software where they already support systemd-login.
* libelogind: use IN_SET macroYu Watanabe2017-11-22
|
* fileio: return 0 from read_one_line_file on successZbigniew Jędrzejewski-Szmek2017-11-22
| | | | Fixup for f4b51a2d09. Suggested by Evgeny Vereshchagin.
* cgroup, unit, fragment parser: make use of new firewall functionsDaniel Mack2017-11-21
|
* Add abstraction model for BPF programsDaniel Mack2017-11-20
| | | | | This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code.
* Prep v235: Add missing includes and dependencies.Sven Eden2017-08-14
|
* Prep v235: Apply upstream fixes (5/10) [src/libelogind]Sven Eden2017-08-14
|
* General: Update build system to upstream support of meson+ninja.Sven Eden2017-08-04
| | | | | | | | Upstream thinks, that the auto tools are too 'legacy', or that they are at least no longer fitting. We follow, as the classic auto tools files have been removed, so no other choice here...
* Fix includes (#5980)Matija Skala2017-07-25
| | | | Needed on musl.
* Prep v233.3: Add all possible coverage tests for elogindSven Eden2017-07-20
|
* Prep v233.3: Unmask various functions for future coverage tests.Sven Eden2017-07-19
| | | | | These functions, although not used by elogind itself, are mostly tiny and crucial for important tests to work.
* sd-event: "when exiting no signal event are pending" is a wrong assertion ↵Franck Bui2017-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#5271) The code make the following assertion: when freeing a event loop object (usually it's done after exiting from the main event loop), no signal events are still queued and are pending. This assertion can be found in event_unmask_signal_data() with "assert(!d->current);" assertion. It appears that this assertion can be wrong at least in a specific case described below. Consider the following example which is inspired from udev: a process defines 3 source events: 2 are created by sd_event_add_signal() and 1 is created by sd_event_add_post(). 1. the process receives the 2 signals consecutively so that signal 'A' source event is queued and pending. Consequently the post source event is also queued and pending. This is done by sd_event_wait(). 2. The callback for signal 'A' is called by sd_event_dispatch(). 3. The next call to sd_event_wait() will queue signal 'B' source event. 4. The callback for the post source event is called and calls sd_event_exit(). 5. the event loop is exited. 6. freeing the event loop object will lead to the assertion failure in event_unmask_signal_data(). This patch simply removes this assertion as it doesn't seem to be a bug if the signal data still reference a signal source at this point.
* sd-event: when an event source fails, don't assume the type of it is still setLennart Poettering2017-07-17
| | | | | | | If a callback of an event source returns an error, then the event source might already be half-destroyed, if the callback dropped all refs. Hence, don't assume that the type is still valid, and save it before we issue the callback.
* sd-event: fix sd_event_source_get_priority() (#4712)Martin Ejdestig2017-07-17
| | | | | To properly store priority in passed in pointer and return 0 for success. Also add a test for verifying that it works correctly.
* Prep v232: Apply missing updates from upstreamSven Eden2017-07-05
|
* sd-event: "when exiting no signal event are pending" is a wrong assertion ↵Franck Bui2017-06-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#5271) The code make the following assertion: when freeing a event loop object (usually it's done after exiting from the main event loop), no signal events are still queued and are pending. This assertion can be found in event_unmask_signal_data() with "assert(!d->current);" assertion. It appears that this assertion can be wrong at least in a specific case described below. Consider the following example which is inspired from udev: a process defines 3 source events: 2 are created by sd_event_add_signal() and 1 is created by sd_event_add_post(). 1. the process receives the 2 signals consecutively so that signal 'A' source event is queued and pending. Consequently the post source event is also queued and pending. This is done by sd_event_wait(). 2. The callback for signal 'A' is called by sd_event_dispatch(). 3. The next call to sd_event_wait() will queue signal 'B' source event. 4. The callback for the post source event is called and calls sd_event_exit(). 5. the event loop is exited. 6. freeing the event loop object will lead to the assertion failure in event_unmask_signal_data(). This patch simply removes this assertion as it doesn't seem to be a bug if the signal data still reference a signal source at this point. (cherry picked from commit 4470860388e12a5dda1d65773e411a349221a3e9)
* Prep v231: Apply missing fixes from upstream (3/6) src/libelogindSven Eden2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (5/8) src/libelogind.Sven Eden2017-06-16
|
* tree-wide: don't assume CLOCK_BOOTIME is generally availableLennart Poettering2017-06-16
| | | | | | | | | | | | Before we invoke now(CLOCK_BOOTTIME), let's make sure we actually have that clock, since now() will otherwise hit an assert. Specifically, let's refuse CLOCK_BOOTTIME early in sd-event if the kernel doesn't actually support it. This is a follow-up for #3037, and specifically: https://github.com/elogind/elogind/pull/3037#issuecomment-210199167
* tree-wide: fall back to now(CLOCK_MONOTONIC) if CLOCK_BOOTTIME unsupported ↵Lubomir Rintel2017-06-16
| | | | | | | | | (#3037) It was added in 2.6.39, and causes an assertion to fail when running in mock hosted on 2.6.32-based RHEL-6: Assertion 'clock_gettime(map_clock_id(clock_id), &ts) == 0' failed at elogind/src/basic/time-util.c:70, function now(). Aborting.
* tree-wide: add new SIGNAL_VALID() macro-like function that validates signal ↵Lennart Poettering2017-06-16
| | | | | | numbers And port all code over to use it.
* time-util: map ALARM clockids to non-ALARM clockids in now()Lennart Poettering2017-06-16
| | | | Fixes: #2597
* Prep v229: Add missing fixes from upstream [3/6] src/libelogindSven Eden2017-05-17
|
* sd-event: permit a USEC_INFINITY timeout as an alternative to a disabling an ↵Lennart Poettering2017-05-17
| | | | | | | event source This should simplify handling of time events in clients and is in-line with the USEC_INFINITY macro we already have. This way setting a timeout to 0 indicates "elapse immediately", and a timeout of USEC_INFINITY "elapse never".
* sd-event: when determining the last allowed time a time event may elapse, ↵Lennart Poettering2017-05-17
| | | | deal with overflows
* sd-event: minor fixups to delays profiling changesVito Caputo2017-05-17
|
* sd-event: check clock argument to sd_event_now()Zbigniew Jędrzejewski-Szmek2017-05-17
| | | | | | | | sd_event_now() is a public function, so we must check all arguments for validity. Update man page and add tests. Sample debug message: Assertion 'IN_SET(clock, CLOCK_REALTIME, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM)' failed at src/libelogind/sd-event/sd-event.c:2719, function sd_event_now(). Ignoring.
* sd-event: improve debugging of event source errorsDaniel Mack2017-05-17
| | | | | | | Printing the pointer variable really doesn't help, so drop that. Instead, add a string lookup table for the EventSourceType enum, and print the type of event source in case of errors.
* sd-event: instrument sd_event_run() for profiling delaysVito Caputo2017-05-17
| | | | | | | | | | | | | Set SD_EVENT_PROFILE_DELAYS to activate accounting and periodic logging of the distribution of delays between sd_event_run() calls. Time spent in dispatching as well as time spent outside of sd_event_run() is measured and accounted for. Every 5 seconds a logarithmic histogram loop iteration delays since 5 seconds previous is logged. This is useful in identifying the frequency and magnitude of latencies affecting the event loop, which should be kept to a minimum.
* sd-event: use prioq_ensure_allocated where possibleEvgeny Vereshchagin2017-05-17
|
* sd-event: define a new PREPARING stateLennart Poettering2017-05-17
| | | | | | | | | | We already have a state RUNNING and EXITING when we dispatch regular and exit callbacks. Let's introduce a new state called PREPARING that is active while we invoke preparation callbacks. This way we have a state each for all three kinds of event handlers. The states are currently not documented, hence let's add a new state to the end, before we start documenting this.
* Prep v228: Condense elogind source masks (4/5)Sven Eden2017-04-26
|
* Prep v228: Add remaining updates from upstream (3/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on the rest of elogind.