hal/hald/linux2 acpi.c,1.47,1.48

Kay Sievers kay at kemper.freedesktop.org
Mon Apr 17 08:04:51 PDT 2006


Update of /cvs/hal/hal/hald/linux2
In directory kemper:/tmp/cvs-serv26982/hald/linux2

Modified Files:
	acpi.c 
Log Message:
2006-04-17  Kay Sievers  <kay.sievers at vrfy.org>

        Read name of cpu from /proc/cpuinfo. Some day we will
        have this in sysfs, but it's not ready for now.
        Thanks for the patch to:
          Jim Krehl <jimmyk at novell.com>

        * hald/linux2/acpi.c: (get_processor_model_name),
        (processor_refresh):


Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- acpi.c	18 Feb 2006 23:11:23 -0000	1.47
+++ acpi.c	17 Apr 2006 15:04:49 -0000	1.48
@@ -618,22 +618,90 @@
 	return TRUE;
 }
 
+static gchar *
+get_processor_model_name (gint proc_num)
+{
+	gchar *model_name;
+
+	gchar  *contents = NULL;
+	GError *error    = NULL;
+
+	gchar **lines;
+
+	gint proc_num_i;
+
+	gchar *cursor;
+	gint   i;
+
+
+	if (g_file_get_contents ("/proc/cpuinfo", & contents, NULL, & error)) {
+		lines = g_strsplit (contents, "\n", 0);
+
+		for (i = 0; lines [i]; ++i) {
+			if (strstr (lines [i], "processor\t:")) {
+				cursor = strstr (lines [i], ":");
+
+				proc_num_i = atoi (cursor + 1);
+
+				if (proc_num_i == proc_num) {
+					for (; lines [i]; ++i) {
+						if (strstr (lines [i], "model name\t:")) {
+							cursor = strstr (lines [i], ":");
+
+							g_strstrip (++ cursor);
+
+							model_name = g_strdup (cursor);
+
+							g_strfreev (lines);
+							g_free     (contents);
+
+							return model_name;
+						}
+					}
+				}
+			}
+		}
+	}
+	else {
+		HAL_ERROR (("Couldn't open /proc/cpuinfo: %s", error->message));
+
+		g_error_free (error);
+	}
+
+	return NULL;
+}
+
 static gboolean
 processor_refresh (HalDevice *d, ACPIDevHandler *handler)
 {
 	const char *path;
 
+	gchar *model_name;
+	gint   proc_num;
+
 	path = hal_device_property_get_string (d, "linux.acpi_path");
 	if (path == NULL)
 		return FALSE;
 
-	hal_device_property_set_string (d, "info.product", "Processor");
+	proc_num = hal_util_grep_int_elem_from_file (
+		path, "info", "processor id", 0, 10, FALSE
+	);
+
+	if ((model_name = get_processor_model_name (proc_num))) {
+		hal_device_property_set_string (d, "info.product", model_name);
+
+		g_free (model_name);
+	}
+	else
+		hal_device_property_set_string (d, "info.product", "Unknown Processor");
+
 	hal_device_property_set_string (d, "info.category", "processor");
 	hal_device_add_capability (d, "processor");
 	hal_util_set_int_elem_from_file (d, "processor.number", path,
 					 "info", "processor id", 0, 10, FALSE);
 	hal_util_set_bool_elem_from_file (d, "processor.can_throttle", path,
 					  "info", "throttling control", 0, "yes", FALSE);
+
 	return TRUE;
 }
 




More information about the hal-commit mailing list