summaryrefslogtreecommitdiff
path: root/src/libelogind
Commit message (Collapse)AuthorAge
* 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.
* sd-bus: add APIs to query the current read and write queue sizeLennart Poettering2018-05-30
|
* sd-login: make use of _cleanup_close_ where possibleLennart Poettering2018-05-30
|
* tree-wide: use reallocarray instead of our home-grown realloc_multiply (#8279)Zbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | There isn't much difference, but in general we prefer to use the standard functions. glibc provides reallocarray since version 2.26. I moved explicit_bzero is configure test to the bottom, so that the two stdlib functions are at the bottom.
* tree-wide: make use of fsync_directory_of_file() all over the placeLennart Poettering2018-05-30
| | | | | | Let's make use this at various places we call fsync(), to make things fully reliable, as the kernel devs suggest to first fsync() files and then fsync() the directories they are located in.
* 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.
* meson: factor out daemon/event/id128 sources into variables (#8170)Davide Cavalca2018-05-30
|
* 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.
* 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 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_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.
* 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.
* bus-message: avoid -Wnull-pointer-arithmetic warning on new clangZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | We just need some pointer, so use alignment directly converted to the right type.
* sd-dameon: also sent ucred when our UID differs from EUIDLennart Poettering2018-05-30
| | | | | | Let's be explicit, and always send the messages from our UID and never our EUID. Previously this behaviour was conditionalized only on whether the PID was specified, which made this non-obvious.
* 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: drop bloom stuff, it's not needed anymore since kdbus is goneLennart Poettering2018-05-30
|
* bus-socket: slight simplification in bus_get_peercred()Zbigniew Jędrzejewski-Szmek2018-05-30
|
* sd-netlink: add generic netlink supportJörg Thalheim2018-05-30
| | | | | | This also adds the ability to incorporate arrays into netlink messages and to determine when a netlink message is too big, used by some generic netlink protocols.
* 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: drop some unused fields from the sd_bus_message structureLennart Poettering2018-05-30
|
* 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: modernize how we generate the match string in sd-bus-trackLennart Poettering2018-05-30
| | | | strjoina() FTW!
* 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.
* tree-wide: install matches asynchronouslyLennart Poettering2018-05-30
| | | | | | | | | Let's remove a number of synchronization points from our service startups: let's drop synchronous match installation, and let's opt for asynchronous instead. Also, let's use sd_bus_match_signal() instead of sd_bus_add_match() where we can.
* sd-bus: when disconnecting a slot, also reset its memoryLennart Poettering2018-05-30
| | | | | Yes, we aren#t accessing this anymore after, but it's still nicer if this is actually guaranteed.
* sd-bus: add new API sd_bus_match_signal() + sd_bus_match_signal_asnyc()Lennart Poettering2018-05-30
| | | | | | These are convenience helpers that hide the match string logic (which we probably should never have exposed), and instead just takes regular C arguments.
* 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: when removing a server-side match, do so in "fire and forget" fashionLennart Poettering2018-05-30
| | | | | | | We currently wait for the RemoveMatch() reply, but then ignore what it actually says. Let's optimize this a bit, and not even ask for an answer back: just enqueue the RemoveMatch() operation, and do not request not wait for any answer.
* 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.
* bus-control: remove kdbus indirection cruftLennart Poettering2018-05-30
| | | | | | | | | When kdbus was still around we always had two implementations of the various control calls: one for dbus1 and one for kdbus. Let'sget rid of this, simplify things, and just merge the wrappers that used to multiplex this with the implementations. No change in behaviour, just some merging of functions
* 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: cast some syscall invocations explicitly to (void)Lennart Poettering2018-05-30
| | | | Let's clarify that we knowingly ignore the return values.