[systemd-devel] [PATCHv2] bus-control: Fix cgroup handling

Lennart Poettering lennart at poettering.net
Mon Aug 18 12:04:31 PDT 2014


On Mon, 18.08.14 13:21, Denis Kenzior (denkenz at gmail.com) wrote:

Thanks! Applied!

> On systems without properly setup systemd, cg_get_root_path returns
> -ENOENT.  This means that busctl doesn't display much information.
> 
> busctl monitor also fails whenever it intercepts messages.
> 
> This fix fakes creates a fake "/" root cgroup which lets busctl work
> on such systems.
> ---
>  src/libsystemd/sd-bus/bus-control.c  |  8 +++-----
>  src/libsystemd/sd-bus/bus-internal.h |  2 ++
>  src/libsystemd/sd-bus/bus-kernel.c   |  8 +++-----
>  src/libsystemd/sd-bus/sd-bus.c       | 18 ++++++++++++++++++
>  4 files changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
> index 076bbce..ad372f6 100644
> --- a/src/libsystemd/sd-bus/bus-control.c
> +++ b/src/libsystemd/sd-bus/bus-control.c
> @@ -495,11 +495,9 @@ static int bus_get_owner_kdbus(
>                                          goto fail;
>                                  }
>  
> -                                if (!bus->cgroup_root) {
> -                                        r = cg_get_root_path(&bus->cgroup_root);
> -                                        if (r < 0)
> -                                                goto fail;
> -                                }
> +                                r = bus_get_root_path(bus);
> +                                if (r < 0)
> +                                        goto fail;
>  
>                                  c->cgroup_root = strdup(bus->cgroup_root);
>                                  if (!c->cgroup_root) {
> diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h
> index 618e82c..8827061 100644
> --- a/src/libsystemd/sd-bus/bus-internal.h
> +++ b/src/libsystemd/sd-bus/bus-internal.h
> @@ -381,3 +381,5 @@ int bus_set_address_system_remote(sd_bus *b, const char *host);
>  int bus_set_address_system_container(sd_bus *b, const char *machine);
>  
>  int bus_remove_match_by_string(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
> +
> +int bus_get_root_path(sd_bus *bus);
> diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
> index 8b961c3..9073b3c 100644
> --- a/src/libsystemd/sd-bus/bus-kernel.c
> +++ b/src/libsystemd/sd-bus/bus-kernel.c
> @@ -542,11 +542,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
>                          m->creds.cgroup = d->str;
>                          m->creds.mask |= (SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID) & bus->creds_mask;
>  
> -                        if (!bus->cgroup_root) {
> -                                r = cg_get_root_path(&bus->cgroup_root);
> -                                if (r < 0)
> -                                        goto fail;
> -                        }
> +                        r = bus_get_root_path(bus);
> +                        if (r < 0)
> +                                goto fail;
>  
>                          m->creds.cgroup_root = bus->cgroup_root;
>  
> diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
> index 0fadd16..7febf3c 100644
> --- a/src/libsystemd/sd-bus/sd-bus.c
> +++ b/src/libsystemd/sd-bus/sd-bus.c
> @@ -3330,3 +3330,21 @@ _public_ int sd_bus_get_name(sd_bus *bus, const char **name) {
>          *name = bus->connection_name;
>          return 0;
>  }
> +
> +int bus_get_root_path(sd_bus *bus) {
> +        int r;
> +
> +        if (bus->cgroup_root)
> +                return 0;
> +
> +        r = cg_get_root_path(&bus->cgroup_root);
> +        if (r == -ENOENT) {
> +                bus->cgroup_root = strdup("/");
> +                if (!bus->cgroup_root)
> +                        return -ENOMEM;
> +
> +                r = 0;
> +        }
> +
> +        return r;
> +}


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list