Comment 10 for bug 136433

Revision history for this message
Sitsofe Wheeler (sitsofe) wrote :

I spent a good long time tracking this down last night (gnome-power-manager uses hal to check. lshal says that hibernate is disabled. lshal was getting its information from /usr/bin/pmi which is part of the powermanagement-interface package).

I have a single swap partition and the problem appears to be this line within pmi:
                hibernate)
                        if grep -q ' /host fuse' /proc/mounts || \
                           swapon -s | tail -n +2 | awk '$2 == "file" { exit 1 }'; then
                                result=1

Alas the file is not commented so it's not clear exactly what the intent of those lines is. But I'm assuming that it is trying to disable hibernate if you are using fuse or (that's the ||) if you are using swap to a file. The problem is that I think the logic is inverted.

The
swapon -s | tail -n +2 | awk '$2 == "file" { exit 1 }'
is the key to the issue. I think this takes the output of swapon -s, skips the first line and then searches the rest for the parameter "file" in field 2 (the type) and returns 1 if it found and 0 otherwise. By contrast, if the grep command finds what you are looking for then it returns 0, if it cannot find what you are looking for then it returns 1.

Shells generally interpret truth as 0 and anything but 0 as false. The above swapon snippet returns false if it thinks you have a swap file causing it to take the first branch on systems that DON'T have swap files. Thus I think it will return that hibernate is not possible on systems without swap files.

(So a quick fix is to remove the swapon check. Alternatively you can fix up the logic using variables to store intermediary values to make things more obvious)