]> PatchyGit - patchyircd.git/commitdiff
make IRCDDATADIR configurable at runtime
authorEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 06:34:53 +0000 (08:34 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 06:46:32 +0000 (08:46 +0200)
README.md
src/config.h
src/main.cpp
src/util.cpp
src/util.h

index a72e2c0..89c90e1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Some things are configurable via compile-time flags. In particular, `-DHAS_TLS`
 and some constants defined in `src/config.h`.
 
 ## Config files
-These have to go in IRCDDATADIR (`data` by default).
+These have to go in datadir (see below).
 
 For TLS you gonna need to place your certificate and private key in
 `cert.pem` and `key.pem` respectively.
@@ -64,3 +64,8 @@ IPv4 and IPv6 must be specified separately.
 
 With `--autojoin \#ircmoment` clients will automatically join the `#ircmoment`
 channel. This option can be specified multiple times.
+
+Data directory can be configured with `--datadir` argument. The default can be
+configured at compile time via IRCDDATADIR define. Otherwise it deafults to
+LOCALSTATEDIR/lib/patchyircd if LOCALSTATEDIR is defined. Otherwise it's "data"
+in the working directory.
index 0139baa..97952c4 100644 (file)
@@ -10,6 +10,3 @@
 #ifndef IRCDHOSTNAME
 #define IRCDHOSTNAME "example.com"
 #endif
-#ifndef IRCDDATADIR
-#define IRCDDATADIR "data"
-#endif
index 45c02ca..70b0640 100644 (file)
@@ -230,6 +230,11 @@ int main(int argc, char *argv[])
                                return fprintf(stderr, "not enough parameters\n"), 1;
                        autojoin.add(argv[i+1]);
                        i += 1;
+               } else if(!strcmp(argv[i], "--datadir")) {
+                       if (i + 1 >= argc)
+                               return fprintf(stderr, "not enough parameters\n"), 1;
+                       datadir = argv[i+1];
+                       i += 1;
                } else {
                        return fprintf(stderr, "unknown flag '%s'\n", argv[i]), 1;
                }
index 9aa24c1..7658e02 100644 (file)
@@ -138,7 +138,14 @@ int irc_glob(const char *key, const char *mask)
        return 1;
 }
 
-static const char *datadir = IRCDDATADIR;
+#ifndef IRCDDATADIR
+# ifdef LOCALSTATEDIR
+#  define IRCDDATADIR LOCALSTATEDIR "/lib/patchyircd"
+# else
+#  define IRCDDATADIR "data"
+# endif
+#endif
+const char *datadir = IRCDDATADIR;
 const char *getdatafile(const char *fn)
 {
        static char buf[256];
index 66c1e57..d06776f 100644 (file)
@@ -27,5 +27,6 @@ char *mystrdup(const char *s);
 time_t get_time(void);
 void set_time(time_t t);
 int irc_glob(const char *key, const char *mask);
+extern const char *datadir;
 const char *getdatafile(const char *fn);
 #endif