* Re: RUN rules to enable/disable printer queues
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
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2005-08-26 1:01 UTC (permalink / raw)
To: linux-hotplug
On Thu, Aug 25, 2005 at 05:43:53PM -0700, Zack Weinberg wrote:
> I have a USB printer which is turned off most of the time. I want to have
> the computer automatically run "lpc start" and "lpc stop" on the relevant
> print queue when the printer is turned on and off, respectively.
>
> I tried to do this with this rule:
>
> BUS="usb", SYSFS{product}="Lexmark Optra E310", SYSFS{serial}="0101137", \
> SYMLINK="lp_epson", RUN+="/etc/udev/scripts/lpqueue.sh"
>
> where lpqueue.sh is a little script I wrote that maps ACTIONd to lpc
> start, and ACTION=remove to lpc stop.
>
> This correctly creates and deletes the lp_epson symlink, but lpqueue.sh is
> only invoked on add events, not remove events, so it can only do half of
> its job.
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.
> I believe that the rule *does* match on both add and remove,
> because if it didn't match on remove, it wouldn't know to delete the
> symlink
udev has it's own database to remember the created nodes and symlinks.
On remove everything that was created with add is removed without a
explicit rule.
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: RUN rules to enable/disable printer queues
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Zack Weinberg @ 2005-08-26 3:06 UTC (permalink / raw)
To: linux-hotplug
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"
BUS="usb", SYSFS{product}="Lexmark Optra E310", \
SYSFS{serial}="0101137", ACTION="add", \
SYMLINK="lp_epson", RUN+="/etc/udev/scripts/lpqueue.sh"
... and it still doesn't work: lpqueue.sh is invoked only on add, not remove.
Even if it did work, I would not be happy about having to duplicate the
BUS=..., SYSFS{product}=..., SYSFS{serial}=... piece. The constraint
you describe (SYMLINK, NAME, etc. implicitly restricting rules to add
events) is silly, because RUN= may do something useful with that
information on remove events as well (or could, if it were all being put
into the environment, as it ought to be).
zw
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: RUN rules to enable/disable printer queues
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
4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2005-08-26 11:46 UTC (permalink / raw)
To: linux-hotplug
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.
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: RUN rules to enable/disable printer queues
2005-08-26 0:43 RUN rules to enable/disable printer queues Zack Weinberg
` (2 preceding siblings ...)
2005-08-26 11:46 ` Kay Sievers
@ 2005-08-26 15:50 ` Ian Pilcher
2005-08-26 19:36 ` Kay Sievers
4 siblings, 0 replies; 6+ messages in thread
From: Ian Pilcher @ 2005-08-26 15:50 UTC (permalink / raw)
To: linux-hotplug
Kay Sievers wrote:
> udev has it's own database to remember the created nodes and symlinks.
> On remove everything that was created with add is removed without a
> explicit rule.
In the future, perhaps it would be possible to add a "destructor" to
the database, a program that would be automatically run before the
device is actually removed. This would obviate the need for separate
rules.
--
====================================
Ian Pilcher i.pilcher@comcast.net
====================================
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: RUN rules to enable/disable printer queues
2005-08-26 0:43 RUN rules to enable/disable printer queues Zack Weinberg
` (3 preceding siblings ...)
2005-08-26 15:50 ` Ian Pilcher
@ 2005-08-26 19:36 ` Kay Sievers
4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2005-08-26 19:36 UTC (permalink / raw)
To: linux-hotplug
[-- 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);
}
^ permalink raw reply [flat|nested] 6+ messages in thread