Magellan Linux

Annotation of /trunk/hal/patches/hal-0.5.10-cleanup-set_suspend_hibernate_keys.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 597 - (hide annotations) (download)
Mon May 19 19:05:19 2008 UTC (16 years, 1 month ago) by niro
File size: 2789 byte(s)
-gentoo patches

1 niro 597 From f0d70628ace93dec0e2ff2d3a2e452f8e8b0427d Mon Sep 17 00:00:00 2001
2     From: Danny Kukawka <danny.kukawka@web.de>
3     Date: Thu, 6 Dec 2007 20:39:19 +0100
4     Subject: [PATCH] cleanup set_suspend_hibernate_keys()
5    
6     This cleans up set_suspend_hibernate_keys(). Reuse existing code where
7     possible, call codesections only if really needed (pmu and suspend2).
8     ---
9     hald/linux/osspec.c | 45 +++++++++++++++++++--------------------------
10     1 files changed, 19 insertions(+), 26 deletions(-)
11    
12     diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
13     index feeb733..d7a8672 100644
14     --- a/hald/linux/osspec.c
15     +++ b/hald/linux/osspec.c
16     @@ -605,27 +605,16 @@ out:
17     static void
18     set_suspend_hibernate_keys (HalDevice *d)
19     {
20     - int can_suspend;
21     - int can_hibernate;
22     - ssize_t read;
23     - size_t len;
24     + gboolean can_suspend;
25     + gboolean can_hibernate;
26     char *poweroptions;
27     const char *pmtype;
28     - FILE *fp;
29    
30     can_suspend = FALSE;
31     can_hibernate = FALSE;
32    
33     /* try to find 'mem' and 'disk' in /sys/power/state */
34     - fp = fopen ("/sys/power/state", "r");
35     - if (fp == NULL) {
36     - HAL_WARNING (("Could not open /sys/power/state"));
37     - goto out;
38     - }
39     - poweroptions = NULL;
40     - len = 0;
41     - read = getline (&poweroptions, &len, fp);
42     - fclose (fp);
43     + poweroptions = hal_util_get_string_from_file("/sys/power/", "state");
44     if (poweroptions == NULL) {
45     HAL_WARNING (("Contents of /sys/power/state invalid"));
46     goto out;
47     @@ -634,21 +623,25 @@ set_suspend_hibernate_keys (HalDevice *d)
48     can_suspend = TRUE;
49     if (strstr (poweroptions, "disk"))
50     can_hibernate = TRUE;
51     - free (poweroptions);
52    
53     - pmtype = hal_device_property_get_string (d, "power_management.type");
54     - if (pmtype != NULL && strcmp(pmtype, "pmu") == 0) {
55     - /* We got our own helper for suspend PMU machines */
56     - can_suspend = TRUE;
57     + if (!can_suspend) {
58     + pmtype = hal_device_property_get_string (d, "power_management.type");
59     + if (pmtype != NULL && strcmp(pmtype, "pmu") == 0) {
60     + /* We got our own helper for suspend PMU machines */
61     + can_suspend = TRUE;
62     + }
63     }
64    
65     - /* check for the presence of suspend2 */
66     - if (access ("/proc/software_suspend", F_OK) == 0)
67     - can_hibernate = TRUE;
68     - if (access ("/proc/suspend2", F_OK) == 0)
69     - can_hibernate = TRUE;
70     - if (access ("/sys/power/suspend2/version", F_OK) == 0)
71     - can_hibernate = TRUE;
72     + if (!can_hibernate) {
73     + /* check for the presence of suspend2 */
74     + if (access ("/proc/software_suspend", F_OK) == 0) {
75     + can_hibernate = TRUE;
76     + } else if (access ("/proc/suspend2", F_OK) == 0) {
77     + can_hibernate = TRUE;
78     + } else if (access ("/sys/power/suspend2/version", F_OK) == 0) {
79     + can_hibernate = TRUE;
80     + }
81     + }
82     out:
83     hal_device_property_set_bool (d, "power_management.can_suspend", can_suspend);
84     hal_device_property_set_bool (d, "power_management.can_suspend_hybrid", FALSE);
85     --
86     1.5.3.7
87