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

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