2 * ircd_util.c: Utility functions for making test ircds
3 * Copyright 2017 Simon Arlott
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.
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.
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
24 #include "tap/basic.h"
26 #include "ircd_util.h"
32 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
34 extern int charybdis_main(int argc
, const char *argv
[]);
36 static char argv0
[BUFSIZE
];
37 static char configfile
[BUFSIZE
];
38 static char logfile
[BUFSIZE
];
39 static char pidfile
[BUFSIZE
];
41 static const char *argv
[] = {
43 "-configfile", configfile
,
50 void ircd_util_init(const char *name
)
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
);
59 rb_lib_init(NULL
, NULL
, NULL
, 0, 1024, DNODE_HEAP_SIZE
, FD_HEAP_SIZE
);
60 rb_linebuf_init(LINEBUF_HEAP_SIZE
);
63 ircd_paths
[IRCD_PATH_IRCD_EXEC
] = argv0
;
64 ircd_paths
[IRCD_PATH_PREFIX
] = ".";
66 snprintf(buf
, sizeof(buf
), "runtime%cmodules", RB_PATH_SEPARATOR
);
67 ircd_paths
[IRCD_PATH_MODULES
] = rb_strdup(buf
);
69 snprintf(buf
, sizeof(buf
), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR
);
70 ircd_paths
[IRCD_PATH_AUTOLOAD_MODULES
] = rb_strdup(buf
);
72 ircd_paths
[IRCD_PATH_ETC
] = "runtime";
73 ircd_paths
[IRCD_PATH_LOG
] = "runtime";
75 snprintf(buf
, sizeof(buf
), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR
);
76 ircd_paths
[IRCD_PATH_USERHELP
] = rb_strdup(buf
);
78 snprintf(buf
, sizeof(buf
), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR
);
79 ircd_paths
[IRCD_PATH_OPERHELP
] = rb_strdup(buf
);
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
);
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
);
90 ircd_paths
[IRCD_PATH_IRCD_PID
] = rb_strdup(pidfile
);
91 ircd_paths
[IRCD_PATH_IRCD_LOG
] = rb_strdup(logfile
);
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
);
97 is_int(0, charybdis_main(ARRAY_SIZE(argv
) - 1, argv
), MSG
);
100 void ircd_util_reload_module(const char *name
)
102 struct module *mod
= findmodule_byname(name
);
105 if (ok(mod
!= NULL
, MSG
)) {
106 origin
= mod
->origin
;
108 if (ok(unload_one_module(name
, false), MSG
)) {
109 ok(load_one_module(name
, origin
, core
), MSG
);
114 void ircd_util_free(void)