summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-10 23:43:23 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-10 23:43:23 +0200
commit3433cb9f5a47477bc02420b2e319d66929f46294 (patch)
tree2714ab7ae81f79ec6ad740fac454b787b9e159d4
parent5fb493c99846cb475dab7321a4d835025c96051b (diff)
Check the return value from server_new
-rw-r--r--cfgdir.c13
-rw-r--r--utils.c20
2 files changed, 27 insertions, 6 deletions
diff --git a/cfgdir.c b/cfgdir.c
index 08b40f1..7e5022b 100644
--- a/cfgdir.c
+++ b/cfgdir.c
@@ -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);
}
diff --git a/utils.c b/utils.c
index 08a5464..45ecf92 100644
--- a/utils.c
+++ b/utils.c
@@ -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)