diff options
author | William Brown <[email protected]> | 2012-11-21 09:06:22 +1030 |
---|---|---|
committer | William Brown <[email protected]> | 2012-11-21 10:14:47 +1030 |
commit | c5c3b2a3d755e32a851bf7b3c7ef92a056b5bdef (patch) | |
tree | 1cae23a91bddca120bc9155630faeb43fe3b54da /src/gpm-manager.c | |
parent | bb165fa927540f40b2b2afce1b4703f6e2cffbb1 (diff) | |
download | mate-power-manager-c5c3b2a3d755e32a851bf7b3c7ef92a056b5bdef.tar.bz2 mate-power-manager-c5c3b2a3d755e32a851bf7b3c7ef92a056b5bdef.tar.xz |
Initial working support for systemd inhibition
Diffstat (limited to 'src/gpm-manager.c')
-rw-r--r-- | src/gpm-manager.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/gpm-manager.c b/src/gpm-manager.c index dc838c5..34d8e9a 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -1851,11 +1851,13 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { //GDBusProxy *proxy; GError *error = NULL; gint32 r = -1; + gint32 fd = -1; GVariant *res; + GUnixFDList *fd_list = NULL; //proxy == NULL; /* Should we define these elsewhere? */ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; - const char* arg_who = "mate-power-manager"; + const char* arg_who = g_get_user_name (); const char* arg_why = "Mate power manager handles these events"; const char* arg_mode = "block"; @@ -1874,7 +1876,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { g_error_free (error); return -1; } - res = g_dbus_proxy_call_sync (proxy, "Inhibit", + res = g_dbus_proxy_call_with_unix_fd_list_sync (proxy, "Inhibit", g_variant_new( "(ssss)", arg_what, arg_who, @@ -1884,20 +1886,26 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { G_DBUS_CALL_FLAGS_NONE, -1, NULL, + &fd_list, + NULL, &error ); - if (error == NULL) { + if (error == NULL && res != NULL) { g_variant_get(res, "(h)", &r); - egg_debug ("Inhibiting systemd sleep - fd = %i", r); - } else if (error != NULL) { + egg_debug ("Inhibiting systemd sleep res = %i", r); + fd = g_unix_fd_list_get (fd_list, r, &error); + if (fd == -1) { + egg_debug("Failed to get systemd inhibitor"); + return r; + } + egg_debug ("System inhibitor fd is %d", fd); + g_object_unref (fd_list); + g_variant_unref (res); + } else if (error != NULL || res == NULL) { egg_error ("Error in dbus - %s", error->message); g_error_free (error); return -EIO; } - if (r < 1) { - egg_error ("Error in FD was less than or 0 - %i", r); - return -EIO; - } egg_debug ("Inhibiting systemd sleep - success"); return r; } |