mirror of
https://github.com/systemd/systemd
synced 2024-07-21 18:24:38 +00:00
Merge pull request #31515 from keszybz/small-cleanups-after-review-of-stable-batch
Small cleanups after review of stable batch
This commit is contained in:
commit
47c2a6e958
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: MIT-0 */
|
||||
|
||||
/* Implements a D-Bus service that automatically reconnects when the system bus is restarted.
|
||||
/* A D-Bus service that automatically reconnects when the system bus is
|
||||
* restarted.
|
||||
*
|
||||
* Compile with 'cc sd_bus_service_reconnect.c $(pkg-config --libs --cflags libsystemd)'
|
||||
*
|
||||
|
@ -10,18 +11,18 @@
|
|||
|
||||
<?xml version="1.0"?> <!--*-nxml-*-->
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<policy user="root">
|
||||
<allow own="org.freedesktop.ReconnectExample"/>
|
||||
<allow send_destination="org.freedesktop.ReconnectExample"/>
|
||||
<allow receive_sender="org.freedesktop.ReconnectExample"/>
|
||||
</policy>
|
||||
<policy user="root">
|
||||
<allow own="org.freedesktop.ReconnectExample"/>
|
||||
<allow send_destination="org.freedesktop.ReconnectExample"/>
|
||||
<allow receive_sender="org.freedesktop.ReconnectExample"/>
|
||||
</policy>
|
||||
|
||||
<policy context="default">
|
||||
<allow send_destination="org.freedesktop.ReconnectExample"/>
|
||||
<allow receive_sender="org.freedesktop.ReconnectExample"/>
|
||||
</policy>
|
||||
<policy context="default">
|
||||
<allow send_destination="org.freedesktop.ReconnectExample"/>
|
||||
<allow receive_sender="org.freedesktop.ReconnectExample"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
|
||||
*
|
||||
|
@ -31,7 +32,7 @@
|
|||
* /org/freedesktop/ReconnectExample \
|
||||
* org.freedesktop.ReconnectExample \
|
||||
* Example
|
||||
* s "example"
|
||||
* s "example"
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -93,7 +94,8 @@ static int on_disconnect(sd_bus_message *message, void *userdata, sd_bus_error *
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Ensure the event loop exits with a clear error if acquiring the well-known service name fails */
|
||||
/* Ensure the event loop exits with a clear error if acquiring the well-known
|
||||
* service name fails */
|
||||
static int request_name_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
|
||||
if (!sd_bus_message_is_method_error(m, NULL))
|
||||
return 1;
|
||||
|
@ -111,8 +113,8 @@ static int request_name_callback(sd_bus_message *m, void *userdata, sd_bus_error
|
|||
}
|
||||
|
||||
static int setup(object *o) {
|
||||
/* If we are reconnecting, then the bus object needs to be closed, detached from
|
||||
* the event loop and recreated.
|
||||
/* If we are reconnecting, then the bus object needs to be closed, detached
|
||||
* from the event loop and recreated.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_detach_event.html
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_close_unref.html
|
||||
*/
|
||||
|
@ -121,9 +123,10 @@ static int setup(object *o) {
|
|||
*o->bus = sd_bus_close_unref(*o->bus);
|
||||
}
|
||||
|
||||
/* Set up a new bus object for the system bus, configure it to wait for D-Bus to be available
|
||||
* instead of failing if it is not, and start it. All the following operations are asynchronous
|
||||
* and will not block waiting for D-Bus to be available.
|
||||
/* Set up a new bus object for the system bus, configure it to wait for D-Bus
|
||||
* to be available instead of failing if it is not, and start it. All the
|
||||
* following operations are asynchronous and will not block waiting for D-Bus
|
||||
* to be available.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_new.html
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_address.html
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_bus_client.html
|
||||
|
@ -150,10 +153,10 @@ static int setup(object *o) {
|
|||
"org.freedesktop.ReconnectExample",
|
||||
vtable,
|
||||
o));
|
||||
/* By default the service is only assigned an ephemeral name. Also add a well-known
|
||||
* one, so that clients know whom to call. This needs to be asynchronous, as
|
||||
* D-Bus might not be yet available. The callback will check whether the error is
|
||||
* expected or not, in case it fails.
|
||||
/* By default the service is only assigned an ephemeral name. Also add a
|
||||
* well-known one, so that clients know whom to call. This needs to be
|
||||
* asynchronous, as D-Bus might not be yet available. The callback will check
|
||||
* whether the error is expected or not, in case it fails.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_request_name.html
|
||||
*/
|
||||
check(sd_bus_request_name_async(*o->bus,
|
||||
|
@ -162,9 +165,9 @@ static int setup(object *o) {
|
|||
0,
|
||||
request_name_callback,
|
||||
o));
|
||||
/* When D-Bus is disconnected this callback will be invoked, which will
|
||||
* set up the connection again. This needs to be asynchronous, as D-Bus might not
|
||||
* yet be available.
|
||||
/* When D-Bus is disconnected this callback will be invoked, which will set up
|
||||
* the connection again. This needs to be asynchronous, as D-Bus might not yet
|
||||
* be available.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_match_signal_async.html
|
||||
*/
|
||||
check(sd_bus_match_signal_async(*o->bus,
|
||||
|
@ -176,7 +179,8 @@ static int setup(object *o) {
|
|||
on_disconnect,
|
||||
NULL,
|
||||
o));
|
||||
/* Attach the bus object to the event loop so that calls and signals are processed.
|
||||
/* Attach the bus object to the event loop so that calls and signals are
|
||||
* processed.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_bus_attach_event.html
|
||||
*/
|
||||
check(sd_bus_attach_event(*o->bus, *o->event, 0));
|
||||
|
@ -186,8 +190,7 @@ static int setup(object *o) {
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
/* The bus should be relinquished before the program terminates. The cleanup
|
||||
* attribute allows us to do it nicely and cleanly whenever we exit the
|
||||
* block.
|
||||
* attribute allows us to do it nicely and cleanly whenever we exit the block.
|
||||
*/
|
||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
|
||||
|
@ -202,8 +205,8 @@ int main(int argc, char **argv) {
|
|||
*/
|
||||
check(sd_event_default(&event));
|
||||
|
||||
/* By default the event loop will terminate when all sources have disappeared, so
|
||||
* we have to keep it 'occupied'. Register signal handling to do so.
|
||||
/* By default the event loop will terminate when all sources have disappeared,
|
||||
* so we have to keep it 'occupied'. Register signal handling to do so.
|
||||
* https://www.freedesktop.org/software/systemd/man/sd_event_add_signal.html
|
||||
*/
|
||||
check(sd_event_add_signal(event, NULL, SIGINT|SD_EVENT_SIGNAL_PROCMASK, NULL, NULL));
|
||||
|
|
|
@ -455,12 +455,12 @@ Virtualization detect_vm(void) {
|
|||
|
||||
/* We have to use the correct order here:
|
||||
*
|
||||
* → First, try to detect Oracle Virtualbox, Amazon EC2 Nitro, Parallels, and Google Compute Engine, even if they use KVM,
|
||||
* as well as Xen even if it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also
|
||||
* since it runs as a user-process nested inside other VMs. Also check for Xen now, because Xen PV
|
||||
* mode does not override CPUID when nested inside another hypervisor.
|
||||
* → First, try to detect Oracle Virtualbox, Amazon EC2 Nitro, Parallels, and Google Compute Engine,
|
||||
* even if they use KVM, as well as Xen, even if it cloaks as Microsoft Hyper-V. Attempt to detect
|
||||
* UML at this stage too, since it runs as a user-process nested inside other VMs. Also check for
|
||||
* Xen now, because Xen PV mode does not override CPUID when nested inside another hypervisor.
|
||||
*
|
||||
* → Second, try to detect from CPUID, this will report KVM for whatever software is used even if
|
||||
* → Second, try to detect from CPUID. This will report KVM for whatever software is used even if
|
||||
* info in DMI is overwritten.
|
||||
*
|
||||
* → Third, try to detect from DMI. */
|
||||
|
|
|
@ -97,7 +97,7 @@ static void pam_bus_data_destroy(pam_handle_t *handle, void *data, int error_sta
|
|||
d->bus && bus_origin_changed(d->bus))
|
||||
/* Please adjust test/units/end.sh when updating the log message. */
|
||||
pam_syslog(handle, LOG_DEBUG,
|
||||
"Attempted to close sd-bus (%s) after fork whose connection is opened before the fork, this should not happen.",
|
||||
"Warning: cannot close sd-bus connection (%s) after fork when it was opened before the fork.",
|
||||
strna(d->cache_id));
|
||||
|
||||
pam_bus_data_free(data);
|
||||
|
|
|
@ -6,8 +6,8 @@ set -o pipefail
|
|||
|
||||
(! journalctl -q -o short-monotonic --grep "didn't pass validation" >>/failed)
|
||||
|
||||
# Here, the redundant '[.]' at the end is for making not the logged self command hit the grep.
|
||||
(! journalctl -q -o short-monotonic --grep 'Attempted to close sd-bus (.*) after fork whose connection is opened before the fork, this should not happen[.]' >>/failed)
|
||||
# Here, the redundant '[ ]' in the pattern is required in order not to match the logged command itself.
|
||||
(! journalctl -q -o short-monotonic --grep 'Warning: cannot close sd-bus connection[ ].*after fork' >>/failed)
|
||||
|
||||
systemctl poweroff --no-block
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue