Contents of /trunk/hal/patches/hal-0.5.10-read-dmi-info-from-sysfs-instead-of-call-dmidecode.patch
Parent Directory | Revision Log
Revision 597 -
(show annotations)
(download)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 11527 byte(s)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 11527 byte(s)
-gentoo patches
1 | From 723b61504e0018c6141939735bf17b9d884c90d7 Mon Sep 17 00:00:00 2001 |
2 | From: Danny Kukawka <danny.kukawka@web.de> |
3 | Date: Thu, 6 Dec 2007 20:08:12 +0100 |
4 | Subject: [PATCH] read dmi info from sysfs instead of call dmidecode |
5 | |
6 | This makes HAL to read dmi/smbios information on Linux from sysfs |
7 | (/sys/devices/virtual/dmi/id) instead of use a prober to call and |
8 | parse dmidecode. |
9 | |
10 | If /sys/devices/virtual/dmi/id isn't available the code falls back |
11 | to the old hald-probe-smbios prober. |
12 | |
13 | Note: there are three files (for serials/uuid) which are readable |
14 | only for root. Solved this by read these files before drop the |
15 | privileges. |
16 | --- |
17 | hald/linux/osspec.c | 230 ++++++++++++++++++++++++++++++++++++-------------- |
18 | 1 files changed, 165 insertions(+), 65 deletions(-) |
19 | |
20 | diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c |
21 | index 25da9dd..feeb733 100644 |
22 | --- a/hald/linux/osspec.c |
23 | +++ b/hald/linux/osspec.c |
24 | @@ -30,6 +30,7 @@ |
25 | #endif |
26 | |
27 | #define _GNU_SOURCE 1 |
28 | +#define DMI_SYSFS_PATH "/sys/class/dmi/id" |
29 | |
30 | #include <ctype.h> |
31 | #include <errno.h> |
32 | @@ -308,6 +309,38 @@ GIOChannel *get_mdstat_channel (void) |
33 | return mdstat_channel; |
34 | } |
35 | |
36 | +/* |
37 | + * NOTE: We need to use this function to parse if HAL is privileged |
38 | + * since some of the dmi keys in sysfs are only readable by root |
39 | + */ |
40 | +static void |
41 | +osspec_privileged_init_preparse_set_dmi (gboolean set, HalDevice *d) |
42 | +{ |
43 | + gchar *buf; |
44 | + static char *product_serial; |
45 | + static char *product_uuid; |
46 | + static gboolean parsed = FALSE; |
47 | + |
48 | + if (g_file_test (DMI_SYSFS_PATH, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) { |
49 | + |
50 | + if (!set){ |
51 | + if ((buf = hal_util_get_string_from_file(DMI_SYSFS_PATH, "product_serial")) != NULL) |
52 | + product_serial = g_strdup ( buf ); |
53 | + if ((buf = hal_util_get_string_from_file(DMI_SYSFS_PATH, "product_uuid")) != NULL) |
54 | + product_uuid = g_strdup ( buf ); |
55 | + |
56 | + parsed = TRUE; |
57 | + } else { |
58 | + if (d != NULL && parsed) { |
59 | + hal_device_property_set_string (d, "system.hardware.serial", product_serial); |
60 | + hal_device_property_set_string (d, "system.hardware.uuid", product_uuid); |
61 | + g_free (product_serial); |
62 | + g_free (product_uuid); |
63 | + parsed = FALSE; |
64 | + } |
65 | + } |
66 | + } |
67 | +} |
68 | |
69 | void |
70 | osspec_privileged_init (void) |
71 | @@ -336,6 +369,8 @@ osspec_privileged_init (void) |
72 | |
73 | if (err != NULL) |
74 | g_error_free (err); |
75 | + |
76 | + osspec_privileged_init_preparse_set_dmi(FALSE, NULL); |
77 | } |
78 | |
79 | void |
80 | @@ -454,11 +489,87 @@ computer_probing_helper_done (HalDevice *d) |
81 | } |
82 | |
83 | static void |
84 | +computer_dmi_map (HalDevice *d, gboolean dmidecode) |
85 | +{ |
86 | + /* Map the chassis type from dmidecode.c to a sensible type used in hal |
87 | + * |
88 | + * See also 3.3.4.1 of the "System Management BIOS Reference Specification, |
89 | + * Version 2.3.4" document, available from http://www.dmtf.org/standards/smbios. |
90 | + * |
91 | + * TODO: figure out WTF the mapping should be; "Lunch Box"? Give me a break :-) |
92 | + */ |
93 | + static const char *chassis_map[] = { |
94 | + "Other", "unknown", /* 0x01 */ |
95 | + "Unknown", "unknown", |
96 | + "Desktop", "desktop", |
97 | + "Low Profile Desktop", "desktop", |
98 | + "Pizza Box", "server", |
99 | + "Mini Tower", "desktop", |
100 | + "Tower", "desktop", |
101 | + "Portable", "laptop", |
102 | + "Laptop", "laptop", |
103 | + "Notebook", "laptop", |
104 | + "Hand Held", "handheld", |
105 | + "Docking Station", "laptop", |
106 | + "All In One", "unknown", |
107 | + "Sub Notebook", "laptop", |
108 | + "Space-saving", "unknown", |
109 | + "Lunch Box", "unknown", |
110 | + "Main Server Chassis", "server", |
111 | + "Expansion Chassis", "unknown", |
112 | + "Sub Chassis", "unknown", |
113 | + "Bus Expansion Chassis", "unknown", |
114 | + "Peripheral Chassis", "unknown", |
115 | + "RAID Chassis", "unknown", |
116 | + "Rack Mount Chassis", "unknown", |
117 | + "Sealed-case PC", "unknown", |
118 | + "Multi-system", "unknown", |
119 | + "CompactPCI", "unknonw", |
120 | + "AdvancedTCA", "unknown", /* 0x1B */ |
121 | + NULL |
122 | + }; |
123 | + |
124 | + |
125 | + if (dmidecode) { |
126 | + /* do mapping from text to text type */ |
127 | + unsigned int i; |
128 | + const char *chassis_type; |
129 | + |
130 | + /* now map the smbios.* properties to our generic system.formfactor property */ |
131 | + if ((chassis_type = hal_device_property_get_string (d, "smbios.chassis.type")) != NULL) { |
132 | + |
133 | + for (i = 0; chassis_map[i] != NULL; i += 2) { |
134 | + if (strcmp (chassis_map[i], chassis_type) == 0) { |
135 | + hal_device_property_set_string (d, "system.formfactor", chassis_map[i+1]); |
136 | + break; |
137 | + } |
138 | + } |
139 | + } |
140 | + } else { |
141 | + gint chassis_type; |
142 | + |
143 | + /* do mapping from integer type to text type*/ |
144 | + /* get the chassis type and map it to the related text info */ |
145 | + if (hal_util_get_int_from_file(DMI_SYSFS_PATH, "chassis_type", &chassis_type, 10)) { |
146 | + |
147 | + if ((chassis_type > 0) && (chassis_type < 28) && (chassis_map[(chassis_type-1)*2] != NULL)) { |
148 | + hal_device_property_set_string (d, "system.chassis.type", chassis_map[((chassis_type-1)*2)]); |
149 | + hal_device_property_set_string (d, "system.formfactor", chassis_map[((chassis_type-1)*2)+1]); |
150 | + } |
151 | + |
152 | + } else { |
153 | + hal_device_property_set_string (d, "system.chassis.type", "Unknown"); |
154 | + hal_device_property_set_string (d, "system.formfactor", "unknown"); |
155 | + } |
156 | + } |
157 | + |
158 | +} |
159 | + |
160 | +static void |
161 | computer_probing_pcbios_helper_done (HalDevice *d, guint32 exit_type, |
162 | gint return_code, gchar **error, |
163 | gpointer data1, gpointer data2) |
164 | { |
165 | - const char *chassis_type; |
166 | const char *system_manufacturer; |
167 | const char *system_product; |
168 | const char *system_version; |
169 | @@ -485,56 +596,7 @@ computer_probing_pcbios_helper_done (HalDevice *d, guint32 exit_type, |
170 | |
171 | |
172 | if (!hal_device_has_property (d, "system.formfactor")) { |
173 | - /* now map the smbios.* properties to our generic system.formfactor property */ |
174 | - if ((chassis_type = hal_device_property_get_string (d, "smbios.chassis.type")) != NULL) { |
175 | - unsigned int i; |
176 | - |
177 | - /* Map the chassis type from dmidecode.c to a sensible type used in hal |
178 | - * |
179 | - * See also 3.3.4.1 of the "System Management BIOS Reference Specification, |
180 | - * Version 2.3.4" document, available from http://www.dmtf.org/standards/smbios. |
181 | - * |
182 | - * TODO: figure out WTF the mapping should be; "Lunch Box"? Give me a break :-) |
183 | - */ |
184 | - static const char *chassis_map[] = { |
185 | - "Other", "unknown", /* 0x01 */ |
186 | - "Unknown", "unknown", |
187 | - "Desktop", "desktop", |
188 | - "Low Profile Desktop", "desktop", |
189 | - "Pizza Box", "server", |
190 | - "Mini Tower", "desktop", |
191 | - "Tower", "desktop", |
192 | - "Portable", "laptop", |
193 | - "Laptop", "laptop", |
194 | - "Notebook", "laptop", |
195 | - "Hand Held", "handheld", |
196 | - "Docking Station", "laptop", |
197 | - "All In One", "unknown", |
198 | - "Sub Notebook", "laptop", |
199 | - "Space-saving", "unknown", |
200 | - "Lunch Box", "unknown", |
201 | - "Main Server Chassis", "server", |
202 | - "Expansion Chassis", "unknown", |
203 | - "Sub Chassis", "unknown", |
204 | - "Bus Expansion Chassis", "unknown", |
205 | - "Peripheral Chassis", "unknown", |
206 | - "RAID Chassis", "unknown", |
207 | - "Rack Mount Chassis", "unknown", |
208 | - "Sealed-case PC", "unknown", |
209 | - "Multi-system", "unknown", |
210 | - "CompactPCI", "unknonw", |
211 | - "AdvancedTCA", "unknown", /* 0x1B */ |
212 | - NULL |
213 | - }; |
214 | - |
215 | - for (i = 0; chassis_map[i] != NULL; i += 2) { |
216 | - if (strcmp (chassis_map[i], chassis_type) == 0) { |
217 | - hal_device_property_set_string (d, "system.formfactor", chassis_map[i+1]); |
218 | - break; |
219 | - } |
220 | - } |
221 | - |
222 | - } |
223 | + computer_dmi_map (d, TRUE); |
224 | } |
225 | out: |
226 | computer_probing_helper_done (d); |
227 | @@ -665,21 +727,59 @@ probe_openfirmware(HalDevice *root) |
228 | detect_openfirmware_formfactor(root); |
229 | } |
230 | |
231 | +static gboolean |
232 | +decode_dmi_from_sysfs (HalDevice *d) |
233 | +{ |
234 | + if (g_file_test (DMI_SYSFS_PATH, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) { |
235 | + |
236 | + osspec_privileged_init_preparse_set_dmi(TRUE, d); |
237 | + hal_util_set_string_from_file(d, "system.firmware.vendor", DMI_SYSFS_PATH, "bios_vendor"); |
238 | + hal_util_set_string_from_file(d, "system.firmware.version", DMI_SYSFS_PATH, "bios_version"); |
239 | + hal_util_set_string_from_file(d, "system.firmware.release_date", DMI_SYSFS_PATH, "bios_date"); |
240 | + hal_util_set_string_from_file(d, "system.hardware.vendor", DMI_SYSFS_PATH, "sys_vendor"); |
241 | + hal_util_set_string_from_file(d, "system.hardware.product", DMI_SYSFS_PATH, "product_name"); |
242 | + hal_util_set_string_from_file(d, "system.hardware.version", DMI_SYSFS_PATH, "product_version"); |
243 | + hal_util_set_string_from_file(d, "system.chassis.manufacturer", DMI_SYSFS_PATH, "chassis_vendor"); |
244 | + computer_dmi_map (d, FALSE); |
245 | + |
246 | + /* compatibility keys, remove 28 Feb 2008 */ |
247 | + hal_device_copy_property (d, "system.hardware.vendor", d , "smbios.system.manufacturer"); |
248 | + hal_device_copy_property (d, "system.hardware.product", d , "smbios.system.product"); |
249 | + hal_device_copy_property (d, "system.hardware.version", d , "smbios.system.version"); |
250 | + hal_device_copy_property (d, "system.hardware.serial", d , "smbios.system.serial"); |
251 | + hal_device_copy_property (d, "system.hardware.uuid", d , "smbios.system.uuid"); |
252 | + hal_device_copy_property (d, "system.firmware.vendor", d , "smbios.bios.vendor"); |
253 | + hal_device_copy_property (d, "system.firmware.version", d , "smbios.bios.version"); |
254 | + hal_device_copy_property (d, "system.firmware.release_date", d , "smbios.bios.release_date"); |
255 | + hal_device_copy_property (d, "system.chassis.manufacturer", d , "smbios.chassis.manufacturer"); |
256 | + hal_device_copy_property (d, "system.chassis.type", d , "smbios.chassis.type"); |
257 | + |
258 | + computer_probing_helper_done (d); |
259 | + return TRUE; |
260 | + |
261 | + } else { |
262 | + return FALSE; |
263 | + } |
264 | + |
265 | +} |
266 | + |
267 | static void |
268 | decode_dmi (HalDevice *d) |
269 | { |
270 | - if (g_file_test ("/usr/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
271 | - g_file_test ("/bin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
272 | - g_file_test ("/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
273 | - g_file_test ("/usr/local/sbin//dmidecode", G_FILE_TEST_IS_EXECUTABLE)) { |
274 | - hald_runner_run (d, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT, |
275 | - computer_probing_pcbios_helper_done, NULL, NULL); |
276 | - } else { |
277 | - /* no probing */ |
278 | - probe_openfirmware (d); |
279 | - computer_probing_helper_done (d); |
280 | - } |
281 | - |
282 | + /* try to get the dmi infos from sysfs instead of call dmidecode*/ |
283 | + if(!decode_dmi_from_sysfs(d)) { |
284 | + if (g_file_test ("/usr/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
285 | + g_file_test ("/bin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
286 | + g_file_test ("/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) || |
287 | + g_file_test ("/usr/local/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE)) { |
288 | + hald_runner_run (d, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT, |
289 | + computer_probing_pcbios_helper_done, NULL, NULL); |
290 | + } else { |
291 | + /* no probing */ |
292 | + probe_openfirmware (d); |
293 | + computer_probing_helper_done (d); |
294 | + } |
295 | + } |
296 | } |
297 | |
298 | static void |
299 | @@ -687,8 +787,8 @@ computer_probing_pm_is_supported_helper_done (HalDevice *d, guint32 exit_type, |
300 | gint return_code, gchar **error, |
301 | gpointer data1, gpointer data2) |
302 | { |
303 | - HAL_INFO (("In computer_probing_pm_is_supported_helper_done")); |
304 | - decode_dmi (d); |
305 | + HAL_INFO (("In computer_probing_pm_is_supported_helper_done")); |
306 | + decode_dmi (d); |
307 | } |
308 | |
309 | static void |
310 | -- |
311 | 1.5.3.7 |
312 |