DEVLINKS and DEVNAME variables in RUN rules
Hi,
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner $$DEVICE $$DEVNAME $$DEVLINKS'"
Would it be possible to have the format applied right before the RUN command is run?
Regards
Signature · 13 lines
Olivier Blin - Mandriva ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Olivier Blin
Hi,
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner$$DEVICE $$DEVNAME $$DEVLINKS'"
Quoted 3 lines
Would it be possible to have the format applied right before the RUN command is run?
Like this? This seems to work for me:
Jan 24 21:04:24 cooker udevd-event[16049]: name_list_add: adding
'/sbin/pam_console_setowner $env{DEVICE} $env{DEVNAME} $env{DEVLINKS}'
Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=14,
string='/sbin/pam_console_setowner ', tail=' $env{DEVNAME} $env{DEVLINKS}'
Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=14,
string='/sbin/pam_console_setowner ', tail=' $env{DEVLINKS}'
Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=14,
string='/sbin/pam_console_setowner /dev/adsp ', tail=''
Jan 24 21:04:25 cooker udevd-event[16049]: run_program: arg[0]
'/sbin/pam_console_setowner'
Jan 24 21:04:25 cooker udevd-event[16049]: run_program:
'/sbin/pam_console_setowner /dev/adsp /dev/sound/adsp'
Jan 24 21:04:25 cooker udevd-event[16049]: run_program: '/sbin/pam_console_setowner' returned with status 0
-andrey
Subject: [PATCH] Allow substitution of environment variables in RUN commands
Apply substitutions immediately before running program, not when rule is parsed. It allows use environment variables set by udev during rule processing as command arguments.
---
udev.c | 9 +++++++-- udev_rules.c | 3 +-- udev_rules.h | 2 +- udevd.c | 9 +++++++-- udevstart.c | 9 +++++++-- 5 files changed, 23 insertions(+), 9 deletions(-)
c1d4190501d381ac2d6987e84b680907c93c0b4d
udev.c +7 -2
@@ -161,8 +161,13 @@ int main(int argc, char *argv[], char *elist_for_each_entry (name_loop, &udev->run_list, node) {if (strncmp (name_loop->name,"socket:" ,strlen ("socket:" )) ==0 )pass_env_to_socket (&name_loop->name[strlen ("socket:" )], devpath, action); -else -run_program (name_loop->name, udev->dev->subsystem,NULL ,0 ,NULL , (udev_log_priority >=LOG_INFO )); +else { +char program[PATH_SIZE ]; + +strlcpy (program, name_loop->name,sizeof (program)); +apply_format (udev, program,sizeof (program)); +run_program (program, udev->dev->subsystem,NULL ,0 ,NULL , (udev_log_priority >=LOG_INFO )); + } } }
udev_rules.c +1 -2
@@ -362,7 +362,7 @@ static int wait_for_sysfs(struct udevicereturn -1 ; } -static void apply_format (struct udevice *udev,char *string,size_t maxsize) +void apply_format (struct udevice *udev,char *string,size_t maxsize) {char temp[PATH_SIZE ];char temp2[PATH_SIZE ];
@@ -1017,7 +1017,6 @@ int udev_rules_get_name(struct udev_rulename_list_cleanup (&udev->run_list); }strlcpy (program,key_val (rule, &rule->run),sizeof (program)); -apply_format (udev, program,sizeof (program));dbg ("add run '%s'" , program);name_list_add (&udev->run_list, program,0 ); }
udev_rules.h +1 -1
@@ -105,7 +105,7 @@ struct udev_rules {extern int udev_rules_init (struct udev_rules *rules,int resolve_names);extern void udev_rules_cleanup (struct udev_rules *rules); -extern void udev_apply_format (struct udevice *udev,char *string,size_t maxsize); +extern void apply_format (struct udevice *udev,char *string,size_t maxsize);extern void udev_rules_iter_init (struct udev_rules *rules);extern struct udev_rule *udev_rules_iter_next (struct udev_rules *rules);
udevd.c +7 -2
@@ -123,10 +123,15 @@ static int udev_event_process(struct uevlist_for_each_entry (name_loop, &udev->run_list, node) {if (strncmp (name_loop->name,"socket:" ,strlen ("socket:" )) ==0 )pass_env_to_socket (&name_loop->name[strlen ("socket:" )], msg->devpath, msg->action); -else -if (run_program (name_loop->name, udev->dev->subsystem,NULL ,0 ,NULL , +else { +char program[PATH_SIZE ]; + +strlcpy (program, name_loop->name,sizeof (program)); +apply_format (udev, program,sizeof (program)); +if (run_program (program, udev->dev->subsystem,NULL ,0 ,NULL , (udev_log_priority >=LOG_INFO ))) retval =-1 ; + } } }
udevstart.c +7 -2
@@ -160,8 +160,13 @@ run:list_for_each_entry (name_loop, &udev->run_list, node) {if (strncmp (name_loop->name,"socket:" ,strlen ("socket:" )) ==0 )pass_env_to_socket (&name_loop->name[strlen ("socket:" )], udev->dev->devpath,"add" ); -else -run_program (name_loop->name, udev->dev->subsystem,NULL ,0 ,NULL , (udev_log_priority >=LOG_INFO )); +else { +char program[PATH_SIZE ]; + +strlcpy (program, name_loop->name,sizeof (program)); +apply_format (udev, program,sizeof (program)); +run_program (program, udev->dev->subsystem,NULL ,0 ,NULL , (udev_log_priority >=LOG_INFO )); + } } } exit:
Signature · 1 line
1.1.4
Kay Sievers
AppliedQuoted 8 lines · Andrey Borzenkov
Quoted 7 lines · Olivier Blin
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner$$DEVICE $$DEVNAME $$DEVLINKS'"
Quoted 8 lines
Quoted 3 lines
Would it be possible to have the format applied right before the RUN command is run?
Like this? This seems to work for me:
Jan 24 21:04:24 cooker udevd-event[16049]: name_list_add: adding'
/sbin/pam_console_setowner$env{DEVICE} $env{DEVNAME} $env{DEVLINKS}'
Applied.
Thanks,
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 12 lines · Kay Sievers
Quoted 11 lines · Andrey Borzenkov
Quoted 9 lines · Olivier Blin
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner$$DEVICE $$DEVNAME $$DEVLINKS'"Would it be possible to have the format applied right before the RUN command is run?
Quoted 7 lines
Quoted 4 lines
Like this? This seems to work for me:
Jan 24 21:04:24 cooker udevd-event[16049]: name_list_add: adding'
/sbin/pam_console_setowner$env{DEVICE} $env{DEVNAME} $env{DEVLINKS}'Applied.
OK the following patch documents this difference (and the fact that RUN is using substitutons at all). I am still curious if there is real life use for something like `PROGRAM="check" RUN="callout %c{1}"'.
regards
- -andrey
Subject: [PATCH] Document when substitutions are applied for RUN and other keys
- ---
udev.8 | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
333ee12327b6792c9ba7cb75e89786cd8d5a171c
udev.8 +0 -0
- --- a/udev.8
+++ b/udev.8
@@ -164,10 +164,15 @@ The
\fBNAME\fR,
\fBSYMLINK\fR,
\fBPROGRAM\fR,
- -\fBOWNER\fR
- -and
+\fBOWNER\fR,
\fBGROUP\fR
- -fields support simple printf\-like string substitutions:
+and
+\fBRUN\fR
+fields support simple printf\-like string substitutions. For \fBRUN\fR they +are applied immediately before program is launched, after all rules have +been processed. It allows use of complete environment set up by earlier rules +including exported variables. For all other fields substitutions are applied +when rule is being processed. The supported substitutions are:
.TP
\fB$kernel\fR, \fB%k\fR
The kernel name for this device.
- --
1.1.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFD18D1R6LMutpd94wRAqMgAJ9DVxZeZ5OFjIfPm8kWVEt8auVX9ACfbBod UwcVMW+MOoKSBfsbjP8+Ugs�pb
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 13 lines · Kay Sievers
Quoted 12 lines · Andrey Borzenkov
Quoted 10 lines · Olivier Blin
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner$$DEVICE $$DEVNAME $$DEVLINKS'"Would it be possible to have the format applied right before the RUN command is run?
Quoted 6 lines
Quoted 4 lines
Like this? This seems to work for me:
Jan 24 21:04:24 cooker udevd-event[16049]: name_list_add: adding'
/sbin/pam_console_setowner$env{DEVICE} $env{DEVNAME} $env{DEVLINKS}'Applied.
Thanks (and spasiba)!
By the way, is there any place where this new 082 release has been announced?
Signature · 13 lines
Olivier Blin - Mandriva ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 18 lines · Andrey Borzenkov
Quoted 17 lines · Kay Sievers
Quoted 15 lines · Andrey Borzenkov
Quoted 9 lines · Olivier Blin
I'd like to use the DEVNAME and DEVLINKS (thanks Kay) environment variables in a RUN rule. Unfortunately, they're not exported yet when the command to be executed is computed (i.e. when the format is applied). So, for now, I'm using a dumb trick:
RUN+="/bin/sh -c '/sbin/pam_console_setowner$$DEVICE $$DEVNAME $$DEVLINKS'"Would it be possible to have the format applied right before the RUN command is run?
Like this? This seems to work for me:
Jan 24 21:04:24 cooker udevd-event[16049]: name_list_add: adding'
/sbin/pam_console_setowner$env{DEVICE} $env{DEVNAME} $env{DEVLINKS}'
Quoted 6 lines
Quoted 2 lines
Applied.
OK the following patch documents this difference (and the fact that RUN is using substitutons at all). I am still curious if there is real life use for something like `PROGRAM="check" RUN="callout %c{1}"'.
Oh, the %c will just be the last result if more than one rule uses PROGRAM and should still work in almost all cases it is used, if at all.
The man page is generated from the xml source in docs/ and we can't patch the man page itself and udev 082 has udev.8 moved to udev.7, cause the command udev does no longer really exist. Can you patch the udev.xml instead?
Thanks,
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 3 lines · Andrey Borzenkov
OK the following patch documents this difference (and the fact that RUN is using substitutons at all).
oops, messed up with git and did not received updates. Here it is against 082.
- -andrey
Subject: [PATCH] Document when substitutions are applied for RUN and other keys
From: Andrey Borzenkov <[email protected]>
- ---
udev.7 | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
udev.7 +0 -0
- --- a/udev.7
+++ b/udev.7
@@ -164,10 +164,15 @@ The
\fBNAME\fR,
\fBSYMLINK\fR,
\fBPROGRAM\fR,
- -\fBOWNER\fR
- -and
+\fBOWNER\fR,
\fBGROUP\fR
- -fields support simple printf\-like string substitutions:
+and
+\fBRUN\fR
+fields support simple printf\-like string substitutions. For \fBRUN\fR they +are applied immediately before program is launched, after all rules have +been processed. It allows use of complete environment set up by earlier rules +including exported variables. For all other fields substitutions are applied +when rule is being processed. The supported substitutions are:
.TP
\fB$kernel\fR, \fB%k\fR
The kernel name for this device.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFD18uIR6LMutpd94wRAkP5AJ0TYQML1hwbGSSfyxlUV61cSwTcAQCbBDoY GFvHdLzdNgQH5ZJqiIaJ2sg=Zh6P
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
udev.7
Quoted 11 lines · Andrey Borzenkov
Quoted 3 lines · Andrey Borzenkov
OK the following patch documents this difference (and the fact that RUN is using substitutons at all).
oops, messed up with git and did not received updates. Here it is against 082.
udev.7 +0
-0
Hehe, no, as mentioned in the last mail, we can't patch the created man page, it comes from "docs/udev.xml". Just edit this file and run "make" and it will create the man page from the docbook source again.
I don't mind putting it in there myself, but if you want to send a new patch, go for it. :)
Thanks,
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 1 line · Kay Sievers
Hehe, no, as mentioned in the last mail,
too late :)
Quoted 2 lines
we can't patch the created man
page, it comes from "docs/udev.xml".
Why is it verion-controlled then?
Quoted 2 lines
I don't mind putting it in there myself, but if you want to send a new patch, go for it. :)
third attempt. I do not mind, I practice (st-)git on your expense :) This time attached due to overly long lines.
-andrey
Subject: [PATCH] Document when substitutions are applied for RUN and other keys
From: Andrey Borzenkov <[email protected]>
---
docs/udev.xml | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
docs/udev.xml +7 -2
@@ -353,8 +353,13 @@ </variablelist> <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>, - <option>OWNER</option> and <option>GROUP</option> fields support simple - printf-like string substitutions:</para> + <option>OWNER</option>, <option>GROUP</option> and <option>RUN</option> + fields support simple printf-like string substitutions. For + <option>RUN</option> they are applied immediately before program + is launched, after all rules have been processed. It allows use of + complete environment set up by earlier rules including exported + variables. For all other fields substitutions are applied when rule + is being processed. The supported substitutions are:</para> <variablelist> <varlistentry> <term><option>$kernel</option>, <option>%k</option></term>
Quoted 4 lines · Andrey Borzenkov
Quoted 1 line · Kay Sievers
Hehe, no, as mentioned in the last mail,
too late :)
Yeah, I know that. :)
Quoted 4 lines
Quoted 2 lines
we can't patch the created man
page, it comes from "docs/udev.xml".Why is it verion-controlled then?
It just avoids the dependency on xmlto, no special reason.
Quoted 5 lines
Quoted 2 lines
I don't mind putting it in there myself, but if you want to send a new patch, go for it. :)
third attempt. I do not mind, I practice (st-)git on your expense :) This time attached due to overly long lines.
Thanks, I've applied this.
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel