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

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