summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-10 23:54:45 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-10 23:54:45 +0200
commit8ab0428f54238a207df8682b586ea0c22240849f (patch)
tree0486df93e6ac03a46e4dba58be974268337d5cc7
parent3433cb9f5a47477bc02420b2e319d66929f46294 (diff)
Add open files to resource debug
-rw-r--r--utils.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index 45ecf92..39f91f1 100644
--- a/utils.c
+++ b/utils.c
@@ -6,6 +6,8 @@
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "main.h"
#include "utils.h"
@@ -112,6 +114,9 @@ debug_resource_usage()
struct allocation *a;
DIR *dir;
struct dirent *dent;
+ char buf[4096];
+ ssize_t r;
+ unsigned file_count = 0;
fprintf(stderr, "Still malloced %i (total %u)\n",
malloc_count, total_malloc_count);
@@ -133,9 +138,21 @@ debug_resource_usage()
!strcmp(dent->d_name, ".."))
continue;
- fprintf(stderr, " * %s\n", dent->d_name);
+ r = readlinkat(dirfd(dir), dent->d_name, buf, sizeof(buf));
+ if (r < 0) {
+ fprintf(stderr, "Failed to readlink %s\n", dent->d_name);
+ continue;
+ }
+ buf[r] = '\0';
+ fprintf(stderr, " * %s -> %s\n", dent->d_name, buf);
+ file_count++;
}
closedir(dir);
+
+ if (file_count > 4) {
+ fprintf(stderr, "Lost file descriptor(s)\n");
+ exit(EXIT_FAILURE);
+ }
}
uint16_t sockaddr_port(struct sockaddr_in46 *addr)