]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #26959 from poettering/creds-mount-dep-fix
authorLennart Poettering <lennart@poettering.net>
Thu, 25 May 2023 09:06:47 +0000 (02:06 -0700)
committerGitHub <noreply@github.com>
Thu, 25 May 2023 09:06:47 +0000 (02:06 -0700)
credential ramfs mount order fixes

85 files changed:
rules.d/60-drm.rules
rules.d/60-persistent-alsa.rules
rules.d/60-persistent-input.rules
rules.d/60-persistent-storage-tape.rules
rules.d/60-persistent-storage.rules.in
rules.d/60-persistent-v4l.rules
rules.d/60-serial.rules
src/analyze/analyze-critical-chain.c
src/analyze/analyze-plot.c
src/analyze/analyze-time-data.c
src/basic/env-file.c
src/basic/string-util.c
src/basic/strv.c
src/busctl/busctl.c
src/core/automount.c
src/core/device.c
src/core/manager-dump.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/service.c
src/core/service.h
src/core/slice.c
src/core/socket.c
src/core/swap.c
src/core/target.c
src/core/timer.c
src/core/unit.c
src/core/unit.h
src/coredump/coredump-vacuum.c
src/coredump/coredump.c
src/home/homed-home.c
src/hostname/hostnamectl.c
src/journal-remote/journal-gatewayd.c
src/journal-remote/journal-upload.c
src/journal/journalctl.c
src/journal/journald-native.c
src/libsystemd-network/lldp-neighbor.c
src/libsystemd-network/sd-dhcp-lease.c
src/libsystemd/sd-bus/bus-control.c
src/libsystemd/sd-bus/bus-introspect.c
src/libsystemd/sd-bus/bus-match.c
src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-journal/catalog.c
src/libsystemd/sd-login/sd-login.c
src/libsystemd/sd-resolve/sd-resolve.c
src/login/inhibit.c
src/login/loginctl.c
src/login/logind-user.c
src/login/test-inhibit.c
src/login/test-session-properties.c
src/login/user-runtime-dir.c
src/network/generator/network-generator.c
src/network/netdev/vlan.c
src/network/networkd-manager.c
src/nspawn/nspawn-network.c
src/nspawn/nspawn.c
src/oom/oomctl.c
src/oom/oomd-manager.c
src/oom/oomd-util.c
src/portable/portable.c
src/portable/portablectl.c
src/resolve/resolved-bus.c
src/resolve/resolved-dns-dnssec.c
src/resolve/resolved-dns-rr.c
src/resolve/resolved-manager.c
src/resolve/test-dnssec-complex.c
src/shared/bus-locator.c
src/shared/bus-locator.h
src/shared/bus-util.c
src/shared/calendarspec.c
src/shared/elf-util.c
src/shared/format-table.c
src/shared/json.c
src/shared/specifier.c
src/sleep/sleep.c
src/system-update-generator/system-update-generator.c
src/udev/udev-builtin-path_id.c
src/ukify/ukify.py
src/update-utmp/update-utmp.c
test/test-network/conf/21-vlan.netdev.d/override.conf
test/test-network/systemd-networkd-tests.py
test/units/testsuite-01.service
test/units/testsuite-01.sh
test/units/testsuite-35.sh

index f7f3435d508afa5477d946217576c96a60a54920..061b2a2a74fda24b612a84770a18a0f63b26f6dc 100644 (file)
@@ -3,6 +3,9 @@
 ACTION!="remove", SUBSYSTEM=="drm", SUBSYSTEMS=="pci|usb|platform", IMPORT{builtin}="path_id"
 
 # by-path
-ENV{ID_PATH}=="?*", KERNEL=="card*", SYMLINK+="dri/by-path/$env{ID_PATH}-card"
-ENV{ID_PATH}=="?*", KERNEL=="controlD*", SYMLINK+="dri/by-path/$env{ID_PATH}-control"
-ENV{ID_PATH}=="?*", KERNEL=="renderD*", SYMLINK+="dri/by-path/$env{ID_PATH}-render"
+KERNEL=="card*",     ENV{ID_PATH}=="?*",                   SYMLINK+="dri/by-path/$env{ID_PATH}-card"
+KERNEL=="card*",     ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="dri/by-path/$env{ID_PATH_WITH_USB_REVISION}-card"
+KERNEL=="controlD*", ENV{ID_PATH}=="?*",                   SYMLINK+="dri/by-path/$env{ID_PATH}-control"
+KERNEL=="controlD*", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="dri/by-path/$env{ID_PATH_WITH_USB_REVISION}-control"
+KERNEL=="renderD*",  ENV{ID_PATH}=="?*",                   SYMLINK+="dri/by-path/$env{ID_PATH}-render"
+KERNEL=="renderD*",  ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="dri/by-path/$env{ID_PATH_WITH_USB_REVISION}-render"
index 8154e2dbb5ea3e498b93a74b6fac3bf0d7169203..466ab1c15123249c4a4e13bac46e11b5858915e7 100644 (file)
@@ -9,6 +9,7 @@ ENV{ID_SERIAL}=="?*", ENV{ID_USB_INTERFACE_NUM}=="?*", SYMLINK+="snd/by-id/$env{
 ENV{ID_SERIAL}=="?*", ENV{ID_USB_INTERFACE_NUM}=="", SYMLINK+="snd/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
 
 IMPORT{builtin}="path_id"
-ENV{ID_PATH}=="?*", SYMLINK+="snd/by-path/$env{ID_PATH}"
+ENV{ID_PATH}=="?*",                   SYMLINK+="snd/by-path/$env{ID_PATH}"
+ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="snd/by-path/$env{ID_PATH_WITH_USB_REVISION}"
 
 LABEL="persistent_alsa_end"
index 52f4ddb7e637c5e6e615f24224b37d4636e0d9bd..d02b46caf07d182ab4db7d7651fcf9c8078764a5 100644 (file)
@@ -33,10 +33,14 @@ SUBSYSTEMS=="usb", ENV{ID_BUS}=="?*", KERNEL=="event*", ENV{.INPUT_CLASS}=="", A
 
 # by-path
 SUBSYSTEMS=="pci|usb|platform|acpi", IMPORT{builtin}="path_id"
-ENV{ID_PATH}=="?*", KERNEL=="mouse*|js*", ENV{.INPUT_CLASS}=="?*", SYMLINK+="input/by-path/$env{ID_PATH}-$env{.INPUT_CLASS}"
-ENV{ID_PATH}=="?*", KERNEL=="event*", ENV{.INPUT_CLASS}=="?*", SYMLINK+="input/by-path/$env{ID_PATH}-event-$env{.INPUT_CLASS}"
+ENV{.INPUT_CLASS}=="?*", KERNEL=="mouse*|js*", ENV{ID_PATH}=="?*",                   SYMLINK+="input/by-path/$env{ID_PATH}-$env{.INPUT_CLASS}"
+ENV{.INPUT_CLASS}=="?*", KERNEL=="mouse*|js*", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="input/by-path/$env{ID_PATH_WITH_USB_REVISION}-$env{.INPUT_CLASS}"
+ENV{.INPUT_CLASS}=="?*", KERNEL=="event*",     ENV{ID_PATH}=="?*",                   SYMLINK+="input/by-path/$env{ID_PATH}-event-$env{.INPUT_CLASS}"
+ENV{.INPUT_CLASS}=="?*", KERNEL=="event*",     ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="input/by-path/$env{ID_PATH_WITH_USB_REVISION}-event-$env{.INPUT_CLASS}"
 # allow empty class for platform, usb and i2c devices; platform supports only a single interface that way
-SUBSYSTEMS=="usb|platform|i2c", ENV{ID_PATH}=="?*", KERNEL=="event*", ENV{.INPUT_CLASS}=="", \
+SUBSYSTEMS=="usb|platform|i2c", KERNEL=="event*", ENV{.INPUT_CLASS}=="", ENV{ID_PATH}=="?*", \
   SYMLINK+="input/by-path/$env{ID_PATH}-event"
+SUBSYSTEMS=="usb|platform|i2c", KERNEL=="event*", ENV{.INPUT_CLASS}=="", ENV{ID_PATH_WITH_USB_REVISION}=="?*", \
+  SYMLINK+="input/by-path/$env{ID_PATH_WITH_USB_REVISION}-event"
 
 LABEL="persistent_input_end"
index 8c00cc76d92005854dacd149c720a713bed45afa..0678d71e6d59508c479778bc727ddede610a304b 100644 (file)
@@ -6,16 +6,23 @@ ACTION=="remove", GOTO="persistent_storage_tape_end"
 ENV{UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG}=="1", GOTO="persistent_storage_tape_end"
 
 # type 8 devices are "Medium Changers"
-SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --sg-version=3 --export --allowlisted -d $devnode", \
-  SYMLINK+="tape/by-id/scsi-$env{ID_SERIAL} tape/by-id/scsi-$env{ID_SERIAL}-changer"
+SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", GOTO="medium_changer_begin"
+GOTO="medium_changer_end"
+
+LABEL="medium_changer_begin"
+
+IMPORT{program}="scsi_id --sg-version=3 --export --allowlisted -d $devnode"
+ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/scsi-$env{ID_SERIAL} tape/by-id/scsi-$env{ID_SERIAL}-changer"
 
 # iSCSI devices from the same host have all the same ID_SERIAL,
 # but additionally a property named ID_SCSI_SERIAL.
-SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", ENV{ID_SCSI_SERIAL}=="?*", \
-  SYMLINK+="tape/by-id/scsi-$env{ID_SCSI_SERIAL}"
+ENV{ID_SCSI_SERIAL}=="?*", SYMLINK+="tape/by-id/scsi-$env{ID_SCSI_SERIAL}"
+
+IMPORT{builtin}="path_id"
+ENV{ID_PATH}=="?*",                   SYMLINK+="tape/by-path/$env{ID_PATH}-changer"
+ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH_WITH_USB_REVISION}-changer"
 
-SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{builtin}="path_id", \
-  SYMLINK+="tape/by-path/$env{ID_PATH}-changer"
+LABEL="medium_changer_end"
 
 SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"
 
@@ -30,7 +37,9 @@ KERNEL=="nst*[0-9]", ENV{ID_SCSI_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS
 
 # by-path (parent device path)
 KERNEL=="st*[0-9]|nst*[0-9]", IMPORT{builtin}="path_id"
-KERNEL=="st*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH}"
-KERNEL=="nst*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH}-nst"
+KERNEL=="st*[0-9]",  ENV{ID_PATH}=="?*",                   SYMLINK+="tape/by-path/$env{ID_PATH}"
+KERNEL=="st*[0-9]",  ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH_WITH_USB_REVISION}"
+KERNEL=="nst*[0-9]", ENV{ID_PATH}=="?*",                   SYMLINK+="tape/by-path/$env{ID_PATH}-nst"
+KERNEL=="nst*[0-9]", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH_WITH_USB_REVISION}-nst"
 
 LABEL="persistent_storage_tape_end"
index 88f88a83edb81a0cdb9eb98130bf6fa0d345a50e..4b921bfe85cb2094c3e430a55da469782ed52ad3 100644 (file)
@@ -111,16 +111,20 @@ KERNEL=="msblk[0-9]p[0-9]|mspblk[0-9]p[0-9]", ENV{ID_NAME}=="?*", ENV{ID_SERIAL}
 # by-path
 ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id"
 ENV{DEVTYPE}=="disk", SUBSYSTEMS=="nvme-subsystem", IMPORT{builtin}="path_id"
-KERNEL=="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-boot%n"
-KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
-ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"
-# compatible links for ATA devices
-KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}"
-ENV{DEVTYPE}=="partition", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}-part%n"
+KERNEL=="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*",                   SYMLINK+="disk/by-path/$env{ID_PATH}-boot%n"
+KERNEL=="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_WITH_USB_REVISION}-boot%n"
+KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*",                   SYMLINK+="disk/by-path/$env{ID_PATH}"
+KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_ATA_COMPAT}=="?*",        SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}"
+KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_WITH_USB_REVISION}"
+ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*",                   SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"
+ENV{DEVTYPE}=="partition", ENV{ID_PATH_ATA_COMPAT}=="?*",        SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}-part%n"
+ENV{DEVTYPE}=="partition", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_WITH_USB_REVISION}-part%n"
 
 # legacy virtio-pci by-path links (deprecated)
-KERNEL=="vd*[!0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}"
-KERNEL=="vd*[0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}-part%n"
+KERNEL=="vd*[!0-9]", ENV{ID_PATH}=="pci-*",                   SYMLINK+="disk/by-path/virtio-$env{ID_PATH}"
+KERNEL=="vd*[!0-9]", ENV{ID_PATH_WITH_USB_REVISION}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH_WITH_USB_REVISION}"
+KERNEL=="vd*[0-9]",  ENV{ID_PATH}=="pci-*",                   SYMLINK+="disk/by-path/virtio-$env{ID_PATH}-part%n"
+KERNEL=="vd*[0-9]",  ENV{ID_PATH_WITH_USB_REVISION}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH_WITH_USB_REVISION}-part%n"
 
 {% if HAVE_BLKID %}
 # allow admin to disable probing the filesystem for slow devices like floppy disk drives
index 93c5ee8c276abf363be6e4b6c8fb1789d7ac1d52..071650a45b098ad44e22e9facf7226da38739daa 100644 (file)
@@ -14,7 +14,9 @@ TEST!="index", GOTO="persistent_v4l_end"
 ATTR{index}!="?*", GOTO="persistent_v4l_end"
 
 IMPORT{builtin}="path_id"
-ENV{ID_PATH}=="?*", KERNEL=="video*|vbi*", SYMLINK+="v4l/by-path/$env{ID_PATH}-video-index$attr{index}"
-ENV{ID_PATH}=="?*", KERNEL=="audio*", SYMLINK+="v4l/by-path/$env{ID_PATH}-audio-index$attr{index}"
+KERNEL=="video*|vbi*", ENV{ID_PATH}=="?*",                   SYMLINK+="v4l/by-path/$env{ID_PATH}-video-index$attr{index}"
+KERNEL=="video*|vbi*", ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="v4l/by-path/$env{ID_PATH_WITH_USB_REVISION}-video-index$attr{index}"
+KERNEL=="audio*",      ENV{ID_PATH}=="?*",                   SYMLINK+="v4l/by-path/$env{ID_PATH}-audio-index$attr{index}"
+KERNEL=="audio*",      ENV{ID_PATH_WITH_USB_REVISION}=="?*", SYMLINK+="v4l/by-path/$env{ID_PATH_WITH_USB_REVISION}-audio-index$attr{index}"
 
 LABEL="persistent_v4l_end"
index a0e66323a9bbb304e0df8e6f1989a594a74a133d..043212273424858876a86ba739678f7dff1e5cec 100644 (file)
@@ -14,8 +14,10 @@ KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="serial_end"
 SUBSYSTEMS=="usb-serial", ENV{.ID_PORT}="$attr{port_number}"
 
 IMPORT{builtin}="path_id"
-ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", SYMLINK+="serial/by-path/$env{ID_PATH}"
-ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", SYMLINK+="serial/by-path/$env{ID_PATH}-port$env{.ID_PORT}"
+ENV{ID_PATH}=="?*",                   ENV{.ID_PORT}=="",   SYMLINK+="serial/by-path/$env{ID_PATH}"
+ENV{ID_PATH_WITH_USB_REVISION}=="?*", ENV{.ID_PORT}=="",   SYMLINK+="serial/by-path/$env{ID_PATH_WITH_USB_REVISION}"
+ENV{ID_PATH}=="?*",                   ENV{.ID_PORT}=="?*", SYMLINK+="serial/by-path/$env{ID_PATH}-port$env{.ID_PORT}"
+ENV{ID_PATH_WITH_USB_REVISION}=="?*", ENV{.ID_PORT}=="?*", SYMLINK+="serial/by-path/$env{ID_PATH_WITH_USB_REVISION}-port$env{.ID_PORT}"
 
 ENV{ID_BUS}=="", GOTO="serial_end"
 ENV{ID_SERIAL}=="", GOTO="serial_end"
index f80f3ddb63c2e2ae7d05f5ebf6c76ab2c8f88687..4a7f452eaf5f375da440b06e8a5baf539610b142 100644 (file)
@@ -29,7 +29,7 @@ static int list_dependencies_print(
         printf("%s", special_glyph(last ? SPECIAL_GLYPH_TREE_RIGHT : SPECIAL_GLYPH_TREE_BRANCH));
 
         if (times) {
-                if (times->time > 0)
+                if (timestamp_is_set(times->time))
                         printf("%s%s @%s +%s%s", ansi_highlight_red(), name,
                                FORMAT_TIMESPAN(times->activating - boot->userspace_time, USEC_PER_MSEC),
                                FORMAT_TIMESPAN(times->time, USEC_PER_MSEC), ansi_normal());
index ef40e64631d5d268aec0d7ac3b831d0dc8498359..0fbe17465e06a34cf57c5f6c0802619f86a8c217 100644 (file)
@@ -206,14 +206,14 @@ static int produce_plot_as_svg(
 
         if (boot->firmware_time > boot->loader_time)
                 m++;
-        if (boot->loader_time > 0) {
+        if (timestamp_is_set(boot->loader_time)) {
                 m++;
                 if (width < 1000.0)
                         width = 1000.0;
         }
-        if (boot->initrd_time > 0)
+        if (timestamp_is_set(boot->initrd_time))
                 m++;
-        if (boot->kernel_done_time > 0)
+        if (timestamp_is_set(boot->kernel_done_time))
                 m++;
 
         for (u = times; u->has_data; u++) {
@@ -295,22 +295,22 @@ static int produce_plot_as_svg(
         svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (SCALE_X * boot->firmware_time));
         svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time);
 
-        if (boot->firmware_time > 0) {
+        if (timestamp_is_set(boot->firmware_time)) {
                 svg_bar("firmware", -(double) boot->firmware_time, -(double) boot->loader_time, y);
                 svg_text(true, -(double) boot->firmware_time, y, "firmware");
                 y++;
         }
-        if (boot->loader_time > 0) {
+        if (timestamp_is_set(boot->loader_time)) {
                 svg_bar("loader", -(double) boot->loader_time, 0, y);
                 svg_text(true, -(double) boot->loader_time, y, "loader");
                 y++;
         }
-        if (boot->kernel_done_time > 0) {
+        if (timestamp_is_set(boot->kernel_done_time)) {
                 svg_bar("kernel", 0, boot->kernel_done_time, y);
                 svg_text(true, 0, y, "kernel");
                 y++;
         }
-        if (boot->initrd_time > 0) {
+        if (timestamp_is_set(boot->initrd_time)) {
                 svg_bar("initrd", boot->initrd_time, boot->userspace_time, y);
                 if (boot->initrd_security_start_time < boot->initrd_security_finish_time)
                         svg_bar("security", boot->initrd_security_start_time, boot->initrd_security_finish_time, y);
@@ -330,7 +330,7 @@ static int produce_plot_as_svg(
         }
 
         svg_bar("active", boot->userspace_time, boot->finish_time, y);
-        if (boot->security_start_time > 0)
+        if (timestamp_is_set(boot->security_start_time))
                 svg_bar("security", boot->security_start_time, boot->security_finish_time, y);
         svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y);
         svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y);
@@ -354,7 +354,7 @@ static int produce_plot_as_svg(
         svg_bar("deactivating", 0, 300000, y);
         svg_text(true, 400000, y, "Deactivating");
         y++;
-        if (boot->security_start_time > 0) {
+        if (timestamp_is_set(boot->security_start_time)) {
                 svg_bar("security", 0, 300000, y);
                 svg_text(true, 400000, y, "Setting up security module");
                 y++;
index baee3cedbb531985f5ee9f9fa31374efccbebb34..70717fc4b27d99f5f6e4c41ec7dc9329259de449 100644 (file)
@@ -173,24 +173,24 @@ int pretty_boot_time(sd_bus *bus, char **ret) {
         if (!text)
                 return log_oom();
 
-        if (t->firmware_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->firmware_time - t->loader_time, USEC_PER_MSEC), " (firmware) + "))
+        if (timestamp_is_set(t->firmware_time) && !strextend(&text, FORMAT_TIMESPAN(t->firmware_time - t->loader_time, USEC_PER_MSEC), " (firmware) + "))
                 return log_oom();
-        if (t->loader_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->loader_time, USEC_PER_MSEC), " (loader) + "))
+        if (timestamp_is_set(t->loader_time) && !strextend(&text, FORMAT_TIMESPAN(t->loader_time, USEC_PER_MSEC), " (loader) + "))
                 return log_oom();
-        if (t->kernel_done_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->kernel_done_time, USEC_PER_MSEC), " (kernel) + "))
+        if (timestamp_is_set(t->kernel_done_time) && !strextend(&text, FORMAT_TIMESPAN(t->kernel_done_time, USEC_PER_MSEC), " (kernel) + "))
                 return log_oom();
-        if (t->initrd_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->userspace_time - t->initrd_time, USEC_PER_MSEC), " (initrd) + "))
+        if (timestamp_is_set(t->initrd_time) && !strextend(&text, FORMAT_TIMESPAN(t->userspace_time - t->initrd_time, USEC_PER_MSEC), " (initrd) + "))
                 return log_oom();
 
         if (!strextend(&text, FORMAT_TIMESPAN(t->finish_time - t->userspace_time, USEC_PER_MSEC), " (userspace) "))
                 return log_oom();
 
-        if (t->kernel_done_time > 0)
+        if (timestamp_is_set(t->kernel_done_time))
                 if (!strextend(&text, "= ", FORMAT_TIMESPAN(t->firmware_time + t->finish_time, USEC_PER_MSEC),  " "))
                         return log_oom();
 
         if (unit_id && timestamp_is_set(activated_time)) {
-                usec_t base = t->userspace_time > 0 ? t->userspace_time : t->reverse_offset;
+                usec_t base = timestamp_is_set(t->userspace_time) ? t->userspace_time : t->reverse_offset;
 
                 if (!strextend(&text, "\n", unit_id, " reached after ", FORMAT_TIMESPAN(activated_time - base, USEC_PER_MSEC), " in userspace."))
                         return log_oom();
index 7b3e209ddcac6aa34dcf2a24ba6ed84287789f98..58d7b3ec359d5a949be7652807980e248d1c3641 100644 (file)
@@ -330,8 +330,7 @@ static int parse_env_file_push(
 
                 if (streq(key, k)) {
                         va_end(aq);
-                        free(*v);
-                        *v = value;
+                        free_and_replace(*v, value);
 
                         return 1;
                 }
index c74ee67dfec24c7d08eb11051d2b4887d98a493d..61737ffb41b367221bef78ae804cba16abd0e728 100644 (file)
@@ -9,6 +9,7 @@
 #include "alloc-util.h"
 #include "escape.h"
 #include "extract-word.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "gunicode.h"
 #include "locale-util.h"
@@ -603,9 +604,9 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
                 STATE_CSI,
                 STATE_CSO,
         } state = STATE_OTHER;
-        char *obuf = NULL;
+        _cleanup_free_ char *obuf = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t osz = 0, isz, shift[2] = {}, n_carriage_returns = 0;
-        FILE *f;
 
         assert(ibuf);
         assert(*ibuf);
@@ -713,11 +714,13 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
                 }
         }
 
-        if (fflush_and_check(f) < 0) {
-                fclose(f);
-                return mfree(obuf);
-        }
-        fclose(f);
+        if (fflush_and_check(f) < 0)
+                return NULL;
+
+        f = safe_fclose(f);
+
+        if (!obuf)
+                return NULL;
 
         free_and_replace(*ibuf, obuf);
 
@@ -955,8 +958,7 @@ int free_and_strdup(char **p, const char *s) {
         } else
                 t = NULL;
 
-        free(*p);
-        *p = t;
+        free_and_replace(*p, t);
 
         return 1;
 }
index 822dadeeb4a1bcdedbbfa9fc8b94344553c713d5..deadb9909e99b7643a0934043200b7c48cbe596e 100644 (file)
@@ -723,8 +723,7 @@ char** strv_shell_escape(char **l, const char *bad) {
                 if (!v)
                         return NULL;
 
-                free(*s);
-                *s = v;
+                free_and_replace(*s, v);
         }
 
         return l;
index 965ded9675ecb57767fb081fb70179507b739cf8..4d69aee5eb727421de3f92c1a7a10e9d4efe50bd 100644 (file)
@@ -1072,6 +1072,9 @@ static int introspect(int argc, char **argv, void *userdata) {
 
                         mf = safe_fclose(mf);
 
+                        if (!buf)
+                                return bus_log_parse_error(ENOMEM);
+
                         z = set_get(members, &((Member) {
                                                 .type = "property",
                                                 .interface = m->interface,
index 89755e3a9b354320679aa3c550317993d3e626b4..5df697bf22080e506aa24614e6484a684f636290 100644 (file)
@@ -283,7 +283,7 @@ static void automount_set_state(Automount *a, AutomountState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(a), "Changed %s -> %s", automount_state_to_string(old_state), automount_state_to_string(state));
 
-        unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static int automount_coldplug(Unit *u) {
index 79082d1688b662dfe86af31aace2f57d80f0199e..60ab59c53b62178418de1df6f1bad52d85d9cb93 100644 (file)
@@ -182,7 +182,7 @@ static void device_set_state(Device *d, DeviceState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(d), "Changed %s -> %s", device_state_to_string(old_state), device_state_to_string(state));
 
-        unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static void device_found_changed(Device *d, DeviceFound previous, DeviceFound now) {
index 5a92356d487e7124b9026f617350e2b4471d365c..35143ebddf479a2e6b35c570ccd7ccc760002f3e 100644 (file)
@@ -95,6 +95,9 @@ int manager_get_dump_string(Manager *m, char **patterns, char **ret) {
 
         f = safe_fclose(f);
 
+        if (!dump)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(dump);
 
         return 0;
index 295e4c66c790b02c1a0e48c2283a9a60166368f1..36ea9bbefb0cc3356f54290cba76ffa6033a4596 100644 (file)
@@ -794,8 +794,7 @@ static void mount_set_state(Mount *m, MountState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(m), "Changed %s -> %s", mount_state_to_string(old_state), mount_state_to_string(state));
 
-        unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state],
-                    m->reload_result == MOUNT_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE);
+        unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state], m->reload_result == MOUNT_SUCCESS);
 }
 
 static int mount_coldplug(Unit *u) {
index c95663c3aaed76d20c27c7e9da56a83685922570..5fb14d9a10b4521ec796cfe965e238f69fce0e77 100644 (file)
@@ -477,7 +477,7 @@ static void path_set_state(Path *p, PathState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(p), "Changed %s -> %s", path_state_to_string(old_state), path_state_to_string(state));
 
-        unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static void path_enter_waiting(Path *p, bool initial, bool from_trigger_notify);
index 5f3b62e02194f62da80f4d8986bc60bf4de26407..761eb5ea56e696eb730debd4dd395fad95037f3e 100644 (file)
@@ -127,7 +127,7 @@ static void scope_set_state(Scope *s, ScopeState state) {
         if (state != old_state)
                 log_debug("%s changed %s -> %s", UNIT(s)->id, scope_state_to_string(old_state), scope_state_to_string(state));
 
-        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static int scope_add_default_dependencies(Scope *s) {
index 41e61987712f2c06ee0dbd390890de686870eb6e..533d7d3771a252b34bbebcef2f09c70442f9c5a8 100644 (file)
@@ -1277,9 +1277,7 @@ static void service_set_state(Service *s, ServiceState state) {
         if (old_state != state)
                 log_unit_debug(UNIT(s), "Changed %s -> %s", service_state_to_string(old_state), service_state_to_string(state));
 
-        unit_notify(UNIT(s), table[old_state], table[state],
-                    (s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
-                    (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
+        unit_notify(UNIT(s), table[old_state], table[state], s->reload_result == SERVICE_SUCCESS);
 }
 
 static usec_t service_coldplug_timeout(Service *s) {
@@ -1946,8 +1944,6 @@ static bool service_will_restart(Unit *u) {
 
         assert(s);
 
-        if (s->will_auto_restart)
-                return true;
         if (IN_SET(s->state, SERVICE_DEAD_BEFORE_AUTO_RESTART, SERVICE_FAILED_BEFORE_AUTO_RESTART, SERVICE_AUTO_RESTART))
                 return true;
 
@@ -1993,19 +1989,14 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
                 log_unit_debug(UNIT(s), "Service restart not allowed.");
         else {
                 const char *reason;
-                bool shall_restart;
 
-                shall_restart = service_shall_restart(s, &reason);
+                allow_restart = service_shall_restart(s, &reason);
                 log_unit_debug(UNIT(s), "Service will %srestart (%s)",
-                                        shall_restart ? "" : "not ",
+                                        allow_restart ? "" : "not ",
                                         reason);
-                if (shall_restart)
-                        s->will_auto_restart = true;
         }
 
-        if (s->will_auto_restart) {
-                s->will_auto_restart = false;
-
+        if (allow_restart) {
                 /* We make two state changes here: one that maps to the high-level UNIT_INACTIVE/UNIT_FAILED
                  * state (i.e. a state indicating deactivation), and then one that that maps to the
                  * high-level UNIT_STARTING state (i.e. a state indicating activation). We do this so that
index 55c4127deed84b7dcc76b9d8e91065cabdc709fd..0e578c9280b841a9effdd971fe53cd1e467cda21 100644 (file)
@@ -181,8 +181,6 @@ struct Service {
         bool main_pid_alien:1;
         bool bus_name_good:1;
         bool forbid_restart:1;
-        /* Keep restart intention between UNIT_FAILED and UNIT_ACTIVATING */
-        bool will_auto_restart:1;
         bool start_timeout_defined:1;
         bool exec_fd_hot:1;
 
index c87b790a974c0dece1c761fa31a1e6a1b32959fb..490aabfd35ebe4ad3ede038030d1aafe53424256 100644 (file)
@@ -43,7 +43,7 @@ static void slice_set_state(Slice *t, SliceState state) {
                           slice_state_to_string(old_state),
                           slice_state_to_string(state));
 
-        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static int slice_add_parent_slice(Slice *s) {
index 0bd1b126526c8a2d90ac3db92fa77bf72b95ffad..a6477de5a027d9a10d01e45de1e3056ba7ad6a27 100644 (file)
@@ -716,7 +716,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                         prefix, strna(s->user),
                         prefix, strna(s->group));
 
-        if (s->keep_alive_time > 0)
+        if (timestamp_is_set(s->keep_alive_time))
                 fprintf(f,
                         "%sKeepAliveTimeSec: %s\n",
                         prefix, FORMAT_TIMESPAN(s->keep_alive_time, USEC_PER_SEC));
@@ -973,7 +973,7 @@ static void socket_apply_socket_options(Socket *s, SocketPort *p, int fd) {
                         log_unit_warning_errno(UNIT(s), r, "SO_KEEPALIVE failed: %m");
         }
 
-        if (s->keep_alive_time > 0) {
+        if (timestamp_is_set(s->keep_alive_time)) {
                 r = setsockopt_int(fd, SOL_TCP, TCP_KEEPIDLE, s->keep_alive_time / USEC_PER_SEC);
                 if (r < 0)
                         log_unit_warning_errno(UNIT(s), r, "TCP_KEEPIDLE failed: %m");
@@ -1844,7 +1844,7 @@ static void socket_set_state(Socket *s, SocketState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(s), "Changed %s -> %s", socket_state_to_string(old_state), socket_state_to_string(state));
 
-        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static int socket_coldplug(Unit *u) {
index 26a950b058d6fc56357b459bf4fbbbd90a67da8a..a57176b1a39f6d8ecc88c3a89bf0575ddd182f4b 100644 (file)
@@ -554,7 +554,7 @@ static void swap_set_state(Swap *s, SwapState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(s), "Changed %s -> %s", swap_state_to_string(old_state), swap_state_to_string(state));
 
-        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 
         /* If there other units for the same device node have a job
            queued it might be worth checking again if it is runnable
index 6225df5b0d4d8d3a5e3df748a0d992d556787b31..3519b4b653a05b1a4b6ca63bc42811e3c67ce083 100644 (file)
@@ -31,7 +31,7 @@ static void target_set_state(Target *t, TargetState state) {
                           target_state_to_string(old_state),
                           target_state_to_string(state));
 
-        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static int target_add_default_dependencies(Target *t) {
index 419416b3255af0847cd52de6030d6e23ec204c78..f6e660550749814df23e167771335d9cf6ce5461 100644 (file)
@@ -298,7 +298,7 @@ static void timer_set_state(Timer *t, TimerState state) {
         if (state != old_state)
                 log_unit_debug(UNIT(t), "Changed %s -> %s", timer_state_to_string(old_state), timer_state_to_string(state));
 
-        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
+        unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
 }
 
 static void timer_enter_waiting(Timer *t, bool time_change);
@@ -399,14 +399,12 @@ static void timer_enter_waiting(Timer *t, bool time_change) {
                          * to that. If we don't, just start from
                          * the activation time. */
 
-                        if (t->last_trigger.realtime > 0)
+                        if (dual_timestamp_is_set(&t->last_trigger))
                                 b = t->last_trigger.realtime;
-                        else {
-                                if (state_translation_table[t->state] == UNIT_ACTIVE)
-                                        b = UNIT(t)->inactive_exit_timestamp.realtime;
-                                else
-                                        b = ts.realtime;
-                        }
+                        else if (dual_timestamp_is_set(&UNIT(t)->inactive_exit_timestamp))
+                                b = UNIT(t)->inactive_exit_timestamp.realtime;
+                        else
+                                b = ts.realtime;
 
                         r = calendar_spec_next_usec(v->calendar_spec, b, &v->next_elapse);
                         if (r < 0)
@@ -690,7 +688,7 @@ static int timer_serialize(Unit *u, FILE *f, FDSet *fds) {
         (void) serialize_item(f, "state", timer_state_to_string(t->state));
         (void) serialize_item(f, "result", timer_result_to_string(t->result));
 
-        if (t->last_trigger.realtime > 0)
+        if (dual_timestamp_is_set(&t->last_trigger))
                 (void) serialize_usec(f, "last-trigger-realtime", t->last_trigger.realtime);
 
         if (t->last_trigger.monotonic > 0)
index fa1474db8d819edb3c0354cdc33cad1d2e5edd42..6c2682f0aa268c9dd3e395efe6963080ac0cd217 100644 (file)
@@ -2131,7 +2131,7 @@ int unit_reload(Unit *u) {
 
         if (!UNIT_VTABLE(u)->reload) {
                 /* Unit doesn't have a reload function, but we need to propagate the reload anyway */
-                unit_notify(u, unit_active_state(u), unit_active_state(u), 0);
+                unit_notify(u, unit_active_state(u), unit_active_state(u), /* reload_success = */ true);
                 return 0;
         }
 
@@ -2642,7 +2642,7 @@ static void unit_emit_audit_stop(Unit *u, UnitActiveState state) {
         }
 }
 
-static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags) {
+static bool unit_process_job(Job *j, UnitActiveState ns, bool reload_success) {
         bool unexpected = false;
         JobResult result;
 
@@ -2684,7 +2684,7 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
 
                 if (j->state == JOB_RUNNING) {
                         if (ns == UNIT_ACTIVE)
-                                job_finish_and_invalidate(j, (flags & UNIT_NOTIFY_RELOAD_FAILURE) ? JOB_FAILED : JOB_DONE, true, false);
+                                job_finish_and_invalidate(j, reload_success ? JOB_DONE : JOB_FAILED, true, false);
                         else if (!IN_SET(ns, UNIT_ACTIVATING, UNIT_RELOADING)) {
                                 unexpected = true;
 
@@ -2715,7 +2715,7 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
         return unexpected;
 }
 
-void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags) {
+void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
         const char *reason;
         Manager *m;
 
@@ -2780,7 +2780,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag
 
                 /* Let's propagate state changes to the job */
                 if (u->job)
-                        unexpected = unit_process_job(u->job, ns, flags);
+                        unexpected = unit_process_job(u->job, ns, reload_success);
                 else
                         unexpected = true;
 
@@ -2797,9 +2797,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag
 
                 if (ns != os && ns == UNIT_FAILED) {
                         log_unit_debug(u, "Unit entered failed state.");
-
-                        if (!(flags & UNIT_NOTIFY_WILL_AUTO_RESTART))
-                                unit_start_on_failure(u, "OnFailure=", UNIT_ATOM_ON_FAILURE, u->on_failure_job_mode);
+                        unit_start_on_failure(u, "OnFailure=", UNIT_ATOM_ON_FAILURE, u->on_failure_job_mode);
                 }
 
                 if (UNIT_IS_ACTIVE_OR_RELOADING(ns) && !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
@@ -2816,8 +2814,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag
                         unit_log_resources(u);
                 }
 
-                if (ns == UNIT_INACTIVE && !IN_SET(os, UNIT_FAILED, UNIT_INACTIVE, UNIT_MAINTENANCE) &&
-                    !(flags & UNIT_NOTIFY_WILL_AUTO_RESTART))
+                if (ns == UNIT_INACTIVE && !IN_SET(os, UNIT_FAILED, UNIT_INACTIVE, UNIT_MAINTENANCE))
                         unit_start_on_failure(u, "OnSuccess=", UNIT_ATOM_ON_SUCCESS, u->on_success_job_mode);
         }
 
index 7e85150643ec4c4418abcfa9870139d9d0295be2..09af8915dc35e33df5e33fca1938aabe6fc7ba45 100644 (file)
@@ -902,12 +902,7 @@ int unit_kill_common(Unit *u, KillWho who, int signo, int code, int value, pid_t
 
 void unit_notify_cgroup_oom(Unit *u, bool managed_oom);
 
-typedef enum UnitNotifyFlags {
-        UNIT_NOTIFY_RELOAD_FAILURE    = 1 << 0,
-        UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1,
-} UnitNotifyFlags;
-
-void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);
+void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success);
 
 int unit_watch_pid(Unit *u, pid_t pid, bool exclusive);
 void unit_unwatch_pid(Unit *u, pid_t pid);
index c6e201ecf20badcc432ab6489551bc2040ca5383..7e0c98cb7d45016c01c319d2320789287763d9ab 100644 (file)
@@ -187,8 +187,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
                                         if (!n)
                                                 return log_oom();
 
-                                        free(c->oldest_file);
-                                        c->oldest_file = n;
+                                        free_and_replace(c->oldest_file, n);
                                         c->oldest_mtime = t;
                                 }
 
index 5fdcfa74372163d6fa0f0b3cecd8dcc0ee5f753e..a6b0d96488a77536aae71cc788baa91174b35c2d 100644 (file)
@@ -707,6 +707,9 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
         if (errno > 0)
                 return -errno;
 
+        if (!buffer)
+                return -ENOMEM;
+
         *open_fds = TAKE_PTR(buffer);
 
         return 0;
index 6e9cfd2776705df1995bea7a2480780eba5614d0..d16509d57437cc73b3a18b47e26885ad049a0d93 100644 (file)
@@ -11,6 +11,7 @@
 #include "blockdev-util.h"
 #include "btrfs-util.h"
 #include "bus-common-errors.h"
+#include "bus-locator.h"
 #include "data-fd-util.h"
 #include "env-util.h"
 #include "errno-list.h"
@@ -2117,15 +2118,7 @@ int home_killall(Home *h) {
         if (asprintf(&unit, "user-" UID_FMT ".slice", h->uid) < 0)
                 return log_oom();
 
-        r = sd_bus_call_method(
-                        h->manager->bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "KillUnit",
-                        &error,
-                        NULL,
-                        "ssi", unit, "all", SIGKILL);
+        r = bus_call_method(h->manager->bus, bus_systemd_mgr, "KillUnit", &error, NULL, "ssi", unit, "all", SIGKILL);
         if (r < 0)
                 log_full_errno(sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ? LOG_DEBUG : LOG_WARNING,
                                r, "Failed to kill login processes of user, ignoring: %s", bus_error_message(&error, r));
index a0e949d82c7d9d4142c3172aa073749ed6a17f6a..8d3cca5c6215c495dee77f765140f48660ab8dc9 100644 (file)
@@ -15,6 +15,7 @@
 #include "build.h"
 #include "bus-common-errors.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-map-properties.h"
 #include "format-table.h"
 #include "hostname-setup.h"
@@ -298,13 +299,7 @@ static int get_one_name(sd_bus *bus, const char* attr, char **ret) {
 
         /* This obtains one string property, and copy it if 'ret' is set, or print it otherwise. */
 
-        r = sd_bus_get_property(
-                        bus,
-                        "org.freedesktop.hostname1",
-                        "/org/freedesktop/hostname1",
-                        "org.freedesktop.hostname1",
-                        attr,
-                        &error, &reply, "s");
+        r = bus_get_property(bus, bus_hostname, attr, &error, &reply, "s");
         if (r < 0)
                 return log_error_errno(r, "Could not get property: %s", bus_error_message(&error, r));
 
@@ -408,15 +403,7 @@ static int show_status(int argc, char **argv, void *userdata) {
                 _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
                 const char *text = NULL;
 
-                r = sd_bus_call_method(
-                                bus,
-                                "org.freedesktop.hostname1",
-                                "/org/freedesktop/hostname1",
-                                "org.freedesktop.hostname1",
-                                "Describe",
-                                &error,
-                                &reply,
-                                NULL);
+                r = bus_call_method(bus, bus_hostname, "Describe", &error, &reply, NULL);
                 if (r < 0)
                         return log_error_errno(r, "Could not get description: %s", bus_error_message(&error, r));
 
@@ -448,14 +435,7 @@ static int set_simple_string_internal(sd_bus *bus, sd_bus_error *error, const ch
         if (!error)
                 error = &e;
 
-        r = sd_bus_call_method(
-                        bus,
-                        "org.freedesktop.hostname1",
-                        "/org/freedesktop/hostname1",
-                        "org.freedesktop.hostname1",
-                        method,
-                        error, NULL,
-                        "sb", value, arg_ask_password);
+        r = bus_call_method(bus, bus_hostname, method, error, NULL, "sb", value, arg_ask_password);
         if (r < 0)
                 return log_error_errno(r, "Could not set %s: %s", target, bus_error_message(error, r));
 
index b6e8469922f9bd75129439dcd7676df301b37d3e..4b4eec01855c66e84ad1857ead6568bc54246033 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "alloc-util.h"
 #include "build.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
@@ -704,14 +705,7 @@ static int get_virtualization(char **v) {
         if (r < 0)
                 return r;
 
-        r = sd_bus_get_property_string(
-                        bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "Virtualization",
-                        NULL,
-                        &b);
+        r = bus_get_property_string(bus, bus_systemd_mgr, "Virtualization", NULL, &b);
         if (r < 0)
                 return r;
 
index b9b310b6644aa2af2b51eb87a8d9e61ae3612840..fac90d22a21b1944fe18b3824ca4eebb7dd8238e 100644 (file)
@@ -271,8 +271,7 @@ int start_upload(Uploader *u,
                 /* truncate the potential old error message */
                 u->error[0] = '\0';
 
-                free(u->answer);
-                u->answer = 0;
+                u->answer = mfree(u->answer);
         }
 
         /* upload to this place */
index b0b95311f1cfbce76e60c18df97a922359f6f298..e379203d5d796de7140eca3c18123a55221e7618 100644 (file)
@@ -21,6 +21,7 @@
 #include "alloc-util.h"
 #include "build.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "catalog.h"
 #include "chase.h"
@@ -1810,6 +1811,10 @@ static int format_journal_url(
                 return r;
 
         f = safe_fclose(f);
+
+        if (!url)
+                return -ENOMEM;
+
         *ret_url = TAKE_PTR(url);
         return 0;
 }
@@ -2246,15 +2251,7 @@ static int run(int argc, char *argv[]) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to open system bus: %m");
 
-                r = sd_bus_call_method(
-                                bus,
-                                "org.freedesktop.machine1",
-                                "/org/freedesktop/machine1",
-                                "org.freedesktop.machine1.Manager",
-                                "OpenMachineRootDirectory",
-                                &error,
-                                &reply,
-                                "s", arg_machine);
+                r = bus_call_method(bus, bus_machine_mgr, "OpenMachineRootDirectory", &error, &reply, "s", arg_machine);
                 if (r < 0)
                         return log_error_errno(r, "Failed to open root directory: %s", bus_error_message(&error, r));
 
index ca23508454fd1f9ea86dee9680c6644e943756b1..4888c38fdb012971d9c3a1ec5e7e14bb404e71e3 100644 (file)
@@ -66,20 +66,16 @@ static void server_process_entry_meta(
                 char *t;
 
                 t = memdup_suffix0(p + 18, l - 18);
-                if (t) {
-                        free(*identifier);
-                        *identifier = t;
-                }
+                if (t)
+                        free_and_replace(*identifier, t);
 
         } else if (l >= 8 &&
                    startswith(p, "MESSAGE=")) {
                 char *t;
 
                 t = memdup_suffix0(p + 8, l - 8);
-                if (t) {
-                        free(*message);
-                        *message = t;
-                }
+                if (t)
+                        free_and_replace(*message, t);
 
         } else if (l > STRLEN("OBJECT_PID=") &&
                    l < STRLEN("OBJECT_PID=")  + DECIMAL_STR_MAX(pid_t) &&
index 6672409d7533c3027f3af22123646c082e4faa71..af61c9b096bbace2e337408e28ba4601fd0178d7 100644 (file)
@@ -159,8 +159,7 @@ static int parse_string(sd_lldp_rx *lldp_rx, char **s, const void *q, size_t n)
         if (!k)
                 return log_oom_debug();
 
-        free(*s);
-        *s = k;
+        free_and_replace(*s, k);
 
         return 1;
 }
index 02c6a6e0d79133e90eb65c5c7dd65563e87bc981..b0a36324121835569471dd6cc35518d3ef92702a 100644 (file)
@@ -451,8 +451,7 @@ static int lease_parse_in_addrs(const uint8_t *option, size_t len, struct in_add
                 if (!addresses)
                         return -ENOMEM;
 
-                free(*ret);
-                *ret = addresses;
+                free_and_replace(*ret, addresses);
                 *n_ret = n_addresses;
         }
 
@@ -795,8 +794,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void
                         if (!p)
                                 return -ENOMEM;
 
-                        free(lease->vendor_specific);
-                        lease->vendor_specific = p;
+                        free_and_replace(lease->vendor_specific, p);
                 }
 
                 lease->vendor_specific_len = len;
@@ -1458,8 +1456,7 @@ int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t
                 if (!p)
                         return -ENOMEM;
 
-                free(lease->client_id);
-                lease->client_id = p;
+                free_and_replace(lease->client_id, p);
                 lease->client_id_len = client_id_len;
         }
 
index 287cde6d419f61973952a4770e707ab1b7c4a5c0..77b4b5bea61ab3c65a7f06eaf8c028c6ada2177d 100644 (file)
@@ -590,10 +590,9 @@ _public_ int sd_bus_get_name_creds(
                                                 if (r < 0)
                                                         return r;
 
-                                                free(c->label);
-                                                c->label = strndup(p, sz);
-                                                if (!c->label)
-                                                        return -ENOMEM;
+                                                r = free_and_strndup(&c->label, p, sz);
+                                                if (r < 0)
+                                                        return r;
 
                                                 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
 
index 49236a8e129d3a4841b15695a38c2de56c419c98..3d4c47c6dd7618d80f42f51798930f9f6216de71 100644 (file)
@@ -268,6 +268,10 @@ int introspect_finish(struct introspect *i, char **ret) {
                 return r;
 
         i->f = safe_fclose(i->f);
+
+        if (!i->introspection)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(i->introspection);
 
         return 0;
index 703b9ac038b69e57432d7fc9740a6d196c022a71..cc043abfe348edabe0e810d3acd5bfb550a0e5b4 100644 (file)
@@ -824,6 +824,7 @@ int bus_match_parse(
 
 char *bus_match_to_string(struct bus_match_component *components, size_t n_components) {
         _cleanup_free_ char *buffer = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t size = 0;
         int r;
 
@@ -832,7 +833,7 @@ char *bus_match_to_string(struct bus_match_component *components, size_t n_compo
 
         assert(components);
 
-        FILE *f = open_memstream_unlocked(&buffer, &size);
+        f = open_memstream_unlocked(&buffer, &size);
         if (!f)
                 return NULL;
 
@@ -855,9 +856,11 @@ char *bus_match_to_string(struct bus_match_component *components, size_t n_compo
         }
 
         r = fflush_and_check(f);
-        safe_fclose(f);
         if (r < 0)
                 return NULL;
+
+        f = safe_fclose(f);
+
         return TAKE_PTR(buffer);
 }
 
index 741d54cabdfb624b33ff76199f8e61bd5a756140..e4e19972649a6c792ff6360b22714005c156835e 100644 (file)
@@ -337,8 +337,7 @@ static int bus_socket_auth_write(sd_bus *b, const char *t) {
         b->auth_iovec[0].iov_base = p;
         b->auth_iovec[0].iov_len += l;
 
-        free(b->auth_buffer);
-        b->auth_buffer = p;
+        free_and_replace(b->auth_buffer, p);
         b->auth_index = 0;
         return 0;
 }
@@ -868,8 +867,7 @@ static int bus_socket_inotify_setup(sd_bus *b) {
                         goto fail;
                 }
 
-                free(absolute);
-                absolute = c;
+                free_and_replace(absolute, c);
 
                 max_follow--;
         }
index 7527abf636cb99756b5fc75f5cec4598b1817f54..06cf396b95901b22e50dbcf1705edacfe083f439 100644 (file)
@@ -145,7 +145,9 @@ static int finish_item(
                 char *payload, size_t payload_size) {
 
         _cleanup_free_ CatalogItem *i = NULL;
-        _cleanup_free_ char *prev = NULL, *combined = NULL;
+        _cleanup_free_ char *combined = NULL;
+        char *prev;
+        int r;
 
         assert(h);
         assert(payload);
@@ -168,19 +170,24 @@ static int finish_item(
                 if (!combined)
                         return log_oom();
 
-                if (ordered_hashmap_update(h, i, combined) < 0)
-                        return log_oom();
-                combined = NULL;
+                r = ordered_hashmap_update(h, i, combined);
+                if (r < 0)
+                        return r;
+
+                TAKE_PTR(combined);
+                free(prev);
         } else {
                 /* A new item */
                 combined = memdup(payload, payload_size + 1);
                 if (!combined)
                         return log_oom();
 
-                if (ordered_hashmap_put(h, i, combined) < 0)
-                        return log_oom();
-                i = NULL;
-                combined = NULL;
+                r = ordered_hashmap_put(h, i, combined);
+                if (r < 0)
+                        return r;
+
+                TAKE_PTR(i);
+                TAKE_PTR(combined);
         }
 
         return 0;
index a81b21062a733089429551f4a9bd5c85a0e0e37f..c5d54bbf74d238afd0c2b567a1ff98e4a7f781a7 100644 (file)
@@ -124,10 +124,9 @@ _public_ int sd_pid_get_cgroup(pid_t pid, char **cgroup) {
          * cgroup, let's return the "/" in the public APIs instead, as
          * that's easier and less ambiguous for people to grok. */
         if (isempty(c)) {
-                free(c);
-                c = strdup("/");
-                if (!c)
-                        return -ENOMEM;
+                r = free_and_strdup(&c, "/");
+                if (r < 0)
+                        return r;
 
         }
 
index 841b863024358e7cee22e6922fd78af04331aea3..dcd3547f8b90a2d63c4f3874e1d1302e967bde92 100644 (file)
@@ -1109,8 +1109,7 @@ static void resolve_freeaddrinfo(struct addrinfo *ai) {
 
                 free(ai->ai_addr);
                 free(ai->ai_canonname);
-                free(ai);
-                ai = next;
+                free_and_replace(ai, next);
         }
 }
 
index 25ba848492dee9527de92a1c2cd460d160632b6a..75dba8c08f5dde213ff65efda91ec84d26f7f2a1 100644 (file)
@@ -11,6 +11,7 @@
 #include "alloc-util.h"
 #include "build.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "fd-util.h"
 #include "format-table.h"
@@ -41,15 +42,7 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) {
         int r;
         int fd;
 
-        r = sd_bus_call_method(
-                        bus,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
-                        "Inhibit",
-                        error,
-                        &reply,
-                        "ssss", arg_what, arg_who, arg_why, arg_mode);
+        r = bus_call_method(bus, bus_login_mgr, "Inhibit", error, &reply, "ssss", arg_what, arg_who, arg_why, arg_mode);
         if (r < 0)
                 return r;
 
@@ -68,15 +61,7 @@ static int print_inhibitors(sd_bus *bus) {
 
         pager_open(arg_pager_flags);
 
-        r = sd_bus_call_method(
-                        bus,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
-                        "ListInhibitors",
-                        &error,
-                        &reply,
-                        "");
+        r = bus_call_method(bus, bus_login_mgr, "ListInhibitors", &error, &reply, NULL);
         if (r < 0)
                 return log_error_errno(r, "Could not get active inhibitors: %s", bus_error_message(&error, r));
 
index dfc738c6d02ee207e4dbcd31eba5bf72e661342b..81bb8f48ddf2ff7534dfb59683047e23fa77ff89 100644 (file)
@@ -54,8 +54,59 @@ static OutputMode arg_output = OUTPUT_SHORT;
 
 STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep);
 
-static OutputFlags get_output_flags(void) {
+typedef struct SessionStatusInfo {
+        const char *id;
+        uid_t uid;
+        const char *name;
+        dual_timestamp timestamp;
+        unsigned vtnr;
+        const char *seat;
+        const char *tty;
+        const char *display;
+        bool remote;
+        const char *remote_host;
+        const char *remote_user;
+        const char *service;
+        pid_t leader;
+        const char *type;
+        const char *class;
+        const char *state;
+        const char *scope;
+        const char *desktop;
+        bool idle_hint;
+        usec_t idle_hint_timestamp;
+} SessionStatusInfo;
 
+typedef struct UserStatusInfo {
+        uid_t uid;
+        bool linger;
+        const char *name;
+        dual_timestamp timestamp;
+        const char *state;
+        char **sessions;
+        const char *display;
+        const char *slice;
+} UserStatusInfo;
+
+typedef struct SeatStatusInfo {
+        const char *id;
+        const char *active_session;
+        char **sessions;
+} SeatStatusInfo;
+
+static void user_status_info_done(UserStatusInfo *info) {
+        assert(info);
+
+        strv_free(info->sessions);
+}
+
+static void seat_status_info_done(SeatStatusInfo *info) {
+        assert(info);
+
+        strv_free(info->sessions);
+}
+
+static OutputFlags get_output_flags(void) {
         return
                 FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
                 (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
@@ -64,8 +115,13 @@ static OutputFlags get_output_flags(void) {
 
 static int get_session_path(sd_bus *bus, const char *session_id, sd_bus_error *error, char **path) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
-        int r;
         char *ans;
+        int r;
+
+        assert(bus);
+        assert(session_id);
+        assert(error);
+        assert(path);
 
         r = bus_call_method(bus, bus_login_mgr, "GetSession", error, &reply, "s", session_id);
         if (r < 0)
@@ -115,6 +171,15 @@ static int show_table(Table *table, const char *word) {
 }
 
 static int list_sessions(int argc, char *argv[], void *userdata) {
+
+        static const struct bus_properties_map map[] = {
+                { "IdleHint",      "b", NULL, offsetof(SessionStatusInfo, idle_hint)           },
+                { "IdleSinceHint", "t", NULL, offsetof(SessionStatusInfo, idle_hint_timestamp) },
+                { "State",         "s", NULL, offsetof(SessionStatusInfo, state)               },
+                { "TTY",           "s", NULL, offsetof(SessionStatusInfo, tty)                 },
+                {},
+        };
+
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(table_unrefp) Table *table = NULL;
@@ -133,7 +198,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return bus_log_parse_error(r);
 
-        table = table_new("session", "uid", "user", "seat", "tty", "state");
+        table = table_new("session", "uid", "user", "seat", "tty", "state", "idle", "since");
         if (!table)
                 return log_oom();
 
@@ -142,10 +207,11 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
         (void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
 
         for (;;) {
-                _cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL;
-                _cleanup_free_ char *tty = NULL, *state = NULL;
+                _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL;
                 const char *id, *user, *seat, *object;
                 uint32_t uid;
+                _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+                SessionStatusInfo i = {};
 
                 r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object);
                 if (r < 0)
@@ -153,38 +219,13 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
                 if (r == 0)
                         break;
 
-                r = sd_bus_get_property_string(bus,
-                                               "org.freedesktop.login1",
-                                               object,
-                                               "org.freedesktop.login1.Session",
-                                               "TTY",
-                                               &error_property,
-                                               &tty);
+                r = bus_map_all_properties(bus, "org.freedesktop.login1", object, map, BUS_MAP_BOOLEAN_AS_BOOL, &e, &m, &i);
                 if (r < 0) {
-                        if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
-                                /* The session is already closed when we're querying the property */
-                                continue;
-
-                        log_warning_errno(r, "Failed to get TTY for session %s, ignoring: %s",
-                                          id, bus_error_message(&error_property, r));
-
-                        sd_bus_error_free(&error_property);
-                }
-
-                r = sd_bus_get_property_string(bus,
-                                               "org.freedesktop.login1",
-                                               object,
-                                               "org.freedesktop.login1.Session",
-                                               "State",
-                                               &error_property,
-                                               &state);
-                if (r < 0) {
-                        if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
-                                /* The session is already closed when we're querying the property */
-                                continue;
-
-                        return log_error_errno(r, "Failed to get state for session %s: %s",
-                                               id, bus_error_message(&error_property, r));
+                        log_full_errno(sd_bus_error_has_name(&e, SD_BUS_ERROR_UNKNOWN_OBJECT) ? LOG_DEBUG : LOG_WARNING,
+                                       r,
+                                       "Failed to get properties of session %s, ignoring: %s",
+                                       id, bus_error_message(&e, r));
+                        continue;
                 }
 
                 r = table_add_many(table,
@@ -192,8 +233,16 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
                                    TABLE_UID, (uid_t) uid,
                                    TABLE_STRING, user,
                                    TABLE_STRING, seat,
-                                   TABLE_STRING, strna(tty),
-                                   TABLE_STRING, state);
+                                   TABLE_STRING, strna(i.tty),
+                                   TABLE_STRING, i.state,
+                                   TABLE_BOOLEAN, i.idle_hint);
+                if (r < 0)
+                        return table_log_add_error(r);
+
+                if (i.idle_hint)
+                        r = table_add_cell(table, NULL, TABLE_TIMESTAMP_RELATIVE, &i.idle_hint_timestamp);
+                else
+                        r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
                 if (r < 0)
                         return table_log_add_error(r);
         }
@@ -206,6 +255,13 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
 }
 
 static int list_users(int argc, char *argv[], void *userdata) {
+
+        static const struct bus_properties_map property_map[] = {
+                { "Linger", "b", NULL, offsetof(UserStatusInfo, linger) },
+                { "State",  "s", NULL, offsetof(UserStatusInfo, state)  },
+                {},
+        };
+
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(table_unrefp) Table *table = NULL;
@@ -232,10 +288,10 @@ static int list_users(int argc, char *argv[], void *userdata) {
 
         for (;;) {
                 _cleanup_(sd_bus_error_free) sd_bus_error error_property = SD_BUS_ERROR_NULL;
-                _cleanup_free_ char *state = NULL;
+                _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply_property = NULL;
+                _cleanup_(user_status_info_done) UserStatusInfo info = {};
                 const char *user, *object;
                 uint32_t uid;
-                int linger;
 
                 r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object);
                 if (r < 0)
@@ -243,44 +299,27 @@ static int list_users(int argc, char *argv[], void *userdata) {
                 if (r == 0)
                         break;
 
-                r = sd_bus_get_property_trivial(bus,
-                                                "org.freedesktop.login1",
-                                                object,
-                                                "org.freedesktop.login1.User",
-                                                "Linger",
-                                                &error_property,
-                                                'b',
-                                                &linger);
-                if (r < 0) {
-                        if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
-                                /* The user logged out when we're querying the property */
-                                continue;
-
-                        return log_error_errno(r, "Failed to get linger status for user %s: %s",
-                                               user, bus_error_message(&error_property, r));
-                }
-
-                r = sd_bus_get_property_string(bus,
-                                               "org.freedesktop.login1",
-                                               object,
-                                               "org.freedesktop.login1.User",
-                                               "State",
-                                               &error_property,
-                                               &state);
+                r = bus_map_all_properties(bus,
+                                           "org.freedesktop.login1",
+                                           object,
+                                           property_map,
+                                           BUS_MAP_BOOLEAN_AS_BOOL,
+                                           &error_property,
+                                           &reply_property,
+                                           &info);
                 if (r < 0) {
-                        if (sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT))
-                                /* The user logged out when we're querying the property */
-                                continue;
-
-                        return log_error_errno(r, "Failed to get state for user %s: %s",
-                                               user, bus_error_message(&error_property, r));
+                        log_full_errno(sd_bus_error_has_name(&error_property, SD_BUS_ERROR_UNKNOWN_OBJECT) ? LOG_DEBUG : LOG_WARNING,
+                                       r,
+                                       "Failed to get properties of user %s, ignoring: %s",
+                                       user, bus_error_message(&error_property, r));
+                        continue;
                 }
 
                 r = table_add_many(table,
                                    TABLE_UID, (uid_t) uid,
                                    TABLE_STRING, user,
-                                   TABLE_BOOLEAN, linger,
-                                   TABLE_STRING, state);
+                                   TABLE_BOOLEAN, info.linger,
+                                   TABLE_STRING, info.state);
                 if (r < 0)
                         return table_log_add_error(r);
         }
@@ -376,62 +415,13 @@ static int show_unit_cgroup(sd_bus *bus, const char *interface, const char *unit
         return 0;
 }
 
-typedef struct SessionStatusInfo {
-        const char *id;
-        uid_t uid;
-        const char *name;
-        struct dual_timestamp timestamp;
-        unsigned vtnr;
-        const char *seat;
-        const char *tty;
-        const char *display;
-        bool remote;
-        const char *remote_host;
-        const char *remote_user;
-        const char *service;
-        pid_t leader;
-        const char *type;
-        const char *class;
-        const char *state;
-        const char *scope;
-        const char *desktop;
-} SessionStatusInfo;
-
-typedef struct UserStatusInfo {
-        uid_t uid;
-        bool linger;
-        const char *name;
-        struct dual_timestamp timestamp;
-        const char *state;
-        char **sessions;
-        const char *display;
-        const char *slice;
-} UserStatusInfo;
-
-typedef struct SeatStatusInfo {
-        const char *id;
-        const char *active_session;
-        char **sessions;
-} SeatStatusInfo;
-
-static void user_status_info_clear(UserStatusInfo *info) {
-        if (info) {
-                strv_free(info->sessions);
-                zero(*info);
-        }
-}
-
-static void seat_status_info_clear(SeatStatusInfo *info) {
-        if (info) {
-                strv_free(info->sessions);
-                zero(*info);
-        }
-}
-
 static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
         const char *contents;
         int r;
 
+        assert(bus);
+        assert(m);
+
         r = sd_bus_message_peek_type(m, NULL, &contents);
         if (r < 0)
                 return r;
@@ -479,26 +469,28 @@ static int prop_map_sessions_strv(sd_bus *bus, const char *member, sd_bus_messag
 
 static int print_session_status_info(sd_bus *bus, const char *path, bool *new_line) {
 
-        static const struct bus_properties_map map[]  = {
-                { "Id",                  "s",    NULL,                     offsetof(SessionStatusInfo, id)                  },
-                { "Name",                "s",    NULL,                     offsetof(SessionStatusInfo, name)                },
-                { "TTY",                 "s",    NULL,                     offsetof(SessionStatusInfo, tty)                 },
-                { "Display",             "s",    NULL,                     offsetof(SessionStatusInfo, display)             },
-                { "RemoteHost",          "s",    NULL,                     offsetof(SessionStatusInfo, remote_host)         },
-                { "RemoteUser",          "s",    NULL,                     offsetof(SessionStatusInfo, remote_user)         },
-                { "Service",             "s",    NULL,                     offsetof(SessionStatusInfo, service)             },
-                { "Desktop",             "s",    NULL,                     offsetof(SessionStatusInfo, desktop)             },
-                { "Type",                "s",    NULL,                     offsetof(SessionStatusInfo, type)                },
-                { "Class",               "s",    NULL,                     offsetof(SessionStatusInfo, class)               },
-                { "Scope",               "s",    NULL,                     offsetof(SessionStatusInfo, scope)               },
-                { "State",               "s",    NULL,                     offsetof(SessionStatusInfo, state)               },
-                { "VTNr",                "u",    NULL,                     offsetof(SessionStatusInfo, vtnr)                },
-                { "Leader",              "u",    NULL,                     offsetof(SessionStatusInfo, leader)              },
-                { "Remote",              "b",    NULL,                     offsetof(SessionStatusInfo, remote)              },
-                { "Timestamp",           "t",    NULL,                     offsetof(SessionStatusInfo, timestamp.realtime)  },
-                { "TimestampMonotonic",  "t",    NULL,                     offsetof(SessionStatusInfo, timestamp.monotonic) },
-                { "User",                "(uo)", prop_map_first_of_struct, offsetof(SessionStatusInfo, uid)                 },
-                { "Seat",                "(so)", prop_map_first_of_struct, offsetof(SessionStatusInfo, seat)                },
+        static const struct bus_properties_map map[] = {
+                { "Id",                 "s",    NULL,                     offsetof(SessionStatusInfo, id)                  },
+                { "Name",               "s",    NULL,                     offsetof(SessionStatusInfo, name)                },
+                { "TTY",                "s",    NULL,                     offsetof(SessionStatusInfo, tty)                 },
+                { "Display",            "s",    NULL,                     offsetof(SessionStatusInfo, display)             },
+                { "RemoteHost",         "s",    NULL,                     offsetof(SessionStatusInfo, remote_host)         },
+                { "RemoteUser",         "s",    NULL,                     offsetof(SessionStatusInfo, remote_user)         },
+                { "Service",            "s",    NULL,                     offsetof(SessionStatusInfo, service)             },
+                { "Desktop",            "s",    NULL,                     offsetof(SessionStatusInfo, desktop)             },
+                { "Type",               "s",    NULL,                     offsetof(SessionStatusInfo, type)                },
+                { "Class",              "s",    NULL,                     offsetof(SessionStatusInfo, class)               },
+                { "Scope",              "s",    NULL,                     offsetof(SessionStatusInfo, scope)               },
+                { "State",              "s",    NULL,                     offsetof(SessionStatusInfo, state)               },
+                { "VTNr",               "u",    NULL,                     offsetof(SessionStatusInfo, vtnr)                },
+                { "Leader",             "u",    NULL,                     offsetof(SessionStatusInfo, leader)              },
+                { "Remote",             "b",    NULL,                     offsetof(SessionStatusInfo, remote)              },
+                { "Timestamp",          "t",    NULL,                     offsetof(SessionStatusInfo, timestamp.realtime)  },
+                { "TimestampMonotonic", "t",    NULL,                     offsetof(SessionStatusInfo, timestamp.monotonic) },
+                { "IdleHint",           "b",    NULL,                     offsetof(SessionStatusInfo, idle_hint)           },
+                { "IdleSinceHint",      "t",    NULL,                     offsetof(SessionStatusInfo, idle_hint_timestamp) },
+                { "User",               "(uo)", prop_map_first_of_struct, offsetof(SessionStatusInfo, uid)                 },
+                { "Seat",               "(so)", prop_map_first_of_struct, offsetof(SessionStatusInfo, seat)                },
                 {}
         };
 
@@ -589,6 +581,14 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
         if (i.state)
                 printf("\t   State: %s\n", i.state);
 
+        if (i.idle_hint && timestamp_is_set(i.idle_hint_timestamp))
+                printf("\t    Idle: %s since %s (%s)\n",
+                       yes_no(i.idle_hint),
+                       FORMAT_TIMESTAMP(i.idle_hint_timestamp),
+                       FORMAT_TIMESTAMP_RELATIVE(i.idle_hint_timestamp));
+        else
+                printf("\t    Idle: %s\n", yes_no(i.idle_hint));
+
         if (i.scope) {
                 printf("\t    Unit: %s\n", i.scope);
                 show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader);
@@ -614,7 +614,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
 
 static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) {
 
-        static const struct bus_properties_map map[]  = {
+        static const struct bus_properties_map map[] = {
                 { "Name",               "s",     NULL,                     offsetof(UserStatusInfo, name)                },
                 { "Linger",             "b",     NULL,                     offsetof(UserStatusInfo, linger)              },
                 { "Slice",              "s",     NULL,                     offsetof(UserStatusInfo, slice)               },
@@ -629,7 +629,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-        _cleanup_(user_status_info_clear) UserStatusInfo i = {};
+        _cleanup_(user_status_info_done) UserStatusInfo i = {};
         int r;
 
         r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
@@ -691,7 +691,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
 
 static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) {
 
-        static const struct bus_properties_map map[]  = {
+        static const struct bus_properties_map map[] = {
                 { "Id",            "s",     NULL, offsetof(SeatStatusInfo, id) },
                 { "ActiveSession", "(so)",  prop_map_first_of_struct, offsetof(SeatStatusInfo, active_session) },
                 { "Sessions",      "a(so)", prop_map_sessions_strv, offsetof(SeatStatusInfo, sessions) },
@@ -700,7 +700,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line)
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-        _cleanup_(seat_status_info_clear) SeatStatusInfo i = {};
+        _cleanup_(seat_status_info_done) SeatStatusInfo i = {};
         int r;
 
         r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, 0, &error, &m, &i);
@@ -917,14 +917,7 @@ static int show_user(int argc, char *argv[], void *userdata) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
 
-                r = sd_bus_call_method(
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "GetUser",
-                                &error, &reply,
-                                "u", (uint32_t) uid);
+                r = bus_call_method(bus, bus_login_mgr, "GetUser", &error, &reply, "u", (uint32_t) uid);
                 if (r < 0)
                         return log_error_errno(r, "Failed to get user: %s", bus_error_message(&error, r));
 
@@ -1015,7 +1008,6 @@ static int activate(int argc, char *argv[], void *userdata) {
         }
 
         for (int i = 1; i < argc; i++) {
-
                 r = bus_call_method(
                                 bus,
                                 bus_login_mgr,
@@ -1045,7 +1037,6 @@ static int kill_session(int argc, char *argv[], void *userdata) {
                 arg_kill_whom = "all";
 
         for (int i = 1; i < argc; i++) {
-
                 r = bus_call_method(
                                 bus,
                                 bus_login_mgr,
index 3920467f444d997eca0f5a23b14e9e7c7d88d4da..6161af9a7453b10f433d2b8544997c2c9be821b9 100644 (file)
@@ -6,6 +6,7 @@
 #include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "cgroup-util.h"
 #include "clean-ipc.h"
@@ -388,13 +389,7 @@ static int user_update_slice(User *u) {
             u->user_record->io_weight == UINT64_MAX)
                 return 0;
 
-        r = sd_bus_message_new_method_call(
-                        u->manager->bus,
-                        &m,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "SetUnitProperties");
+        r = bus_message_new_method_call(u->manager->bus, &m, bus_systemd_mgr, "SetUnitProperties");
         if (r < 0)
                 return bus_log_create_error(r);
 
index aefae277fc06a2419e7685f9aac326831afdb15a..f59cca8fed7b45bd3bdf42b0fd6595faeaa2356c 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "sd-bus.h"
 
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "fd-util.h"
 #include "macro.h"
@@ -16,14 +17,7 @@ static int inhibit(sd_bus *bus, const char *what) {
         int fd;
         int r;
 
-        r = sd_bus_call_method(bus,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
-                        "Inhibit",
-                        &error,
-                        &reply,
-                        "ssss", what, who, reason, mode);
+        r = bus_call_method(bus, bus_login_mgr, "Inhibit", &error, &reply, "ssss", what, who, reason, mode);
         assert_se(r >= 0);
 
         r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd);
@@ -41,14 +35,7 @@ static void print_inhibitors(sd_bus *bus) {
         unsigned n = 0;
         int r;
 
-        r = sd_bus_call_method(bus,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
-                        "ListInhibitors",
-                        &error,
-                        &reply,
-                        "");
+        r = bus_call_method(bus, bus_login_mgr, "ListInhibitors", &error, &reply, NULL);
         assert_se(r >= 0);
 
         r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
index 48aa21abef290a0dfb4925d3baf170773b2973e9..b5b5f60eaaac29b82fe1c3a9b323f365f27544bf 100644 (file)
@@ -57,7 +57,7 @@ TEST(set_type) {
 
         /* Type is reset to the original value when we release control of the session */
         assert_se(!streq(type, "tty"));
-        assert_se(bus_call_method(bus, &session, "ReleaseControl", NULL, NULL, "") >= 0);
+        assert_se(bus_call_method(bus, &session, "ReleaseControl", NULL, NULL, NULL) >= 0);
         type = mfree(type);
         assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type) >= 0);
         assert_se(streq(type, "tty"));
index f96a2d8662350cd9c95a61146c97457555283b9f..5a16d1684d7aa24edfc43af42496817ba5fcf5c6 100644 (file)
@@ -6,6 +6,7 @@
 #include "sd-bus.h"
 
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "dev-setup.h"
 #include "format-util.h"
 #include "fs-util.h"
@@ -33,13 +34,13 @@ static int acquire_runtime_dir_properties(uint64_t *size, uint64_t *inodes) {
         if (r < 0)
                 return log_error_errno(r, "Failed to connect to system bus: %m");
 
-        r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectorySize", &error, 't', size);
+        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', size);
         if (r < 0) {
                 log_warning_errno(r, "Failed to acquire runtime directory size, ignoring: %s", bus_error_message(&error, r));
                 *size = physical_memory_scale(10U, 100U); /* 10% */
         }
 
-        r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectoryInodesMax", &error, 't', inodes);
+        r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', inodes);
         if (r < 0) {
                 log_warning_errno(r, "Failed to acquire number of inodes for runtime directory, ignoring: %s", bus_error_message(&error, r));
                 *inodes = DIV_ROUND_UP(*size, 4096);
index 1090934bfc15e03d00e2503b4b62a1429d7f8bf8..569dcdf5114d78ee2b6f0f54bf6169d9ee293fb4 100644 (file)
@@ -1199,30 +1199,31 @@ void link_dump(Link *link, FILE *f) {
 
 int network_format(Network *network, char **ret) {
         _cleanup_free_ char *s = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t sz = 0;
         int r;
 
         assert(network);
         assert(ret);
 
-        {
-                _cleanup_fclose_ FILE *f = NULL;
-
-                f = open_memstream_unlocked(&s, &sz);
-                if (!f)
-                        return -ENOMEM;
+        f = open_memstream_unlocked(&s, &sz);
+        if (!f)
+                return -ENOMEM;
 
-                network_dump(network, f);
+        network_dump(network, f);
 
-                /* Add terminating 0, so that the output buffer is a valid string. */
-                fputc('\0', f);
+        /* Add terminating 0, so that the output buffer is a valid string. */
+        fputc('\0', f);
 
-                r = fflush_and_check(f);
-        }
+        r = fflush_and_check(f);
         if (r < 0)
                 return r;
 
-        assert(s);
+        f = safe_fclose(f);
+
+        if (!s)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(s);
         assert(sz > 0);
         return (int) sz - 1;
@@ -1230,30 +1231,31 @@ int network_format(Network *network, char **ret) {
 
 int netdev_format(NetDev *netdev, char **ret) {
         _cleanup_free_ char *s = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t sz = 0;
         int r;
 
         assert(netdev);
         assert(ret);
 
-        {
-                _cleanup_fclose_ FILE *f = NULL;
-
-                f = open_memstream_unlocked(&s, &sz);
-                if (!f)
-                        return -ENOMEM;
+        f = open_memstream_unlocked(&s, &sz);
+        if (!f)
+                return -ENOMEM;
 
-                netdev_dump(netdev, f);
+        netdev_dump(netdev, f);
 
-                /* Add terminating 0, so that the output buffer is a valid string. */
-                fputc('\0', f);
+        /* Add terminating 0, so that the output buffer is a valid string. */
+        fputc('\0', f);
 
-                r = fflush_and_check(f);
-        }
+        r = fflush_and_check(f);
         if (r < 0)
                 return r;
 
-        assert(s);
+        f = safe_fclose(f);
+
+        if (!s)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(s);
         assert(sz > 0);
         return (int) sz - 1;
@@ -1261,30 +1263,31 @@ int netdev_format(NetDev *netdev, char **ret) {
 
 int link_format(Link *link, char **ret) {
         _cleanup_free_ char *s = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t sz = 0;
         int r;
 
         assert(link);
         assert(ret);
 
-        {
-                _cleanup_fclose_ FILE *f = NULL;
-
-                f = open_memstream_unlocked(&s, &sz);
-                if (!f)
-                        return -ENOMEM;
+        f = open_memstream_unlocked(&s, &sz);
+        if (!f)
+                return -ENOMEM;
 
-                link_dump(link, f);
+        link_dump(link, f);
 
-                /* Add terminating 0, so that the output buffer is a valid string. */
-                fputc('\0', f);
+        /* Add terminating 0, so that the output buffer is a valid string. */
+        fputc('\0', f);
 
-                r = fflush_and_check(f);
-        }
+        r = fflush_and_check(f);
         if (r < 0)
                 return r;
 
-        assert(s);
+        f = safe_fclose(f);
+
+        if (!s)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(s);
         assert(sz > 0);
         return (int) sz - 1;
index a3d961dac3ca4ac913aa7f7d642f8d79d466bab5..5eb36ef6801f3fe4ea9511d7e366fb6667c0239f 100644 (file)
@@ -144,6 +144,7 @@ int config_parse_vlan_qos_maps(
         for (const char *p = rvalue;;) {
                 _cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL;
                 _cleanup_free_ char *w = NULL;
+                unsigned from, to;
 
                 r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
                 if (r == -ENOMEM)
@@ -155,20 +156,20 @@ int config_parse_vlan_qos_maps(
                 if (r == 0)
                         return 0;
 
-                m = new0(struct ifla_vlan_qos_mapping, 1);
-                if (!m)
-                        return log_oom();
-
-                r = parse_range(w, &m->from, &m->to);
+                r = parse_range(w, &from, &to);
                 if (r < 0) {
                         log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w);
                         continue;
                 }
 
-                if (m->to > m->from || m->to == 0 || m->from == 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s, ignoring: %s", lvalue, w);
-                        continue;
-                }
+                m = new(struct ifla_vlan_qos_mapping, 1);
+                if (!m)
+                        return log_oom();
+
+                *m = (struct ifla_vlan_qos_mapping) {
+                        .from = from,
+                        .to = to,
+                };
 
                 r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m));
                 if (r < 0) {
index aae619a0a8b58aff65a50ebcdff9ad18ebf68230..303b76c0c69b86b8ad3a7133d915460be3aec350 100644 (file)
@@ -148,12 +148,10 @@ static int manager_connect_bus(Manager *m) {
         if (r < 0)
                 return log_error_errno(r, "Failed to request match on Connected signal: %m");
 
-        r = sd_bus_match_signal_async(
+        r = bus_match_signal_async(
                         m->bus,
                         NULL,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
+                        bus_login_mgr,
                         "PrepareForSleep",
                         match_prepare_for_sleep, NULL, m);
         if (r < 0)
index b1c4f1cad8e4dba8563e7abcf8f0838395ff120d..c2ba00c4381c69bafddfc764f679436fec470cbc 100644 (file)
@@ -712,10 +712,9 @@ int veth_extra_parse(char ***l, const char *p) {
         if (r < 0)
                 return r;
         if (r == 0 || !ifname_valid(b)) {
-                free(b);
-                b = strdup(a);
-                if (!b)
-                        return -ENOMEM;
+                r = free_and_strdup(&b, a);
+                if (r < 0)
+                        return r;
         }
 
         if (p)
index 5d49e05064cf9c83c0451f979ba4b16668d5556c..74b15dcb44a99b1b8edb4d0e41c6524c0b1703cc 100644 (file)
@@ -30,6 +30,7 @@
 #include "btrfs-util.h"
 #include "build.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "cap-list.h"
 #include "capability-util.h"
@@ -2092,13 +2093,7 @@ static int resolved_listening(void) {
         if (r == 0)
                 return 0;
 
-        r = sd_bus_get_property_string(bus,
-                                       "org.freedesktop.resolve1",
-                                       "/org/freedesktop/resolve1",
-                                       "org.freedesktop.resolve1.Manager",
-                                       "DNSStubListener",
-                                       &error,
-                                       &dns_stub_listener_mode);
+        r = bus_get_property_string(bus, bus_resolve_mgr, "DNSStubListener", &error, &dns_stub_listener_mode);
         if (r < 0)
                 return log_debug_errno(r, "Failed to query DNSStubListener property: %s", bus_error_message(&error, r));
 
index d18f999841002996fdb996673eeb671acbfcafd2..eb15f508de00fcaf1edaec25ee97d39f7b004fa2 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "build.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "copy.h"
 #include "main-func.h"
 #include "pretty-print.h"
@@ -55,15 +56,7 @@ static int dump_state(int argc, char *argv[], void *userdata) {
 
         pager_open(arg_pager_flags);
 
-        r = sd_bus_call_method(
-                        bus,
-                        "org.freedesktop.oom1",
-                        "/org/freedesktop/oom1",
-                        "org.freedesktop.oom1.Manager",
-                        "DumpByFileDescriptor",
-                        &error,
-                        &reply,
-                        NULL);
+        r = bus_call_method(bus, bus_oom_mgr, "DumpByFileDescriptor", &error, &reply, NULL);
         if (r < 0)
                 return log_error_errno(r, "Failed to dump context: %s", bus_error_message(&error, r));
 
index 08a29ec77bd84ec075ecf50401ec07cc1c9c70d9..3f050cdbb29fadd4aa95b6e06dcb03511bbda0d3 100644 (file)
@@ -847,6 +847,9 @@ int manager_get_dump_string(Manager *m, char **ret) {
 
         f = safe_fclose(f);
 
+        if (!dump)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(dump);
         return 0;
 }
index 49c10b5e16c235d4f9860531e33a6eb76e664975..6309d2c4739907c3f81dac56e8eb91eaabb5f05f 100644 (file)
@@ -299,6 +299,11 @@ static int dump_kill_candidates(OomdCGroupContext **sorted, int n, int dump_unti
         if (r < 0)
                 return r;
 
+        f = safe_fclose(f);
+
+        if (!dump)
+                return -ENOMEM;
+
         return log_dump(LOG_INFO, dump);
 }
 
index e5f2f38a211a8bc797b3da1aaaafc5632989e3ed..7ab3ac6e97525bff924a2c23a853783f0a6169d8 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "bus-common-errors.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "chase.h"
 #include "conf-files.h"
 #include "copy.h"
@@ -780,13 +781,7 @@ static int unit_file_is_active(
                 _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
                 const char *at, *prefix, *joined;
 
-                r = sd_bus_message_new_method_call(
-                                bus,
-                                &m,
-                                "org.freedesktop.systemd1",
-                                "/org/freedesktop/systemd1",
-                                "org.freedesktop.systemd1.Manager",
-                                "ListUnitsByPatterns");
+                r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "ListUnitsByPatterns");
                 if (r < 0)
                         return r;
 
index eec9c63d0b8ca0f1026c5b4ed6c2265ae7544784..39f17a8de7b0c15576d442fefac8bd1dce70dcac 100644 (file)
@@ -242,13 +242,7 @@ static int maybe_reload(sd_bus **bus) {
         if (r < 0)
                 return r;
 
-        r = sd_bus_message_new_method_call(
-                        *bus,
-                        &m,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "Reload");
+        r = bus_message_new_method_call(*bus, &m, bus_systemd_mgr, "Reload");
         if (r < 0)
                 return bus_log_create_error(r);
 
@@ -566,12 +560,10 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) {
         if (!names)
                 return log_oom();
 
-        r = sd_bus_message_new_method_call(
+        r = bus_message_new_method_call(
                 bus,
                 &m,
-                "org.freedesktop.systemd1",
-                "/org/freedesktop/systemd1",
-                "org.freedesktop.systemd1.Manager",
+                bus_systemd_mgr,
                 enable ? "EnableUnitFilesWithFlags" : "DisableUnitFilesWithFlags");
         if (r < 0)
                 return bus_log_create_error(r);
index 1c1e5bc3aadda2d97cd5727dca301d0e0391a1fc..12d0d28babb9a896c0cc6b18fc771f22833a4e63 100644 (file)
@@ -3,6 +3,7 @@
 #include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "bus-get-properties.h"
+#include "bus-locator.h"
 #include "bus-log-control-api.h"
 #include "bus-message-util.h"
 #include "bus-polkit.h"
@@ -2282,12 +2283,10 @@ int manager_connect_bus(Manager *m) {
         if (r < 0)
                 return log_error_errno(r, "Failed to attach bus to event loop: %m");
 
-        r = sd_bus_match_signal_async(
+        r = bus_match_signal_async(
                         m->bus,
                         NULL,
-                        "org.freedesktop.login1",
-                        "/org/freedesktop/login1",
-                        "org.freedesktop.login1.Manager",
+                        bus_login_mgr,
                         "PrepareForSleep",
                         match_prepare_for_sleep,
                         NULL,
index fc076856b601d636d1b6e3095bfaaaa14c7eefef..e7c18c29a0b2e81dbb8f5e40c84d2b63f5871c55 100644 (file)
@@ -867,10 +867,14 @@ static int dnssec_rrset_serialize_sig(
         }
 
         r = fflush_and_check(f);
-        f = safe_fclose(f);  /* sig_data may be reallocated when f is closed. */
         if (r < 0)
                 return r;
 
+        f = safe_fclose(f);  /* sig_data may be reallocated when f is closed. */
+
+        if (!sig_data)
+                return -ENOMEM;
+
         *ret_sig_data = TAKE_PTR(sig_data);
         *ret_sig_size = sig_size;
         return 0;
index d3175b1b9de30c265ae23c520b344f8545e11a0b..44d1d1f1e6e4ddcaac83fa4d4593ca56e9c516fd 100644 (file)
@@ -1222,19 +1222,20 @@ int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical) {
                 return 0;
 
         r = dns_packet_append_rr(&packet, rr, 0, &start, &rds);
-        if (r < 0)
+        if (r < 0) {
+                dns_packet_unref(&packet);
                 return r;
+        }
 
         assert(start == 0);
         assert(packet._data);
 
         free(rr->wire_format);
-        rr->wire_format = packet._data;
+        rr->wire_format = TAKE_PTR(packet._data);
         rr->wire_format_size = packet.size;
         rr->wire_format_rdata_offset = rds;
         rr->wire_format_canonical = canonical;
 
-        packet._data = NULL;
         dns_packet_unref(&packet);
 
         return 0;
index 184d8e3f3d33982123a4c415edd65c0daf8d7c29..67786d39fdbca3633c561eecec7bb086faeafc3c 100644 (file)
@@ -519,6 +519,11 @@ static int manager_sigusr1(sd_event_source *s, const struct signalfd_siginfo *si
         if (fflush_and_check(f) < 0)
                 return log_oom();
 
+        f = safe_fclose(f);
+
+        if (!buffer)
+                return -ENOMEM;
+
         log_dump(LOG_INFO, buffer);
         return 0;
 }
index d8aeb7061f9036ee32d1862a96d1f4eeba5b8976..976d197bb49b97b46c8d87cabfb45c66e9a5c5ad 100644 (file)
@@ -7,6 +7,7 @@
 #include "af-list.h"
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-locator.h"
 #include "dns-type.h"
 #include "random-util.h"
 #include "resolved-def.h"
@@ -46,13 +47,7 @@ static void test_rr_lookup(sd_bus *bus, const char *name, uint16_t type, const c
                 name = m;
         }
 
-        assert_se(sd_bus_message_new_method_call(
-                                  bus,
-                                  &req,
-                                  "org.freedesktop.resolve1",
-                                  "/org/freedesktop/resolve1",
-                                  "org.freedesktop.resolve1.Manager",
-                                  "ResolveRecord") >= 0);
+        assert_se(bus_message_new_method_call(bus, &req, bus_resolve_mgr, "ResolveRecord") >= 0);
 
         assert_se(sd_bus_message_append(req, "isqqt", 0, name, DNS_CLASS_IN, type, UINT64_C(0)) >= 0);
 
@@ -83,13 +78,7 @@ static void test_hostname_lookup(sd_bus *bus, const char *name, int family, cons
                 name = m;
         }
 
-        assert_se(sd_bus_message_new_method_call(
-                                  bus,
-                                  &req,
-                                  "org.freedesktop.resolve1",
-                                  "/org/freedesktop/resolve1",
-                                  "org.freedesktop.resolve1.Manager",
-                                  "ResolveHostname") >= 0);
+        assert_se(bus_message_new_method_call(bus, &req, bus_resolve_mgr, "ResolveHostname") >= 0);
 
         assert_se(sd_bus_message_append(req, "isit", 0, name, family, UINT64_C(0)) >= 0);
 
index 5b9a6dbc438f681e5e817b361a8487206939ed88..ff7a872bdb3310a6ccade423f97c8e7736c26520 100644 (file)
@@ -39,6 +39,12 @@ const BusLocator* const bus_network_mgr = &(BusLocator){
         .interface = "org.freedesktop.network1.Manager"
 };
 
+const BusLocator* const bus_oom_mgr = &(BusLocator){
+        .destination = "org.freedesktop.oom1",
+        .path = "/org/freedesktop/oom1",
+        .interface = "org.freedesktop.oom1.Manager"
+};
+
 const BusLocator* const bus_portable_mgr = &(BusLocator){
         .destination = "org.freedesktop.portable1",
         .path = "/org/freedesktop/portable1",
@@ -63,6 +69,12 @@ const BusLocator* const bus_timedate = &(BusLocator){
         .interface = "org.freedesktop.timedate1"
 };
 
+const BusLocator* const bus_timesync_mgr = &(BusLocator){
+        .destination = "org.freedesktop.timesync1",
+        .path = "/org/freedesktop/timesync1",
+        .interface = "org.freedesktop.timesync1.Manager"
+};
+
 const BusLocator* const bus_hostname = &(BusLocator){
         .destination = "org.freedesktop.hostname1",
         .path = "/org/freedesktop/hostname1",
index 9662c906e18d72fba31952cd138ff30d4b3fdb6a..4f50a9727f560c34d742bbeeb375aa554fac08cb 100644 (file)
@@ -10,16 +10,18 @@ typedef struct BusLocator {
 } BusLocator;
 
 extern const BusLocator* const bus_home_mgr;
+extern const BusLocator* const bus_hostname;
 extern const BusLocator* const bus_import_mgr;
 extern const BusLocator* const bus_locale;
 extern const BusLocator* const bus_login_mgr;
 extern const BusLocator* const bus_machine_mgr;
 extern const BusLocator* const bus_network_mgr;
+extern const BusLocator* const bus_oom_mgr;
 extern const BusLocator* const bus_portable_mgr;
 extern const BusLocator* const bus_resolve_mgr;
 extern const BusLocator* const bus_systemd_mgr;
 extern const BusLocator* const bus_timedate;
-extern const BusLocator* const bus_hostname;
+extern const BusLocator* const bus_timesync_mgr;
 
 /* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface strings encapsulated
  * within a single struct. */
index ca0d77c1367ab6c0ab2fd9f9a8b2085c6800c504..b99883a088e23353c8e32e9be39ff6e222019c64 100644 (file)
@@ -628,6 +628,9 @@ static int method_dump_memory_state_by_fd(sd_bus_message *message, void *userdat
 
         dump_file = safe_fclose(dump_file);
 
+        if (!dump)
+                return -ENOMEM;
+
         fd = acquire_data_fd(dump, dump_size, 0);
         if (fd < 0)
                 return fd;
index 86a6d3f6080971b1972c3ed7d622b4d137bc0981..fa19e4c95a5e8dcb811fb0421763c644cc9831ec 100644 (file)
@@ -12,6 +12,7 @@
 #include "alloc-util.h"
 #include "calendarspec.h"
 #include "errno-util.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "macro.h"
 #include "parse-util.h"
@@ -37,8 +38,7 @@ assert_cc(INT_MAX >= USEC_PER_SEC);
 static CalendarComponent* chain_free(CalendarComponent *c) {
         while (c) {
                 CalendarComponent *n = c->next;
-                free(c);
-                c = n;
+                free_and_replace(c, n);
         }
         return NULL;
 }
@@ -337,9 +337,9 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us
 }
 
 int calendar_spec_to_string(const CalendarSpec *c, char **p) {
-        char *buf = NULL;
+        _cleanup_free_ char *buf = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t sz = 0;
-        FILE *f;
         int r;
 
         assert(c);
@@ -384,14 +384,15 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
         }
 
         r = fflush_and_check(f);
-        fclose(f);
-
-        if (r < 0) {
-                free(buf);
+        if (r < 0)
                 return r;
-        }
 
-        *p = buf;
+        f = safe_fclose(f);
+
+        if (!buf)
+                return -ENOMEM;
+
+        *p = TAKE_PTR(buf);
         return 0;
 }
 
index 98c47d912500c9783cfdd35a6327fe778a0ff630..5885215a1ca24876bebbee9b847a02b5927863b6 100644 (file)
@@ -621,8 +621,13 @@ static int parse_core(int fd, const char *executable, char **ret, JsonVariant **
                         return log_warning_errno(r, "Could not parse core file, flushing file buffer failed: %m");
 
                 c.f = safe_fclose(c.f);
+
+                if (!buf)
+                        return log_oom();
+
                 *ret = TAKE_PTR(buf);
         }
+
         if (ret_package_metadata)
                 *ret_package_metadata = TAKE_PTR(package_metadata);
 
@@ -735,8 +740,13 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
                         return log_warning_errno(r, "Could not parse ELF file, flushing file buffer failed: %m");
 
                 c.f = safe_fclose(c.f);
+
+                if (!buf)
+                        return log_oom();
+
                 *ret = TAKE_PTR(buf);
         }
+
         if (ret_package_metadata)
                 *ret_package_metadata = TAKE_PTR(elf_metadata);
 
index 204e8b68b6d5903c9b066862e60b68990816e819..83b749d677a4a9d90c012a6f0b53a9957abe3882 100644 (file)
@@ -2537,6 +2537,9 @@ int table_format(Table *t, char **ret) {
 
         f = safe_fclose(f);
 
+        if (!buf)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(buf);
 
         return 0;
index 73050b55c856e20885db3f71b30f3e77a49b46f3..5bf00f009fcba9a8a8a1a0ff61c611a0a73025d6 100644 (file)
@@ -1769,6 +1769,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
 
 int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
         _cleanup_free_ char *s = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         size_t sz = 0;
         int r;
 
@@ -1781,26 +1782,26 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
         if (flags & JSON_FORMAT_OFF)
                 return -ENOEXEC;
 
-        {
-                _cleanup_fclose_ FILE *f = NULL;
-
-                f = open_memstream_unlocked(&s, &sz);
-                if (!f)
-                        return -ENOMEM;
+        f = open_memstream_unlocked(&s, &sz);
+        if (!f)
+                return -ENOMEM;
 
-                r = json_variant_dump(v, flags, f, NULL);
-                if (r < 0)
-                        return r;
+        r = json_variant_dump(v, flags, f, NULL);
+        if (r < 0)
+                return r;
 
-                /* Add terminating 0, so that the output buffer is a valid string. */
-                fputc('\0', f);
+        /* Add terminating 0, so that the output buffer is a valid string. */
+        fputc('\0', f);
 
-                r = fflush_and_check(f);
-        }
+        r = fflush_and_check(f);
         if (r < 0)
                 return r;
 
-        assert(s);
+        f = safe_fclose(f);
+
+        if (!s)
+                return -ENOMEM;
+
         *ret = TAKE_PTR(s);
         assert(sz > 0);
         return (int) sz - 1;
index 31390fbd89d51581a88b6480450409380ae31933..e5a1f94f2a2945478c6c9f2918ea18fb19ccfaa3 100644 (file)
@@ -284,7 +284,7 @@ int specifier_architecture(char specifier, const void *data, const char *root, c
  * installation. */
 
 static int parse_os_release_specifier(const char *root, const char *id, char **ret) {
-        char *v = NULL;
+        _cleanup_free_ char *v = NULL;
         int r;
 
         assert(ret);
@@ -293,7 +293,7 @@ static int parse_os_release_specifier(const char *root, const char *id, char **r
         if (r >= 0)
                 /* parse_os_release() calls parse_env_file() which only sets the return value for
                  * entries found. Let's make sure we set the return value in all cases. */
-                *ret = v;
+                *ret = TAKE_PTR(v);
 
         /* Translate error for missing os-release file to EUNATCH. */
         return r == -ENOENT ? -EUNATCH : r;
index a8a451ee1a88339908f1119ffa81655a6c09dd39..a9445c1a619d37fba2588ccd3ef64414b212f288 100644 (file)
@@ -147,13 +147,7 @@ static int lock_all_homes(void) {
         if (r < 0)
                 return log_warning_errno(r, "Failed to connect to system bus, ignoring: %m");
 
-        r = sd_bus_message_new_method_call(
-                        bus,
-                        &m,
-                        "org.freedesktop.home1",
-                        "/org/freedesktop/home1",
-                        "org.freedesktop.home1.Manager",
-                        "LockAllHomes");
+        r = bus_message_new_method_call(bus, &m, bus_home_mgr, "LockAllHomes");
         if (r < 0)
                 return bus_log_create_error(r);
 
index ee5f8ec12ecf261cdfcc319429ec58603444149d..83b06902ab3046046d381474c4bb6c4ecfbacb1f 100644 (file)
 static const char *arg_dest = NULL;
 
 static int generate_symlink(void) {
-        _cleanup_free_ char *j = NULL;
-
         FOREACH_STRING(p, "/system-update", "/etc/system-update") {
-                if (laccess(p, F_OK) >= 0)
-                        goto link_found;
+                if (laccess(p, F_OK) >= 0) {
+                        _cleanup_free_ char *j = NULL;
+
+                        j = path_join(arg_dest, SPECIAL_DEFAULT_TARGET);
+                        if (!j)
+                                return log_oom();
+
+                        if (symlink(SYSTEM_DATA_UNIT_DIR "/system-update.target", j) < 0)
+                                return log_error_errno(errno, "Failed to create symlink %s: %m", j);
+
+                        return 1;
+                }
 
                 if (errno != ENOENT)
                         log_warning_errno(errno, "Failed to check if %s symlink exists, ignoring: %m", p);
         }
 
         return 0;
-
-link_found:
-        j = path_join(arg_dest, SPECIAL_DEFAULT_TARGET);
-        if (!j)
-                return log_oom();
-
-        if (symlink(SYSTEM_DATA_UNIT_DIR "/system-update.target", j) < 0)
-                return log_error_errno(errno, "Failed to create symlink %s: %m", j);
-
-        return 1;
 }
 
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
index 404196f409e76b21572cbed8584c11b59b231224..467c9a6ad3981ece6d1d8c4ae09ddd1362d18cec 100644 (file)
@@ -9,11 +9,13 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <linux/usb/ch11.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "device-util.h"
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "parse-util.h"
@@ -487,8 +489,51 @@ static void handle_scsi_tape(sd_device *dev, char **path) {
                 path_prepend(path, "st%c", name[2]);
 }
 
+static int get_usb_revision(sd_device *dev) {
+        uint8_t protocol;
+        const char *s;
+        int r;
+
+        assert(dev);
+
+        /* Returns usb revision 1, 2, or 3. */
+
+        r = sd_device_get_sysattr_value(dev, "bDeviceProtocol", &s);
+        if (r < 0)
+                return r;
+
+        r = safe_atou8_full(s, 16, &protocol);
+        if (r < 0)
+                return r;
+
+        switch (protocol) {
+        case USB_HUB_PR_HS_NO_TT: /* Full speed hub (USB1) or Hi-speed hub without TT (USB2) */
+
+                /* See speed_show() in drivers/usb/core/sysfs.c of the kernel. */
+                r = sd_device_get_sysattr_value(dev, "speed", &s);
+                if (r < 0)
+                        return r;
+
+                if (streq(s, "480"))
+                        return 2;
+
+                return 1;
+
+        case USB_HUB_PR_HS_SINGLE_TT: /* Hi-speed hub with single TT */
+        case USB_HUB_PR_HS_MULTI_TT: /* Hi-speed hub with multiple TT */
+                return 2;
+
+        case USB_HUB_PR_SS: /* Super speed hub */
+                return 3;
+
+        default:
+                return -EPROTONOSUPPORT;
+        }
+}
+
 static sd_device *handle_usb(sd_device *parent, char **path) {
         const char *devtype, *str, *port;
+        int r;
 
         if (sd_device_get_devtype(parent, &devtype) < 0)
                 return parent;
@@ -502,12 +547,28 @@ static sd_device *handle_usb(sd_device *parent, char **path) {
                 return parent;
         port++;
 
-        /* USB host number may change across reboots (and probably even without reboot). The part after
-         * USB host number is determined by device topology and so does not change. Hence, drop the
-         * host number and always use '0' instead. */
+        parent = skip_subsystem(parent, "usb");
+        if (!parent)
+                return NULL;
 
-        path_prepend(path, "usb-0:%s", port);
-        return skip_subsystem(parent, "usb");
+        /* USB host number may change across reboots (and probably even without reboot). The part after USB
+         * host number is determined by device topology and so does not change. Hence, drop the host number
+         * and always use '0' instead.
+         *
+         * xHCI host controllers may register two (or more?) USB root hubs for USB 2.0 and USB 3.0, and the
+         * sysname, whose host number replaced with 0, of a device under the hubs may conflict with others.
+         * To avoid the conflict, let's include the USB revision of the root hub to the PATH_ID.
+         * See issue https://github.com/systemd/systemd/issues/19406 for more details. */
+        r = get_usb_revision(parent);
+        if (r < 0) {
+                log_device_debug_errno(parent, r, "Failed to get the USB revision number, ignoring: %m");
+                path_prepend(path, "usb-0:%s", port);
+        } else {
+                assert(r > 0);
+                path_prepend(path, "usbv%i-0:%s", r, port);
+        }
+
+        return parent;
 }
 
 static sd_device *handle_bcma(sd_device *parent, char **path) {
@@ -589,6 +650,66 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
         return 0;
 }
 
+static void add_id_with_usb_revision(sd_device *dev, bool test, char *path) {
+        char *p;
+        int r;
+
+        assert(dev);
+        assert(path);
+
+        /* When the path contains the USB revision, let's adds ID_PATH_WITH_USB_REVISION property and
+         * drop the version specifier for later use. */
+
+        p = strstrafter(path, "-usbv");
+        if (!p)
+                return;
+        if (!ascii_isdigit(p[0]))
+                return;
+        if (p[1] != '-')
+                return;
+
+        r = udev_builtin_add_property(dev, test, "ID_PATH_WITH_USB_REVISION", path);
+        if (r < 0)
+                log_device_debug_errno(dev, r, "Failed to add ID_PATH_WITH_USB_REVISION property, ignoring: %m");
+
+        /* Drop the USB revision specifier for backward compatibility. */
+        memmove(p - 1, p + 1, strlen(p + 1) + 1);
+}
+
+static void add_id_tag(sd_device *dev, bool test, const char *path) {
+        char tag[UDEV_NAME_SIZE];
+        size_t i = 0;
+        int r;
+
+        /* compose valid udev tag name */
+        for (const char *p = path; *p; p++) {
+                if (ascii_isdigit(*p) ||
+                    ascii_isalpha(*p) ||
+                    *p == '-') {
+                        tag[i++] = *p;
+                        continue;
+                }
+
+                /* skip all leading '_' */
+                if (i == 0)
+                        continue;
+
+                /* avoid second '_' */
+                if (tag[i-1] == '_')
+                        continue;
+
+                tag[i++] = '_';
+        }
+        /* strip trailing '_' */
+        while (i > 0 && tag[i-1] == '_')
+                i--;
+        tag[i] = '\0';
+
+        r = udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
+        if (r < 0)
+                log_device_debug_errno(dev, r, "Failed to add ID_PATH_TAG property, ignoring: %m");
+}
+
 static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test) {
         sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         _cleanup_(sd_device_unrefp) sd_device *dev_other_branch = NULL;
@@ -748,37 +869,13 @@ static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test)
             !supported_transport)
                 return -ENOENT;
 
-        {
-                char tag[UDEV_NAME_SIZE];
-                size_t i = 0;
-
-                /* compose valid udev tag name */
-                for (const char *p = path; *p; p++) {
-                        if (ascii_isdigit(*p) ||
-                            ascii_isalpha(*p) ||
-                            *p == '-') {
-                                tag[i++] = *p;
-                                continue;
-                        }
-
-                        /* skip all leading '_' */
-                        if (i == 0)
-                                continue;
-
-                        /* avoid second '_' */
-                        if (tag[i-1] == '_')
-                                continue;
+        add_id_with_usb_revision(dev, test, path);
 
-                        tag[i++] = '_';
-                }
-                /* strip trailing '_' */
-                while (i > 0 && tag[i-1] == '_')
-                        i--;
-                tag[i] = '\0';
+        r = udev_builtin_add_property(dev, test, "ID_PATH", path);
+        if (r < 0)
+                log_device_debug_errno(dev, r, "Failed to add ID_PATH property, ignoring: %m");
 
-                udev_builtin_add_property(dev, test, "ID_PATH", path);
-                udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
-        }
+        add_id_tag(dev, test, path);
 
         /*
          * Compatible link generation for ATA devices
index d87670eb24aaa6e4c90ec6c3844656b830d85db8..60b2bf030be6d98a7dafa965d451320f3b350ad4 100755 (executable)
@@ -635,7 +635,7 @@ def make_uki(opts):
 
     if sign_kernel:
         linux_signed = tempfile.NamedTemporaryFile(prefix='linux-signed')
-        linux = linux_signed.name
+        linux = pathlib.Path(linux_signed.name)
         sign(sign_tool, opts.linux, linux, opts=opts)
     else:
         linux = opts.linux
index 7449a2321c5a715e95d2876499cf127587dc55db..5651ec11dacf9900fcebef702020d91b7e7a3a06 100644 (file)
 
 #include "alloc-util.h"
 #include "bus-error.h"
+#include "bus-locator.h"
 #include "bus-util.h"
 #include "format-util.h"
 #include "log.h"
 #include "macro.h"
 #include "main-func.h"
 #include "process-util.h"
+#include "random-util.h"
 #include "special.h"
 #include "stdio-util.h"
 #include "strv.h"
 #include "unit-name.h"
 #include "utmp-wtmp.h"
+#include "verbs.h"
 
 typedef struct Context {
         sd_bus *bus;
@@ -43,27 +46,23 @@ static void context_clear(Context *c) {
 #endif
 }
 
-static usec_t get_startup_monotonic_time(Context *c) {
+static int get_startup_monotonic_time(Context *c, usec_t *ret) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-        usec_t t = 0;
         int r;
 
         assert(c);
+        assert(ret);
 
-        r = sd_bus_get_property_trivial(
+        r = bus_get_property_trivial(
                         c->bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
+                        bus_systemd_mgr,
                         "UserspaceTimestampMonotonic",
                         &error,
-                        't', &t);
-        if (r < 0) {
-                log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r));
-                return 0;
-        }
+                        't', ret);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to get timestamp, ignoring: %s", bus_error_message(&error, r));
 
-        return t;
+        return 0;
 }
 
 static int get_current_runlevel(Context *c) {
@@ -71,116 +70,129 @@ static int get_current_runlevel(Context *c) {
                 const int runlevel;
                 const char *special;
         } table[] = {
-                /* The first target of this list that is active or has
-                 * a job scheduled wins. We prefer runlevels 5 and 3
-                 * here over the others, since these are the main
-                 * runlevels used on Fedora. It might make sense to
-                 * change the order on some distributions. */
+                /* The first target of this list that is active or has a job scheduled wins. We prefer
+                 * runlevels 5 and 3 here over the others, since these are the main runlevels used on Fedora.
+                 * It might make sense to change the order on some distributions. */
                 { '5', SPECIAL_GRAPHICAL_TARGET  },
                 { '3', SPECIAL_MULTI_USER_TARGET },
                 { '1', SPECIAL_RESCUE_TARGET     },
         };
-
-        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
 
         assert(c);
 
-        for (size_t i = 0; i < ELEMENTSOF(table); i++) {
-                _cleanup_free_ char *state = NULL, *path = NULL;
-
-                path = unit_dbus_path_from_name(table[i].special);
-                if (!path)
-                        return log_oom();
-
-                r = sd_bus_get_property_string(
-                                c->bus,
-                                "org.freedesktop.systemd1",
-                                path,
-                                "org.freedesktop.systemd1.Unit",
-                                "ActiveState",
-                                &error,
-                                &state);
-                if (r < 0)
-                        return log_warning_errno(r, "Failed to get state: %s", bus_error_message(&error, r));
+        for (unsigned n_attempts = 0;;) {
+                FOREACH_ARRAY(e, table, ELEMENTSOF(table)) {
+                        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+                        _cleanup_free_ char *state = NULL, *path = NULL;
+
+                        path = unit_dbus_path_from_name(e->special);
+                        if (!path)
+                                return log_oom();
+
+                        r = sd_bus_get_property_string(
+                                        c->bus,
+                                        "org.freedesktop.systemd1",
+                                        path,
+                                        "org.freedesktop.systemd1.Unit",
+                                        "ActiveState",
+                                        &error,
+                                        &state);
+                        if ((r == -ENOTCONN ||
+                             sd_bus_error_has_names(&error,
+                                                    SD_BUS_ERROR_NO_REPLY,
+                                                    SD_BUS_ERROR_DISCONNECTED)) &&
+                            ++n_attempts < 64) {
+
+                                /* systemd might have dropped off momentarily, let's not make this an error,
+                                 * and wait some random time. Let's pick a random time in the range 0ms…250ms,
+                                 * linearly scaled by the number of failed attempts. */
+
+                                usec_t usec = random_u64_range(UINT64_C(10) * USEC_PER_MSEC +
+                                                               UINT64_C(240) * USEC_PER_MSEC * n_attempts/64);
+                                log_debug_errno(r, "Failed to get state of %s, retrying after %s: %s",
+                                                e->special, FORMAT_TIMESPAN(usec, USEC_PER_MSEC), bus_error_message(&error, r));
+                                (void) usleep(usec);
+                                goto reconnect;
+                        }
+                        if (r < 0)
+                                return log_warning_errno(r, "Failed to get state of %s: %s", e->special, bus_error_message(&error, r));
+
+                        if (STR_IN_SET(state, "active", "reloading"))
+                                return e->runlevel;
+                }
 
-                if (STR_IN_SET(state, "active", "reloading"))
-                        return table[i].runlevel;
-        }
+                return 0;
 
-        return 0;
+reconnect:
+                c->bus = sd_bus_flush_close_unref(c->bus);
+                r = bus_connect_system_systemd(&c->bus);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to reconnect to system bus: %m");
+        }
 }
 
-static int on_reboot(Context *c) {
-        int r = 0, q;
-        usec_t t;
-        usec_t boottime;
+static int on_reboot(int argc, char *argv[], void *userdata) {
+        Context *c = ASSERT_PTR(userdata);
+        usec_t t = 0, boottime;
+        int r, q = 0;
 
-        assert(c);
-
-        /* We finished start-up, so let's write the utmp
-         * record and send the audit msg */
+        /* We finished start-up, so let's write the utmp record and send the audit msg. */
 
 #if HAVE_AUDIT
         if (c->audit_fd >= 0)
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
                     errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
 #endif
 
-        /* If this call fails it will return 0, which
-         * utmp_put_reboot() will then fix to the current time */
-        t = get_startup_monotonic_time(c);
+        /* If this call fails, then utmp_put_reboot() will fix to the current time. */
+        (void) get_startup_monotonic_time(c, &t);
         boottime = map_clock_usec(t, CLOCK_MONOTONIC, CLOCK_REALTIME);
-        /* We query the recorded monotonic time here (instead of the system clock CLOCK_REALTIME),
-         * even though we actually want the system clock time. That's because there's a likely
-         * chance that the system clock wasn't set right during early boot. By manually converting
-         * the monotonic clock to the system clock here we can compensate
-         * for incorrectly set clocks during early boot. */
+        /* We query the recorded monotonic time here (instead of the system clock CLOCK_REALTIME), even
+         * though we actually want the system clock time. That's because there's a likely chance that the
+         * system clock wasn't set right during early boot. By manually converting the monotonic clock to the
+         * system clock here we can compensate for incorrectly set clocks during early boot. */
 
-        q = utmp_put_reboot(boottime);
-        if (q < 0)
-                r = log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_reboot(boottime);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
-static int on_shutdown(Context *c) {
-        int r = 0, q;
-
-        assert(c);
+static int on_shutdown(int argc, char *argv[], void *userdata) {
+        int r, q = 0;
 
-        /* We started shut-down, so let's write the utmp
-         * record and send the audit msg */
+        /* We started shut-down, so let's write the utmp record and send the audit msg. */
 
 #if HAVE_AUDIT
+        Context *c = ASSERT_PTR(userdata);
+
         if (c->audit_fd >= 0)
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
                     errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
 #endif
 
-        q = utmp_put_shutdown();
-        if (q < 0)
-                r = log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_shutdown();
+        if (r < 0)
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
-static int on_runlevel(Context *c) {
-        int r = 0, q, previous, runlevel;
+static int on_runlevel(int argc, char *argv[], void *userdata) {
+        Context *c = ASSERT_PTR(userdata);
+        int r, q = 0, previous, runlevel;
 
-        assert(c);
-
-        /* We finished changing runlevel, so let's write the
-         * utmp record and send the audit msg */
+        /* We finished changing runlevel, so let's write the utmp record and send the audit msg. */
 
         /* First, get last runlevel */
-        q = utmp_get_runlevel(&previous, NULL);
-
-        if (q < 0) {
-                if (!IN_SET(q, -ESRCH, -ENOENT))
-                        return log_error_errno(q, "Failed to get current runlevel: %m");
+        r = utmp_get_runlevel(&previous, NULL);
+        if (r < 0) {
+                if (!IN_SET(r, -ESRCH, -ENOENT))
+                        return log_error_errno(r, "Failed to get the last runlevel from utmp: %m");
 
                 previous = 0;
         }
@@ -190,7 +202,7 @@ static int on_runlevel(Context *c) {
         if (runlevel < 0)
                 return runlevel;
         if (runlevel == 0) {
-                log_warning("Failed to get new runlevel, utmp update skipped.");
+                log_warning("Failed to get the current runlevel, utmp update skipped.");
                 return 0;
         }
 
@@ -207,18 +219,25 @@ static int on_runlevel(Context *c) {
 
                 if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s,
                                                 "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM)
-                        r = log_error_errno(errno, "Failed to send audit message: %m");
+                        q = log_error_errno(errno, "Failed to send audit message: %m");
         }
 #endif
 
-        q = utmp_put_runlevel(runlevel, previous);
-        if (q < 0 && !IN_SET(q, -ESRCH, -ENOENT))
-                return log_error_errno(q, "Failed to write utmp record: %m");
+        r = utmp_put_runlevel(runlevel, previous);
+        if (r < 0 && !IN_SET(r, -ESRCH, -ENOENT))
+                return log_error_errno(r, "Failed to write utmp record: %m");
 
-        return r;
+        return q;
 }
 
 static int run(int argc, char *argv[]) {
+        static const Verb verbs[] = {
+                { "reboot",   1, 1, 0, on_reboot   },
+                { "shutdown", 1, 1, 0, on_shutdown },
+                { "runlevel", 1, 1, 0, on_runlevel },
+                {}
+        };
+
         _cleanup_(context_clear) Context c = {
 #if HAVE_AUDIT
                 .audit_fd = -EBADF,
@@ -226,10 +245,6 @@ static int run(int argc, char *argv[]) {
         };
         int r;
 
-        if (argc != 2)
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                       "This program requires one argument.");
-
         log_setup();
 
         umask(0022);
@@ -238,20 +253,14 @@ static int run(int argc, char *argv[]) {
         /* If the kernel lacks netlink or audit support, don't worry about it. */
         c.audit_fd = audit_open();
         if (c.audit_fd < 0)
-                log_full_errno(IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT) ? LOG_DEBUG : LOG_ERR,
-                               errno, "Failed to connect to audit log: %m");
+                log_full_errno(IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT) ? LOG_DEBUG : LOG_WARNING,
+                               errno, "Failed to connect to audit log, ignoring: %m");
 #endif
         r = bus_connect_system_systemd(&c.bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to get D-Bus connection: %m");
 
-        if (streq(argv[1], "reboot"))
-                return on_reboot(&c);
-        if (streq(argv[1], "shutdown"))
-                return on_shutdown(&c);
-        if (streq(argv[1], "runlevel"))
-                return on_runlevel(&c);
-        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown command %s", argv[1]);
+        return dispatch_verb(argc, argv, verbs, &c);
 }
 
 DEFINE_MAIN_FUNCTION(run);
index 3b8d47d9b1db5d884f7e141e4907916232e16d62..c71077d274a69ea0367b51c4a458d161ed22e221 100644 (file)
@@ -3,7 +3,9 @@ MTUBytes=2000
 
 [VLAN]
 Id=99
-GVRP=true
-MVRP=true
-LooseBinding=true
-ReorderHeader=true
+GVRP=yes
+MVRP=yes
+LooseBinding=yes
+ReorderHeader=yes
+EgressQOSMaps=0-1 1-3 10-3 6-6 7-7
+IngressQOSMaps=15-13 20-100
index fe72f37ce4f478faaa21bdde6751675a120e4074..8b01718d55e649379b602dbea496f8262194f2eb 100755 (executable)
@@ -1285,12 +1285,14 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
         output = check_output('ip -d link show vlan99')
         print(output)
-        self.assertRegex(output, ' mtu 2000 ')
-        self.assertRegex(output, 'REORDER_HDR')
-        self.assertRegex(output, 'LOOSE_BINDING')
-        self.assertRegex(output, 'GVRP')
-        self.assertRegex(output, 'MVRP')
-        self.assertRegex(output, ' id 99 ')
+        self.assertIn(' mtu 2000 ', output)
+        self.assertIn('REORDER_HDR', output)
+        self.assertIn('LOOSE_BINDING', output)
+        self.assertIn('GVRP', output)
+        self.assertIn('MVRP', output)
+        self.assertIn(' id 99 ', output)
+        self.assertIn('ingress-qos-map { 4:100 7:13 }', output)
+        self.assertIn('egress-qos-map { 0:1 1:3 6:6 7:7 10:3 }', output)
 
         output = check_output('ip -4 address show dev test1')
         print(output)
index a55cc526a54edf69eebea85c95ffc7f9fafb5ea0..9074e0968f8931d9597b7629abaa88f582e48bf2 100644 (file)
@@ -1,10 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=TEST-01-BASIC
-# Order the test unit after systemd-update-utmp-runlevel.service, since
-# the service doesn't play well with daemon-reexec
-# See: https://github.com/systemd/systemd/issues/27167
-After=multi-user.target systemd-update-utmp-runlevel.service
+After=multi-user.target
 Wants=systemd-resolved.service systemd-networkd.service
 
 [Service]
index 91dd47ca145717d2612746507b62376a7aab7a0f..475eaa2923df5195ec17f6ab76abeefcd611a079 100755 (executable)
@@ -44,4 +44,17 @@ systemctl daemon-reload
 # of systemd-analyze blame. See issue #27187.
 systemd-analyze blame
 
+# Test for 'systemd-update-utmp runlevel' vs 'systemctl daemon-reexec'.
+# See issue #27163.
+# shellcheck disable=SC2034
+for _ in {0..10}; do
+    systemctl daemon-reexec &
+    pid_reexec=$!
+    # shellcheck disable=SC2034
+    for _ in {0..10}; do
+        SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/systemd-update-utmp runlevel
+    done
+    wait "$pid_reexec"
+done
+
 echo OK >/testok
index e9d88e1c8370f5e88aca3bc93b5f97e33cf5ee93..659882ed7ae36f2699a71aaa7029ebd3c760acea 100755 (executable)
@@ -522,7 +522,9 @@ testcase_session_properties() {
     /usr/lib/systemd/tests/unit-tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}" /dev/tty2
 }
 
-testcase_list_users_sessions() {
+testcase_list_users_sessions_seats() {
+    local session seat
+
     if [[ ! -c /dev/tty2 ]]; then
         echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
         return
@@ -534,10 +536,21 @@ testcase_list_users_sessions() {
     # Activate the session
     loginctl activate "$(loginctl --no-legend | awk '$3 == "logind-test-user" { print $1 }')"
 
+    session=$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $1 }')
+    : check that we got a valid session id
+    busctl get-property org.freedesktop.login1 "/org/freedesktop/login1/session/_3${session?}" org.freedesktop.login1.Session Id
+    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $2 }')" "$(id -ru logind-test-user)"
+    seat=$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $4 }')
+    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $5 }')" tty2
+    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $6 }')" active
+    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $7 }')" no
+    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $8 }')" ''
+
+    loginctl list-seats --no-legend | grep -Fwq "${seat?}"
+
     assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $1 }')" "$(id -ru logind-test-user)"
     assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $3 }')" no
     assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $4 }')" active
-    assert_eq "$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $6 }')" active
 
     loginctl enable-linger logind-test-user
     assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $3 }')" yes