diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-07-08 17:51:55 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-07-14 14:57:19 +0200 |
commit | 77ee1783ebc8385013e95161427e1f945691ced0 (patch) | |
tree | e7c3548e7ec3a7ed0988642b33be0d3cab594b03 /src/udev/udevadm-settle.c | |
parent | a18c7865bea4588932ff72de5630e40e1c1389b3 (diff) | |
download | systemd-77ee1783ebc8385013e95161427e1f945691ced0.tar.gz |
udevadm: beef up deprecation log warning
Let's add a catalog entry explaining further details.
Most importantly though: talk to PID 1 directly, via the private D-Bus
socket, so that this actually works correctly during early boot, where
D-Bus is not around.
Diffstat (limited to 'src/udev/udevadm-settle.c')
-rw-r--r-- | src/udev/udevadm-settle.c | 85 |
1 files changed, 51 insertions, 34 deletions
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 5730349ba5..66c7103d78 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -14,7 +14,9 @@ #include "sd-bus.h" #include "sd-login.h" +#include "sd-messages.h" +#include "bus-util.h" #include "io-util.h" #include "libudev-util.h" #include "string-util.h" @@ -87,54 +89,69 @@ static int parse_argv(int argc, char *argv[]) { static int emit_deprecation_warning(void) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - _cleanup_free_ char *unit = NULL, *unit_path = NULL; - _cleanup_strv_free_ char **a = NULL, **b = NULL; + _cleanup_strv_free_ char **a = NULL; + _cleanup_free_ char *unit = NULL; int r; r = sd_pid_get_unit(0, &unit); - if (r < 0 || !streq(unit, "systemd-udev-settle.service")) + if (r < 0) { + log_debug_errno(r, "Failed to determine unit we run in, ignoring: %m"); return 0; + } - log_notice("systemd-udev-settle.service is deprecated."); + if (!streq(unit, "systemd-udev-settle.service")) + return 0; - r = sd_bus_open_system(&bus); - if (r < 0) - return log_debug_errno(r, "Failed to open system bus, skipping dependency queries: %m"); - - unit_path = unit_dbus_path_from_name("systemd-udev-settle.service"); - if (!unit_path) - return -ENOMEM; - - (void) sd_bus_get_property_strv( - bus, - "org.freedesktop.systemd1", - unit_path, - "org.freedesktop.systemd1.Unit", - "WantedBy", - NULL, - &a); - - (void) sd_bus_get_property_strv( - bus, - "org.freedesktop.systemd1", - unit_path, - "org.freedesktop.systemd1.Unit", - "RequiredBy", - NULL, - &b); - - r = strv_extend_strv(&a, b, true); + r = bus_connect_system_systemd(&bus); if (r < 0) - return r; + log_debug_errno(r, "Failed to open connection to systemd, skipping dependency queries: %m"); + else { + _cleanup_strv_free_ char **b = NULL; + _cleanup_free_ char *unit_path = NULL; + + unit_path = unit_dbus_path_from_name("systemd-udev-settle.service"); + if (!unit_path) + return -ENOMEM; + + (void) sd_bus_get_property_strv( + bus, + "org.freedesktop.systemd1", + unit_path, + "org.freedesktop.systemd1.Unit", + "WantedBy", + NULL, + &a); + + (void) sd_bus_get_property_strv( + bus, + "org.freedesktop.systemd1", + unit_path, + "org.freedesktop.systemd1.Unit", + "RequiredBy", + NULL, + &b); + + r = strv_extend_strv(&a, b, true); + if (r < 0) + return r; + } - if (!strv_isempty(a)) { + if (strv_isempty(a)) + /* Print a simple message if we cannot determine the dependencies */ + log_notice("systemd-udev-settle.service is deprecated."); + else { + /* Print a longer, structured message if we can acquire the dependencies (this should be the + * common case). This is hooked up with a catalog entry and everything. */ _cleanup_free_ char *t = NULL; t = strv_join(a, ", "); if (!t) return -ENOMEM; - log_notice("Hint: please fix %s not to pull it in.", t); + log_struct(LOG_NOTICE, + "MESSAGE=systemd-udev-settle.service is deprecated. Please fix %s not to pull it in.", t, + "OFFENDING_UNITS=%s", t, + "MESSAGE_ID=" SD_MESSAGE_SYSTEMD_UDEV_SETTLE_DEPRECATED_STR); } return 0; |