diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-10 23:43:23 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-10 23:43:23 +0200 |
commit | 3433cb9f5a47477bc02420b2e319d66929f46294 (patch) | |
tree | 2714ab7ae81f79ec6ad740fac454b787b9e159d4 | |
parent | 5fb493c99846cb475dab7321a4d835025c96051b (diff) |
Check the return value from server_new
-rw-r--r-- | cfgdir.c | 13 | ||||
-rw-r--r-- | utils.c | 20 |
2 files changed, 27 insertions, 6 deletions
@@ -412,7 +412,7 @@ cfgdir_init(struct cfg *cfg) int ifd; int iwd; struct inotify_ev *iev; - DIR *cfgdir; + DIR *dir; struct dirent *dent; struct server *scfg; @@ -438,20 +438,21 @@ cfgdir_init(struct cfg *cfg) cfg->iev = iev; uring_read(cfg, &iev->task, iev->buf, sizeof(iev->buf), inotify_cb); - cfgdir = opendir("."); - if (!cfgdir) + dir = opendir("."); + if (!dir) perrordie("opendir"); - while ((dent = readdir(cfgdir)) != NULL) { + while ((dent = readdir(dir)) != NULL) { if (dent->d_type != DT_REG && dent->d_type != DT_UNKNOWN) continue; if (!scfg_valid_filename(dent->d_name)) continue; scfg = server_new(cfg, dent->d_name); - uring_openat(cfg, &scfg->task, scfg->name, scfg_open_cb); + if (scfg) + uring_openat(cfg, &scfg->task, scfg->name, scfg_open_cb); } - closedir(cfgdir); + closedir(dir); } @@ -4,6 +4,8 @@ #include <limits.h> #include <arpa/inet.h> #include <string.h> +#include <sys/types.h> +#include <dirent.h> #include "main.h" #include "utils.h" @@ -108,6 +110,8 @@ void debug_resource_usage() { struct allocation *a; + DIR *dir; + struct dirent *dent; fprintf(stderr, "Still malloced %i (total %u)\n", malloc_count, total_malloc_count); @@ -116,6 +120,22 @@ debug_resource_usage() fprintf(stderr, "* Lost allocation - %s:%i - ptr: %p, size: %zu\n", a->callerfn, a->line, a->ptr, a->size); } + + dir = opendir("/proc/self/fd"); + if (!dir) { + fprintf(stderr, "Failed to open fd dir\n"); + return; + } + + fprintf(stderr, "Open files:\n"); + while ((dent = readdir(dir)) != NULL) { + if (!strcmp(dent->d_name, ".") || + !strcmp(dent->d_name, "..")) + continue; + + fprintf(stderr, " * %s\n", dent->d_name); + } + closedir(dir); } uint16_t sockaddr_port(struct sockaddr_in46 *addr) |