From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrey Borzenkov Date: Tue, 24 Jan 2006 18:05:51 +0000 Subject: Re: DEVLINKS and DEVNAME variables in RUN rules Message-Id: <200601242105.54783.arvidjaar@mail.ru> MIME-Version: 1 Content-Type: multipart/mixed; boundary="nextPart5870122.pOIq2PEuTp" List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org --nextPart5870122.pOIq2PEuTp Content-Type: multipart/mixed; boundary="Boundary-01=_Cym1DKYHCMzYt0d" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_Cym1DKYHCMzYt0d Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Tuesday 24 January 2006 19:24, Olivier Blin wrote: > 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+=3D"/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=20 '/sbin/pam_console_setowner $env{DEVICE} $env{DEVNAME} $env{DEVLINKS}' Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=3D14,=20 string=3D'/sbin/pam_console_setowner ', tail=3D' $env{DEVNAME} $env{DEVLINK= S}' Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=3D14,=20 string=3D'/sbin/pam_console_setowner ', tail=3D' $env{DEVLINKS}' Jan 24 21:04:25 cooker udevd-event[16049]: apply_format: format=3D14,=20 string=3D'/sbin/pam_console_setowner /dev/adsp ', tail=3D'' Jan 24 21:04:25 cooker udevd-event[16049]: run_program: arg[0]=20 '/sbin/pam_console_setowner' Jan 24 21:04:25 cooker udevd-event[16049]: run_program:=20 '/sbin/pam_console_setowner /dev/adsp /dev/sound/adsp' Jan 24 21:04:25 cooker udevd-event[16049]: run_program:=20 '/sbin/pam_console_setowner' returned with status 0 =2Dandrey --Boundary-01=_Cym1DKYHCMzYt0d Content-Type: text/plain; charset="iso-8859-1"; name="0001-Allow-substitution-of-environment-variables-in-RUN-commands.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Allow-substitution-of-environment-variables-in-RUN-commands.txt" 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. =2D-- 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 diff --git a/udev.c b/udev.c index 4762ab1..f808abf 100644 =2D-- a/udev.c +++ b/udev.c @@ -161,8 +161,13 @@ int main(int argc, char *argv[], char *e list_for_each_entry(name_loop, &udev->run_list, node) { if (strncmp(name_loop->name, "socket:", strlen("socket:")) =3D=3D 0) pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, actio= n); =2D else =2D run_program(name_loop->name, udev->dev->subsystem, NULL, 0, NULL, (u= dev_log_priority >=3D 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_pr= iority >=3D LOG_INFO)); + } } } =20 diff --git a/udev_rules.c b/udev_rules.c index e9d8d75..fbcbbe0 100644 =2D-- a/udev_rules.c +++ b/udev_rules.c @@ -362,7 +362,7 @@ static int wait_for_sysfs(struct udevice return -1; } =20 =2Dstatic void apply_format(struct udevice *udev, char *string, size_t maxs= ize) +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_rule name_list_cleanup(&udev->run_list); } strlcpy(program, key_val(rule, &rule->run), sizeof(program)); =2D apply_format(udev, program, sizeof(program)); dbg("add run '%s'", program); name_list_add(&udev->run_list, program, 0); } diff --git a/udev_rules.h b/udev_rules.h index 125babf..b183d9b 100644 =2D-- a/udev_rules.h +++ b/udev_rules.h @@ -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); =20 =2Dextern void udev_apply_format(struct udevice *udev, char *string, size_t= maxsize); +extern void apply_format(struct udevice *udev, char *string, size_t maxsiz= e); =20 extern void udev_rules_iter_init(struct udev_rules *rules); extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules); diff --git a/udevd.c b/udevd.c index c45d3a4..af5685c 100644 =2D-- a/udevd.c +++ b/udevd.c @@ -123,10 +123,15 @@ static int udev_event_process(struct uev list_for_each_entry(name_loop, &udev->run_list, node) { if (strncmp(name_loop->name, "socket:", strlen("socket:")) =3D=3D 0) pass_env_to_socket(&name_loop->name[strlen("socket:")], msg->devpath, = msg->action); =2D else =2D 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 >=3D LOG_INFO))) retval =3D -1; + } } } =20 diff --git a/udevstart.c b/udevstart.c index 8c414f1..11bdf79 100644 =2D-- a/udevstart.c +++ b/udevstart.c @@ -160,8 +160,13 @@ run: list_for_each_entry(name_loop, &udev->run_list, node) { if (strncmp(name_loop->name, "socket:", strlen("socket:")) =3D=3D 0) pass_env_to_socket(&name_loop->name[strlen("socket:")], udev->dev->dev= path, "add"); =2D else =2D run_program(name_loop->name, udev->dev->subsystem, NULL, 0, NULL, (u= dev_log_priority >=3D 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_pr= iority >=3D LOG_INFO)); + } } } exit: =2D-=20 1.1.4 --Boundary-01=_Cym1DKYHCMzYt0d-- --nextPart5870122.pOIq2PEuTp Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQBD1myCR6LMutpd94wRAu9VAKCLuCqg/Vk/DBmc58MIOPA6kRjIzgCdHXhD c7hukmTJClQ/UxOfiPvfUeE= =GQK8 -----END PGP SIGNATURE----- --nextPart5870122.pOIq2PEuTp-- ------------------------------------------------------- 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&kid=103432&bid=230486&dat=121642 _______________________________________________ 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