diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-22 12:00:05 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-22 12:00:05 +0200 |
commit | 77071eb45391c9f0bbc593bcf2c10605ed1d5d17 (patch) | |
tree | cf1bd5d9d39c77dfc2fc84b98fcf3b5ace4eb989 | |
parent | f2489c89e95c07495768b5401b63ba31ec39d72d (diff) |
Rename proxy and cfgdir to more descriptive names
-rw-r--r-- | cfgdir.h | 10 | ||||
-rw-r--r-- | igmp.c | 2 | ||||
-rw-r--r-- | main.c | 19 | ||||
-rw-r--r-- | main.h | 2 | ||||
-rw-r--r-- | meson.build | 4 | ||||
-rw-r--r-- | server-config.c (renamed from cfgdir.c) | 56 | ||||
-rw-r--r-- | server-config.h | 10 | ||||
-rw-r--r-- | server-proxy.c (renamed from proxy.c) | 2 | ||||
-rw-r--r-- | server-proxy.h (renamed from proxy.h) | 4 | ||||
-rw-r--r-- | server.c | 2 | ||||
-rw-r--r-- | uring.c | 6 | ||||
-rw-r--r-- | uring.h | 2 |
12 files changed, 61 insertions, 58 deletions
diff --git a/cfgdir.h b/cfgdir.h deleted file mode 100644 index 2fe36eb..0000000 --- a/cfgdir.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef foocfgdirhfoo -#define foocfgdirhfoo - -void cfgdir_delete(); - -void cfgdir_refdump(); - -void cfgdir_init(); - -#endif @@ -12,7 +12,7 @@ #include <errno.h> #include <sys/ioctl.h> -/* Remove later */ +/* FIXME: Remove later */ #include <time.h> #include "main.h" @@ -21,7 +21,7 @@ #include "uring.h" #include "config.h" #include "server.h" -#include "cfgdir.h" +#include "server-config.h" #include "announce.h" #include "systemd.h" #include "igmp.h" @@ -568,14 +568,13 @@ dump_tree() info("Dumping Tree"); info("============"); uring_task_refdump(&cfg->task); - uring_refdump(cfg->uev); - idle_refdump(cfg->idle); if (cfg->sev) uring_task_refdump(&cfg->sev->task); - igmp_refdump(cfg->igmp); - announce_refdump(cfg->aev); - if (cfg->iev) - cfgdir_refdump(cfg->iev); + uring_refdump(); + idle_refdump(); + igmp_refdump(); + announce_refdump(); + server_cfg_monitor_refdump(); list_for_each_entry(server, &cfg->servers, list) server_refdump(server); info("============"); @@ -642,11 +641,11 @@ signalfd_read(struct uring_task *task, int res) verbose("got a signal to dump tree"); sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting"); dump_tree(); - uring_task_put(&sev->task); + uring_task_destroy(&sev->task); igmp_delete(); announce_delete(); idle_delete(); - cfgdir_delete(); + server_cfg_monitor_delete(); list_for_each_entry_safe(server, stmp, &cfg->servers, list) server_delete(server); uring_delete(); @@ -753,7 +752,7 @@ main(int argc, char **argv) signalfd_init(); - cfgdir_init(); + server_cfg_monitor_init(); announce_init(); @@ -146,7 +146,7 @@ struct cfg { char *igmp_iface; struct uring_ev *uev; - struct inotify_ev *iev; + struct server_cfg_monitor *server_cfg_monitor; struct signalfd_ev *sev; struct announce *aev; struct igmp *igmp; diff --git a/meson.build b/meson.build index fa9199e..a4472cd 100644 --- a/meson.build +++ b/meson.build @@ -8,9 +8,9 @@ mcproxy_sources = [ 'main.c', 'uring.c', 'server.c', - 'proxy.c', + 'server-proxy.c', + 'server-config.c', 'announce.c', - 'cfgdir.c', 'config.c', 'rcon.c', 'idle.c', diff --git a/cfgdir.c b/server-config.c index ec8a0bf..d42022b 100644 --- a/cfgdir.c +++ b/server-config.c @@ -12,9 +12,9 @@ #include "main.h" #include "uring.h" -#include "cfgdir.h" #include "config.h" #include "server.h" +#include "server-config.h" static void scfg_dns_cb(struct dns_async *dns, bool (*server_cb)(struct server *, struct saddr *)) @@ -398,21 +398,23 @@ scfg_valid_filename(const char *name) return true; } -struct inotify_ev { +struct server_cfg_monitor { struct uring_task task; char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event)))); }; static void -inotify_free(struct uring_task *task) +scfgm_free(struct uring_task *task) { - struct inotify_ev *iev = container_of(task, struct inotify_ev, task); + struct server_cfg_monitor *scfgm = container_of(task, + struct server_cfg_monitor, + task); assert_return(task); debug(DBG_CFG, "called"); - xfree(iev); - cfg->iev = NULL; + xfree(scfgm); + cfg->server_cfg_monitor = NULL; } static void @@ -461,7 +463,9 @@ inotify_event_dump(const struct inotify_event *event) static void inotify_cb(struct uring_task *task, int res) { - struct inotify_ev *iev = container_of(task, struct inotify_ev, task); + struct server_cfg_monitor *scfgm = container_of(task, + struct server_cfg_monitor, + task); const struct inotify_event *event; char *ptr; struct server *server; @@ -474,7 +478,7 @@ inotify_cb(struct uring_task *task, int res) return; } - for (ptr = iev->buf; ptr < iev->buf + res; ptr += sizeof(struct inotify_event) + event->len) { + for (ptr = scfgm->buf; ptr < scfgm->buf + res; ptr += sizeof(struct inotify_event) + event->len) { event = (const struct inotify_event *)ptr; if (debug_enabled(DBG_CFG)) @@ -501,41 +505,41 @@ inotify_cb(struct uring_task *task, int res) error("inotify: unknown event: 0x%08x", event->mask); } - uring_read(&iev->task, iev->buf, sizeof(iev->buf), inotify_cb); + uring_read(&scfgm->task, scfgm->buf, sizeof(scfgm->buf), inotify_cb); } void -cfgdir_refdump() +server_cfg_monitor_refdump() { - assert_return_silent(cfg->iev); + assert_return_silent(cfg->server_cfg_monitor); - uring_task_refdump(&cfg->iev->task); + uring_task_refdump(&cfg->server_cfg_monitor->task); } void -cfgdir_delete() +server_cfg_monitor_delete() { - assert_return(cfg->iev); + assert_return(cfg->server_cfg_monitor); - debug(DBG_CFG, "closing fd %i", cfg->iev->task.fd); - uring_task_destroy(&cfg->iev->task); - cfg->iev = NULL; + debug(DBG_CFG, "closing fd %i", cfg->server_cfg_monitor->task.fd); + uring_task_destroy(&cfg->server_cfg_monitor->task); + cfg->server_cfg_monitor = NULL; } void -cfgdir_init() +server_cfg_monitor_init() { int ifd; int iwd; - struct inotify_ev *iev; + struct server_cfg_monitor *scfgm; DIR *dir; struct dirent *dent; struct server *server; - assert_return(!cfg->iev); + assert_return(!cfg->server_cfg_monitor); - iev = zmalloc(sizeof(*iev)); - if (!iev) + scfgm = zmalloc(sizeof(*scfgm)); + if (!scfgm) die("malloc: %m"); ifd = inotify_init1(IN_CLOEXEC); @@ -551,10 +555,10 @@ cfgdir_init() if (iwd < 0) die("inotify_add_watch: %m"); - uring_task_init(&iev->task, "server_config", uring_parent(), inotify_free); - uring_task_set_fd(&iev->task, ifd); - cfg->iev = iev; - uring_read(&iev->task, iev->buf, sizeof(iev->buf), inotify_cb); + uring_task_init(&scfgm->task, "server-config-monitor", uring_parent(), scfgm_free); + uring_task_set_fd(&scfgm->task, ifd); + cfg->server_cfg_monitor = scfgm; + uring_read(&scfgm->task, scfgm->buf, sizeof(scfgm->buf), inotify_cb); dir = opendir("."); if (!dir) diff --git a/server-config.h b/server-config.h new file mode 100644 index 0000000..590dae0 --- /dev/null +++ b/server-config.h @@ -0,0 +1,10 @@ +#ifndef fooserverconfighfoo +#define fooserverconfighfoo + +void server_cfg_monitor_delete(); + +void server_cfg_monitor_refdump(); + +void server_cfg_monitor_init(); + +#endif @@ -8,7 +8,7 @@ #include "main.h" #include "uring.h" #include "server.h" -#include "proxy.h" +#include "server-proxy.h" #include "utils.h" static void @@ -1,5 +1,5 @@ -#ifndef fooproxyhfoo -#define fooproxyhfoo +#ifndef fooserverproxyhfoo +#define fooserverproxyhfoo struct server_proxy { struct connection client_conn; @@ -14,7 +14,7 @@ #include "main.h" #include "uring.h" #include "server.h" -#include "proxy.h" +#include "server-proxy.h" #include "utils.h" #include "config.h" #include "idle.h" @@ -571,11 +571,11 @@ uring_free(struct uring_task *task) } void -uring_refdump(struct uring_ev *uev) +uring_refdump() { - assert_return(uev); + assert_return(cfg->uev); - uring_task_refdump(&uev->task); + uring_task_refdump(&cfg->uev->task); } void @@ -62,7 +62,7 @@ void uring_poll_cancel(struct uring_task *task); void uring_delete(); -void uring_refdump(struct uring_ev *uev); +void uring_refdump(); void uring_init(); |