solanum/tests/ircd_util.c

117 lines
3.3 KiB
C
Raw Permalink Normal View History

2017-08-05 13:09:01 +00:00
/*
* ircd_util.c: Utility functions for making test ircds
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tap/basic.h"
#include "ircd_util.h"
2017-08-05 13:09:01 +00:00
#include "defaults.h"
#include "client.h"
#include "modules.h"
2017-08-05 13:09:01 +00:00
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
2020-10-15 14:51:12 +00:00
extern int solanum_main(int argc, const char *argv[]);
2017-08-05 13:09:01 +00:00
static char argv0[BUFSIZE];
static char configfile[BUFSIZE];
static char logfile[BUFSIZE];
static char pidfile[BUFSIZE];
static const char *argv[] = {
argv0,
"-configfile", configfile,
"-logfile", logfile,
"-pidfile", pidfile,
"-conftest",
NULL,
};
void ircd_util_init(const char *name)
{
rb_strlcpy(argv0, name, sizeof(argv0));
snprintf(configfile, sizeof(configfile), "%sonf", name);
snprintf(logfile, sizeof(logfile), "%s.log", name);
snprintf(pidfile, sizeof(pidfile), "%s.pid", name);
unlink(logfile);
unlink(pidfile);
rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
rb_linebuf_init(LINEBUF_HEAP_SIZE);
char buf[BUFSIZE];
ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0;
ircd_paths[IRCD_PATH_PREFIX] = ".";
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/modules");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf);
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/modules/autoload");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf);
ircd_paths[IRCD_PATH_ETC] = "runtime";
ircd_paths[IRCD_PATH_LOG] = "runtime";
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/help/users");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf);
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/help/opers");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf);
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/motd");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf);
ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "%s.ban.db", name);
ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "%s.ban.db-journal", name);
unlink(buf);
ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile);
ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile);
2021-07-09 00:11:22 +00:00
snprintf(buf, sizeof(buf), "runtime/bin");
2017-08-05 13:09:01 +00:00
ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf);
ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf);
2020-10-15 14:51:12 +00:00
is_int(0, solanum_main(ARRAY_SIZE(argv) - 1, argv), MSG);
2017-08-05 13:09:01 +00:00
}
void ircd_util_reload_module(const char *name)
{
struct module *mod = findmodule_byname(name);
2019-08-31 15:32:55 +00:00
int origin, core;
if (ok(mod != NULL, MSG)) {
2019-08-31 15:32:55 +00:00
origin = mod->origin;
core = mod->core;
if (ok(unload_one_module(name, false), MSG)) {
2019-08-31 15:32:55 +00:00
ok(load_one_module(name, origin, core), MSG);
}
}
}
2017-08-05 13:09:01 +00:00
void ircd_util_free(void)
{
}