tag 416618 patch
thanks

> yes, I'd like to have a patch :)

Attached.

> I'm sorry but I don't have much time to dedicat to cpufreqd right now
> (and a new release will be delayed by that anyway).
 
Doesn't really matter. It's only I already patched 2.0.0 and though
others might be interested as well. Maybe forwarding to upstream might
be a good idea too.

> By the way, you will need to add some lines to cpufreqd_acpi.c too.

Good point. I had to adapt it a bit. 

Helmut Grohne
diff -ruN cpufreqd-2.2.1/configure cpufreqd-2.2.1.1/configure
--- cpufreqd-2.2.1/configure	2006-11-21 22:25:00.000000000 +0100
+++ cpufreqd-2.2.1.1/configure	2007-04-06 18:54:30.000000000 +0200
@@ -23473,9 +23473,9 @@
 	DISABLED_PLUGINS="$DISABLED_PLUGINS acpi_event"
 fi
 if test x"${acpi_enable}" = xyes; then
-	ENABLED_PLUGINS="$ENABLED_PLUGINS acpi_battery acpi_ac acpi_temperature"
+	ENABLED_PLUGINS="$ENABLED_PLUGINS acpi_battery acpi_ac acpi_lid acpi_temperature"
 else
-	DISABLED_PLUGINS="$DISABLED_PLUGINS acpi_battery acpi_ac acpi_temperature"
+	DISABLED_PLUGINS="$DISABLED_PLUGINS acpi_battery acpi_ac acpi_lid acpi_temperature"
 fi
 
 ###################
diff -ruN cpufreqd-2.2.1/NEWS cpufreqd-2.2.1.1/NEWS
--- cpufreqd-2.2.1/NEWS	2006-11-03 20:47:55.000000000 +0100
+++ cpufreqd-2.2.1.1/NEWS	2007-04-06 18:55:24.000000000 +0200
@@ -18,6 +18,7 @@
 
 * acpi_ac		OK
 * acpi_battery		OK
+* acpi_lid		OK
 * acpi_temperature	OK
 * programs		OK
 * cpu			OK
diff -ruN cpufreqd-2.2.1/README cpufreqd-2.2.1.1/README
--- cpufreqd-2.2.1/README	2006-11-03 20:47:55.000000000 +0100
+++ cpufreqd-2.2.1.1/README	2007-04-06 18:55:53.000000000 +0200
@@ -41,6 +41,7 @@
 ---+---+-------------------+---------------------
  R |   | acpi_ac           | OK!
  R |   | acpi_battery      | OK!
+ R |   | acpi_lid          | OK!
  R |   | acpi_temperature  | OK!
  R |   | acpi_event        | planned
  R |   | apm               | OK!
diff -ruN cpufreqd-2.2.1/src/Makefile.am cpufreqd-2.2.1.1/src/Makefile.am
--- cpufreqd-2.2.1/src/Makefile.am	2006-11-03 20:47:55.000000000 +0100
+++ cpufreqd-2.2.1.1/src/Makefile.am	2007-04-06 19:34:55.000000000 +0200
@@ -99,6 +99,7 @@
 cpufreqd_acpi_la_SOURCES = \
 		cpufreqd_acpi.c \
 		cpufreqd_acpi_ac.c \
+		cpufreqd_acpi_lid.c \
 		cpufreqd_acpi_battery.c \
 		cpufreqd_acpi_event.c \
 		cpufreqd_acpi_temperature.c
@@ -196,6 +197,7 @@
 		cpufreqd_log.h \
 		cpufreqd_acpi.h \
 		cpufreqd_acpi_ac.h \
+		cpufreqd_acpi_lid.h \
 		cpufreqd_acpi_battery.h \
 		cpufreqd_acpi_event.h \
 		cpufreqd_acpi_temperature.h \
diff -ruN cpufreqd-2.2.1/src/cpufreqd_acpi.c cpufreqd-2.2.1.1/src/cpufreqd_acpi.c
--- cpufreqd-2.2.1/src/cpufreqd_acpi.c	2006-11-03 20:47:55.000000000 +0100
+++ cpufreqd-2.2.1.1/src/cpufreqd_acpi.c	2007-04-06 19:29:49.000000000 +0200
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 2006  Mattia Dongili <[EMAIL PROTECTED]>
+ *  			modified by Helmut Grohne <[EMAIL PROTECTED]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -22,11 +23,13 @@
 #include "cpufreqd_plugin.h"
 #include "cpufreqd_acpi.h"
 #include "cpufreqd_acpi_ac.h"
+#include "cpufreqd_acpi_lid.h"
 #include "cpufreqd_acpi_battery.h"
 #include "cpufreqd_acpi_event.h"
 #include "cpufreqd_acpi_temperature.h"
 
 static short acpi_ac_failed;
+static short acpi_lid_failed;
 static short acpi_batt_failed;
 static short acpi_ev_failed;
 static short acpi_temp_failed;
@@ -71,6 +74,8 @@
 	}
 	clog(LOG_DEBUG, "Initializing AC\n");
 	acpi_ac_failed = acpi_ac_init();
+	clog(LOG_DEBUG, "Initializing Lid\n");
+	acpi_lid_failed = acpi_lid_init();
 	clog(LOG_DEBUG, "Initializing BATTERY\n");
 	acpi_batt_failed = acpi_battery_init();
 	clog(LOG_DEBUG, "Initializing TEMPERATURE\n");
@@ -78,7 +83,7 @@
 	clog(LOG_DEBUG, "Initializing EVENT\n");
 	acpi_ev_failed = acpi_event_init();
 	/* return error _only_ if all components failed */
-	return acpi_ev_failed && acpi_ac_failed && acpi_batt_failed && acpi_temp_failed;
+	return acpi_ev_failed && acpi_ac_failed && acpi_lid_failed && acpi_batt_failed && acpi_temp_failed;
 }
 
 static int acpi_exit (void) {
@@ -87,6 +92,10 @@
 		clog(LOG_DEBUG, "Closing AC\n");
 		ret |= acpi_ac_exit();
 	}
+	if (!acpi_lid_failed) {
+		clog(LOG_DEBUG, "Closing Lid\n");
+		ret |= acpi_lid_exit();
+	}
 	if (!acpi_batt_failed) {
 		clog(LOG_DEBUG, "Closing BATTERY\n");
 		ret |= acpi_battery_exit();
@@ -106,6 +115,8 @@
 
 	if (!acpi_ac_failed)
 		acpi_ac_update();
+	if (!acpi_lid_failed)
+		acpi_lid_update();
 
 	acpi_event_lock();
 	if (!acpi_batt_failed)
@@ -122,6 +133,7 @@
 
 static struct cpufreqd_keyword kw[] = {
 	{ .word = "ac", .parse = &acpi_ac_parse, .evaluate = &acpi_ac_evaluate },
+	{ .word = "lid", .parse = &acpi_lid_parse, .evaluate = &acpi_lid_evaluate },
 	{ .word = "battery_interval", .parse = &acpi_battery_parse, .evaluate = &acpi_battery_evaluate },
 	{ .word = "acpi_temperature", .parse = &acpi_temperature_parse,   .evaluate = &acpi_temperature_evaluate },
 	{ .word = NULL, .parse = NULL, .evaluate = NULL, .free = NULL }
diff -ruN cpufreqd-2.2.1/src/cpufreqd_acpi_lid.c cpufreqd-2.2.1.1/src/cpufreqd_acpi_lid.c
--- cpufreqd-2.2.1/src/cpufreqd_acpi_lid.c	1970-01-01 01:00:00.000000000 +0100
+++ cpufreqd-2.2.1.1/src/cpufreqd_acpi_lid.c	2007-04-06 19:12:39.000000000 +0200
@@ -0,0 +1,173 @@
+/*
+ *  Copyright (C) 2002-2006  Mattia Dongili <[EMAIL PROTECTED]>
+ *                           George Staikos <[EMAIL PROTECTED]>
+ *                           modified by Helmut Grohne <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cpufreqd_plugin.h"
+#include "cpufreqd_acpi_lid.h"
+
+#define ACPI_LID_DIR "/proc/acpi/button/lid/"
+#define ACPI_LID_FILE "/state"
+#define ACPI_LID_FORMAT "state:      %s\n"
+
+#define OPEN   1
+#define CLOSED 0
+
+static char *lid_filelist[64];
+static unsigned short lid_state;
+static int lid_dir_num;
+
+static int no_dots(const struct dirent *d) {
+	return d->d_name[0]!= '.';
+}
+
+/*  static int acpi_lid_init(void)
+ *
+ *  test if LID dirs are present
+ */
+int acpi_lid_init(void) {
+	struct dirent **namelist = NULL;
+	int n = 0;
+
+	/* get LID path */
+	n = scandir(ACPI_LID_DIR, &namelist, no_dots, NULL);
+	if (n > 0) {
+		lid_dir_num = n;
+		*lid_filelist = malloc(n * 64 * sizeof(char));
+		while (n--) {
+			snprintf(lid_filelist[n], 64, "%s%s%s", ACPI_LID_DIR, namelist[n]->d_name, ACPI_LID_FILE);
+			clog(LOG_INFO, "LID path %s\n", lid_filelist[n]);
+			free(namelist[n]);
+		} 
+		free(namelist);
+
+	} else if (n < 0) {
+		clog(LOG_DEBUG, "no acpi_lid module compiled or inserted? (%s: %s)\n",
+				ACPI_LID_DIR, strerror(errno));
+		return -1;
+
+	} else {
+		clog(LOG_NOTICE, "no lid button found, not a laptop?\n");
+		return -1;
+	}
+	return 0;
+}
+
+int acpi_lid_exit(void) {
+	if (lid_filelist != NULL)
+		free(*lid_filelist);
+	clog(LOG_INFO, "exited.\n");
+	return 0;
+}
+
+/*  static int acpi_lid_update(void)
+ *  
+ *  reads lid state
+ */
+int acpi_lid_update(void) {
+	char temp[50];
+	int i=0;
+	FILE *fp = NULL;
+
+	lid_state = OPEN;
+	clog(LOG_DEBUG, "called\n");
+	for (i=0; i<lid_dir_num; i++) {
+		fp = fopen(lid_filelist[i], "r");
+		if (!fp) {
+			clog(LOG_ERR, "%s: %s\n", lid_filelist[i], strerror(errno));
+			return -1;
+		}
+		fscanf(fp, ACPI_LID_FORMAT, temp);
+		fclose(fp);
+
+		clog(LOG_DEBUG, "read %s\n", temp);
+		lid_state |= (strncmp(temp, "closed", 7)==0 ? CLOSED : OPEN);
+	}
+
+	clog(LOG_INFO, "lid_button is %s\n",
+			lid_state==OPEN ? "open" : "closed");
+
+	return 0;
+}
+
+/*
+ *  parse the 'lid' keywork
+ */
+int acpi_lid_parse(const char *ev, void **obj) {
+	int *ret = malloc(sizeof(int));
+	if (ret == NULL) {
+		clog(LOG_ERR, "couldn't make enough room for lid_status (%s)\n",
+				strerror(errno));
+		return -1;
+	}
+
+	*ret = 0;
+
+	clog(LOG_DEBUG, "called with: %s\n", ev);
+
+	if (strncmp(ev, "open", 2) == 0) {
+		*ret = OPEN;
+	} else if (strncmp(ev, "closed", 3) == 0) {
+		*ret = CLOSED;
+	} else {
+		clog(LOG_ERR, "couldn't parse %s\n", ev);
+		free(ret);
+		return -1;
+	}
+
+	clog(LOG_INFO, "parsed: %s\n", *ret==OPEN ? "open" : "closed");
+
+	*obj = ret;
+	return 0;
+}
+
+/*
+ *  evaluate the 'lid' keywork
+ */
+int acpi_lid_evaluate(const void *s) {
+	const int *lid = (const int *)s;
+
+	clog(LOG_DEBUG, "called: %s [%s]\n",
+			*lid==OPEN ? "open" : "closed", lid_state==OPEN ? "open" : "closed");
+
+	return (*lid == lid_state) ? MATCH : DONT_MATCH;
+}
+
+#if 0
+static struct cpufreqd_keyword kw[] = {
+	{ .word = "lid", .parse = &acpi_lid_parse, .evaluate = &acpi_lid_evaluate },
+	{ .word = NULL, .parse = NULL, .evaluate = NULL, .free = NULL }
+};
+
+static struct cpufreqd_plugin acpi_lid = {
+	.plugin_name	= "acpi_lid_plugin",	/* plugin_name */
+	.keywords	= kw,			/* config_keywords */
+	.plugin_init	= &acpi_lid_init,	/* plugin_init */
+	.plugin_exit	= &acpi_lid_exit,	/* plugin_exit */
+	.plugin_update	= &acpi_lid_update	/* plugin_update */
+};
+
+struct cpufreqd_plugin *create_plugin (void) {
+	return &acpi_lid;
+}
+#endif
diff -ruN cpufreqd-2.2.1/src/cpufreqd_acpi_lid.h cpufreqd-2.2.1.1/src/cpufreqd_acpi_lid.h
--- cpufreqd-2.2.1/src/cpufreqd_acpi_lid.h	1970-01-01 01:00:00.000000000 +0100
+++ cpufreqd-2.2.1.1/src/cpufreqd_acpi_lid.h	2007-04-06 19:02:38.000000000 +0200
@@ -0,0 +1,26 @@
+/*
+ *  Copyright (C) 2002-2006  Mattia Dongili <[EMAIL PROTECTED]>
+ *                           George Staikos <[EMAIL PROTECTED]>
+ *                           modified by Helmut Grohne <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+int acpi_lid_init(void);
+int acpi_lid_exit(void);
+int acpi_lid_update(void);
+int acpi_lid_parse(const char *ev, void **obj);
+int acpi_lid_evaluate(const void *s);

Attachment: signature.asc
Description: Digital signature

Reply via email to