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

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