diff options
author | Victor Lowther <victor.lowther@gmail.com> | 2010-06-13 21:07:31 -0500 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-06-14 08:59:40 +0100 |
commit | 6770e8cb3462a37ac477b1750269763ec22e2b7a (patch) | |
tree | 35e2d0203d027572708c89db8655ab7bd5276e27 /src/linux/up-backend.c | |
parent | da3a51d2e8be3c42f63b5f8e6a795b11e7ccbc1e (diff) |
Use pm-is-supported to test if various sleep modes are supported.
pm-is-supported does all the work upower was duplicating, and it handles more
use cases than the old upower code did. No point in duplicating functionality.
Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'src/linux/up-backend.c')
-rw-r--r-- | src/linux/up-backend.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index 61dddc9..a2cf61d 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -322,38 +322,40 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon) /** * up_backend_supports_sleep_state: + * + * use pm-is-supported to test for supported sleep states **/ static gboolean up_backend_supports_sleep_state (const gchar *state) { - gchar *contents = NULL; + gboolean ret = FALSE; + gchar *command; GError *error = NULL; - gboolean ret; - const gchar *filename = "/sys/power/state"; + gint exit_status; - /* see what kernel can do */ - ret = g_file_get_contents (filename, &contents, NULL, &error); + /* run script from pm-utils */ + command = g_strdup_printf ("/usr/bin/pm-is-supported --%s", state); + egg_debug ("excuting command: %s", command); + ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error); if (!ret) { - egg_warning ("failed to open %s: %s", filename, error->message); + egg_warning ("failed to run script: %s", error->message); g_error_free (error); goto out; } - - /* does the kernel advertise this */ - ret = (g_strstr_len (contents, -1, state) != NULL); + if (WIFEXITED(exit_status) && (WEXITSTATUS(exit_status) == EXIT_SUCCESS)) + ret = TRUE; out: - g_free (contents); + g_free (command); return ret; } - /** * up_backend_kernel_can_suspend: **/ gboolean up_backend_kernel_can_suspend (UpBackend *backend) { - return up_backend_supports_sleep_state ("mem"); + return up_backend_supports_sleep_state ("suspend"); } /** @@ -362,7 +364,7 @@ up_backend_kernel_can_suspend (UpBackend *backend) gboolean up_backend_kernel_can_hibernate (UpBackend *backend) { - return up_backend_supports_sleep_state ("disk"); + return up_backend_supports_sleep_state ("hibernate"); } /** |