From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 26 Aug 2005 19:36:43 +0000 Subject: Re: RUN rules to enable/disable printer queues Message-Id: <20050826193643.GB7047@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="6c2NcOVqGQ03X4Wi" List-Id: References: <32962.66.92.218.83.1125017033.squirrel@mail.panix.com> In-Reply-To: <32962.66.92.218.83.1125017033.squirrel@mail.panix.com> To: linux-hotplug@vger.kernel.org --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 26, 2005 at 01:46:25PM +0200, Kay Sievers wrote: > On Thu, Aug 25, 2005 at 08:06:05PM -0700, Zack Weinberg wrote: > > Kay Sievers said: > > > > > Use two rules, one for ACTION="add" and one for "remove" if you want to > > > name the device at the same time. The SYMLINK key prevents rule to be > > > catched by a "remove" cause it is only valid to _create_ a link - same > > > for NAME, OWNER, GROUP, MODE. > > > > Okay, so now I have > > > > BUS=="usb", SYSFS{product}=="Lexmark Optra E310", \ > > SYSFS{serial}=="0101137", ACTION=="remove", \ > > RUN+="/etc/udev/scripts/lpqueue.sh" > > > ... and it still doesn't work: lpqueue.sh is invoked only on add, not remove. > > The device is removed, so sysfs is obviously not available. The attached patch should make it possible to store a variable in the environment and at the same time in the udev database. This variable is also available at "remove": ACTION=="add", KERNEL=="sda", ENV{MY_DEVICE}="1234", RUN+="/bin/logger add $devpath" ACTION=="remove", ENV{MY_DEVICE}=="1234", RUN+="/bin/logger remove $devpath" This way it is also possible to export "remove" values, that are used in a RUN key: ACTION=="add", KERNEL=="sda", ENV{MY_REMOVE}="/bin/logger remove $devpath", RUN+="/bin/logger add $devpath" ACTION=="remove", ENV{MY_REMOVE}!="", RUN+="$env{MY_REMOVE}" Kay --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="udev-env-at-remove-01.patch" diff --git a/udev_event.c b/udev_event.c --- a/udev_event.c +++ b/udev_event.c @@ -91,15 +91,21 @@ int udev_process_event(struct udev_rules } sysfs_close_class_device(class_dev); } else if (strcmp(udev->action, "remove") == 0) { + struct name_entry *name_loop; + + /* get data from db, remove db-entry, delete node */ dbg("node remove"); + retval = udev_remove_device(udev); + + /* restore stored persistent data */ + list_for_each_entry(name_loop, &udev->env_list, node) + putenv(name_loop->name); + udev_rules_get_run(rules, udev, NULL, NULL); if (udev->ignore_device) { dbg("device event will be ignored"); return -1; } - - /* get name from db, remove db-entry, delete node */ - retval = udev_remove_device(udev); } /* export name of device node or netif */ diff --git a/udev_rules.c b/udev_rules.c --- a/udev_rules.c +++ b/udev_rules.c @@ -859,6 +859,7 @@ try_parent: const char *key_name = key_pair_name(rule, pair); const char *value = key_val(rule, &pair->key); + name_list_key_add(&udev->env_list, key_name, value); setenv(key_name, value, 1); dbg("export ENV '%s=%s'", key_name, value); } --6c2NcOVqGQ03X4Wi-- ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel