summaryrefslogtreecommitdiff
path: root/shared/config-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared/config-parser.c')
-rw-r--r--shared/config-parser.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 8ea6557..4dc446c 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -529,29 +529,17 @@ bool scfg_parse(struct server_config *scfg, char *buf, bool async,
case SCFG_KEY_SYSTEMD_SERVICE:
if (scfg->systemd_service)
ERROR("systemd service defined multiple times");
- else {
- const char *suffix;
- char *tmp;
-
- suffix = strrchr(value.str, '.');
- if (!suffix || !streq(suffix, ".service")) {
- tmp = zmalloc(strlen(value.str) +
- STRLEN(".service") + 1);
- if (tmp)
- sprintf(tmp, "%s.service",
- value.str);
- } else
- tmp = xstrdup(value.str);
-
- if (!tmp)
- ERROR("malloc/strdup failure");
-
- scfg->systemd_service = tmp;
- scfg->systemd_obj =
- systemd_object_path(scfg->systemd_service);
- if (!scfg->systemd_obj)
- ERROR("failed to create object_path");
- }
+
+ const char *suffix = strrchr(value.str, '.');
+ if (!suffix || !streq(suffix, ".service"))
+ scfg->systemd_service = xsprintf(NULL,
+ "%s.service",
+ value.str);
+ else
+ scfg->systemd_service = xstrdup(value.str);
+
+ if (!scfg->systemd_service)
+ ERROR("malloc/strdup failure");
break;
@@ -563,6 +551,22 @@ bool scfg_parse(struct server_config *scfg, char *buf, bool async,
}
}
+ if (!scfg->systemd_service &&
+ (scfg->stop_method == SERVER_STOP_METHOD_SYSTEMD ||
+ scfg->start_method == SERVER_START_METHOD_SYSTEMD)) {
+ scfg->systemd_service = xsprintf(NULL,
+ "minecserver@%s.service",
+ scfg->name);
+ if (!scfg->systemd_service)
+ ERROR("failed to create systemd_service string");
+ }
+
+ if (scfg->systemd_service && !scfg->systemd_obj) {
+ scfg->systemd_obj = systemd_object_path(scfg->systemd_service);
+ if (!scfg->systemd_obj)
+ ERROR("failed to create object_path");
+ }
+
return true;
}
@@ -605,14 +609,31 @@ bool scfg_init(struct server_config *scfg, const char *filename)
assert_return(scfg, false);
if (filename) {
+ const char *suffix;
+
+ suffix = strrchr(filename, '.');
+ if (!suffix || suffix == filename) {
+ error("invalid filename: %s", filename);
+ return false;
+ }
+
+ scfg->name = xstrndup(filename, suffix - filename);
+ if (!scfg->name) {
+ error("xstrndup: %m");
+ return false;
+ }
+
scfg->filename = xstrdup(filename);
-
if (!scfg->filename) {
error("strdup: %m");
+ xfree(scfg->name);
+ scfg->name = NULL;
return false;
}
- } else
+ } else {
+ scfg->name = NULL;
scfg->filename = NULL;
+ }
scfg->type = SERVER_TYPE_UNDEFINED;
scfg->pretty_name = NULL;