diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-31 18:15:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-31 18:16:02 +0200 |
commit | a7edaadd78271e1c35ff9032f068cb08de645437 (patch) | |
tree | 24e18127aab17c7c2b05dca7b0845f03e6ad7acf | |
parent | 98178d3947d951ca001eaf400b5f362f458dceb5 (diff) |
journal-gatewayd: query PID 1 for virtalization
Since journal-gatewayd is now running unprivileged, and detecting
virtalization requires privileges, query PID1 via D-Bus for the used
virtualization.
This is also the first time we use libsystemd-bus for more than just
testing.
https://bugs.freedesktop.org/show_bug.cgi?id=62173
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | src/journal/journal-gatewayd.c | 56 | ||||
-rw-r--r-- | src/systemd/sd-bus-protocol.h (renamed from src/libsystemd-bus/sd-bus-protocol.h) | 0 | ||||
-rw-r--r-- | src/systemd/sd-bus.h (renamed from src/libsystemd-bus/sd-bus.h) | 0 |
4 files changed, 56 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index 07f4362791..ef13ad20ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -167,6 +167,7 @@ AM_CPPFLAGS = \ -I $(top_srcdir)/src/core \ -I $(top_srcdir)/src/libudev \ -I $(top_srcdir)/src/udev \ + -I $(top_srcdir)/src/libsystemd-bus \ $(OUR_CPPFLAGS) AM_CFLAGS = $(OUR_CFLAGS) @@ -1666,9 +1667,9 @@ EXTRA_DIST += \ # ------------------------------------------------------------------------------ libsystemd_bus_la_SOURCES = \ + src/systemd/sd-bus.h \ + src/systemd/sd-bus-protocol.h \ src/libsystemd-bus/sd-bus.c \ - src/libsystemd-bus/sd-bus.h \ - src/libsystemd-bus/sd-bus-protocol.h \ src/libsystemd-bus/bus-control.c \ src/libsystemd-bus/bus-control.h \ src/libsystemd-bus/bus-error.c \ @@ -2867,6 +2868,7 @@ systemd_journal_gatewayd_LDADD = \ libsystemd-journal-internal.la \ libsystemd-id128-internal.la \ libsystemd-daemon.la \ + libsystemd-bus.la \ $(MICROHTTPD_LIBS) systemd_journal_gatewayd_CFLAGS = \ diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c index 8161b7e56b..133d0ae478 100644 --- a/src/journal/journal-gatewayd.c +++ b/src/journal/journal-gatewayd.c @@ -31,9 +31,11 @@ #include "util.h" #include "sd-journal.h" #include "sd-daemon.h" +#include "sd-bus.h" +#include "bus-message.h" +#include "bus-internal.h" #include "logs-show.h" #include "microhttpd-util.h" -#include "virt.h" #include "build.h" #include "fileio.h" @@ -740,6 +742,52 @@ static int request_handler_file( return ret; } +static int get_virtualization(char **v) { + _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; + _cleanup_bus_unref_ sd_bus *bus = NULL; + const char *t; + char *b; + int r; + + r = sd_bus_open_system(&bus); + if (r < 0) + return r; + + r = sd_bus_message_new_method_call( + bus, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.DBus.Properties", + "Get", + &m); + if (r < 0) + return r; + + r = sd_bus_message_append(m, "ss", "org.freedesktop.systemd1.Manager", "Virtualization"); + if (r < 0) + return r; + + r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply); + if (r < 0) + return r; + + r = sd_bus_message_read(reply, "v", "s", &t); + if (r < 0) + return r; + + if (isempty(t)) { + *v = NULL; + return 0; + } + + b = strdup(t); + if (!b) + return -ENOMEM; + + *v = b; + return 1; +} + static int request_handler_machine( struct MHD_Connection *connection, void *connection_cls) { @@ -751,7 +799,7 @@ static int request_handler_machine( uint64_t cutoff_from, cutoff_to, usage; char *json; sd_id128_t mid, bid; - const char *v = "bare"; + _cleanup_free_ char *v = NULL; assert(connection); assert(m); @@ -782,7 +830,7 @@ static int request_handler_machine( parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &os_name, NULL); - detect_virtualization(&v); + get_virtualization(&v); r = asprintf(&json, "{ \"machine_id\" : \"" SD_ID128_FORMAT_STR "\"," @@ -797,7 +845,7 @@ static int request_handler_machine( SD_ID128_FORMAT_VAL(bid), hostname_cleanup(hostname), os_name ? os_name : "Linux", - v, + v ? v : "bare", (unsigned long long) usage, (unsigned long long) cutoff_from, (unsigned long long) cutoff_to); diff --git a/src/libsystemd-bus/sd-bus-protocol.h b/src/systemd/sd-bus-protocol.h index 7922f6b702..7922f6b702 100644 --- a/src/libsystemd-bus/sd-bus-protocol.h +++ b/src/systemd/sd-bus-protocol.h diff --git a/src/libsystemd-bus/sd-bus.h b/src/systemd/sd-bus.h index f792bfaf6c..f792bfaf6c 100644 --- a/src/libsystemd-bus/sd-bus.h +++ b/src/systemd/sd-bus.h |