diff options
author | David Härdeman <david@hardeman.nu> | 2020-07-01 08:07:18 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-07-01 08:07:18 +0200 |
commit | 86727730b8e4cfce2a4ecf2e787c8bf7f57af924 (patch) | |
tree | 9a2f5c93474600f85aa35606ae2b3856f8a08165 /minecproxy | |
parent | ff9d60b0d5b27369073a329cd5ceb5d6c94bdf84 (diff) |
Improve line/error reporting in server config parsing
Diffstat (limited to 'minecproxy')
-rw-r--r-- | minecproxy/server-config.c | 7 | ||||
-rw-r--r-- | minecproxy/server.c | 7 | ||||
-rw-r--r-- | minecproxy/systemd.c | 9 |
3 files changed, 18 insertions, 5 deletions
diff --git a/minecproxy/server-config.c b/minecproxy/server-config.c index de9265d..1bc3d38 100644 --- a/minecproxy/server-config.c +++ b/minecproxy/server-config.c @@ -19,6 +19,8 @@ static void scfg_read_cb(struct uring_task *task, int res) { struct server *server = container_of(task, struct server, task); + const char *error; + unsigned lineno; assert_return(task); assert_task_alive(DBG_CFG, task); @@ -33,8 +35,9 @@ static void scfg_read_cb(struct uring_task *task, int res) uring_task_close_fd(&server->task); if (!scfg_parse(&server->scfg, server->tbuf.buf, - server_async_dns_update)) { - error("%s: failed to parse config file", server->name); + server_async_dns_update, &lineno, &error)) { + error("%s: failed to parse config file, line %u: %s", + server->name, lineno, error); server_delete(server); return; } diff --git a/minecproxy/server.c b/minecproxy/server.c index b06286b..f1f0006 100644 --- a/minecproxy/server.c +++ b/minecproxy/server.c @@ -423,6 +423,7 @@ bool server_announce(struct server *server, int fd) bool server_commit(struct server *server) { + const char *error; struct saddr *saddr, *tmp; int r; @@ -445,8 +446,9 @@ bool server_commit(struct server *server) return false; } - if (!scfg_validate(&server->scfg)) { - error("%s: failed to validate config file", server->name); + if (!scfg_validate(&server->scfg, &error)) { + error("%s: failed to validate config file (%s)", + server->name, error); server_delete(server); return false; } @@ -468,7 +470,6 @@ bool server_commit(struct server *server) list_for_each_entry_safe(saddr, tmp, &server->scfg.locals, list) { struct server_local *local; - /* FIXME: error checks */ list_del(&saddr->list); local = local_new(server, saddr); if (!local) { diff --git a/minecproxy/systemd.c b/minecproxy/systemd.c index 96ff50f..3351f1c 100644 --- a/minecproxy/systemd.c +++ b/minecproxy/systemd.c @@ -1,6 +1,7 @@ #include <string.h> #include <stdlib.h> #include <systemd/sd-bus.h> +#include <errno.h> #include "main.h" #include "server.h" @@ -58,11 +59,15 @@ bool systemd_service_running(struct server *server) server->scfg.systemd_obj, false); +again: r = sd_bus_get_property_string(bus, SYSTEMD_DBUS_SERVICE, server->scfg.systemd_obj, SYSTEMD_DBUS_INTERFACE, "ActiveState", &error, &status); if (r < 0) { + if (sd_bus_error_get_errno(&error) == EINTR) + goto again; + error("failed to get status for service %s (%s): %s", server->scfg.systemd_service, server->scfg.systemd_obj, error.message); @@ -96,10 +101,14 @@ static bool systemd_service_action(struct server *server, const char *action) server->scfg.systemd_obj && action, false); +again: r = sd_bus_call_method(bus, SYSTEMD_DBUS_SERVICE, server->scfg.systemd_obj, SYSTEMD_DBUS_INTERFACE, action, &error, &m, "s", "fail"); if (r < 0) { + if (sd_bus_error_get_errno(&error) == EINTR) + goto again; + error("failed to perform action %s on systemd service %s: %s", action, server->scfg.systemd_service, error.message); goto out; |