diff options
-rw-r--r-- | utils.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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) |