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

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