[systemd-commits] 3 commits - TODO src/core src/libsystemd src/shared src/systemctl

Lennart Poettering lennart at kemper.freedesktop.org
Thu Jan 22 18:00:19 PST 2015


 TODO                              |   12 ++++--------
 src/core/dbus-unit.c              |   36 ++++++++++++++++++++++++++++++++++++
 src/libsystemd/sd-bus/bus-creds.c |    2 +-
 src/shared/cgroup-util.c          |   11 +++++++++++
 src/shared/cgroup-util.h          |    1 +
 src/systemctl/systemctl.c         |   24 +++++++++++++++++++++++-
 6 files changed, 76 insertions(+), 10 deletions(-)

New commits:
commit 17fe56148c44dfa5583a8643c1918fd6eccf2aee
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 02:59:58 2015 +0100

    update TODO

diff --git a/TODO b/TODO
index f494f6d..2406a87 100644
--- a/TODO
+++ b/TODO
@@ -31,16 +31,14 @@ External:
 
 Release 219 preparations:
 
-* rework journald sigbus stuff to use mutex
-
-* "systemctl kill" is broken
-
-* the dbus1 connection user id is actually the euid, not the uid, and creds should return that
-
 * sd-bus make dsrt happy, and change userspace header for kdbus to yyyyuta{tv}v
 
 Features:
 
+* Rework systemctl's GetAll property parsing to use the generic bus_map_all_properties() API
+
+* rework journald sigbus stuff to use mutex
+
 * import-dkr: support tarsum checksum verification, if it becomes reality one day...
 
 * import-dkr: convert json bits to nspawn configuration
@@ -49,8 +47,6 @@ Features:
 
 * core/cgroup: support net_cls modules, and support automatically allocating class ids, then add support for making firewall changes depending on it, to implement a per-service firewall
 
-* bus-proxy: reload policy when PID 1 reports a reload
-
 * introduce systemd-nspawn-ephemeral at .service, and hook it into "machinectl start" with a new --ephemeral switch
 
 * logind,machined: add generic catch-all polkit verbs for most priviliged operations, similar to systemd itself

commit 1c0216696a5024db431ce397e8f2ca052084a71e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 02:59:30 2015 +0100

    sd-bus: fix typo

diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 54e76ab..ea8a619 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -220,7 +220,7 @@ _public_ int sd_bus_creds_get_gid(sd_bus_creds *c, gid_t *gid) {
         assert_return(c, -EINVAL);
         assert_return(gid, -EINVAL);
 
-        if (!(c->mask & SD_BUS_CREDS_UID))
+        if (!(c->mask & SD_BUS_CREDS_GID))
                 return -ENODATA;
 
         *gid = c->gid;

commit 934277fe6a26ff2a4da37059c70d84ab6a700781
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 02:58:02 2015 +0100

    core: add a property that shows the current memory usage of a unit
    
    This is exposed the memory.usage_in_bytes cgroup property on the bus,
    and makes "systemctl status" show it in its default output.

diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index b968009..fe876b3 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -638,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
 };
 
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 86729f1..0d3cc53 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1592,6 +1592,17 @@ int cg_set_attribute(const char *controller, const char *path, const char *attri
         return write_string_file_no_create(p, value);
 }
 
+int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) {
+        _cleanup_free_ char *p = NULL;
+        int r;
+
+        r = cg_get_path(controller, path, attribute, &p);
+        if (r < 0)
+                return r;
+
+        return read_one_line_file(p, ret);
+}
+
 static const char mask_names[] =
         "cpu\0"
         "cpuacct\0"
diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h
index 89dc2b1..96a3d3b 100644
--- a/src/shared/cgroup-util.h
+++ b/src/shared/cgroup-util.h
@@ -85,6 +85,7 @@ int cg_attach_fallback(const char *controller, const char *path, pid_t pid);
 int cg_create_and_attach(const char *controller, const char *path, pid_t pid);
 
 int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
+int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret);
 
 int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
 int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index cdc1a50..44b65bb 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3224,6 +3224,10 @@ typedef struct UnitStatusInfo {
         /* Swap */
         const char *what;
 
+        /* CGroup */
+        uint64_t memory_current;
+        uint64_t memory_limit;
+
         LIST_HEAD(ExecStatusInfo, exec);
 } UnitStatusInfo;
 
@@ -3482,6 +3486,17 @@ static void print_status_info(
         if (i->status_errno > 0)
                 printf("    Error: %i (%s)\n", i->status_errno, strerror(i->status_errno));
 
+        if (i->memory_current != (uint64_t) -1) {
+                char buf[FORMAT_BYTES_MAX];
+
+                printf("   Memory: %s", format_bytes(buf, sizeof(buf), i->memory_current));
+
+                if (i->memory_limit != (uint64_t) -1)
+                        printf(" (limit: %s)\n", format_bytes(buf, sizeof(buf), i->memory_limit));
+                else
+                        printf("\n");
+        }
+
         if (i->control_group &&
             (i->main_pid > 0 || i->control_pid > 0 ||
              ((arg_transport != BUS_TRANSPORT_LOCAL && arg_transport != BUS_TRANSPORT_MACHINE) || cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, i->control_group, false) == 0))) {
@@ -3696,6 +3711,10 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
                         i->condition_timestamp = (usec_t) u;
                 else if (streq(name, "AssertTimestamp"))
                         i->assert_timestamp = (usec_t) u;
+                else if (streq(name, "MemoryCurrent"))
+                        i->memory_current = u;
+                else if (streq(name, "MemoryLimit"))
+                        i->memory_limit = u;
 
                 break;
         }
@@ -4166,7 +4185,10 @@ static int show_one(
 
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        UnitStatusInfo info = {};
+        UnitStatusInfo info = {
+                .memory_current = (uint64_t) -1,
+                .memory_limit = (uint64_t) -1,
+        };
         ExecStatusInfo *p;
         int r;
 



More information about the systemd-commits mailing list