[systemd-devel] [PATCH] unit: fix unit_stop

Lennart Poettering lennart at poettering.net
Fri Jul 26 10:09:08 PDT 2013


On Fri, 26.07.13 16:28, Ronny Chevalier (rchevalier at aldebaran-robotics.com) wrote:

> If we don't add the unit to the cleanup queue after it has been
> stopped, no UnitRemoved will be sent. Since this signal is only sent
> when we free a unit. So we need to add it to the cleanup queue if we
> manage to stop it.

UnitRemoved is about unloading, not about stopping.

A unit will stay loaded as long as it is referenced and GC'ed only if
there's not reference anymore and it is stopped and has no processes
running anymore.

If you want to follow the state of a unit, then watch for
PropertiesChanged signals and the ActiveState variable therein

> ---
>  src/core/unit.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/core/unit.c b/src/core/unit.c
> index 0e9329f..c91c12f 100644
> --- a/src/core/unit.c
> +++ b/src/core/unit.c
> @@ -1171,6 +1171,7 @@ bool unit_can_isolate(Unit *u) {
>  int unit_stop(Unit *u) {
>          UnitActiveState state;
>          Unit *following;
> +        int ret;
>  
>          assert(u);
>  
> @@ -1192,7 +1193,11 @@ int unit_stop(Unit *u) {
>  
>          unit_add_to_dbus_queue(u);
>  
> -        return UNIT_VTABLE(u)->stop(u);
> +        ret = UNIT_VTABLE(u)->stop(u);
> +        if (ret == 0)
> +                unit_add_to_cleanup_queue(u);
> +
> +        return ret;
>  }
>  
>  /* Errors:


Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list