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

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