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. 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. 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; 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" 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); 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