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

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