Blame SOURCES/acpid-2.0.19-kacpimon-dynamic-connections.patch

f51b12
diff --git a/kacpimon/connection_list.c b/kacpimon/connection_list.c
f51b12
index 9b0b0a8..f228186 100644
f51b12
--- a/kacpimon/connection_list.c
f51b12
+++ b/kacpimon/connection_list.c
f51b12
@@ -22,6 +22,7 @@
f51b12
 
f51b12
 #include <unistd.h>
f51b12
 #include <stdio.h>
f51b12
+#include <stdlib.h>
f51b12
 
f51b12
 #include "connection_list.h"
f51b12
 
f51b12
@@ -30,9 +31,9 @@
f51b12
 /*---------------------------------------------------------------*/
f51b12
 /* private objects */
f51b12
 
f51b12
-#define MAX_CONNECTIONS 20
f51b12
+static int capacity = 0;
f51b12
 
f51b12
-static struct connection connection_list[MAX_CONNECTIONS];
f51b12
+static struct connection *connection_list = NULL;
f51b12
 
f51b12
 static int nconnections = 0;
f51b12
 
f51b12
@@ -51,9 +52,19 @@ add_connection(struct connection *p)
f51b12
 {
f51b12
 	if (nconnections < 0)
f51b12
 		return;
f51b12
-	if (nconnections >= MAX_CONNECTIONS) {
f51b12
-		printf("add_connection(): Too many connections.\n");
f51b12
-		return;
f51b12
+
f51b12
+	/* if the list is full, allocate more space */
f51b12
+	if (nconnections >= capacity) {
f51b12
+		/* no more than 1024 */
f51b12
+		if (capacity > 1024) {
f51b12
+			printf("add_connection(): Too many connections.\n");
f51b12
+			return;
f51b12
+		}
f51b12
+
f51b12
+		/* another 20 */
f51b12
+		capacity += 20;
f51b12
+		connection_list =
f51b12
+			realloc(connection_list, sizeof(struct connection) * capacity);
f51b12
 	}
f51b12
 
f51b12
 	if (nconnections == 0)
f51b12
@@ -70,6 +81,30 @@ add_connection(struct connection *p)
f51b12
 
f51b12
 /*---------------------------------------------------------------*/
f51b12
 
f51b12
+void
f51b12
+delete_all_connections(void)
f51b12
+{
f51b12
+	int i = 0;
f51b12
+
f51b12
+	/* For each connection */
f51b12
+	for (i = 0; i <= get_number_of_connections(); ++i)
f51b12
+	{
f51b12
+		struct connection *p;
f51b12
+
f51b12
+		p = get_connection(i);
f51b12
+
f51b12
+		/* If this connection is invalid, try the next. */
f51b12
+		if (p == 0)
f51b12
+			continue;
f51b12
+
f51b12
+		close(p -> fd);
f51b12
+	}
f51b12
+	free(connection_list);
f51b12
+	connection_list = NULL;
f51b12
+}
f51b12
+
f51b12
+/*---------------------------------------------------------------*/
f51b12
+
f51b12
 struct connection *
f51b12
 find_connection(int fd)
f51b12
 {
f51b12
diff --git a/kacpimon/connection_list.h b/kacpimon/connection_list.h
f51b12
index 1d037cf..a787637 100644
f51b12
--- a/kacpimon/connection_list.h
f51b12
+++ b/kacpimon/connection_list.h
f51b12
@@ -56,4 +56,7 @@ extern const fd_set *get_fdset(void);
f51b12
 /* get the highest fd that was added to the list */
f51b12
 extern int get_highestfd(void);
f51b12
 
f51b12
+/* delete all connections, closing the fds */
f51b12
+extern void delete_all_connections(void);
f51b12
+
f51b12
 #endif /* CONNECTION_LIST_H__ */
f51b12
diff --git a/kacpimon/kacpimon.c b/kacpimon/kacpimon.c
f51b12
index 1ddb9aa..253d270 100644
f51b12
--- a/kacpimon/kacpimon.c
f51b12
+++ b/kacpimon/kacpimon.c
f51b12
@@ -164,27 +164,6 @@ static void monitor(void)
f51b12
 
f51b12
 // ---------------------------------------------------------------
f51b12
 
f51b12
-static void close_all(void)
f51b12
-{
f51b12
-	int i = 0;
f51b12
-
f51b12
-	/* For each connection */
f51b12
-	for (i = 0; i <= get_number_of_connections(); ++i)
f51b12
-	{
f51b12
-		struct connection *p;
f51b12
-
f51b12
-		p = get_connection(i);
f51b12
-
f51b12
-		/* If this connection is invalid, try the next. */
f51b12
-		if (p == 0)
f51b12
-			continue;
f51b12
-
f51b12
-		close(p -> fd);
f51b12
-	}
f51b12
-}
f51b12
-
f51b12
-// ---------------------------------------------------------------
f51b12
-
f51b12
 int main(void)
f51b12
 {
f51b12
 	printf("Kernel ACPI Event Monitor...\n");
f51b12
@@ -199,7 +178,7 @@ int main(void)
f51b12
 
f51b12
 	printf("Closing files...\n");
f51b12
 
f51b12
-	close_all();
f51b12
+	delete_all_connections();
f51b12
 
f51b12
 	printf("Goodbye\n");
f51b12