Blame SOURCES/acpid-2.0.19-dynamic-connections.patch

7da3f6
--- a/acpid.c	
7da3f6
+++ a/acpid.c	
7da3f6
@@ -456,6 +456,7 @@ void
7da3f6
 clean_exit_with_status(int status)
7da3f6
 {
7da3f6
 	acpid_cleanup_rules(1);
7da3f6
+	delete_all_connections();
7da3f6
 	acpid_log(LOG_NOTICE, "exiting");
7da3f6
 	unlink(pidfile);
7da3f6
 	exit(status);
7da3f6
--- a/connection_list.c	
7da3f6
+++ a/connection_list.c	
7da3f6
@@ -35,9 +35,9 @@ 
7da3f6
 /*---------------------------------------------------------------*/
7da3f6
 /* private objects */
7da3f6
 
7da3f6
-#define MAX_CONNECTIONS 20
7da3f6
+static int capacity = 0;
7da3f6
 
7da3f6
-static struct connection connection_list[MAX_CONNECTIONS];
7da3f6
+static struct connection *connection_list = NULL;
7da3f6
 
7da3f6
 static int nconnections = 0;
7da3f6
 
7da3f6
@@ -56,12 +56,20 @@ add_connection(struct connection *p)
7da3f6
 {
7da3f6
 	if (nconnections < 0)
7da3f6
 		return;
7da3f6
-	if (nconnections >= MAX_CONNECTIONS) {
7da3f6
-		acpid_log(LOG_ERR, "Too many connections.");
7da3f6
-		/* ??? This routine should return -1 in this situation so that */
7da3f6
-		/*   callers can clean up any open fds and whatnot.  */
7da3f6
-		return;
7da3f6
-	}
7da3f6
+
7da3f6
+	/* if the list is full, allocate more space */
7da3f6
+	if (nconnections >= capacity) {
7da3f6
+		/* no more than 1024 */
7da3f6
+		if (capacity > 1024) {
7da3f6
+			acpid_log(LOG_ERR, "Too many connections.");
7da3f6
+			return;
7da3f6
+		}
7da3f6
+
7da3f6
+		/* another 20 */
7da3f6
+		capacity += 20;
7da3f6
+		connection_list =
7da3f6
+			realloc(connection_list, sizeof(struct connection) * capacity);
7da3f6
+	}
7da3f6
 
7da3f6
 	if (nconnections == 0)
7da3f6
 		FD_ZERO(&allfds);
7da3f6
@@ -82,7 +89,9 @@ delete_connection(int fd)
7da3f6
 {
7da3f6
 	int i;
7da3f6
 
7da3f6
-	close(fd);
7da3f6
+	/* close anything other than stdin/stdout/stderr */
7da3f6
+	if (fd > 2)
7da3f6
+		close(fd);
7da3f6
 
7da3f6
 	/* remove from the fd set */
7da3f6
 	FD_CLR(fd, &allfds);
7da3f6
@@ -110,6 +119,21 @@ delete_connection(int fd)
7da3f6
 
7da3f6
 /*---------------------------------------------------------------*/
7da3f6
 
7da3f6
+void
7da3f6
+delete_all_connections(void)
7da3f6
+{
7da3f6
+	/* while there are still connections to delete */
7da3f6
+	while (nconnections) {
7da3f6
+		/* delete the connection at the end of the list */
7da3f6
+		delete_connection(connection_list[nconnections-1].fd);
7da3f6
+	}
7da3f6
+
7da3f6
+	free(connection_list);
7da3f6
+	connection_list = NULL;
7da3f6
+}
7da3f6
+
7da3f6
+/*---------------------------------------------------------------*/
7da3f6
+
7da3f6
 struct connection *
7da3f6
 find_connection(int fd)
7da3f6
 {
7da3f6
--- a/connection_list.h	
7da3f6
+++ a/connection_list.h	
7da3f6
@@ -75,4 +75,7 @@ extern const fd_set *get_fdset(void);
7da3f6
 /* get the highest fd that was added to the list */
7da3f6
 extern int get_highestfd(void);
7da3f6
 
7da3f6
+/* delete all connections, closing the fds */
7da3f6
+extern void delete_all_connections(void);
7da3f6
+
7da3f6
 #endif /* CONNECTION_LIST_H__ */