From 1f7ebb234761d8aa5edf0ea784c2dd9e2e247218 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 31 Jan 2024 13:06:16 -0500 Subject: Fix up mission directory handler --- src/main.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 1dccea2..d1df20e 100644 --- a/src/main.c +++ b/src/main.c @@ -186,6 +186,24 @@ int main(int argc, char *argv[], char *arge[]) { msg(OMC_MSG_L1, "Initializing\n"); + // Set up PREFIX/etc directory information + // The user may manipulate the base directory path with OMC_SYSCONFDIR + // environment variable + char omc_sysconfdir_tmp[PATH_MAX]; + if (getenv("OMC_SYSCONFDIR")) { + strncpy(omc_sysconfdir_tmp, getenv("OMC_SYSCONFDIR"), sizeof(omc_sysconfdir_tmp)); + } else { + strncpy(omc_sysconfdir_tmp, OMC_SYSCONFDIR, sizeof(omc_sysconfdir_tmp) - 1); + } + + globals.sysconfdir = realpath(omc_sysconfdir_tmp, NULL); + if (!globals.sysconfdir) { + msg(OMC_MSG_ERROR | OMC_MSG_L1, "Unable to resolve path to configuration directory: %s\n", omc_sysconfdir_tmp); + exit(1); + } else { + memset(omc_sysconfdir_tmp, 0, sizeof(omc_sysconfdir_tmp)); + } + if (config_input) { msg(OMC_MSG_L2, "Reading OMC global configuration: %s\n", config_input); cfg = ini_open(config_input); @@ -241,19 +259,13 @@ int main(int argc, char *argv[], char *arge[]) { tpl_register("system.platform", ctx.system.platform[DELIVERY_PLATFORM_RELEASE]); char missionfile[PATH_MAX] = {0}; + if (getenv("OMC_SYSCONFDIR")) { - globals.sysconfdir = calloc(PATH_MAX, sizeof(*globals.sysconfdir)); - } else { - globals.sysconfdir = strdup(OMC_SYSCONFDIR); - } - if (!globals.sysconfdir) { - msg(OMC_MSG_ERROR | OMC_MSG_L1, "Unable to allocate memory for system configuration directory path\n"); - exit(1); - } - if (getenv("OMC_SYSCONFDIR")) { - sprintf(missionfile, "%s/%s/%s/%s.ini", getenv("OMC_SYSCONFDIR"), "mission", ctx.meta.mission, ctx.meta.mission); + sprintf(missionfile, "%s/%s/%s/%s.ini", + getenv("OMC_SYSCONFDIR"), "mission", ctx.meta.mission, ctx.meta.mission); } else { - sprintf(missionfile, "%s/%s/%s/%s.ini", OMC_SYSCONFDIR, "mission", ctx.meta.mission, ctx.meta.mission); + sprintf(missionfile, "%s/%s/%s/%s.ini", + globals.sysconfdir, "mission", ctx.meta.mission, ctx.meta.mission); } struct INIFILE *cfg_mission; -- cgit