From 995aec875973e29caf42b037736349fc8839ee40 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 5 Jun 2005 05:13:33 +0200 Subject: [PATCH] udev: clear lists if a new value is assigned Former values are cleared if SYMLINK= is used. To add a value SYMLINK+= is now needed. Signed-off-by: Kay Sievers --- test/udev-test.pl | 63 +++++++++++++++++++++++++++++++---------------- udev_rules.c | 18 ++++++++++++++ udev_utils.c | 4 +++ 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/test/udev-test.pl b/test/udev-test.pl index 27fe3545..884abf9e 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -783,9 +783,9 @@ EOF exp_name => "symlink-only2", exp_target => "link", rules => < "yes", exp_rem_error => "yes", rules => < "yes", option => "clean", rules => < "symlink0", exp_target => "ttyUSB0", rules => < "symlink-ttyUSB0", exp_target => "ttyUSB0", rules => < "major-188:0", exp_target => "ttyUSB0", rules => < "symlink-0:0:0:0", exp_target => "node", rules => < "test", exp_target => "ttyUSB0", rules => < "test", exp_target => "ttyUSB0", rules => < "this", exp_target => "ttyUSB0", rules => < "test", exp_target => "link", rules => < "188:0", exp_target => "ttyUSB0", rules => < "188", exp_target => "ttyUSB0", rules => < "percent%sign", exp_target => "ttyUSB0", rules => < "%ttyUSB0_name", exp_target => "ttyUSB0", rules => < "link1", exp_target => "node", rules => < "link4", exp_target => "node", rules => < "/block/sda/sda1", exp_name => "last", rules => < "reset list to current value", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "three", + not_exp_name => "two", + exp_target => "node", + rules => <{exp_name}"); + if (defined($rules->{not_exp_name})) { + if ((-e "$PWD/$udev_root$rules->{not_exp_name}") || + (-l "$PWD/$udev_root$rules->{not_exp_name}")) { + print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; + $error++ + } + } if (defined($rules->{exp_perms})) { permissions_test($rules, $uid, $gid, $mode); } diff --git a/udev_rules.c b/udev_rules.c index 42509f16..631cc427 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -782,6 +782,15 @@ int udev_rules_get_name(struct udevice *udev, struct sysfs_class_device *class_d if (rule->symlink_operation == KEY_OP_ASSIGN_FINAL) udev->symlink_final = 1; + else if (rule->symlink_operation == KEY_OP_ASSIGN) { + struct name_entry *name_loop; + struct name_entry *temp_loop; + + list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) { + list_del(&name_loop->node); + free(name_loop); + } + } info("configured rule in '%s[%i]' applied, added symlink '%s'", rule->config_file, rule->config_line, rule->symlink); strlcpy(temp, rule->symlink, sizeof(temp)); @@ -821,6 +830,15 @@ int udev_rules_get_name(struct udevice *udev, struct sysfs_class_device *class_d if (rule->run_operation == KEY_OP_ASSIGN_FINAL) udev->run_final = 1; + else if (rule->run_operation == KEY_OP_ASSIGN) { + struct name_entry *name_loop; + struct name_entry *temp_loop; + + list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) { + list_del(&name_loop->node); + free(name_loop); + } + } strlcpy(program, rule->run, sizeof(program)); apply_format(udev, program, sizeof(program), class_dev, sysfs_device); dbg("add run '%s'", program); diff --git a/udev_utils.c b/udev_utils.c index 70b20e3a..d6056310 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -108,6 +108,10 @@ void udev_cleanup_device(struct udevice *udev) list_del(&name_loop->node); free(name_loop); } + list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) { + list_del(&name_loop->node); + free(name_loop); + } } int string_is_true(const char *str) -- 2.39.5