[gnome-battery-bench] SystemInfo: can use helper binary to get helper
- From: Christian Kellner <gicmo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-battery-bench] SystemInfo: can use helper binary to get helper
- Date: Wed, 3 May 2017 15:25:39 +0000 (UTC)
commit 1a5023ea8d05ce09fa253b046f7a9de324fcf4ca
Author: Christian Kellner <gicmo gnome org>
Date: Wed May 3 17:23:23 2017 +0200
SystemInfo: can use helper binary to get helper
If getting the renderer via the session fails, we can use a helper
binary provided by gnome-session to get the information.
configure.ac | 12 ++++++++++
src/Makefile.am | 1 +
src/system-info.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 68 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5ff4a65..68b5516 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,18 @@ AM_CONDITIONAL(BUILD_DOCS, [ test $ASCIIDOC != x -a $XMLTO != x ])
GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
AC_SUBST(GLIB_COMPILE_RESOURCES)
+dnl needed to locate gnome-session-check-accelerated
+AC_ARG_WITH([gnome-session-libexecdir],
+ AS_HELP_STRING([--with-gnome-session-libexecdir=DIR], [Directory for gnome-session s libexecdir]),
+ [],
+ [with_gnome_session_libexecdir=${libexecdir}])
+if test x$with_gnome_session_libexecdir == xno; then
+ with_gnome_session_libexecdir=${libexecdir}
+fi
+AS_AC_EXPAND(GNOMESESSIONDIR, $with_gnome_session_libexecdir)
+AC_SUBST([gnome_session_libexecdir], [$GNOMESESSIONDIR])
+
+
GNOME_COMPILE_WARNINGS([error])
case "$WARN_CFLAGS" in
*-Werror*)
diff --git a/src/Makefile.am b/src/Makefile.am
index ce6227c..072f870 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ EXTRA_DIST = integration-test
AM_CPPFLAGS = \
-DPKGDATADIR=\"$(pkgdatadir)\" \
-DDATADIR=\"$(datadir)\" \
+ -DGNOME_SESSION_DIR="\"$(gnome_session_libexecdir)\"" \
$(NULL)
bin_PROGRAMS=gnome-battery-bench gbb
diff --git a/src/system-info.c b/src/system-info.c
index eb50f57..47c0b01 100644
--- a/src/system-info.c
+++ b/src/system-info.c
@@ -500,12 +500,12 @@ get_batteries (void)
}
static char *
-get_renderer_info (void)
+get_renderer_from_session (void)
{
g_autoptr(GDBusProxy) proxy = NULL;
g_autoptr(GVariant) var = NULL;
g_autoptr(GError) error = NULL;
- const char *renderer = "Unknown";
+ const char *renderer = NULL;
proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
@@ -518,21 +518,71 @@ get_renderer_info (void)
if (error != NULL) {
g_warning("Failed to connect to org.gnome.SessionManager: %s",
error->message);
- goto out;
+ return NULL;
}
var = g_dbus_proxy_get_cached_property(proxy, "Renderer");
if (!var) {
g_warning("Failed to obtain 'Renderer' property from org.gnome.SessionManager");
- goto out;
+ return NULL;
}
renderer = g_variant_get_string(var, NULL);
-out:
+ if (renderer != NULL && renderer[0] != '\0') {
+ return NULL;
+ }
+
return g_strstrip(g_strdup(renderer));
}
+static char *
+get_renderer_from_helper (void)
+{
+ g_autoptr(GError) error = NULL;
+ char *argv[] = { GNOME_SESSION_DIR "/gnome-session-check-accelerated", NULL };
+ char *stdout_str = NULL;
+ int exit_status;
+ gboolean ok;
+
+ ok = g_spawn_sync(NULL,
+ (char **) argv,
+ NULL,
+ G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL,
+ &stdout_str,
+ NULL,
+ &exit_status,
+ &error);
+
+ if (!ok || !g_spawn_check_exit_status(exit_status, &error) ||
+ stdout_str == NULL || stdout_str[0] == '\0') {
+ g_warning("Failed to obtain get renderer via helper binary: %s",
+ error->message);
+ return NULL;
+ }
+
+ return g_strstrip(stdout_str);
+}
+
+static char *
+get_renderer_info (void)
+{
+ char *renderer = NULL;
+
+ renderer = get_renderer_from_session();
+ if (renderer != NULL) {
+ return renderer;
+ }
+
+ renderer = get_renderer_from_helper();
+ if (renderer != NULL) {
+ return renderer;
+ }
+
+ return g_strdup("Unknown");
+}
+
static void gbb_system_info_init (GbbSystemInfo *info)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]