summaryrefslogtreecommitdiffstats
path: root/src/core/dbus-util.h
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-01-02 18:30:16 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-01-02 18:33:16 +0100
commit681ae88e06f2acbfb3b7adf681a681c32c1d5843 (patch)
tree4e05ca3755ab51e24ff94a37ccb3f082019b1d6a /src/core/dbus-util.h
parentdbus-cgroup: add missing space (diff)
downloadsystemd-681ae88e06f2acbfb3b7adf681a681c32c1d5843.tar.xz
systemd-681ae88e06f2acbfb3b7adf681a681c32c1d5843.zip
dbus-cgroup: simplify bus_cgroup_set_property()
Diffstat (limited to 'src/core/dbus-util.h')
-rw-r--r--src/core/dbus-util.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/core/dbus-util.h b/src/core/dbus-util.h
index bef8bc35e1..8260298577 100644
--- a/src/core/dbus-util.h
+++ b/src/core/dbus-util.h
@@ -256,6 +256,86 @@
} \
struct __useless_struct_to_allow_trailing_semicolon__
+#define BUS_DEFINE_SET_CGROUP_WEIGHT(function, mask, check, val, str) \
+ int bus_cgroup_set_##function( \
+ Unit *u, \
+ const char *name, \
+ uint64_t *p, \
+ sd_bus_message *message, \
+ UnitWriteFlags flags, \
+ sd_bus_error *error) { \
+ \
+ uint64_t v; \
+ int r; \
+ \
+ assert(p); \
+ \
+ r = sd_bus_message_read(message, "t", &v); \
+ if (r < 0) \
+ return r; \
+ \
+ if (!check(v)) \
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
+ "Value specified in %s is out of range", name); \
+ \
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
+ *p = v; \
+ unit_invalidate_cgroup(u, (mask)); \
+ \
+ if (v == (val)) \
+ unit_write_settingf(u, flags, name, \
+ "%s=" str, name); \
+ else \
+ unit_write_settingf(u, flags, name, \
+ "%s=%" PRIu64, name, v); \
+ } \
+ \
+ return 1; \
+ } \
+ struct __useless_struct_to_allow_trailing_semicolon__
+
+#define BUS_DEFINE_SET_CGROUP_SCALE(function, mask, scale) \
+ int bus_cgroup_set_##function##_scale( \
+ Unit *u, \
+ const char *name, \
+ uint64_t *p, \
+ sd_bus_message *message, \
+ UnitWriteFlags flags, \
+ sd_bus_error *error) { \
+ \
+ uint64_t v; \
+ uint32_t raw; \
+ int r; \
+ \
+ assert(p); \
+ \
+ r = sd_bus_message_read(message, "u", &raw); \
+ if (r < 0) \
+ return r; \
+ \
+ v = scale(raw, UINT32_MAX); \
+ if (v <= 0 || v >= UINT64_MAX) \
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
+ "Value specified in %s is out of range", name); \
+ \
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
+ const char *e; \
+ \
+ *p = v; \
+ unit_invalidate_cgroup(u, (mask)); \
+ \
+ /* Chop off suffix */ \
+ assert_se(e = endswith(name, "Scale")); \
+ name = strndupa(name, e - name); \
+ \
+ unit_write_settingf(u, flags, name, "%s=%" PRIu32 "%%", name, \
+ (uint32_t) (DIV_ROUND_UP((uint64_t) raw * 100U, (uint64_t) UINT32_MAX))); \
+ } \
+ \
+ return 1; \
+ } \
+ struct __useless_struct_to_allow_trailing_semicolon__
+
int bus_set_transient_mode_t(Unit *u, const char *name, mode_t *p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
int bus_set_transient_unsigned(Unit *u, const char *name, unsigned *p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
int bus_set_transient_user(Unit *u, const char *name, char **p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);