]>
Commit | Line | Data |
---|---|---|
d2b5f411 SA |
1 | /* |
2 | * ircd_util.c: Utility functions for making test ircds | |
3 | * Copyright 2017 Simon Arlott | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
18 | * USA | |
19 | */ | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include <stdlib.h> | |
23 | #include <unistd.h> | |
24 | #include "tap/basic.h" | |
25 | ||
692fbac6 SA |
26 | #include "ircd_util.h" |
27 | ||
d2b5f411 SA |
28 | #include "defaults.h" |
29 | #include "client.h" | |
692fbac6 | 30 | #include "modules.h" |
d2b5f411 SA |
31 | |
32 | #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ | |
33 | ||
34 | extern int charybdis_main(int argc, const char *argv[]); | |
35 | ||
36 | static char argv0[BUFSIZE]; | |
37 | static char configfile[BUFSIZE]; | |
38 | static char logfile[BUFSIZE]; | |
39 | static char pidfile[BUFSIZE]; | |
40 | ||
41 | static const char *argv[] = { | |
42 | argv0, | |
43 | "-configfile", configfile, | |
44 | "-logfile", logfile, | |
45 | "-pidfile", pidfile, | |
46 | "-conftest", | |
47 | NULL, | |
48 | }; | |
49 | ||
50 | void ircd_util_init(const char *name) | |
51 | { | |
52 | rb_strlcpy(argv0, name, sizeof(argv0)); | |
53 | snprintf(configfile, sizeof(configfile), "%sonf", name); | |
54 | snprintf(logfile, sizeof(logfile), "%s.log", name); | |
55 | snprintf(pidfile, sizeof(pidfile), "%s.pid", name); | |
56 | unlink(logfile); | |
57 | unlink(pidfile); | |
58 | ||
59 | rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE); | |
60 | rb_linebuf_init(LINEBUF_HEAP_SIZE); | |
61 | ||
62 | char buf[BUFSIZE]; | |
63 | ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0; | |
64 | ircd_paths[IRCD_PATH_PREFIX] = "."; | |
65 | ||
66 | snprintf(buf, sizeof(buf), "runtime%cmodules", RB_PATH_SEPARATOR); | |
67 | ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf); | |
68 | ||
69 | snprintf(buf, sizeof(buf), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR); | |
70 | ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf); | |
71 | ||
72 | ircd_paths[IRCD_PATH_ETC] = "runtime"; | |
73 | ircd_paths[IRCD_PATH_LOG] = "runtime"; | |
74 | ||
75 | snprintf(buf, sizeof(buf), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR); | |
76 | ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf); | |
77 | ||
78 | snprintf(buf, sizeof(buf), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR); | |
79 | ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf); | |
80 | ||
81 | snprintf(buf, sizeof(buf), "runtime%cmotd", RB_PATH_SEPARATOR); | |
82 | ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf); | |
83 | ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf); | |
84 | ||
85 | snprintf(buf, sizeof(buf), "%s.ban.db", name); | |
86 | ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf); | |
87 | snprintf(buf, sizeof(buf), "%s.ban.db-journal", name); | |
88 | unlink(buf); | |
89 | ||
90 | ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile); | |
91 | ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile); | |
92 | ||
93 | snprintf(buf, sizeof(buf), "runtime%cbin", RB_PATH_SEPARATOR); | |
94 | ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf); | |
95 | ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf); | |
96 | ||
97 | is_int(0, charybdis_main(ARRAY_SIZE(argv) - 1, argv), MSG); | |
98 | } | |
99 | ||
692fbac6 SA |
100 | void ircd_util_reload_module(const char *name) |
101 | { | |
102 | struct module *mod = findmodule_byname(name); | |
493f729e | 103 | int origin, core; |
692fbac6 SA |
104 | |
105 | if (ok(mod != NULL, MSG)) { | |
493f729e SA |
106 | origin = mod->origin; |
107 | core = mod->core; | |
692fbac6 | 108 | if (ok(unload_one_module(name, false), MSG)) { |
493f729e | 109 | ok(load_one_module(name, origin, core), MSG); |
692fbac6 SA |
110 | } |
111 | } | |
112 | } | |
113 | ||
d2b5f411 SA |
114 | void ircd_util_free(void) |
115 | { | |
116 | } |