|
|
d4a401 |
diff --git a/kacpimon/connection_list.c b/kacpimon/connection_list.c
|
|
|
d4a401 |
index 9b0b0a8..f228186 100644
|
|
|
d4a401 |
--- a/kacpimon/connection_list.c
|
|
|
d4a401 |
+++ b/kacpimon/connection_list.c
|
|
|
d4a401 |
@@ -22,6 +22,7 @@
|
|
|
d4a401 |
|
|
|
d4a401 |
#include <unistd.h>
|
|
|
d4a401 |
#include <stdio.h>
|
|
|
d4a401 |
+#include <stdlib.h>
|
|
|
d4a401 |
|
|
|
d4a401 |
#include "connection_list.h"
|
|
|
d4a401 |
|
|
|
d4a401 |
@@ -30,9 +31,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 |
@@ -51,9 +52,19 @@ add_connection(struct connection *p)
|
|
|
d4a401 |
{
|
|
|
d4a401 |
if (nconnections < 0)
|
|
|
d4a401 |
return;
|
|
|
d4a401 |
- if (nconnections >= MAX_CONNECTIONS) {
|
|
|
d4a401 |
- printf("add_connection(): Too many connections.\n");
|
|
|
d4a401 |
- return;
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+ /* if the list is full, allocate more space */
|
|
|
d4a401 |
+ if (nconnections >= capacity) {
|
|
|
d4a401 |
+ /* no more than 1024 */
|
|
|
d4a401 |
+ if (capacity > 1024) {
|
|
|
d4a401 |
+ printf("add_connection(): Too many connections.\n");
|
|
|
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 |
@@ -70,6 +81,30 @@ add_connection(struct connection *p)
|
|
|
d4a401 |
|
|
|
d4a401 |
/*---------------------------------------------------------------*/
|
|
|
d4a401 |
|
|
|
d4a401 |
+void
|
|
|
d4a401 |
+delete_all_connections(void)
|
|
|
d4a401 |
+{
|
|
|
d4a401 |
+ int i = 0;
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+ /* For each connection */
|
|
|
d4a401 |
+ for (i = 0; i <= get_number_of_connections(); ++i)
|
|
|
d4a401 |
+ {
|
|
|
d4a401 |
+ struct connection *p;
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+ p = get_connection(i);
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+ /* If this connection is invalid, try the next. */
|
|
|
d4a401 |
+ if (p == 0)
|
|
|
d4a401 |
+ continue;
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+ close(p -> fd);
|
|
|
d4a401 |
+ }
|
|
|
d4a401 |
+ free(connection_list);
|
|
|
d4a401 |
+ connection_list = NULL;
|
|
|
d4a401 |
+}
|
|
|
d4a401 |
+
|
|
|
d4a401 |
+/*---------------------------------------------------------------*/
|
|
|
d4a401 |
+
|
|
|
d4a401 |
struct connection *
|
|
|
d4a401 |
find_connection(int fd)
|
|
|
d4a401 |
{
|
|
|
d4a401 |
diff --git a/kacpimon/connection_list.h b/kacpimon/connection_list.h
|
|
|
d4a401 |
index 1d037cf..a787637 100644
|
|
|
d4a401 |
--- a/kacpimon/connection_list.h
|
|
|
d4a401 |
+++ b/kacpimon/connection_list.h
|
|
|
d4a401 |
@@ -56,4 +56,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__ */
|
|
|
d4a401 |
diff --git a/kacpimon/kacpimon.c b/kacpimon/kacpimon.c
|
|
|
d4a401 |
index 1ddb9aa..253d270 100644
|
|
|
d4a401 |
--- a/kacpimon/kacpimon.c
|
|
|
d4a401 |
+++ b/kacpimon/kacpimon.c
|
|
|
d4a401 |
@@ -164,27 +164,6 @@ static void monitor(void)
|
|
|
d4a401 |
|
|
|
d4a401 |
// ---------------------------------------------------------------
|
|
|
d4a401 |
|
|
|
d4a401 |
-static void close_all(void)
|
|
|
d4a401 |
-{
|
|
|
d4a401 |
- int i = 0;
|
|
|
d4a401 |
-
|
|
|
d4a401 |
- /* For each connection */
|
|
|
d4a401 |
- for (i = 0; i <= get_number_of_connections(); ++i)
|
|
|
d4a401 |
- {
|
|
|
d4a401 |
- struct connection *p;
|
|
|
d4a401 |
-
|
|
|
d4a401 |
- p = get_connection(i);
|
|
|
d4a401 |
-
|
|
|
d4a401 |
- /* If this connection is invalid, try the next. */
|
|
|
d4a401 |
- if (p == 0)
|
|
|
d4a401 |
- continue;
|
|
|
d4a401 |
-
|
|
|
d4a401 |
- close(p -> fd);
|
|
|
d4a401 |
- }
|
|
|
d4a401 |
-}
|
|
|
d4a401 |
-
|
|
|
d4a401 |
-// ---------------------------------------------------------------
|
|
|
d4a401 |
-
|
|
|
d4a401 |
int main(void)
|
|
|
d4a401 |
{
|
|
|
d4a401 |
printf("Kernel ACPI Event Monitor...\n");
|
|
|
d4a401 |
@@ -199,7 +178,7 @@ int main(void)
|
|
|
d4a401 |
|
|
|
d4a401 |
printf("Closing files...\n");
|
|
|
d4a401 |
|
|
|
d4a401 |
- close_all();
|
|
|
d4a401 |
+ delete_all_connections();
|
|
|
d4a401 |
|
|
|
d4a401 |
printf("Goodbye\n");
|
|
|
d4a401 |
|