Check if swap exists before determining how much is free

Signed-off-by: Richard Hughes <richard@hughsie.com>
This commit is contained in:
Debbie Beliveau 2009-12-16 16:29:29 +00:00 committed by Richard Hughes
parent 0348f788d9
commit bbb102c394

View file

@ -250,6 +250,7 @@ dkp_daemon_check_swap_space (DkpDaemon *daemon)
gboolean ret;
guint active = 0;
guint swap_free = 0;
guint swap_total = 0;
guint len;
guint i;
gfloat percentage = 0.0f;
@ -271,12 +272,21 @@ dkp_daemon_check_swap_space (DkpDaemon *daemon)
if (len > 3) {
if (g_strcmp0 (tokens[0], "SwapFree") == 0)
swap_free = atoi (tokens[len-2]);
if (g_strcmp0 (tokens[0], "SwapTotal") == 0)
swap_total = atoi (tokens[len-2]);
else if (g_strcmp0 (tokens[0], "Active") == 0)
active = atoi (tokens[len-2]);
}
g_strfreev (tokens);
}
/* first check if we even have swap, if not consider all swap space used */
if (swap_total == 0) {
egg_debug ("no swap space found");
percentage = 100.0f;
goto out;
}
/* work out how close to the line we are */
if (swap_free > 0 && active > 0)
percentage = (active * 100) / swap_free;