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

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