diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2014-10-13 10:00:22 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2014-10-13 10:00:22 +0300 |
commit | b65cb6f48bfa768acafdb7b6dcee32f600925688 (patch) | |
tree | d5126974f1a6d992faafab64c34532bf569e7362 /src/ck-sysdeps-linux.c | |
parent | d79c28572185335bd7c0d4f8bbce63d3904d1d6c (diff) | |
download | ConsoleKit2-b65cb6f48bfa768acafdb7b6dcee32f600925688.tar.gz |
More Suspend DBUS API work
We need a Can/Auth split for suspend/hibernate because the user
may be authorized but the system is unable to perform those
actions. Additionally start working the inhibit calls. We also
need to actually add the suspend/hibernate tools.
Diffstat (limited to 'src/ck-sysdeps-linux.c')
-rw-r--r-- | src/ck-sysdeps-linux.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/ck-sysdeps-linux.c b/src/ck-sysdeps-linux.c index 153f784..c3786bf 100644 --- a/src/ck-sysdeps-linux.c +++ b/src/ck-sysdeps-linux.c @@ -778,6 +778,43 @@ ck_get_active_console_num (int console_fd, return ret; } +static gboolean +linux_supports_sleep_state (const gchar *state) +{ + gboolean ret = FALSE; + gchar *command; + GError *error = NULL; + gint exit_status; + + /* run script from pm-utils */ + command = g_strdup_printf ("/usr/bin/pm-is-supported --%s", state); + g_debug ("excuting command: %s", command); + ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error); + if (!ret) { + g_warning ("failed to run script: %s", error->message); + g_error_free (error); + goto out; + } + ret = (WIFEXITED(exit_status) && (WEXITSTATUS(exit_status) == EXIT_SUCCESS)); + +out: + g_free (command); + + return ret; +} + +gboolean +ck_system_can_suspend (void) +{ + return linux_supports_sleep_state ("suspend"); +} + +gboolean +ck_system_can_hibernate (void) +{ + return linux_supports_sleep_state ("hibernate"); +} + #ifdef HAVE_SYS_VT_SIGNAL /* For the moment this is Linux only. * Returns the vt file descriptor or < 0 on failure. |