From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: RUN rules to enable/disable printer queues
Date: Fri, 26 Aug 2005 19:36:43 +0000 [thread overview]
Message-ID: <20050826193643.GB7047@vrfy.org> (raw)
In-Reply-To: <32962.66.92.218.83.1125017033.squirrel@mail.panix.com>
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
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
[-- Attachment #2: udev-env-at-remove-01.patch --]
[-- Type: text/plain, Size: 1183 bytes --]
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);
}
prev parent reply other threads:[~2005-08-26 19:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-26 0:43 RUN rules to enable/disable printer queues Zack Weinberg
2005-08-26 1:01 ` Kay Sievers
2005-08-26 3:06 ` Zack Weinberg
2005-08-26 11:46 ` Kay Sievers
2005-08-26 15:50 ` Ian Pilcher
2005-08-26 19:36 ` Kay Sievers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050826193643.GB7047@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.