From 2efa43dc4a0ddc9409c510e54a0f6f58670c720d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 12:54:58 +0900 Subject: [PATCH 1/6] core/device: make devices with ID_RENAMING= property be considered not ready --- src/core/device.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/device.c b/src/core/device.c index b006add405..a979caf21c 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -17,6 +17,7 @@ #include "stat-util.h" #include "string-util.h" #include "swap.h" +#include "udev-util.h" #include "unit-name.h" #include "unit.h" @@ -729,6 +730,9 @@ static bool device_is_ready(sd_device *dev) { assert(dev); + if (device_is_renaming(dev) > 0) + return false; + if (sd_device_get_property_value(dev, "SYSTEMD_READY", &ready) < 0) return true; From 08caaee0ac6b1c7c2d89a699b44307cbb7440c10 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 14:42:36 +0900 Subject: [PATCH 2/6] sd-device: move device_action_from_string() and friends to device-private.h --- src/libsystemd/sd-device/device-internal.h | 16 ---------------- src/libsystemd/sd-device/device-private.h | 18 ++++++++++++++++++ src/test/test-tables.c | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libsystemd/sd-device/device-internal.h b/src/libsystemd/sd-device/device-internal.h index 3ffca35cbe..4d03d09cd6 100644 --- a/src/libsystemd/sd-device/device-internal.h +++ b/src/libsystemd/sd-device/device-internal.h @@ -81,19 +81,6 @@ struct sd_device { bool db_persist:1; /* don't clean up the db when switching from initrd to real root */ }; -typedef enum DeviceAction { - DEVICE_ACTION_ADD, - DEVICE_ACTION_REMOVE, - DEVICE_ACTION_CHANGE, - DEVICE_ACTION_MOVE, - DEVICE_ACTION_ONLINE, - DEVICE_ACTION_OFFLINE, - DEVICE_ACTION_BIND, - DEVICE_ACTION_UNBIND, - _DEVICE_ACTION_MAX, - _DEVICE_ACTION_INVALID = -1, -} DeviceAction; - int device_new_aux(sd_device **ret); int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db); int device_add_property_internal(sd_device *device, const char *key, const char *value); @@ -108,6 +95,3 @@ int device_set_devnum(sd_device *device, const char *major, const char *minor); int device_set_subsystem(sd_device *device, const char *_subsystem); int device_set_driver(sd_device *device, const char *_driver); int device_set_usec_initialized(sd_device *device, usec_t when); - -DeviceAction device_action_from_string(const char *s) _pure_; -const char *device_action_to_string(DeviceAction a) _const_; diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 49e02db81e..46e10105c9 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -8,6 +8,8 @@ #include "sd-device.h" +#include "macro.h" + int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len); int device_new_from_strv(sd_device **ret, char **strv); int device_new_from_stat_rdev(sd_device **ret, const struct stat *st); @@ -55,3 +57,19 @@ int device_read_db_internal(sd_device *device, bool force); static inline int device_read_db(sd_device *device) { return device_read_db_internal(device, false); } + +typedef enum DeviceAction { + DEVICE_ACTION_ADD, + DEVICE_ACTION_REMOVE, + DEVICE_ACTION_CHANGE, + DEVICE_ACTION_MOVE, + DEVICE_ACTION_ONLINE, + DEVICE_ACTION_OFFLINE, + DEVICE_ACTION_BIND, + DEVICE_ACTION_UNBIND, + _DEVICE_ACTION_MAX, + _DEVICE_ACTION_INVALID = -1, +} DeviceAction; + +DeviceAction device_action_from_string(const char *s) _pure_; +const char *device_action_to_string(DeviceAction a) _const_; diff --git a/src/test/test-tables.c b/src/test/test-tables.c index 49268eae22..070d1b4fe0 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -5,7 +5,7 @@ #include "cgroup.h" #include "compress.h" #include "condition.h" -#include "device-internal.h" +#include "device-private.h" #include "device.h" #include "execute.h" #include "import-util.h" From dcee4a134c9e41a54b640bb7fdbb608c9826c792 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 14:43:33 +0900 Subject: [PATCH 3/6] udevadm trigger: make --action option support all possible actions This also make udevadm abort operations if invalid action is specified. --- src/udev/udevadm-trigger.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 63ceaaf957..b5e5f091ca 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -7,6 +7,7 @@ #include "sd-event.h" #include "device-enumerator-private.h" +#include "device-private.h" #include "fd-util.h" #include "fileio.h" #include "path-util.h" @@ -199,11 +200,10 @@ int trigger_main(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg); break; case 'c': - if (STR_IN_SET(optarg, "add", "remove", "change")) - action = optarg; - else - log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown action '%s'", optarg); + if (device_action_from_string(optarg) < 0) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown action '%s'", optarg); + action = optarg; break; case 's': r = sd_device_enumerator_add_match_subsystem(e, optarg, true); From cd648ae1954f04ff41ce1f06268ea274df7ebd87 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 14:45:38 +0900 Subject: [PATCH 4/6] man: mention possible actions supported by "udevadm trigger" --- man/udevadm.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/man/udevadm.xml b/man/udevadm.xml index f25a1dfb48..d4fdaea6ff 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -220,8 +220,10 @@ - Type of event to be triggered. The default value is - change. + Type of event to be triggered. Possible actions are add, + remove, change, move, + online, offline, bind, + and unbind. The default value is change. From 1ec38b8574f94fa9c9a3dd11e76294c100420e0f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 14:47:43 +0900 Subject: [PATCH 5/6] test: add test for ID_RENAMING= udev property handling by pid1 --- test/TEST-29-UDEV-ID_RENAMING/Makefile | 1 + test/TEST-29-UDEV-ID_RENAMING/test.sh | 49 ++++++++++++++++++++++ test/TEST-29-UDEV-ID_RENAMING/testsuite.sh | 45 ++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 120000 test/TEST-29-UDEV-ID_RENAMING/Makefile create mode 100755 test/TEST-29-UDEV-ID_RENAMING/test.sh create mode 100755 test/TEST-29-UDEV-ID_RENAMING/testsuite.sh diff --git a/test/TEST-29-UDEV-ID_RENAMING/Makefile b/test/TEST-29-UDEV-ID_RENAMING/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-29-UDEV-ID_RENAMING/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-29-UDEV-ID_RENAMING/test.sh b/test/TEST-29-UDEV-ID_RENAMING/test.sh new file mode 100755 index 0000000000..74362c052a --- /dev/null +++ b/test/TEST-29-UDEV-ID_RENAMING/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh +set -e +TEST_DESCRIPTION="UDEV ID_RENAMING property" +TEST_NO_NSPAWN=1 + +. $TEST_BASE_DIR/test-functions +QEMU_TIMEOUT=300 + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + + # mask some services that we do not want to run in these tests + ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service + ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket + ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service < /run/udev/rules.d/50-testsuite.rules < /testok + +exit 0 From 8c8b67ffec093a89b6c9fe3e94dae770d4de2569 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Mar 2019 14:49:09 +0900 Subject: [PATCH 6/6] TODO: update --- TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO b/TODO index bcf1d02b94..9e4e07da5e 100644 --- a/TODO +++ b/TODO @@ -23,9 +23,6 @@ Janitorial Clean-ups: Features: -* check ID_RENAMING= property from PID1's .device logic, and don't consider - devices that are being renamed. - * make MAINPID= message reception checks even stricter: if service uses User=, then check sending UID and ignore message if it doesn't match the user or root.