From: Egor Date: Thu, 27 Mar 2025 06:34:53 +0000 (+0200) Subject: make IRCDDATADIR configurable at runtime X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=e4445711ad16654da125c5864213de40e519354c;p=patchyircd.git make IRCDDATADIR configurable at runtime --- diff --git a/README.md b/README.md index a72e2c0..89c90e1 100644 --- 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. diff --git a/src/config.h b/src/config.h index 0139baa..97952c4 100644 --- a/src/config.h +++ b/src/config.h @@ -10,6 +10,3 @@ #ifndef IRCDHOSTNAME #define IRCDHOSTNAME "example.com" #endif -#ifndef IRCDDATADIR -#define IRCDDATADIR "data" -#endif diff --git a/src/main.cpp b/src/main.cpp index 45c02ca..70b0640 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; } diff --git a/src/util.cpp b/src/util.cpp index 9aa24c1..7658e02 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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]; diff --git a/src/util.h b/src/util.h index 66c1e57..d06776f 100644 --- a/src/util.h +++ b/src/util.h @@ -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