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

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