detecting hibernation capability

Joe Shaw joeshaw at novell.com
Wed Nov 30 09:00:08 PST 2005


Hi,

On Wed, 2005-11-30 at 16:43 +0000, Richard Hughes wrote:
> +static void
> +set_suspend_hibernate_keys (HalDevice *d)
> +{
> +       unsigned int len = 128;
> +       char *poweroptions = NULL;
> +       int can_hibernate = FALSE;
> +       int can_suspend = FALSE;
> +
> +       FILE *fp = fopen ("/sys/power/state", "r");
> +       if (!fp) {
> +               HAL_WARNING (("Could not open /sys/power/state!"));
> +               return;
> +       }

We should probably still set the properties to FALSE even if we can't
open /sys/power/state.

> +       getline(&poweroptions, &len, fp);

Shouldn't len be unassigned here?  I think, since poweroptions will be
allocated automatically by getline(), that len will be filled in with
the correct value.  I think setting it to 128 is unnecessary.

> +       fclose (fp);
> +       if (poweroptions) {
> +               if (strstr (poweroptions, "mem"))
> +                       can_suspend = TRUE;
> +               if (strstr (poweroptions, "disk"))
> +                       can_hibernate = TRUE;
> +               free (poweroptions);
> +       }
> +       hal_device_property_set_bool (d, "power_management.can_suspend", can_suspend);
> +       hal_device_property_set_bool (d, "power_management.can_hibernate", can_hibernate);
> +}

Joe



More information about the hal mailing list