summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-01-03 16:28:30 +0100
committerGitHub <noreply@github.com>2019-01-03 16:28:30 +0100
commit88514e7bae0c918ca4b93714fbf2ae0f8f33855d (patch)
tree7d9668bc8bda8f1680cf8baee13e728e06a487bd /src/libsystemd
parentMerge pull request #11250 from yuwata/dhcp-coding-style-fixes (diff)
parenttest: add test for sending/receiving an invalid device (diff)
downloadsystemd-88514e7bae0c918ca4b93714fbf2ae0f8f33855d.tar.xz
systemd-88514e7bae0c918ca4b93714fbf2ae0f8f33855d.zip
Merge pull request #11244 from yuwata/revert-udev-changes
udev: revert bind/unbind patch and one more
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-device/device-private.c9
-rw-r--r--src/libsystemd/sd-device/sd-device.c3
-rw-r--r--src/libsystemd/sd-device/test-sd-device-monitor.c81
3 files changed, 57 insertions, 36 deletions
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 01a5aa3d3f..36beb3e7df 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -326,15 +326,6 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
action = device_action_from_string(value);
if (action == _DEVICE_ACTION_INVALID)
return -EINVAL;
- /* FIXME: remove once we no longer flush previuos state for each action */
- if (action == DEVICE_ACTION_BIND || action == DEVICE_ACTION_UNBIND) {
- static bool warned;
- if (!warned) {
- log_device_debug(device, "sd-device: ignoring actions 'bind' and 'unbind'");
- warned = true;
- }
- return -EINVAL;
- }
} else if (streq(key, "SEQNUM")) {
r = safe_atou64(value, &seqnum);
if (r < 0)
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index db58615df5..9b1ef44480 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -1002,6 +1002,9 @@ static int device_set_sysname(sd_device *device) {
const char *pos;
size_t len = 0;
+ if (!device->devpath)
+ return -EINVAL;
+
pos = strrchr(device->devpath, '/');
if (!pos)
return -EINVAL;
diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c
index 9e5ca11fe9..48b49fb783 100644
--- a/src/libsystemd/sd-device/test-sd-device-monitor.c
+++ b/src/libsystemd/sd-device/test-sd-device-monitor.c
@@ -24,11 +24,43 @@ static int monitor_handler(sd_device_monitor *m, sd_device *d, void *userdata) {
return sd_event_exit(sd_device_monitor_get_event(m), 0);
}
-static int test_send_receive_one(sd_device *device, bool subsystem_filter, bool tag_filter, bool use_bpf) {
+static int test_receive_device_fail(void) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
- const char *syspath, *subsystem, *tag, *devtype = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
+ const char *syspath;
int r;
+ log_info("/* %s */", __func__);
+
+ /* Try to send device with invalid action and without seqnum. */
+ assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
+ assert_se(device_add_property(loopback, "ACTION", "hoge") >= 0);
+
+ assert_se(sd_device_get_syspath(loopback, &syspath) >= 0);
+
+ assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
+ assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
+ assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
+
+ assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
+ assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
+ assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
+ assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
+
+ /* Do not use assert_se() here. */
+ r = device_monitor_send_device(monitor_server, monitor_client, loopback);
+ if (r < 0)
+ return log_error_errno(r, "Failed to send loopback device: %m");
+
+ assert_se(sd_event_run(sd_device_monitor_get_event(monitor_client), 0) >= 0);
+
+ return 0;
+}
+
+static void test_send_receive_one(sd_device *device, bool subsystem_filter, bool tag_filter, bool use_bpf) {
+ _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
+ const char *syspath, *subsystem, *tag, *devtype = NULL;
+
log_device_info(device, "/* %s(subsystem_filter=%s, tag_filter=%s, use_bpf=%s) */", __func__,
true_false(subsystem_filter), true_false(tag_filter), true_false(use_bpf));
@@ -56,14 +88,8 @@ static int test_send_receive_one(sd_device *device, bool subsystem_filter, bool
if ((subsystem_filter || tag_filter) && use_bpf)
assert_se(sd_device_monitor_filter_update(monitor_client) >= 0);
- /* Do not use assert_se() here. */
- r = device_monitor_send_device(monitor_server, monitor_client, device);
- if (r < 0)
- return log_error_errno(r, "Failed to send loopback device: %m");
-
+ assert_se(device_monitor_send_device(monitor_server, monitor_client, device) >= 0);
assert_se(sd_event_loop(sd_device_monitor_get_event(monitor_client)) == 0);
-
- return 0;
}
static void test_subsystem_filter(sd_device *device) {
@@ -111,22 +137,23 @@ int main(int argc, char *argv[]) {
if (getuid() != 0)
return log_tests_skipped("not root");
- assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
- assert_se(device_add_property(loopback, "ACTION", "add") >= 0);
- assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
-
- r = test_send_receive_one(loopback, false, false, false);
+ r = test_receive_device_fail();
if (r < 0) {
assert_se(r == -EPERM && detect_container() > 0);
return log_tests_skipped("Running in container? Skipping remaining tests");
}
- assert_se(test_send_receive_one(loopback, true, false, false) >= 0);
- assert_se(test_send_receive_one(loopback, false, true, false) >= 0);
- assert_se(test_send_receive_one(loopback, true, true, false) >= 0);
- assert_se(test_send_receive_one(loopback, true, false, true) >= 0);
- assert_se(test_send_receive_one(loopback, false, true, true) >= 0);
- assert_se(test_send_receive_one(loopback, true, true, true) >= 0);
+ assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
+ assert_se(device_add_property(loopback, "ACTION", "add") >= 0);
+ assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
+
+ test_send_receive_one(loopback, false, false, false);
+ test_send_receive_one(loopback, true, false, false);
+ test_send_receive_one(loopback, false, true, false);
+ test_send_receive_one(loopback, true, true, false);
+ test_send_receive_one(loopback, true, false, true);
+ test_send_receive_one(loopback, false, true, true);
+ test_send_receive_one(loopback, true, true, true);
test_subsystem_filter(loopback);
@@ -139,13 +166,13 @@ int main(int argc, char *argv[]) {
assert_se(device_add_property(sda, "ACTION", "change") >= 0);
assert_se(device_add_property(sda, "SEQNUM", "11") >= 0);
- assert_se(test_send_receive_one(sda, false, false, false) >= 0);
- assert_se(test_send_receive_one(sda, true, false, false) >= 0);
- assert_se(test_send_receive_one(sda, false, true, false) >= 0);
- assert_se(test_send_receive_one(sda, true, true, false) >= 0);
- assert_se(test_send_receive_one(sda, true, false, true) >= 0);
- assert_se(test_send_receive_one(sda, false, true, true) >= 0);
- assert_se(test_send_receive_one(sda, true, true, true) >= 0);
+ test_send_receive_one(sda, false, false, false);
+ test_send_receive_one(sda, true, false, false);
+ test_send_receive_one(sda, false, true, false);
+ test_send_receive_one(sda, true, true, false);
+ test_send_receive_one(sda, true, false, true);
+ test_send_receive_one(sda, false, true, true);
+ test_send_receive_one(sda, true, true, true);
return 0;
}