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

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