summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus/sd-bus.c
Commit message (Collapse)AuthorAge
* sd-bus: enable support for user bus instancesCameron Nemo2018-11-08
| | | | | | | Bug: #87 Closes: #87 Signed-off-by: Cameron Nemo <camerontnorman@gmail.com> Signed-off-by: Sven Eden <sven.eden@prydeworx.com>
* Prep v239: Fix new sd_bus_open_user_with_description()Sven Eden2018-08-24
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | 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-08-24
| | | | | | | | | | | | | | | | 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.
* 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
* sd-bus: use free_and_strdup()Yu Watanabe2018-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
|
* 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
* 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)
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/libelogind (3/6)
* sd-bus: add APIs to query the current read and write queue sizeLennart Poettering2018-05-30
|
* sd-bus: synthesize a description for user/system bus if otherwise unsetLennart Poettering2018-05-30
| | | | | Let's make debugging easier, by synthesizing a name when we have some indication what kind of bus this is.
* sd-bus: cleanup ssh sessions (Closes: #8076)Shawn Landden2018-05-30
| | | | | | | | | | | | | | | | | | | we still invoke ssh unnecessarily when there in incompatible or erreneous input The fallow-up to finish that would make the code a bit more verbose, as it would require repeating this bit: ``` r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); ``` in every verb, after parsing. v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL v3: refactor, wait in bus_start_address()
* sd-bus: explicitly convert int to boolYu Watanabe2018-05-30
|
* sd-bus: use free_and_replace()Yu Watanabe2018-05-30
|
* sd-bus: avoid potential memory leaksYu Watanabe2018-05-30
|
* sd-bus: cleanup ssh sessions (Closes: #8076)Shawn Landden2018-05-30
| | | | | | | | | | | | | | | | | | | | we still invoke ssh unnecessarily when there in incompatible or erreneous input The fallow-up to finish that would make the code a bit more verbose, as it would require repeating this bit: ``` r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); ``` in every verb, after parsing. v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL v3: refactor, wait in bus_start_address() (cherry picked from commit 392cf1d05dbfa1395f6d99102e5ea41debb58fec)
* sd-bus: avoid potential memory leaksYu Watanabe2018-05-30
| | | | (cherry picked from commit b4ca3f45dc5742ad76e8feebd363c490f92b804f)
* Add support for SD_BUS_DEFAULT*Nathaniel McCallum2018-05-30
| | | | | | | | | | | | | | | | | | | | | | Currently, sd-bus supports the ability to have thread-local default busses. However, this is less useful than it can be since all functions which require an sd_bus* as input require the caller to pass it. This patch adds a new macro which allows the developer to pass a constant SD_BUS_DEFAULT, SD_BUS_DEFAULT_USER or SD_BUS_DEFAULT_SYSTEM instead. This reduces work for the caller. For example: r = sd_bus_default(&bus); r = sd_bus_call_method(bus, ...); sd_bus_unref(bus); Becomes: r = sd_bus_call_method(SD_BUS_DEFAULT, ...); If the specified thread-local default bus does not exist, the function calls will return -ENOPKG. No bus will ever be implicitly created.
* log: minimize includes in log.hLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* sd-bus: remove 'hint_sync_call' parameter from various function callsLennart Poettering2018-05-30
| | | | | | This is unused since kdbus is gone, hence remove this too. This permits us to get rid of sd_bus_send_internal() and just implement sd_bus_send() directly.
* sd-bus: add API to optionally set a sender field on all outgoing messagesLennart Poettering2018-05-30
| | | | | | | | | | This is useful on direct connections to generate messages with valid sender fields. This is particularly useful for services that are accessible both through direct connections and the broker, as it allows clients to install matches on the sender service name, and they work the same in both cases.
* sd-bus: accept NULL callbacks in sd_bus_call_async()Lennart Poettering2018-05-30
| | | | | | This way sd_bus_call_method_async() (which is just a wrapper around sd_bus_call_async()) can be used to put method calls together that expect no reply.
* sd-bus: log about bus state changesLennart Poettering2018-05-30
| | | | | Let's unify all state changes in a new helper function, from which we can then debug log all state changes
* sd-bus: add new sd_bus_set_connected_signal() APILennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | With this new API sd-bus can synthesize a local "Connected" signal when the connection is fully established. It mirrors the local "Disconnected" signal that is already generated when the connection is terminated. This is useful to be notified when connection setup is done, in order to start method calls then, in particular when using "slow" connection methods (for example slow TCP, or most importantly the "watch_bind" inotify logic). Note that one could also use hook into the initial NameAcquired signal received from the bus broker, but that scheme works only if we actually connect to a bus. The benefit of "Connected" OTOH is that it works with any kind of connection. Ideally, we'd just generate this message unconditionally, but in order not to break clients that do not expect this message it is opt-in.
* sd-bus: add new sd_bus_is_ready() APILennart Poettering2018-05-30
| | | | | | | | This new call is much light sd_bus_is_open(), but returns true only if the connection is fully set up, i.e. after we finished with the authentication and Hello() phase. This API is useful for clients in particular when using the "watch_bind" feature, as that way it can be determined in advance whether it makes sense to sync on some operation.
* sd-bus: drop references to legacy /var/run D-Bus socketLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | Let's directly reference /run instead, so that we can work without /var being around, or with /var/run being incorrectly set up. Note that we keep the old socket path in place when referencing the system bus of containers, as they might be foreign operating systems, that still don't have adopted /run, and where it makes sense to use the standardized name instead. On local systems, we insist on /run being set up properly however, hence this limitation does not apply. Also, get rid of the UNIX_SYSTEM_BUS_ADDRESS and UNIX_USER_BUS_ADDRESS_FMT defines. They had a purpose when we still did kdbus, as we then had to support two different backends. But since that's gone, we don't need this indirection anymore, hence settle on a one define only.
* sd-bus: add asynchronous version of sd_bus_match()Lennart Poettering2018-05-30
| | | | | | | We usually enqueue a number of these calls on each service initialization. Let's do this asynchronously, and thus remove synchronization points. This improves both performance behaviour and reduces the chances to deadlock.
* sd-bus: remove bus_remove_match_by_string() helper which is unusedLennart Poettering2018-05-30
|
* sd-bus: drop unused parameters from bus_add_match_internal()Lennart Poettering2018-05-30
| | | | | We don't need the match components anymore, since kdbus is gone, hence drop it.
* sd-bus: add APIs to request/release names asynchronouslyLennart Poettering2018-05-30
| | | | | | | | | | | They do the same thing as their synchronous counterparts, but only enqueue the operation, thus removing synchronization points during service initialization. If the callback function is passed as NULL we'll fallback to generic implementations of the reply handlers, that terminate the connection if the requested name cannot be acquired, under the assumption that not being able to acquire the name is a technical problem.
* sd-bus: get rid of kdbus flags cruftLennart Poettering2018-05-30
| | | | | We only need three bits from the old kdbus flags cruft, hence let's make them proper booleans.
* sd-bus: start reply callback timeouts only when the connection is establishedLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | Currently, reply callback timeouts are started the instant the method calls are enqueued, which can be very early on. For example, the Hello() method call is enqueued right when sd_bus_start() is called, i.e. before the socket connection and everything is established. With this change we instead start the method timeout the moment we actually leave the authentication phase of the connection. This way, the timeout the kernel applies on socket connecting, and we apply on the authentication phase no longer runs in parallel to the Hello() method call, but all three run serially one after the other, which is definitely a cleaner approach. Moreover, this makes the "watch bind" feature a lot more useful, as it allows enqueuing method calls while we are still waiting for inotify events, without them timeouting until the connection is actually established, i.e. when the method call actually has a chance of being actually run. This is a change of behaviour of course, but I think the new behaviour is much better than the old one, since we don't race timeouts against each other anymore...
* sd-bus: optionally, use inotify to wait for bus sockets to appearLennart Poettering2018-05-30
| | | | | | | | | | | This adds a "watch-bind" feature to sd-bus connections. If set and the AF_UNIX socket we are connecting to doesn't exist yet, we'll establish an inotify watch instead, and wait for the socket to appear. In other words, a missing AF_UNIX just makes connecting slower. This is useful for daemons such as networkd or resolved that shall be able to run during early-boot, before dbus-daemon is up, and want to connect to dbus-daemon as soon as it becomes ready.
* sd-bus: when attached to an sd-event loop, disconnect on processing errorsLennart Poettering2018-05-30
| | | | | | If we can't process the bus for some reason we shouldn't just disable the event source, but log something and give up on the connection. Hence do that, and disconnect.
* sd-bus: propagate handling errors for Hello method reply directlyLennart Poettering2018-05-30
| | | | | | | | | | | | | Currently, when sd-bus is used to issue a method call, and we get a reply and the specified reply handler fails, we log this locally at debug priority and proceed. The idea is that a bad server-side reply should not be fatal for the program, except when the developer explicitly terminates the event loop. The reply to the initial Hello() method call we issue when joining a bus should not be handled like that however. Instead, propagate the error immediately, as anything that is wrong with the Hello() reply should be considered a fatal connection problem.
* sd-bus: minor coding style fixLennart Poettering2018-05-30
|
* sd-bus: when debug logging about messages, show the same bits of it everywhereLennart Poettering2018-05-30
| | | | Also, include the message signature everywhere.
* sd-bus: let's use mfree() where we canLennart Poettering2018-05-30
|
* sd-bus: use SO_PEERGROUPS when available to identify groups of peerLennart Poettering2018-05-30
|
* Prep v236 : Add missing SPDX-License-Identifier (4/9) src/libelogindSven Eden2018-03-26
|
* Replace free and reassignment with free_and_replaceDaniel Lockyer2017-11-24
|