[systemd-devel] [RFC][PATCH] Escape unit name from udev
MUNEDA Takahiro
muneda.takahiro at jp.fujitsu.com
Thu May 2 07:48:46 PDT 2013
On Tue, 23 Apr 2013 13:34:38 -0400,
MUNEDA Takahiro <muneda.takahiro at jp.fujitsu.com> wrote:
> This patch escapes a unit name which was derived from udev.
>
> Please imagine following udev rule.
>
> ACTION=="online|offline", TAG+="systemd", ENV{SYSTEMD_WANTS}="muneda@%p.service"
> ACTION=="online|offline", TAG+="systemd", ENV{SYSTEMD_WANTS}="muneda@%r.service"
> ACTION=="online|offline", TAG+="systemd", ENV{SYSTEMD_WANTS}="muneda@%S.service"
>
> When unit name is derived from udev via
> udev_device_get_property_value(), the name may contains '/' if
> ENV{SYSTEMD_WANTS} has the udev options $devpath(%p), $root(%r), or
> $sys(%S). However, '/' is a invalid char for unit name so processing
> of this rule fails as Invalid argument with following message.
>
> Apr 22 13:21:37 localhost systemd[1]: Failed to load device unit: Invalid argument
> Apr 22 13:21:37 localhost systemd[1]: Failed to process udev device event: Invalid argument
>
> This patch escapes those invalid chars in a unit name.
> Tested with 202, and confirmed to apply cleanly on top of commit 195f8e36.
Ping, any comments?
I would like to get information which device had invoked the event.
If I sould not use $devpath(%p) in ENV{SYSTEMD_WANTS}, does anyone
have good idea to get those?
I know I can get them by calling application directly from udev rule,
but the command which is called from udev rule may be killed by
systemd-udevd if it runs longer than 30 sec. I'm expecting my
operations takes longer than 30 sec ;(
This idea comes from this thread.
http://lists.freedesktop.org/archives/systemd-devel/2012-November/007390.html
Thanks in advance,
Takahiro
> ---
> src/core/device.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/src/core/device.c b/src/core/device.c
> index 734d3f3..7b28aba 100644
> --- a/src/core/device.c
> +++ b/src/core/device.c
> @@ -281,16 +281,22 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
> size_t l;
>
> FOREACH_WORD_QUOTED(w, l, wants, state) {
> - char *e;
> + char *e, *n;
>
> e = strndup(w, l);
> if (!e) {
> r = -ENOMEM;
> goto fail;
> }
> -
> - r = unit_add_dependency_by_name(u, UNIT_WANTS, e, NULL, true);
> + n = unit_name_mangle(e);
> + if (!n) {
> + r = -ENOMEM;
> + goto fail;
> + }
> free(e);
> +
> + r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true);
> + free(n);
> if (r < 0)
> goto fail;
> }
>
More information about the systemd-devel
mailing list