summaryrefslogtreecommitdiff
path: root/src/libelogind
Commit message (Collapse)AuthorAge
* tree-wide: unify how we define bit mak enumsLennart Poettering2018-08-24
| | | | | | Let's always write "1 << 0", "1 << 1" and so on, except where we need more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force 64bit values.
* core: introduce a new load state "bad-setting"Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | Since bb28e68477a3a39796e4999a6cbc6ac6345a9159 parsing failures of certain unit file settings will result in load failures of units. This introduces a new load state "bad-setting" that is entered in precisely this case. With this addition error messages on bad settings should be a lot more explicit, as we don't have to show some generic "errno" error in that case, but can explicitly say that a bad setting is at fault. Internally this unit load state is entered as soon as any configuration loader call returns ENOEXEC. Hence: config parser calls should return ENOEXEC now for such essential unit file settings. Turns out, they generally already do. Fixes: #9107
* 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-bus: also add destroy callbacks to sd_bus_track objectsLennart Poettering2018-08-24
| | | | | This augments previous work for this for sd_bus_slot objects, and adds the same concept to sd_bus_track objects, too.
* bus: optionally call a callbacks for cleanupZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | This adds a function sd_bus_slot_set_destroy_callback() to set a function which can free userdata or perform other cleanups. sd_bus_slot_get_destory_callback() queries the callback, and is included for completeness. Without something like this, for floating asynchronous callbacks, which might be called or not, depending on the sequence of events, it's hard to perform resource cleanup. The alternative would be to always perform the cleanup from the caller too, but that requires more coordination and keeping of some shared state. It's nicer to keep the cleanup contained between the callback and the function that requests the callback.
* 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
|
* sd-id128: return -ENOMEDIUM on null idZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | We currently return -ENOMEDIUM when /etc/machine-id is empty, and -EINVAL when it is all zeros. But -EINVAL is also used for invalid args. The distinction between empty and all-zero is not very important, let's use the same return code. Also document -ENOENT and -ENOMEDIUM since they can be a bit surprising.
* tree-wide: make use of memory_startswith() at various placesLennart Poettering2018-08-24
|
* sd-bus: make add match method callback slot "floating"Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | When we allocate an asynchronous match object we will allocate an asynchronous bus call object to install the match server side. Previously the call slot would be created as regular slot, i.e. non-floating which meant installing the match even if it was itself floating would result in a non-floating slot to be created internally, which ultimately would mean the sd_bus object would be referenced by it, and thus never be freed. Let's fix that by making the match method callback floating in any case as we have no interest in leaving the bus allocated beyond the match slot. Fixes: #8551
* bus-slot: for bus slot objects with no explicit description use the match ↵Lennart Poettering2018-08-24
| | | | | | | string as description Let's make debugging a but easier with implicit descriptions for some match objects.
* sd-bus: add new sd_bus_slot_set_floating() callLennart Poettering2018-08-24
| | | | | | | | | | This new call allows explicit control of the "floating" state of a bus slot object. This is useful for creating a bus slot object first, retaining a reference to it, using it for making changes to the slot object (for example, set a description) and then handing it over to sd-bus for lifecycle management. It's also useful to fix #8551.
* sd-bus: use _cleanup_ moreZbigniew Jędrzejewski-Szmek2018-08-24
|
* add new portable service frameworkLennart Poettering2018-08-24
| | | | | | | | | | | This adds a small service "systemd-portabled" and a matching client "portablectl", which implement the "portable service" concept. The daemon implements the actual operations, is PolicyKit-enabled and is activated on demand with exit-on-idle. Both the daemon and the client are an optional build artifact, enabled by default rhough.
* fileio: accept FILE* in addition to path in parse_env_file()Lennart Poettering2018-08-24
| | | | | | | 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.
* tree-wide: do not wrap assert_se in extra parenthesesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | We were inconsitently using them in some cases, but in majority not. Using assignment in assert_se is very common, not an exception like in 'if', so let's drop the extra parens everywhere.
* sd-bus: use free_and_strdup()Yu Watanabe2018-08-24
|
* path-util: introduce empty_to_root() and use it many placesYu Watanabe2018-08-24
|
* sd-bus: use automatic cleanup moreDavid Tardon2018-08-24
|
* meson: add support for building static libsystemd and libudevDavide Cavalca2018-08-24
|
* tree-wide: use strv_free_and_replace() macroYu Watanabe2018-08-24
|
* sd-bus: add bus_freep and use _cleanup_Zbigniew Jędrzejewski-Szmek2018-08-24
|
* sd-bus: use automatic cleanup moreZbigniew Jędrzejewski-Szmek2018-08-24
|
* sd-bus: trivial simplificationZbigniew Jędrzejewski-Szmek2018-08-24
|
* use max. message size allowed by DBus spec (#8936)David Tardon2018-08-24
| | | | C.f. https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* bus-message: use streq_ptr() (#8786)Yu Watanabe2018-08-24
|
* timedate: move error mapping to bus-common-errors.[ch]Yu Watanabe2018-08-24
|
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* 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.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* sd-bus: allow description to be set for system/user busses (#8594)Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but don't allow the description to be set. After they return, the bus is is already started, and sd_bus_set_description() fails with -EBUSY. It would be possible to allow sd_bus_set_description() to update the description "live", but messages are already emitted from sd_bus_open functions, so it's better to allow the description to be set in sd_bus_open/sd_bus_open_system/sd_bus_open_user. Fixes message like: Bus n/a: changing state UNSET → OPENING
* sd-event: use _cleanup_ to manage temporary referencesZbigniew Jędrzejewski-Szmek2018-08-24
|
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* sd-bus: allow description to be set for system/user busses (#8594)Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but don't allow the description to be set. After they return, the bus is is already started, and sd_bus_set_description() fails with -EBUSY. It would be possible to allow sd_bus_set_description() to update the description "live", but messages are already emitted from sd_bus_open functions, so it's better to allow the description to be set in sd_bus_open/sd_bus_open_system/sd_bus_open_user. Fixes message like: Bus n/a: changing state UNSET → OPENING
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* sd-bus: drop fd_nonblock() calls that are implied by rearrange_stdio() (#8514)Lennart Poettering2018-06-28
| | | | (cherry picked from commit 68b525d1d1e8153cbc2e2354fa650aa165f7a434)
* sd-bus: do not try to close already closed fd (#8392)Yu Watanabe2018-06-28
| | | | | | Fixes #8376, which is introduced by 2b33ab0957f453a06b58e4bee482f2c2d4e100c1. (cherry picked from commit 280029d18f470a64403d68717eef1be5274ff8af)
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/libelogind (3/6)
* Prep v238: Remove obsolete sources and add missing new ones.Sven Eden2018-06-05
|
* Prep v238: Applied some upstream updates to src/libelogind (5/5)Sven Eden2018-06-04
|
* sd-bus: let's better not invade stdio territory when duplicating fdsLennart Poettering2018-05-30
|
* tree-wide: port various places over to use new rearrange_stdio()Lennart Poettering2018-05-30
|
* coccinelle: add reallocarray() coccinelle scriptLennart Poettering2018-05-30
| | | | | Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.