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

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