]> jfr.im git - solanum.git/blob - tests/ircd_util.c
modules/m_challenge.c: log correct mechanism
[solanum.git] / tests / ircd_util.c
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
26 #include "ircd_util.h"
27
28 #include "defaults.h"
29 #include "client.h"
30 #include "modules.h"
31
32 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
33
34 extern int solanum_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/modules");
67 ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf);
68
69 snprintf(buf, sizeof(buf), "runtime/modules/autoload");
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/help/users");
76 ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf);
77
78 snprintf(buf, sizeof(buf), "runtime/help/opers");
79 ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf);
80
81 snprintf(buf, sizeof(buf), "runtime/motd");
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/bin");
94 ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf);
95 ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf);
96
97 is_int(0, solanum_main(ARRAY_SIZE(argv) - 1, argv), MSG);
98 }
99
100 void ircd_util_reload_module(const char *name)
101 {
102 struct module *mod = findmodule_byname(name);
103 int origin, core;
104
105 if (ok(mod != NULL, MSG)) {
106 origin = mod->origin;
107 core = mod->core;
108 if (ok(unload_one_module(name, false), MSG)) {
109 ok(load_one_module(name, origin, core), MSG);
110 }
111 }
112 }
113
114 void ircd_util_free(void)
115 {
116 }