uxc: support config in uvol
authorDaniel Golle <daniel@makrotopia.org>
Sun, 15 Aug 2021 13:06:39 +0000 (14:06 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 15 Aug 2021 14:16:39 +0000 (15:16 +0100)
In case '/var/state/uxc' exists and is a directory (or symlink pointing
to a directory), use that instead of '/etc/uxc'.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
uxc.c

diff --git a/uxc.c b/uxc.c
index 35036dd816f44424dc7023e0a0d58ce94d5c820b..5163b9a3e265e97c361c6d90f30a370fa8103658 100644 (file)
--- a/uxc.c
+++ b/uxc.c
 
 #define UXC_VERSION "0.2"
 #define OCI_VERSION_STRING "1.0.2"
-#define UXC_CONFDIR "/etc/uxc"
+#define UXC_ETC_CONFDIR "/etc/uxc"
+#define UXC_VOL_CONFDIR "/var/state/uxc"
 
 static bool verbose = false;
+static char *confdir = UXC_ETC_CONFDIR;
 
 struct runtime_state {
        struct avl_node avl;
@@ -134,8 +136,14 @@ static int conf_load(void)
        glob_t gl;
        char *globstr;
        void *c, *o;
+       struct stat sb;
+
+       if (!stat(UXC_VOL_CONFDIR, &sb)) {
+               if (sb.st_mode & S_IFDIR)
+                       confdir = UXC_VOL_CONFDIR;
+       }
 
-       if (asprintf(&globstr, "%s/*.json", UXC_CONFDIR) == -1)
+       if (asprintf(&globstr, "%s/*.json", confdir) == -1)
                return ENOMEM;
 
        blob_buf_init(&conf, 0);
@@ -642,12 +650,12 @@ static int uxc_set(char *name, char *path, bool autostart, bool add, char *pidfi
                        return ENOTDIR;
        }
 
-       ret = mkdir(UXC_CONFDIR, 0755);
+       ret = mkdir(confdir, 0755);
 
        if (ret && errno != EEXIST)
                return ret;
 
-       if (asprintf(&fname, "%s/%s.json", UXC_CONFDIR, name) == -1)
+       if (asprintf(&fname, "%s/%s.json", confdir, name) == -1)
                return ENOMEM;
 
        f = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0644);