mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-02-04 18:50:31 +01:00
Check if swap exists before determining how much is free
Signed-off-by: Richard Hughes <richard@hughsie.com>
This commit is contained in:
parent
0348f788d9
commit
bbb102c394
1 changed files with 10 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue