[systemd-devel] [RFC] [PATCH] core: avoid duplicate unit property set

WaLyong Cho walyong.cho at samsung.com
Sun Dec 7 22:32:46 PST 2014


Hi,

First, I'd like to ask unit property should be applied immediately when
systemctl set-property is called?
If yes, after systemctl set-property, why we can see the message for
daemon-reload. I think that should be re-loaded automatically.
If no, some of unit properties are set immediatly.

See below:
# systemctl set-property dbus.service CPUShares=1200
# systemctl status dbus.service
* dbus.service - D-Bus System Message Bus
   Loaded: loaded (/usr/lib/systemd/system/dbus.service; enabled; vendor
preset: disabled)
   Active: active (running) since Mon 2014-12-08 14:59:12 KST; 1min 30s ago
     Docs: man:dbus-daemon(1)
 Main PID: 31 (dbus-daemon)
   CGroup: /machine.slice/machine-container.scope/system.slice/dbus.service
           `-31 /usr/bin/dbus-daemon --system --address=systemd:
--nofork --nopidfile --systemd-activation

Dec 08 14:59:12 container systemd[1]: Starting D-Bus System Message Bus...
Dec 08 14:59:12 container systemd[1]: Started D-Bus System Message Bus.
Dec 08 14:59:12 container dbus[31]: [system] Successfully activated
service 'org.freedesktop.systemd1'

Warning: Unit file changed on disk, 'systemctl daemon-reload' recommended.

systemctl status saied "systemctl daemon-reload" is needed. It sound
something is changed and to apply that daemon-reload is needed.
But I can notice that property already applied.

# systemctl show dbus.service | grep CPUShares
CPUShares=1200
StartupCPUShares=18446744073709551615


This immediate property set make duplicate operation when systemd-run is
called. The first will be set by transient property set in method call
handler. The second will be set by unit_load_dropin() the last actual load.

What it the most proper way?


WaLyong

On 12/08/2014 03:12 PM, WaLyong Cho wrote:
> Currently, unit property set apis set unit property and also make a
> dropin files in each dbus-xyz.c. And the dropin will set its
> properties again in unit_load().
> So don't need to set property immediatly. That will be set next
> unit_load(). Just write dropin files only.
> ---
>  src/core/dbus-cgroup.c   | 325 ++++++++++++++---------------------------------
>  src/core/dbus-cgroup.h   |   2 +-
>  src/core/dbus-execute.c  |  77 +++--------
>  src/core/dbus-execute.h  |   2 +-
>  src/core/dbus-kill.c     |  26 ++--
>  src/core/dbus-kill.h     |   2 +-
>  src/core/dbus-mount.c    |   8 +-
>  src/core/dbus-scope.c    |   6 +-
>  src/core/dbus-service.c  |  77 +++++------
>  src/core/dbus-slice.c    |   6 +-
>  src/core/dbus-socket.c   |   6 +-
>  src/core/dbus-swap.c     |   6 +-
>  src/core/dbus-unit.c     |  12 +-
>  src/core/load-fragment.c |  61 ++++++---
>  14 files changed, 227 insertions(+), 389 deletions(-)
> 
> diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
> index db99834..ffbd8d5 100644
> --- a/src/core/dbus-cgroup.c
> +++ b/src/core/dbus-cgroup.c
> @@ -24,6 +24,7 @@
>  #include "cgroup-util.h"
>  #include "cgroup.h"
>  #include "dbus-cgroup.h"
> +#include "strv.h"
>  
>  static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
>  
> @@ -173,16 +174,15 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
>  
>  static int bus_cgroup_set_transient_property(
>                  Unit *u,
> -                CGroupContext *c,
>                  const char *name,
>                  sd_bus_message *message,
>                  UnitSetPropertiesMode mode,
>                  sd_bus_error *error) {
>  
> +
>          int r;
>  
>          assert(u);
> -        assert(c);
>          assert(name);
>          assert(message);
>  
> @@ -194,8 +194,9 @@ static int bus_cgroup_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->delegate = b;
> -                        unit_write_drop_in_private(u, mode, name, b ? "Delegate=yes" : "Delegate=no");
> +                        r = unit_write_drop_in_private(u, mode, name, b ? "Delegate=yes" : "Delegate=no");
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -206,7 +207,6 @@ static int bus_cgroup_set_transient_property(
>  
>  int bus_cgroup_set_property(
>                  Unit *u,
> -                CGroupContext *c,
>                  const char *name,
>                  sd_bus_message *message,
>                  UnitSetPropertiesMode mode,
> @@ -215,7 +215,6 @@ int bus_cgroup_set_property(
>          int r;
>  
>          assert(u);
> -        assert(c);
>          assert(name);
>          assert(message);
>  
> @@ -227,9 +226,9 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->cpu_accounting = b;
> -                        u->cgroup_realized_mask &= ~CGROUP_CPUACCT;
> -                        unit_write_drop_in_private(u, mode, name, b ? "CPUAccounting=yes" : "CPUAccounting=no");
> +                        r = unit_write_drop_in_private(u, mode, name, b ? "CPUAccounting=yes" : "CPUAccounting=no");
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -251,9 +250,9 @@ int bus_cgroup_set_property(
>                  }
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->cpu_shares = ul;
> -                        u->cgroup_realized_mask &= ~CGROUP_CPU;
> -                        unit_write_drop_in_private_format(u, mode, name, "CPUShares=%lu", ul);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "CPUShares=%lu", ul);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -275,9 +274,9 @@ int bus_cgroup_set_property(
>                  }
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->startup_cpu_shares = ul;
> -                        u->cgroup_realized_mask &= ~CGROUP_CPU;
> -                        unit_write_drop_in_private_format(u, mode, name, "StartupCPUShares=%lu", ul);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "StartupCPUShares=%lu", ul);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -293,9 +292,9 @@ int bus_cgroup_set_property(
>                          return sd_bus_error_set_errnof(error, EINVAL, "CPUQuotaPerSecUSec value out of range");
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->cpu_quota_per_sec_usec = u64;
> -                        u->cgroup_realized_mask &= ~CGROUP_CPU;
> -                        unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (c->cpu_quota_per_sec_usec / 10000));
> +                        r = unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (u64 / 10000));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -308,9 +307,9 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->blockio_accounting = b;
> -                        u->cgroup_realized_mask &= ~CGROUP_BLKIO;
> -                        unit_write_drop_in_private(u, mode, name, b ? "BlockIOAccounting=yes" : "BlockIOAccounting=no");
> +                        r = unit_write_drop_in_private(u, mode, name, b ? "BlockIOAccounting=yes" : "BlockIOAccounting=no");
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -332,9 +331,9 @@ int bus_cgroup_set_property(
>                  }
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->blockio_weight = ul;
> -                        u->cgroup_realized_mask &= ~CGROUP_BLKIO;
> -                        unit_write_drop_in_private_format(u, mode, name, "BlockIOWeight=%lu", ul);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "BlockIOWeight=%lu", ul);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -356,58 +355,38 @@ int bus_cgroup_set_property(
>                  }
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->startup_blockio_weight = ul;
> -                        u->cgroup_realized_mask &= ~CGROUP_BLKIO;
> -                        unit_write_drop_in_private_format(u, mode, name, "StartupBlockIOWeight=%lu", ul);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "StartupBlockIOWeight=%lu", ul);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
>  
> -        } else if (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth")) {
> +        } else if (STR_IN_SET(name,
> +                              "BlockIOReadBandwidth",
> +                              "BlockIOWriteBandwidth")) {
>                  const char *path;
> -                bool read = true;
> -                unsigned n = 0;
>                  uint64_t u64;
> +                _cleanup_free_ char *buf = NULL;
> +                _cleanup_fclose_ FILE *f = NULL;
> +
> +                if (mode != UNIT_CHECK) {
> +                        size_t size = 0;
>  
> -                if (streq(name, "BlockIOWriteBandwidth"))
> -                        read = false;
> +                        f = open_memstream(&buf, &size);
> +                        if (!f)
> +                                return -ENOMEM;
> +
> +                        fprintf(f, "%s=\n", name);
> +                }
>  
>                  r = sd_bus_message_enter_container(message, 'a', "(st)");
>                  if (r < 0)
>                          return r;
>  
> -                while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
> -
> -                        if (mode != UNIT_CHECK) {
> -                                CGroupBlockIODeviceBandwidth *a = NULL, *b;
> -
> -                                LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
> -                                        if (path_equal(path, b->path) && read == b->read) {
> -                                                a = b;
> -                                                break;
> -                                        }
> -                                }
> -
> -                                if (!a) {
> -                                        a = new0(CGroupBlockIODeviceBandwidth, 1);
> -                                        if (!a)
> -                                                return -ENOMEM;
> -
> -                                        a->read = read;
> -                                        a->path = strdup(path);
> -                                        if (!a->path) {
> -                                                free(a);
> -                                                return -ENOMEM;
> -                                        }
> -
> -                                        LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a);
> -                                }
> -
> -                                a->bandwidth = u64;
> -                        }
> -
> -                        n++;
> -                }
> +                while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0)
> +                        if (mode != UNIT_CHECK)
> +                                fprintf(f, "%s=%s %" PRIu64 "\n", name, path, u64);
>                  if (r < 0)
>                          return r;
>  
> @@ -416,112 +395,49 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        CGroupBlockIODeviceBandwidth *a, *next;
> -                        _cleanup_free_ char *buf = NULL;
> -                        _cleanup_fclose_ FILE *f = NULL;
> -                        size_t size = 0;
> -
> -                        if (n == 0) {
> -                                LIST_FOREACH_SAFE(device_bandwidths, a, next, c->blockio_device_bandwidths)
> -                                        if (a->read == read)
> -                                                cgroup_context_free_blockio_device_bandwidth(c, a);
> -                        }
> -
> -                        u->cgroup_realized_mask &= ~CGROUP_BLKIO;
> -
> -                        f = open_memstream(&buf, &size);
> -                        if (!f)
> -                                return -ENOMEM;
> -
> -                         if (read) {
> -                                fputs("BlockIOReadBandwidth=\n", f);
> -                                 LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
> -                                        if (a->read)
> -                                                fprintf(f, "BlockIOReadBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
> -                        } else {
> -                                fputs("BlockIOWriteBandwidth=\n", f);
> -                                LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
> -                                        if (!a->read)
> -                                                fprintf(f, "BlockIOWriteBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
> -                        }
> -
>                          fflush(f);
> -                        unit_write_drop_in_private(u, mode, name, buf);
> +                        r = unit_write_drop_in_private(u, mode, name, buf);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
>  
>          } else if (streq(name, "BlockIODeviceWeight")) {
> +                _cleanup_free_ char *buf = NULL;
> +                _cleanup_fclose_ FILE *f = NULL;
>                  const char *path;
>                  uint64_t u64;
> -                unsigned n = 0;
> +
> +                if (mode != UNIT_CHECK) {
> +                        size_t size = 0;
> +
> +                        f = open_memstream(&buf, &size);
> +                        if (!f)
> +                                return -ENOMEM;
> +
> +                        fputs("BlockIODeviceWeight=\n", f);
> +                }
>  
>                  r = sd_bus_message_enter_container(message, 'a', "(st)");
>                  if (r < 0)
>                          return r;
>  
> -                while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
> -                        unsigned long ul = u64;
> -
> -                        if (ul < 10 || ul > 1000)
> -                                return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
> -
> -                        if (mode != UNIT_CHECK) {
> -                                CGroupBlockIODeviceWeight *a = NULL, *b;
> -
> -                                LIST_FOREACH(device_weights, b, c->blockio_device_weights) {
> -                                        if (path_equal(b->path, path)) {
> -                                                a = b;
> -                                                break;
> -                                        }
> -                                }
> -
> -                                if (!a) {
> -                                        a = new0(CGroupBlockIODeviceWeight, 1);
> -                                        if (!a)
> -                                                return -ENOMEM;
> -
> -                                        a->path = strdup(path);
> -                                        if (!a->path) {
> -                                                free(a);
> -                                                return -ENOMEM;
> -                                        }
> -                                        LIST_PREPEND(device_weights,c->blockio_device_weights, a);
> -                                }
> -
> -                                a->weight = ul;
> -                        }
> -
> -                        n++;
> -                }
> +                while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0)
> +                        if (mode != UNIT_CHECK)
> +                                fprintf(f, "%s=%s %lu\n", name, path, u64);
> +                if (r < 0)
> +                        return r;
>  
>                  r = sd_bus_message_exit_container(message);
>                  if (r < 0)
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        _cleanup_free_ char *buf = NULL;
> -                        _cleanup_fclose_ FILE *f = NULL;
> -                        CGroupBlockIODeviceWeight *a;
> -                        size_t size = 0;
> -
> -                        if (n == 0) {
> -                                while (c->blockio_device_weights)
> -                                        cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
> -                        }
> -
> -                        u->cgroup_realized_mask &= ~CGROUP_BLKIO;
> -
> -                        f = open_memstream(&buf, &size);
> -                        if (!f)
> -                                return -ENOMEM;
> -
> -                        fputs("BlockIODeviceWeight=\n", f);
> -                        LIST_FOREACH(device_weights, a, c->blockio_device_weights)
> -                                fprintf(f, "BlockIODeviceWeight=%s %lu\n", a->path, a->weight);
> -
>                          fflush(f);
> -                        unit_write_drop_in_private(u, mode, name, buf);
> +                        r = unit_write_drop_in_private(u, mode, name, buf);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -534,9 +450,9 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->memory_accounting = b;
> -                        u->cgroup_realized_mask &= ~CGROUP_MEMORY;
> -                        unit_write_drop_in_private(u, mode, name, b ? "MemoryAccounting=yes" : "MemoryAccounting=no");
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, yes_no(b));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -549,9 +465,9 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->memory_limit = limit;
> -                        u->cgroup_realized_mask &= ~CGROUP_MEMORY;
> -                        unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64, name, limit);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64, name, limit);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -569,70 +485,35 @@ int bus_cgroup_set_property(
>                          return -EINVAL;
>  
>                  if (mode != UNIT_CHECK) {
> -                        char *buf;
> -
> -                        c->device_policy = p;
> -                        u->cgroup_realized_mask &= ~CGROUP_DEVICE;
> -
> -                        buf = strappenda("DevicePolicy=", policy);
> -                        unit_write_drop_in_private(u, mode, name, buf);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, policy);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
>  
>          } else if (streq(name, "DeviceAllow")) {
> +                _cleanup_free_ char *buf = NULL;
> +                _cleanup_fclose_ FILE *f = NULL;
>                  const char *path, *rwm;
> -                unsigned n = 0;
> -
> -                r = sd_bus_message_enter_container(message, 'a', "(ss)");
> -                if (r < 0)
> -                        return r;
> -
> -                while ((r = sd_bus_message_read(message, "(ss)", &path, &rwm)) > 0) {
> -
> -                        if ((!startswith(path, "/dev/") &&
> -                             !startswith(path, "block-") &&
> -                             !startswith(path, "char-")) ||
> -                            strpbrk(path, WHITESPACE))
> -                            return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires device node");
> -
> -                        if (isempty(rwm))
> -                                rwm = "rwm";
> -
> -                        if (!in_charset(rwm, "rwm"))
> -                                return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires combination of rwm flags");
> -
> -                        if (mode != UNIT_CHECK) {
> -                                CGroupDeviceAllow *a = NULL, *b;
> -
> -                                LIST_FOREACH(device_allow, b, c->device_allow) {
> -                                        if (path_equal(b->path, path)) {
> -                                                a = b;
> -                                                break;
> -                                        }
> -                                }
>  
> -                                if (!a) {
> -                                        a = new0(CGroupDeviceAllow, 1);
> -                                        if (!a)
> -                                                return -ENOMEM;
> +                if (mode != UNIT_CHECK) {
> +                        size_t size = 0;
>  
> -                                        a->path = strdup(path);
> -                                        if (!a->path) {
> -                                                free(a);
> -                                                return -ENOMEM;
> -                                        }
> +                        f = open_memstream(&buf, &size);
> +                        if (!f)
> +                                return -ENOMEM;
>  
> -                                        LIST_PREPEND(device_allow, c->device_allow, a);
> -                                }
> +                        fputs("DeviceAllow=\n", f);
> +                }
>  
> -                                a->r = !!strchr(rwm, 'r');
> -                                a->w = !!strchr(rwm, 'w');
> -                                a->m = !!strchr(rwm, 'm');
> -                        }
> +                r = sd_bus_message_enter_container(message, 'a', "(ss)");
> +                if (r < 0)
> +                        return r;
>  
> -                        n++;
> -                }
> +                while ((r = sd_bus_message_read(message, "(ss)", &path, &rwm)) > 0)
> +                        if (mode != UNIT_CHECK)
> +                                fprintf(f, "DeviceAllow=%s %s\n", path, rwm);
>                  if (r < 0)
>                          return r;
>  
> @@ -641,28 +522,10 @@ int bus_cgroup_set_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        _cleanup_free_ char *buf = NULL;
> -                        _cleanup_fclose_ FILE *f = NULL;
> -                        CGroupDeviceAllow *a;
> -                        size_t size = 0;
> -
> -                        if (n == 0) {
> -                                while (c->device_allow)
> -                                        cgroup_context_free_device_allow(c, c->device_allow);
> -                        }
> -
> -                        u->cgroup_realized_mask &= ~CGROUP_DEVICE;
> -
> -                        f = open_memstream(&buf, &size);
> -                        if (!f)
> -                                return -ENOMEM;
> -
> -                        fputs("DeviceAllow=\n", f);
> -                        LIST_FOREACH(device_allow, a, c->device_allow)
> -                                fprintf(f, "DeviceAllow=%s %s%s%s\n", a->path, a->r ? "r" : "", a->w ? "w" : "", a->m ? "m" : "");
> -
>                          fflush(f);
> -                        unit_write_drop_in_private(u, mode, name, buf);
> +                        r = unit_write_drop_in_private(u, mode, name, buf);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -670,7 +533,7 @@ int bus_cgroup_set_property(
>          }
>  
>          if (u->transient && u->load_state == UNIT_STUB) {
> -                r = bus_cgroup_set_transient_property(u, c, name, message, mode, error);
> +                r = bus_cgroup_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>  
> diff --git a/src/core/dbus-cgroup.h b/src/core/dbus-cgroup.h
> index c2a3910..5567e61 100644
> --- a/src/core/dbus-cgroup.h
> +++ b/src/core/dbus-cgroup.h
> @@ -26,4 +26,4 @@
>  
>  extern const sd_bus_vtable bus_cgroup_vtable[];
>  
> -int bus_cgroup_set_property(Unit *u, CGroupContext *c, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> +int bus_cgroup_set_property(Unit *u, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
> index bbcd610..e32ae8e 100644
> --- a/src/core/dbus-execute.c
> +++ b/src/core/dbus-execute.c
> @@ -759,7 +759,6 @@ int bus_property_get_exec_command_list(
>  
>  int bus_exec_context_set_transient_property(
>                  Unit *u,
> -                ExecContext *c,
>                  const char *name,
>                  sd_bus_message *message,
>                  UnitSetPropertiesMode mode,
> @@ -768,7 +767,6 @@ int bus_exec_context_set_transient_property(
>          int r;
>  
>          assert(u);
> -        assert(c);
>          assert(name);
>          assert(message);
>  
> @@ -780,22 +778,9 @@ int bus_exec_context_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -
> -                        if (isempty(uu)) {
> -                                free(c->user);
> -                                c->user = NULL;
> -                        } else {
> -                                char *t;
> -
> -                                t = strdup(uu);
> -                                if (!t)
> -                                        return -ENOMEM;
> -
> -                                free(c->user);
> -                                c->user = t;
> -                        }
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "User=%s\n", uu);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "User=%s\n", uu);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -808,22 +793,9 @@ int bus_exec_context_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -
> -                        if (isempty(gg)) {
> -                                free(c->group);
> -                                c->group = NULL;
> -                        } else {
> -                                char *t;
> -
> -                                t = strdup(gg);
> -                                if (!t)
> -                                        return -ENOMEM;
> -
> -                                free(c->group);
> -                                c->group = t;
> -                        }
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "Group=%s\n", gg);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "Group=%s\n", gg);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -839,8 +811,9 @@ int bus_exec_context_set_transient_property(
>                          return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Nice value out of range");
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->nice = n;
> -                        unit_write_drop_in_private_format(u, mode, name, "Nice=%i\n", n);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "Nice=%i\n", n);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -858,20 +831,14 @@ int bus_exec_context_set_transient_property(
>  
>                  if (mode != UNIT_CHECK) {
>                          _cleanup_free_ char *joined = NULL;
> -                        char **e;
> -
> -                        e = strv_env_merge(2, c->environment, l);
> -                        if (!e)
> -                                return -ENOMEM;
> -
> -                        strv_free(c->environment);
> -                        c->environment = e;
>  
> -                        joined = strv_join_quoted(c->environment);
> +                        joined = strv_join_quoted(l);
>                          if (!joined)
>                                  return -ENOMEM;
>  
> -                        unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
> +                        r = unit_write_drop_in_private_format(u, mode, name, "Environment=%s\n", joined);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -894,22 +861,12 @@ int bus_exec_context_set_transient_property(
>                  }
>  
>                  if (mode != UNIT_CHECK) {
> -                        int z;
> -
> -                        z = rlimit_from_string(name);
> -
> -                        if (!c->rlimit[z]) {
> -                                c->rlimit[z] = new(struct rlimit, 1);
> -                                if (!c->rlimit[z])
> -                                        return -ENOMEM;
> -                        }
> -
> -                        c->rlimit[z]->rlim_cur = c->rlimit[z]->rlim_max = x;
> -
>                          if (x == RLIM_INFINITY)
> -                                unit_write_drop_in_private_format(u, mode, name, "%s=infinity\n", name);
> +                                r = unit_write_drop_in_private_format(u, mode, name, "%s=infinity\n", name);
>                          else
> -                                unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64 "\n", name, rl);
> +                                r = unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64 "\n", name, rl);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> diff --git a/src/core/dbus-execute.h b/src/core/dbus-execute.h
> index e4c2d5d..baeb2c8 100644
> --- a/src/core/dbus-execute.h
> +++ b/src/core/dbus-execute.h
> @@ -43,4 +43,4 @@ int bus_property_get_exec_output(sd_bus *bus, const char *path, const char *inte
>  int bus_property_get_exec_command(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
>  int bus_property_get_exec_command_list(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
>  
> -int bus_exec_context_set_transient_property(Unit *u, ExecContext *c, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> +int bus_exec_context_set_transient_property(Unit *u, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c
> index fb29e14..a095693 100644
> --- a/src/core/dbus-kill.c
> +++ b/src/core/dbus-kill.c
> @@ -36,7 +36,6 @@ const sd_bus_vtable bus_kill_vtable[] = {
>  
>  int bus_kill_context_set_transient_property(
>                  Unit *u,
> -                KillContext *c,
>                  const char *name,
>                  sd_bus_message *message,
>                  UnitSetPropertiesMode mode,
> @@ -45,7 +44,6 @@ int bus_kill_context_set_transient_property(
>          int r;
>  
>          assert(u);
> -        assert(c);
>          assert(name);
>          assert(message);
>  
> @@ -62,9 +60,9 @@ int bus_kill_context_set_transient_property(
>                          return -EINVAL;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->kill_mode = k;
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "KillMode=%s\n", kill_mode_to_string(k));
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, kill_mode_to_string(k));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -80,9 +78,9 @@ int bus_kill_context_set_transient_property(
>                          return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->kill_signal = sig;
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "KillSignal=%s\n", signal_to_string(sig));
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, signal_to_string(sig));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -95,9 +93,9 @@ int bus_kill_context_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->send_sighup = b;
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b));
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, yes_no(b));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -110,9 +108,9 @@ int bus_kill_context_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        c->send_sigkill = b;
> -
> -                        unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b));
> +                        r = unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, yes_no(b));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> diff --git a/src/core/dbus-kill.h b/src/core/dbus-kill.h
> index 7c15f3a..4968804 100644
> --- a/src/core/dbus-kill.h
> +++ b/src/core/dbus-kill.h
> @@ -27,4 +27,4 @@
>  
>  extern const sd_bus_vtable bus_kill_vtable[];
>  
> -int bus_kill_context_set_transient_property(Unit *u, KillContext *c, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> +int bus_kill_context_set_transient_property(Unit *u, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
> diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c
> index 53fe4ed..97d28e9 100644
> --- a/src/core/dbus-mount.c
> +++ b/src/core/dbus-mount.c
> @@ -176,11 +176,11 @@ int bus_mount_set_property(
>          Mount *m = MOUNT(u);
>          int r;
>  
> -        assert(m);
> +        assert(u);
>          assert(name);
>          assert(message);
>  
> -        r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, mode, error);
> +        r = bus_cgroup_set_property(u, name, message, mode, error);
>          if (r != 0)
>                  return r;
>  
> @@ -191,11 +191,11 @@ int bus_mount_set_property(
>                  if (r != 0)
>                          return r;
>  
> -                r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, mode, error);
> +                r = bus_exec_context_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>  
> -                r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, mode, error);
> +                r = bus_kill_context_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>          }
> diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
> index a762223..b61902c 100644
> --- a/src/core/dbus-scope.c
> +++ b/src/core/dbus-scope.c
> @@ -168,11 +168,11 @@ int bus_scope_set_property(
>          Scope *s = SCOPE(u);
>          int r;
>  
> -        assert(s);
> +        assert(u);
>          assert(name);
>          assert(message);
>  
> -        r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
> +        r = bus_cgroup_set_property(u, name, message, mode, error);
>          if (r != 0)
>                  return r;
>  
> @@ -183,7 +183,7 @@ int bus_scope_set_property(
>                  if (r != 0)
>                          return r;
>  
> -                r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error);
> +                r = bus_kill_context_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>          }
> diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
> index 5a881e8..6368beb 100644
> --- a/src/core/dbus-service.c
> +++ b/src/core/dbus-service.c
> @@ -93,8 +93,9 @@ static int bus_service_set_transient_property(
>                          return r;
>  
>                  if (mode != UNIT_CHECK) {
> -                        s->remain_after_exit = b;
> -                        unit_write_drop_in_private_format(UNIT(s), mode, name, "RemainAfterExit=%s\n", yes_no(b));
> +                        r = unit_write_drop_in_private_format(UNIT(s), mode, name, "RemainAfterExit=%s\n", yes_no(b));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -112,19 +113,31 @@ static int bus_service_set_transient_property(
>                          return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid service type %s", t);
>  
>                  if (mode != UNIT_CHECK) {
> -                        s->type = k;
> -                        unit_write_drop_in_private_format(UNIT(s), mode, name, "Type=%s\n", service_type_to_string(s->type));
> +                        r = unit_write_drop_in_private_format(UNIT(s), mode, name, "Type=%s\n", service_type_to_string(s->type));
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
>  
>          } else if (streq(name, "ExecStart")) {
> -                unsigned n = 0;
> +
> +                _cleanup_free_ char *buf = NULL;
> +                _cleanup_fclose_ FILE *f = NULL;
> +                size_t size = 0;
>  
>                  r = sd_bus_message_enter_container(message, 'a', "(sasb)");
>                  if (r < 0)
>                          return r;
>  
> +                if (mode != UNIT_CHECK) {
> +                        f = open_memstream(&buf, &size);
> +                        if (!f)
> +                                return -ENOMEM;
> +
> +                        fputs("ExecStart=\n", f);
> +                }
> +
>                  while ((r = sd_bus_message_enter_container(message, 'r', "sasb")) > 0) {
>                          _cleanup_strv_free_ char **argv = NULL;
>                          const char *path;
> @@ -151,6 +164,7 @@ static int bus_service_set_transient_property(
>  
>                          if (mode != UNIT_CHECK) {
>                                  ExecCommand *c;
> +                                _cleanup_free_ char *a;
>  
>                                  c = new0(ExecCommand, 1);
>                                  if (!c)
> @@ -168,38 +182,6 @@ static int bus_service_set_transient_property(
>                                  c->ignore = b;
>  
>                                  path_kill_slashes(c->path);
> -                                exec_command_append_list(&s->exec_command[SERVICE_EXEC_START], c);
> -                        }
> -
> -                        n++;
> -                }
> -
> -                if (r < 0)
> -                        return r;
> -
> -                r = sd_bus_message_exit_container(message);
> -                if (r < 0)
> -                        return r;
> -
> -                if (mode != UNIT_CHECK) {
> -                        _cleanup_free_ char *buf = NULL;
> -                        _cleanup_fclose_ FILE *f = NULL;
> -                        ExecCommand *c;
> -                        size_t size = 0;
> -
> -                        if (n == 0) {
> -                                exec_command_free_list(s->exec_command[SERVICE_EXEC_START]);
> -                                s->exec_command[SERVICE_EXEC_START] = NULL;
> -                        }
> -
> -                        f = open_memstream(&buf, &size);
> -                        if (!f)
> -                                return -ENOMEM;
> -
> -                        fputs("ExecStart=\n", f);
> -
> -                        LIST_FOREACH(command, c, s->exec_command[SERVICE_EXEC_START]) {
> -                                _cleanup_free_ char *a;
>  
>                                  a = strv_join_quoted(c->argv);
>                                  if (!a)
> @@ -210,9 +192,20 @@ static int bus_service_set_transient_property(
>                                          c->path,
>                                          a);
>                          }
> +                }
>  
> +                if (r < 0)
> +                        return r;
> +
> +                r = sd_bus_message_exit_container(message);
> +                if (r < 0)
> +                        return r;
> +
> +                if (mode != UNIT_CHECK) {
>                          fflush(f);
> -                        unit_write_drop_in_private(UNIT(s), mode, name, buf);
> +                        r = unit_write_drop_in_private(UNIT(s), mode, name, buf);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -231,11 +224,11 @@ int bus_service_set_property(
>          Service *s = SERVICE(u);
>          int r;
>  
> -        assert(s);
> +        assert(u);
>          assert(name);
>          assert(message);
>  
> -        r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
> +        r = bus_cgroup_set_property(u, name, message, mode, error);
>          if (r != 0)
>                  return r;
>  
> @@ -246,11 +239,11 @@ int bus_service_set_property(
>                  if (r != 0)
>                          return r;
>  
> -                r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, mode, error);
> +                r = bus_exec_context_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>  
> -                r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error);
> +                r = bus_kill_context_set_transient_property(u, name, message, mode, error);
>                  if (r != 0)
>                          return r;
>          }
> diff --git a/src/core/dbus-slice.c b/src/core/dbus-slice.c
> index 8bc90b1..88c3c0d 100644
> --- a/src/core/dbus-slice.c
> +++ b/src/core/dbus-slice.c
> @@ -37,12 +37,10 @@ int bus_slice_set_property(
>                  UnitSetPropertiesMode mode,
>                  sd_bus_error *error) {
>  
> -        Slice *s = SLICE(u);
> -
> -        assert(name);
>          assert(u);
> +        assert(name);
>  
> -        return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
> +        return bus_cgroup_set_property(u, name, message, mode, error);
>  }
>  
>  int bus_slice_commit_properties(Unit *u) {
> diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c
> index 50b1674..6c7e6c4 100644
> --- a/src/core/dbus-socket.c
> +++ b/src/core/dbus-socket.c
> @@ -142,13 +142,11 @@ int bus_socket_set_property(
>                  UnitSetPropertiesMode mode,
>                  sd_bus_error *error) {
>  
> -        Socket *s = SOCKET(u);
> -
> -        assert(s);
> +        assert(u);
>          assert(name);
>          assert(message);
>  
> -        return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
> +        return bus_cgroup_set_property(u, name, message, mode, error);
>  }
>  
>  int bus_socket_commit_properties(Unit *u) {
> diff --git a/src/core/dbus-swap.c b/src/core/dbus-swap.c
> index 1e7f66d..107d0f4 100644
> --- a/src/core/dbus-swap.c
> +++ b/src/core/dbus-swap.c
> @@ -99,13 +99,11 @@ int bus_swap_set_property(
>                  UnitSetPropertiesMode mode,
>                  sd_bus_error *error) {
>  
> -        Swap *s = SWAP(u);
> -
> -        assert(s);
> +        assert(u);
>          assert(name);
>          assert(message);
>  
> -        return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
> +        return bus_cgroup_set_property(u, name, message, mode, error);
>  }
>  
>  int bus_swap_commit_properties(Unit *u) {
> diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
> index cc09a26..408e1c5 100644
> --- a/src/core/dbus-unit.c
> +++ b/src/core/dbus-unit.c
> @@ -857,7 +857,9 @@ static int bus_unit_set_transient_property(
>                          if (r < 0)
>                                  return r;
>  
> -                        unit_write_drop_in_format(u, mode, name, "[Unit]\nDescription=%s\n", d);
> +                        r = unit_write_drop_in_format(u, mode, name, "[Unit]\nDescription=%s\n", d);
> +                        if (r < 0)
> +                                return r;
>                  }
>  
>                  return 1;
> @@ -889,7 +891,9 @@ static int bus_unit_set_transient_property(
>  
>                          if (mode != UNIT_CHECK) {
>                                  unit_ref_set(&u->slice, slice);
> -                                unit_write_drop_in_private_format(u, mode, name, "Slice=%s\n", s);
> +                                r = unit_write_drop_in_private_format(u, mode, name, "Slice=%s\n", s);
> +                                if (r < 0)
> +                                        return r;
>                          }
>                  }
>  
> @@ -931,7 +935,9 @@ static int bus_unit_set_transient_property(
>                                  if (!label)
>                                          return -ENOMEM;
>  
> -                                unit_write_drop_in_format(u, mode, label, "[Unit]\n%s=%s\n", name, other);
> +                                r = unit_write_drop_in_format(u, mode, label, "[Unit]\n%s=%s\n", name, other);
> +                                if (r < 0)
> +                                        return r;
>                          }
>  
>                  }
> diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
> index d385968..1326eff 100644
> --- a/src/core/load-fragment.c
> +++ b/src/core/load-fragment.c
> @@ -2741,6 +2741,7 @@ int config_parse_device_allow(
>          _cleanup_free_ char *path = NULL;
>          CGroupContext *c = data;
>          CGroupDeviceAllow *a;
> +        bool already = false;
>          const char *m;
>          size_t n;
>  
> @@ -2774,12 +2775,21 @@ int config_parse_device_allow(
>                  return 0;
>          }
>  
> -        a = new0(CGroupDeviceAllow, 1);
> -        if (!a)
> -                return log_oom();
> +        LIST_FOREACH(device_allow, a, c->device_allow) {
> +                already = path_equal(a->path, path);
> +                if (already)
> +                        break;
> +        }
> +
> +        if (!already) {
> +                a = new0(CGroupDeviceAllow, 1);
> +                if (!a)
> +                        return log_oom();
> +
> +                a->path = path;
> +                path = NULL;
> +        }
>  
> -        a->path = path;
> -        path = NULL;
>          a->r = !!strchr(m, 'r');
>          a->w = !!strchr(m, 'w');
>          a->m = !!strchr(m, 'm');
> @@ -2838,6 +2848,7 @@ int config_parse_blockio_device_weight(
>          _cleanup_free_ char *path = NULL;
>          CGroupBlockIODeviceWeight *w;
>          CGroupContext *c = data;
> +        bool already = false;
>          unsigned long lu;
>          const char *weight;
>          size_t n;
> @@ -2880,12 +2891,20 @@ int config_parse_blockio_device_weight(
>                  return 0;
>          }
>  
> -        w = new0(CGroupBlockIODeviceWeight, 1);
> -        if (!w)
> -                return log_oom();
> +        LIST_FOREACH(device_weights, w, c->blockio_device_weights) {
> +                already = path_equal(w->path, path);
> +                if (already)
> +                        break;
> +        }
>  
> -        w->path = path;
> -        path = NULL;
> +        if (!already) {
> +                w = new0(CGroupBlockIODeviceWeight, 1);
> +                if (!w)
> +                        return log_oom();
> +
> +                w->path = path;
> +                path = NULL;
> +        }
>  
>          w->weight = lu;
>  
> @@ -2910,7 +2929,7 @@ int config_parse_blockio_bandwidth(
>          CGroupContext *c = data;
>          const char *bandwidth;
>          off_t bytes;
> -        bool read;
> +        bool read, already = false;
>          size_t n;
>          int r;
>  
> @@ -2957,14 +2976,22 @@ int config_parse_blockio_bandwidth(
>                  return 0;
>          }
>  
> -        b = new0(CGroupBlockIODeviceBandwidth, 1);
> -        if (!b)
> -                return log_oom();
> +        LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
> +                already = path_equal(path, b->path) && read == b->read;
> +                if (already)
> +                        break;
> +        }
> +
> +        if (!already) {
> +                b = new0(CGroupBlockIODeviceBandwidth, 1);
> +                if (!b)
> +                        return log_oom();
>  
> -        b->path = path;
> -        path = NULL;
> +                b->path = path;
> +                path = NULL;
> +                b->read = read;
> +        }
>          b->bandwidth = (uint64_t) bytes;
> -        b->read = read;
>  
>          LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b);
>  
> 


More information about the systemd-devel mailing list