[systemd-commits] 2 commits - src/analyze src/hostname

Lennart Poettering lennart at kemper.freedesktop.org
Sun May 18 09:47:43 PDT 2014


 src/analyze/analyze.c    |  109 ++++++++++++++++++++++++++++++++++++-----------
 src/hostname/hostnamed.c |    6 ++
 2 files changed, 90 insertions(+), 25 deletions(-)

New commits:
commit 7e690cefd4f09bb6370f91611f623adea841bdf4
Author: Djalal Harouni <tixxdz at opendz.org>
Date:   Wed Apr 23 23:03:35 2014 +0100

    analyze: read host and system information from remote
    
    This makes "systemd-analyze plot" read host information from remote.
    
    While we are it show if this is a virtualized system.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=76498
    
    Reported-by: Zach <zachcook1991 at gmail.com>

diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index ebaa9d0..4c5fcfe 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -100,6 +100,16 @@ struct unit_times {
         usec_t time;
 };
 
+struct host_info {
+        char *hostname;
+        char *kernel_name;
+        char *kernel_release;
+        char *kernel_version;
+        char *os_pretty_name;
+        char *virtualization;
+        char *architecture;
+};
+
 static void pager_open_if_enabled(void) {
 
         if (arg_no_pager)
@@ -170,21 +180,6 @@ static int compare_unit_start(const void *a, const void *b) {
                        ((struct unit_times *)b)->activating);
 }
 
-static int get_os_name(char **_n) {
-        char *n = NULL;
-        int r;
-
-        r = parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &n, NULL);
-        if (r < 0)
-                return r;
-
-        if (!n)
-                return -ENOENT;
-
-        *_n = n;
-        return 0;
-}
-
 static void free_unit_times(struct unit_times *t, unsigned n) {
         struct unit_times *p;
 
@@ -372,6 +367,63 @@ finish:
         return 0;
 }
 
+static void free_host_info(struct host_info *hi) {
+        free(hi->hostname);
+        free(hi->kernel_name);
+        free(hi->kernel_release);
+        free(hi->kernel_version);
+        free(hi->os_pretty_name);
+        free(hi->virtualization);
+        free(hi->architecture);
+        free(hi);
+}
+
+static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
+        int r;
+        struct host_info *host;
+
+        static const struct bus_properties_map hostname_map[] = {
+                { "Hostname", "s", NULL, offsetof(struct host_info, hostname) },
+                { "KernelName", "s", NULL, offsetof(struct host_info, kernel_name) },
+                { "KernelRelease", "s", NULL, offsetof(struct host_info, kernel_release) },
+                { "KernelVersion", "s", NULL, offsetof(struct host_info, kernel_version) },
+                { "OperatingSystemPrettyName", "s", NULL, offsetof(struct host_info, os_pretty_name) },
+                {}
+        };
+
+        static const struct bus_properties_map manager_map[] = {
+                { "Virtualization", "s", NULL, offsetof(struct host_info, virtualization) },
+                { "Architecture",   "s", NULL, offsetof(struct host_info, architecture) },
+                {}
+        };
+
+        host = new0(struct host_info, 1);
+        if (!host)
+                return log_oom();
+
+        r = bus_map_all_properties(bus,
+                                   "org.freedesktop.hostname1",
+                                   "/org/freedesktop/hostname1",
+                                   hostname_map,
+                                   host);
+        if (r < 0)
+                goto fail;
+
+        r = bus_map_all_properties(bus,
+                                   "org.freedesktop.systemd1",
+                                   "/org/freedesktop/systemd1",
+                                   manager_map,
+                                   host);
+        if (r < 0)
+                goto fail;
+
+        *hi = host;
+        return 0;
+fail:
+        free_host_info(host);
+        return r;
+}
+
 static int pretty_boot_time(sd_bus *bus, char **_buf) {
         char ts[FORMAT_TIMESPAN_MAX];
         struct boot_times *t;
@@ -437,10 +489,10 @@ static void svg_graph_box(double height, double begin, double end) {
 static int analyze_plot(sd_bus *bus) {
         struct unit_times *times;
         struct boot_times *boot;
-        struct utsname name;
+        struct host_info *host = NULL;
         int n, m = 1, y=0;
         double width;
-        _cleanup_free_ char *pretty_times = NULL, *osname = NULL;
+        _cleanup_free_ char *pretty_times = NULL;
         struct unit_times *u;
 
         n = acquire_boot_times(bus, &boot);
@@ -451,12 +503,13 @@ static int analyze_plot(sd_bus *bus) {
         if (n < 0)
                 return n;
 
-        get_os_name(&osname);
-        assert_se(uname(&name) >= 0);
+        n = acquire_host_info(bus, &host);
+        if (n < 0)
+                return n;
 
         n = acquire_time_data(bus, &times);
         if (n <= 0)
-                return n;
+                goto out;
 
         qsort(times, n, sizeof(struct unit_times), compare_unit_start);
 
@@ -551,9 +604,14 @@ static int analyze_plot(sd_bus *bus) {
 
         svg("<rect class=\"background\" width=\"100%%\" height=\"100%%\" />\n");
         svg("<text x=\"20\" y=\"50\">%s</text>", pretty_times);
-        svg("<text x=\"20\" y=\"30\">%s %s (%s %s) %s</text>",
-            isempty(osname) ? "Linux" : osname,
-            name.nodename, name.release, name.version, name.machine);
+        svg("<text x=\"20\" y=\"30\">%s %s (%s %s %s) %s %s</text>",
+            isempty(host->os_pretty_name) ? "Linux" : host->os_pretty_name,
+            isempty(host->hostname) ? "" : host->hostname,
+            isempty(host->kernel_name) ? "" : host->kernel_name,
+            isempty(host->kernel_release) ? "" : host->kernel_release,
+            isempty(host->kernel_version) ? "" : host->kernel_version,
+            isempty(host->architecture) ? "" : host->architecture,
+            isempty(host->virtualization) ? "" : host->virtualization);
 
         svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (SCALE_X * boot->firmware_time));
         svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time);
@@ -636,7 +694,10 @@ static int analyze_plot(sd_bus *bus) {
 
         free_unit_times(times, (unsigned) n);
 
-        return 0;
+        n = 0;
+out:
+        free_host_info(host);
+        return n;
 }
 
 static int list_dependencies_print(const char *name, unsigned int level, unsigned int branches,

commit 9be3455f55a5aa445ae8ae69301c54d19111d2e4
Author: Djalal Harouni <tixxdz at opendz.org>
Date:   Wed Apr 23 23:03:34 2014 +0100

    hostnamed: expose KernelVersion on the bus
    
    This is needed to fix bug:
    
    https://bugs.freedesktop.org/show_bug.cgi?id=76498
    
    Reported-by: Zach <zachcook1991 at gmail.com>

diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 48cbbdb..5c767cd 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -43,6 +43,7 @@ enum {
         PROP_CHASSIS,
         PROP_KERNEL_NAME,
         PROP_KERNEL_RELEASE,
+        PROP_KERNEL_VERSION,
         PROP_OS_PRETTY_NAME,
         PROP_OS_CPE_NAME,
         _PROP_MAX
@@ -82,7 +83,9 @@ static int context_read_data(Context *c) {
         assert_se(uname(&u) >= 0);
         c->data[PROP_KERNEL_NAME] = strdup(u.sysname);
         c->data[PROP_KERNEL_RELEASE] = strdup(u.release);
-        if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE])
+        c->data[PROP_KERNEL_VERSION] = strdup(u.version);
+        if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] ||
+            !c->data[PROP_KERNEL_VERSION])
                 return -ENOMEM;
 
         c->data[PROP_HOSTNAME] = gethostname_malloc();
@@ -567,6 +570,7 @@ static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("KernelName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("KernelRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BUS_VTABLE_UNPRIVILEGED),



More information about the systemd-commits mailing list