diff options
author | Richard Hughes <richard@hughsie.com> | 2010-03-29 14:18:42 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-03-29 14:18:42 +0100 |
commit | 0198498350363a79cf42707543b43b31cedbc731 (patch) | |
tree | fa6e2becd5899f2130bdaa7e88a9848cf7a23b71 /src/up-daemon.c | |
parent | 4620a9d122ef52c1b806b8d634c4a53ed2fe3134 (diff) | |
download | upower-0198498350363a79cf42707543b43b31cedbc731.tar.gz |
Get the encrypted swap status from the backend, rather than hardcoding Linux specifics
Diffstat (limited to 'src/up-daemon.c')
-rw-r--r-- | src/up-daemon.c | 109 |
1 files changed, 1 insertions, 108 deletions
diff --git a/src/up-daemon.c b/src/up-daemon.c index ab6c21c..cf65ba2 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -108,113 +108,6 @@ G_DEFINE_TYPE (UpDaemon, up_daemon, G_TYPE_OBJECT) #define UP_DAEMON_POLL_BATTERY_NUMBER_TIMES 5 /** - * up_daemon_check_encrypted_swap: - * - * user@local:~$ cat /proc/swaps - * Filename Type Size Used Priority - * /dev/mapper/cryptswap1 partition 4803392 35872 -1 - * - * user@local:~$ cat /etc/crypttab - * # <target name> <source device> <key file> <options> - * cryptswap1 /dev/sda5 /dev/urandom swap,cipher=aes-cbc-essiv:sha256 - * - * Loop over the swap partitions in /proc/swaps, looking for matches in /etc/crypttab - **/ -static gboolean -up_daemon_check_encrypted_swap (UpDaemon *daemon) -{ - gchar *contents_swaps = NULL; - gchar *contents_crypttab = NULL; - gchar **lines_swaps = NULL; - gchar **lines_crypttab = NULL; - GError *error = NULL; - gboolean ret; - gboolean encrypted_swap = FALSE; - const gchar *filename_swaps = "/proc/swaps"; - const gchar *filename_crypttab = "/etc/crypttab"; - GPtrArray *devices = NULL; - gchar *device; - guint i, j; - - /* get swaps data */ - ret = g_file_get_contents (filename_swaps, &contents_swaps, NULL, &error); - if (!ret) { - egg_warning ("failed to open %s: %s", filename_swaps, error->message); - g_error_free (error); - goto out; - } - - /* get crypttab data */ - ret = g_file_get_contents (filename_crypttab, &contents_crypttab, NULL, &error); - if (!ret) { - egg_warning ("failed to open %s: %s", filename_crypttab, error->message); - g_error_free (error); - goto out; - } - - /* split both into lines */ - lines_swaps = g_strsplit (contents_swaps, "\n", -1); - lines_crypttab = g_strsplit (contents_crypttab, "\n", -1); - - /* get valid swap devices */ - devices = g_ptr_array_new_with_free_func (g_free); - for (i=0; lines_swaps[i] != NULL; i++) { - - /* is a device? */ - if (lines_swaps[i][0] != '/') - continue; - - /* only look at first parameter */ - g_strdelimit (lines_swaps[i], "\t ", '\0'); - - /* add base device to list */ - device = g_path_get_basename (lines_swaps[i]); - egg_debug ("adding swap device: %s", device); - g_ptr_array_add (devices, device); - } - - /* no swap devices? */ - if (devices->len == 0) { - egg_debug ("no swap devices"); - goto out; - } - - /* find matches in crypttab */ - for (i=0; lines_crypttab[i] != NULL; i++) { - - /* ignore invalid lines */ - if (lines_crypttab[i][0] == '#' || - lines_crypttab[i][0] == '\n' || - lines_crypttab[i][0] == '\t' || - lines_crypttab[i][0] == '\0') - continue; - - /* only look at first parameter */ - g_strdelimit (lines_crypttab[i], "\t ", '\0'); - - /* is a swap device? */ - for (j=0; j<devices->len; j++) { - device = g_ptr_array_index (devices, j); - if (g_strcmp0 (device, lines_crypttab[i]) == 0) { - egg_debug ("swap device %s is encrypted (so cannot hibernate)", device); - encrypted_swap = TRUE; - goto out; - } - egg_debug ("swap device %s is not encrypted (allows hibernate)", device); - } - } - -out: - if (devices != NULL) - g_ptr_array_unref (devices); - g_free (contents_swaps); - g_free (contents_crypttab); - g_strfreev (lines_swaps); - g_strfreev (lines_crypttab); - return encrypted_swap; -} - -/** * up_daemon_check_swap_space: **/ static gfloat @@ -1068,7 +961,7 @@ up_daemon_init (UpDaemon *daemon) /* is the swap usable? */ if (daemon->priv->kernel_can_hibernate) - daemon->priv->hibernate_has_encrypted_swap = up_daemon_check_encrypted_swap (daemon); + daemon->priv->hibernate_has_encrypted_swap = up_backend_has_encrypted_swap (daemon->priv->backend); } /** |