[systemd-devel] [PATCH] Remove device and its relatives when action is offlined

MUNEDA Takahiro muneda.takahiro at jp.fujitsu.com
Mon Sep 9 14:23:55 PDT 2013


On Fri, 06 Sep 2013 22:41:05 -0400,
MUNEDA Takahiro <muneda.takahiro at jp.fujitsu.com> wrote:

> When an unit is called via udev rules like below, only first 'online'
> works correctly.  Even if 'offline' event has happen, device and its
> relative data still exists inside systemd, then following online
> events will be ignored since systemd thinks it's already done.  The
> device and its relatives should be removed when 'offline' event has
> happened.
> 
>    ACTION=="online|offline", TAG+="systemd", ENV{SYSTEMD_WANTS}="muneda@$devpath_$env{ACTION}.service"
> 
> Tested with
>    kernel-3.10.10-200.fc19.x86_64
>    systemd-204-9.fc19.x86_64
> 
> And I confirmed that this patch can apply cleanly on git HEAD
> (a012ab5).

Ok, I found out another problem.
Even if I have a following udev rules and 'remove' event happens, no 
systemd service will be called.

  ACTION=="add|remove", TAG+="systemd", ENV{SYSTEMD_WANTS}="muneda at .service"

My final goal is to invoke my systemd service which calls programs 
that needs a bit long time when I do add/online or remove/offline my 
device.  udev provided this feature before it's merged into systemd.  
My previous patch let 'offline' event to remove device information 
from systemd (probably, remove from udev database?), but systemd does 
not call service as I expected.

Thanks,
Takahiro

> ---
>   src/core/device.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/core/device.c b/src/core/device.c
> index 9fca82a..467c5ef 100644
> --- a/src/core/device.c
> +++ b/src/core/device.c
> @@ -589,7 +589,7 @@ void device_fd_event(Manager *m, int events) {
>   
>           ready = udev_device_get_property_value(dev, "SYSTEMD_READY");
>   
> -        if (streq(action, "remove") || (ready && parse_boolean(ready) == 0)) {
> +        if (streq(action, "remove") || streq(action, "offline") || (ready && parse_boolean(ready) == 0)) {
>                   if ((r = device_process_removed_device(m, dev)) < 0) {
>                           log_error("Failed to process udev device event: %s", strerror(-r));
>                           goto fail;
> 


More information about the systemd-devel mailing list