]> jfr.im git - solanum.git/commitdiff
ircd: start staging for relocatable paths
authorWilliam Pitcock <redacted>
Thu, 24 Mar 2016 23:45:28 +0000 (18:45 -0500)
committerWilliam Pitcock <redacted>
Thu, 24 Mar 2016 23:45:28 +0000 (18:45 -0500)
include/defaults.h
ircd/authd.c
ircd/bandbi.c
ircd/cache.c
ircd/ircd.c
ircd/ircd_lexer.l
ircd/modules.c
ircd/restart.c
ircd/sslproc.c
modules/m_rehash.c

index 29b05cfb36d214d333d24c635a39eb3596e966bb..599b2611f59fb9d0924baea915e1567d779731e0 100644 (file)
  * First, set other fd limits based on values from user
  */
 
+typedef enum {
+       IRCD_PATH_PREFIX,
+       IRCD_PATH_MODULES,
+       IRCD_PATH_AUTOLOAD_MODULES,
+       IRCD_PATH_ETC,
+       IRCD_PATH_LOG,
+       IRCD_PATH_USERHELP,
+       IRCD_PATH_OPERHELP,
+       IRCD_PATH_IRCD_EXEC,
+       IRCD_PATH_IRCD_CONF,
+       IRCD_PATH_IRCD_MOTD,
+       IRCD_PATH_IRCD_LOG,
+       IRCD_PATH_IRCD_PID,
+       IRCD_PATH_IRCD_OMOTD,
+       IRCD_PATH_BANDB,
+       IRCD_PATH_BIN,
+       IRCD_PATH_LIBEXEC,
+       IRCD_PATH_COUNT
+} ircd_path_t;
+
+extern const char *ircd_paths[IRCD_PATH_COUNT];
 
 #define MAXCONNECTIONS 65535 /* default max connections if getrlimit doesn't work */
 /* class {} default values */
index 491d02379f048a4b329ed6467678818b3a7a7141..30dd30cbb23f1094043179ea20a6270c2e118325 100644 (file)
@@ -55,20 +55,20 @@ start_authd(void)
 #endif
        if(authd_path == NULL)
        {
-               snprintf(fullpath, sizeof(fullpath), "%s/authd%s", PKGLIBEXECDIR, suffix);
+               snprintf(fullpath, sizeof(fullpath), "%s%cauthd%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix);
 
                if(access(fullpath, X_OK) == -1)
                {
-                       snprintf(fullpath, sizeof(fullpath), "%s/libexec/charybdis/authd%s",
-                                ConfigFileEntry.dpath, suffix);
+                       snprintf(fullpath, sizeof(fullpath), "%s%cbin%cauthd%s",
+                                ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
                        if(access(fullpath, X_OK) == -1)
                        {
                                ilog(L_MAIN,
-                                    "Unable to execute authd in %s or %s/libexec/charybdis",
-                                    PKGLIBEXECDIR, ConfigFileEntry.dpath);
+                                    "Unable to execute authd in %s or %s/bin",
+                                    ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                                      "Unable to execute authd in %s or %s/libexec/charybdis",
-                                                      PKGLIBEXECDIR, ConfigFileEntry.dpath);
+                                                      "Unable to execute authd in %s or %s/bin",
+                                                      ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                return 1;
                        }
 
index aa9410d29f481813846fe28c4375786abf372cea..15171b646f71802c9bc99d5207dcc25c317e7677 100644 (file)
@@ -80,21 +80,21 @@ start_bandb(void)
        const char *suffix = "";
 #endif
 
-       rb_setenv("BANDB_DBPATH", PKGLOCALSTATEDIR "/ban.db", 1);
+       rb_setenv("BANDB_DBPATH", ircd_paths[IRCD_PATH_BANDB], 1);
        if(bandb_path == NULL)
        {
-               snprintf(fullpath, sizeof(fullpath), "%s/bandb%s", PKGLIBEXECDIR, suffix);
+               snprintf(fullpath, sizeof(fullpath), "%s%cbandb%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix);
 
                if(access(fullpath, X_OK) == -1)
                {
-                       snprintf(fullpath, sizeof(fullpath), "%s/bin/bandb%s",
-                                   ConfigFileEntry.dpath, suffix);
+                       snprintf(fullpath, sizeof(fullpath), "%s%cbin%cbandb%s",
+                                   ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
 
                        if(access(fullpath, X_OK) == -1)
                        {
                                ilog(L_MAIN,
                                     "Unable to execute bandb%s in %s or %s/bin",
-                                    suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath);
+                                    suffix, ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                return 0;
                        }
                }
index 1a2cb14fabb0067cd1103d7572b996bea44cb55d..3e40eb3683e08e5315a73e8790367d09d03f3e8c 100644 (file)
@@ -64,8 +64,8 @@ init_cache(void)
 
        user_motd_changed[0] = '\0';
 
-       user_motd = cache_file(MPATH, "ircd.motd", 0);
-       oper_motd = cache_file(OPATH, "opers.motd", 0);
+       user_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_MOTD], "ircd.motd", 0);
+       oper_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_OMOTD], "opers.motd", 0);
        memset(&links_cache_list, 0, sizeof(links_cache_list));
 
        help_dict_oper = rb_dictionary_create("oper help", strcasecmp);
@@ -253,7 +253,7 @@ load_help(void)
                free_cachefile(cacheptr);
        }
 
-       helpfile_dir = opendir(HPATH);
+       helpfile_dir = opendir(ircd_paths[IRCD_PATH_OPERHELP]);
 
        if(helpfile_dir == NULL)
                return;
@@ -262,13 +262,13 @@ load_help(void)
        {
                if(ldirent->d_name[0] == '.')
                        continue;
-               snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name);
+               snprintf(filename, sizeof(filename), "%s%c%s", ircd_paths[IRCD_PATH_OPERHELP], RB_PATH_SEPARATOR, ldirent->d_name);
                cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER);
                rb_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
        }
 
        closedir(helpfile_dir);
-       helpfile_dir = opendir(UHPATH);
+       helpfile_dir = opendir(ircd_path[IRCD_PATH_USERHELP]);
 
        if(helpfile_dir == NULL)
                return;
@@ -277,7 +277,7 @@ load_help(void)
        {
                if(ldirent->d_name[0] == '.')
                        continue;
-               snprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name);
+               snprintf(filename, sizeof(filename), "%s%c%s", ircd_paths[IRCD_PATH_USERHELP], RB_PATH_SEPARATOR, ldirent->d_name);
 
 #if defined(S_ISLNK) && defined(HAVE_LSTAT)
                if(lstat(filename, &sb) < 0)
@@ -341,7 +341,7 @@ cache_user_motd(void)
        struct stat sb;
        struct tm *local_tm;
 
-       if(stat(MPATH, &sb) == 0)
+       if(stat(ircd_paths[IRCD_PATH_IRCD_MOTD], &sb) == 0)
        {
                local_tm = localtime(&sb.st_mtime);
 
@@ -355,7 +355,7 @@ cache_user_motd(void)
                }
        }
        free_cachefile(user_motd);
-       user_motd = cache_file(MPATH, "ircd.motd", 0);
+       user_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_MOTD], "ircd.motd", 0);
 }
 
 
index b3f1b5d0b58a05d689f4eb20c6df89b204ba1552..2012ad3724a1b135f631e5caf8d71afef7f18e25 100644 (file)
@@ -94,9 +94,6 @@ rb_dlink_list global_serv_list;    /* global servers on the network */
 rb_dlink_list local_oper_list;     /* our opers, duplicated in lclient_list */
 rb_dlink_list oper_list;           /* network opers */
 
-const char *logFileName = LPATH;
-const char *pidFileName = PPATH;
-
 char **myargv;
 bool dorehash = false;
 bool dorehashbans = false;
@@ -118,6 +115,28 @@ int split_users;
 int split_servers;
 int eob_count;
 
+const char *ircd_paths[IRCD_PATH_COUNT] = {
+       [IRCD_PATH_PREFIX] = DPATH,
+       [IRCD_PATH_MODULES] = MODPATH,
+       [IRCD_PATH_AUTOLOAD_MODULES] = AUTOMODPATH,
+       [IRCD_PATH_ETC] = ETCPATH,
+       [IRCD_PATH_LOG] = LOGPATH,
+       [IRCD_PATH_USERHELP] = UHPATH,
+       [IRCD_PATH_OPERHELP] = HPATH,
+       [IRCD_PATH_IRCD_EXEC] = SPATH,
+       [IRCD_PATH_IRCD_CONF] = CPATH,
+       [IRCD_PATH_IRCD_MOTD] = MPATH,
+       [IRCD_PATH_IRCD_LOG] = LPATH,
+       [IRCD_PATH_IRCD_PID] = PPATH,
+       [IRCD_PATH_IRCD_OMOTD] = OPATH,
+       [IRCD_PATH_BANDB] = DBPATH,
+       [IRCD_PATH_BIN] = BINPATH,
+       [IRCD_PATH_LIBEXEC] = PKGLIBEXECDIR,
+};
+
+const char *logFileName = LPATH;
+const char *pidFileName = PPATH;
+
 void
 ircd_shutdown(const char *reason)
 {
@@ -562,8 +581,8 @@ charybdis_main(int argc, char *argv[])
 
        init_sys();
 
-       ConfigFileEntry.dpath = DPATH;
-       ConfigFileEntry.configfile = CPATH;     /* Server configuration file */
+       ConfigFileEntry.dpath = ircd_paths[IRCD_PATH_PREFIX];
+       ConfigFileEntry.configfile = ircd_paths[IRCD_PATH_IRCD_CONF];   /* Server configuration file */
        ConfigFileEntry.connect_timeout = 30;   /* Default to 30 */
 
        umask(077);             /* better safe than sorry --SRB */
index 4ccee128dc5d783e8e48d6025a795493d02b1252..ae96b407da455ea48da27f7283a612c87cd5bbb5 100644 (file)
@@ -193,10 +193,10 @@ void cinclude(void)
     
     if (tmp_fbfile_in == NULL)
     {
-      /* if its not found in PREFIX, look in ETCPATH */
+      /* if its not found in PREFIX, look in IRCD_PATH_ETC */
       char fnamebuf[BUFSIZE];
 
-      snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", ETCPATH, c);
+      snprintf(fnamebuf, sizeof(fnamebuf), "%s%c%s", IRCD_PATH_ETC, RB_PATH_SEPARATOR, c);
       tmp_fbfile_in = fopen(fnamebuf, "r");
 
       /* wasnt found there either.. error. */
index da3da94714c1c7ac8544ddd9f049667afc91687e..2173dd69fee0f972fe6442c55eb7495a5a30059d 100644 (file)
@@ -129,8 +129,8 @@ modules_init(void)
        mod_add_cmd(&modrestart_msgtab);
 
        /* Add the default paths we look in to the module system --nenolod */
-       mod_add_path(MODPATH);
-       mod_add_path(AUTOMODPATH);
+       mod_add_path(ircd_paths[IRCD_PATH_MODULES]);
+       mod_add_path(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
 }
 
 /* mod_find_path()
@@ -243,11 +243,11 @@ load_all_modules(int warn)
 
        max_mods = MODS_INCREMENT;
 
-       system_module_dir = opendir(AUTOMODPATH);
+       system_module_dir = opendir(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
 
        if(system_module_dir == NULL)
        {
-               ilog(L_MAIN, "Could not load modules from %s: %s", AUTOMODPATH, strerror(errno));
+               ilog(L_MAIN, "Could not load modules from %s: %s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], strerror(errno));
                return;
        }
 
@@ -258,7 +258,7 @@ load_all_modules(int warn)
                len = strlen(ldirent->d_name);
                if(len > module_ext_len && !strcasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT))
                {
-                       (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
+                       (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s%c%s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], RB_PATH_SEPARATOR, ldirent->d_name);
                        (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0);
                }
 
@@ -281,7 +281,7 @@ load_core_modules(int warn)
 
        for (i = 0; core_module_table[i]; i++)
        {
-               snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
+               snprintf(module_name, sizeof(module_name), "%s%c%s%s", ircd_paths[IRCD_PATH_MODULES], RB_PATH_SEPARATOR,
                            core_module_table[i], LT_MODULE_EXT);
 
                if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1)
index 1a63b57262c7fbdef3273beb5e3427d2b3a0041f..f91f9293c17a8ab3b5ac9d05fc99fddc6c670f9a 100644 (file)
@@ -72,10 +72,10 @@ server_reboot(void)
                close(i);
 
        unlink(pidFileName);
-       execv(SPATH, (void *)myargv);
+       execv(ircd_paths[IRCD_PATH_IRCD_EXEC], (void *)myargv);
 
        /* use this if execv of SPATH fails */
-       snprintf(path, sizeof(path), "%s/bin/ircd", ConfigFileEntry.dpath);
+       snprintf(path, sizeof(path), "%s%cbin%circd", ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
 
        execv(path, (void *)myargv);
        exit(-1);
index 6d53caf3af623dd9956aae8df2af76d47cc308d7..2edd091eb4d09059f92c343cde78e9486f270933 100644 (file)
@@ -278,17 +278,17 @@ start_ssldaemon(int count, const char *ssl_cert, const char *ssl_private_key, co
 
        if(ssld_path == NULL)
        {
-               snprintf(fullpath, sizeof(fullpath), "%s/ssld%s", PKGLIBEXECDIR, suffix);
+               snprintf(fullpath, sizeof(fullpath), "%s%cssld%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix);
 
                if(access(fullpath, X_OK) == -1)
                {
-                       snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld%s",
-                                   ConfigFileEntry.dpath, suffix);
+                       snprintf(fullpath, sizeof(fullpath), "%s%cbin%cssld%s",
+                                   ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
                        if(access(fullpath, X_OK) == -1)
                        {
                                ilog(L_MAIN,
                                     "Unable to execute ssld%s in %s or %s/bin",
-                                    suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath);
+                                    suffix, ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                return 0;
                        }
                }
index bd6670aaaf757e1d46657c25433789215ea0c72e..3151abfa810dd472fddbe855532661a98d14a821 100644 (file)
@@ -117,7 +117,7 @@ rehash_omotd(struct Client *source_p)
                remote_rehash_oper_p = source_p;
 
        free_cachefile(oper_motd);
-       oper_motd = cache_file(OPATH, "opers.motd", 0);
+       oper_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_OMOTD], "opers.motd", 0);
 }
 
 static void