From: Andrey Borzenkov <arvidjaar@mail.ru>
To: linux-hotplug@vger.kernel.org
Subject: Re: DEVLINKS and DEVNAME variables in RUN rules
Date: Tue, 24 Jan 2006 18:05:51 +0000 [thread overview]
Message-ID: <200601242105.54783.arvidjaar@mail.ru> (raw)
In-Reply-To: <m3bqy1a91w.fsf@dynamo.mandriva.com>
[-- Attachment #1.1: Type: text/plain, Size: 1427 bytes --]
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+="/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}'
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
[-- Attachment #1.2: 0001-Allow-substitution-of-environment-variables-in-RUN-commands.txt --]
[-- Type: text/plain, Size: 4123 bytes --]
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
diff --git a/udev.c b/udev.c
index 4762ab1..f808abf 100644
--- 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:")) == 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));
+ }
}
}
diff --git a/udev_rules.c b/udev_rules.c
index e9d8d75..fbcbbe0 100644
--- a/udev_rules.c
+++ b/udev_rules.c
@@ -362,7 +362,7 @@ static int wait_for_sysfs(struct udevice
return -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_rule
name_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);
}
diff --git a/udev_rules.h b/udev_rules.h
index 125babf..b183d9b 100644
--- 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);
-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);
diff --git a/udevd.c b/udevd.c
index c45d3a4..af5685c 100644
--- 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:")) == 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;
+ }
}
}
diff --git a/udevstart.c b/udevstart.c
index 8c414f1..11bdf79 100644
--- 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:")) == 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:
--
1.1.4
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2006-01-24 18:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-24 16:24 DEVLINKS and DEVNAME variables in RUN rules Olivier Blin
2006-01-24 18:05 ` Andrey Borzenkov [this message]
2006-01-24 19:43 ` Kay Sievers
2006-01-25 18:18 ` Andrey Borzenkov
2006-01-25 18:25 ` Olivier Blin
2006-01-25 18:52 ` Kay Sievers
2006-01-25 19:03 ` Andrey Borzenkov
2006-01-25 19:10 ` Kay Sievers
2006-01-25 19:38 ` Andrey Borzenkov
2006-01-26 1:18 ` Kay Sievers
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=200601242105.54783.arvidjaar@mail.ru \
--to=arvidjaar@mail.ru \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).