X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fdbus-unit.c;h=fe876b3ffe69316604b2342fe4c17c8044a19ee9;hb=cc98b3025eeb89addb76a27390cb2baca4eab8b9;hp=36b68aee9ed92f4031404172d535826e084968b8;hpb=da927ba997d68401563b927f92e6e40e021a8e5c;p=elogind.git diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 36b68aee9..fe876b3ff 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -26,7 +26,7 @@ #include "strv.h" #include "path-util.h" #include "fileio.h" -#include "bus-errors.h" +#include "bus-common-errors.h" #include "dbus.h" #include "dbus-manager.h" #include "dbus-unit.h" @@ -169,6 +169,29 @@ static int property_get_sub_state( return sd_bus_message_append(reply, "s", unit_sub_state_to_string(u)); } +static int property_get_unit_file_preset( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + Unit *u = userdata; + int r; + + assert(bus); + assert(reply); + assert(u); + + r = unit_get_unit_file_preset(u); + + return sd_bus_message_append(reply, "s", + r < 0 ? "": + r > 0 ? "enabled" : "disabled"); +} + static int property_get_unit_file_state( sd_bus *bus, const char *path, @@ -552,6 +575,7 @@ const sd_bus_vtable bus_unit_vtable[] = { SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Unit, source_path), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DropInPaths", "as", NULL, offsetof(Unit, dropin_paths), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("UnitFileState", "s", property_get_unit_file_state, 0, 0), + SD_BUS_PROPERTY("UnitFilePreset", "s", property_get_unit_file_preset, 0, 0), BUS_PROPERTY_DUAL_TIMESTAMP("InactiveExitTimestamp", offsetof(Unit, inactive_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), BUS_PROPERTY_DUAL_TIMESTAMP("ActiveEnterTimestamp", offsetof(Unit, active_enter_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), BUS_PROPERTY_DUAL_TIMESTAMP("ActiveExitTimestamp", offsetof(Unit, active_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), @@ -614,10 +638,46 @@ static int property_get_slice( return sd_bus_message_append(reply, "s", unit_slice_name(u)); } +static int property_get_current_memory( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + Unit *u = userdata; + uint64_t sz = (uint64_t) -1; + int r; + + assert(bus); + assert(reply); + assert(u); + + if (u->cgroup_path && + (u->cgroup_realized_mask & CGROUP_MEMORY)) { + _cleanup_free_ char *v = NULL; + + r = cg_get_attribute("memory", u->cgroup_path, "memory.usage_in_bytes", &v); + if (r < 0 && r != -ENOENT) + log_unit_warning_errno(u->id, r, "Couldn't read memory.usage_in_bytes attribute: %m"); + + if (v) { + r = safe_atou64(v, &sz); + if (r < 0) + log_unit_warning_errno(u->id, r, "Failed to parse memory.usage_in_bytes attribute: %m"); + } + } + + return sd_bus_message_append(reply, "t", sz); +} + const sd_bus_vtable bus_unit_cgroup_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Slice", "s", property_get_slice, 0, 0), SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Unit, cgroup_path), 0), + SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0), SD_BUS_VTABLE_END };