2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2012-02-18 04:54:44 +01:00
|
|
|
|
2019-09-29 01:45:36 +02:00
|
|
|
#include <ircd/matrix.h>
|
2018-01-10 09:56:33 +01:00
|
|
|
#include <RB_INC_SYS_RESOURCE_H
|
2018-11-03 12:05:12 +01:00
|
|
|
#include <ircd/asio.h>
|
2016-09-22 00:07:14 +02:00
|
|
|
#include "lgetopt.h"
|
2018-02-22 22:33:53 +01:00
|
|
|
#include "construct.h"
|
2019-02-10 01:06:59 +01:00
|
|
|
#include "signals.h"
|
|
|
|
#include "console.h"
|
2016-07-01 05:04:00 +02:00
|
|
|
|
2016-08-31 10:03:12 +02:00
|
|
|
bool printversion;
|
2016-09-03 18:16:04 +02:00
|
|
|
bool cmdline;
|
2018-12-06 04:00:43 +01:00
|
|
|
bool quietmode;
|
2020-01-13 03:22:47 +01:00
|
|
|
bool single;
|
2018-12-09 00:17:13 +01:00
|
|
|
bool debugmode;
|
|
|
|
bool nolisten;
|
|
|
|
bool noautomod;
|
|
|
|
bool checkdb;
|
|
|
|
bool pitrecdb;
|
2020-01-12 04:14:32 +01:00
|
|
|
bool repairdb;
|
2018-12-09 00:17:13 +01:00
|
|
|
bool nojs;
|
|
|
|
bool nodirect;
|
|
|
|
bool noaio;
|
2019-08-11 07:06:08 +02:00
|
|
|
bool noiou;
|
2019-03-25 23:17:09 +01:00
|
|
|
bool no6;
|
2019-06-23 02:39:25 +02:00
|
|
|
bool yes6;
|
2019-04-03 19:49:07 +02:00
|
|
|
bool norun;
|
2019-04-15 20:08:40 +02:00
|
|
|
bool read_only;
|
|
|
|
bool write_avoid;
|
2019-06-01 11:02:37 +02:00
|
|
|
bool soft_assert;
|
2019-09-29 01:45:36 +02:00
|
|
|
bool nomatrix;
|
2019-11-30 21:46:10 +01:00
|
|
|
bool matrix {true}; // matrix server by default.
|
2020-04-25 06:26:06 +02:00
|
|
|
bool defaults;
|
2020-04-25 01:42:15 +02:00
|
|
|
std::vector<std::string> execute;
|
2019-10-03 01:49:30 +02:00
|
|
|
std::array<bool, 7> smoketest;
|
2019-04-24 10:01:48 +02:00
|
|
|
|
2019-04-23 10:51:21 +02:00
|
|
|
lgetopt opts[]
|
2016-08-31 10:03:12 +02:00
|
|
|
{
|
2018-12-09 00:17:13 +01:00
|
|
|
{ "help", nullptr, lgetopt::USAGE, "Print this text" },
|
|
|
|
{ "version", &printversion, lgetopt::BOOL, "Print version and exit" },
|
|
|
|
{ "debug", &debugmode, lgetopt::BOOL, "Enable options for debugging" },
|
|
|
|
{ "quiet", &quietmode, lgetopt::BOOL, "Suppress log messages at the terminal." },
|
2020-01-13 03:22:47 +01:00
|
|
|
{ "single", &single, lgetopt::BOOL, "Single user mode for maintenance and diagnostic." },
|
2018-12-09 00:17:13 +01:00
|
|
|
{ "console", &cmdline, lgetopt::BOOL, "Drop to a command line immediately after startup" },
|
2020-04-25 01:42:15 +02:00
|
|
|
{ "execute", &execute, lgetopt::STRINGS, "Execute command lines immediately after startup" },
|
2018-12-09 00:17:13 +01:00
|
|
|
{ "nolisten", &nolisten, lgetopt::BOOL, "Normal execution but without listening sockets" },
|
|
|
|
{ "noautomod", &noautomod, lgetopt::BOOL, "Normal execution but without autoloading modules" },
|
|
|
|
{ "checkdb", &checkdb, lgetopt::BOOL, "Perform complete checks of databases when opening" },
|
|
|
|
{ "pitrecdb", &pitrecdb, lgetopt::BOOL, "Allow Point-In-Time-Recover if DB reports corruption after crash" },
|
2020-01-12 04:14:32 +01:00
|
|
|
{ "repairdb", &repairdb, lgetopt::BOOL, "Perform full DB repair after deep block/file corruption." },
|
2018-12-09 00:17:13 +01:00
|
|
|
{ "nojs", &nojs, lgetopt::BOOL, "Disable SpiderMonkey JS subsystem from initializing. (noop when not available)." },
|
|
|
|
{ "nodirect", &nodirect, lgetopt::BOOL, "Disable direct IO (O_DIRECT) for unsupporting filesystems." },
|
|
|
|
{ "noaio", &noaio, lgetopt::BOOL, "Disable the AIO interface in favor of traditional syscalls. " },
|
2019-08-11 07:06:08 +02:00
|
|
|
{ "noiou", &noiou, lgetopt::BOOL, "Disable the io_uring interface and fallback to AIO or system calls. " },
|
2019-06-23 02:39:25 +02:00
|
|
|
{ "no6", &no6, lgetopt::BOOL, "Disable IPv6 operations (default)" },
|
|
|
|
{ "6", &yes6, lgetopt::BOOL, "Enable IPv6 operations" },
|
2019-04-03 19:49:07 +02:00
|
|
|
{ "norun", &norun, lgetopt::BOOL, "[debug & testing only] Initialize but never run the event loop." },
|
2019-04-15 20:08:40 +02:00
|
|
|
{ "ro", &read_only, lgetopt::BOOL, "Read-only mode. No writes to database allowed." },
|
|
|
|
{ "wa", &write_avoid, lgetopt::BOOL, "Like read-only mode, but writes permitted if triggered." },
|
2019-04-24 10:01:48 +02:00
|
|
|
{ "smoketest", &smoketest[0], lgetopt::BOOL, "Starts and stops the daemon to return success."},
|
2019-06-01 11:02:37 +02:00
|
|
|
{ "sassert", &soft_assert, lgetopt::BOOL, "Softens assertion effects in debug mode."},
|
2019-09-29 01:45:36 +02:00
|
|
|
{ "nomatrix", &nomatrix, lgetopt::BOOL, "Prevent loading the matrix application module."},
|
2019-10-13 04:17:31 +02:00
|
|
|
{ "matrix", &matrix, lgetopt::BOOL, "Allow loading the matrix application module."},
|
2020-04-25 06:26:06 +02:00
|
|
|
{ "defaults", &defaults, lgetopt::BOOL, "Use configuration defaults without database load for this execution."},
|
2018-12-09 00:17:13 +01:00
|
|
|
{ nullptr, nullptr, lgetopt::STRING, nullptr },
|
2016-08-31 10:03:12 +02:00
|
|
|
};
|
|
|
|
|
2019-03-02 20:58:40 +01:00
|
|
|
const char *const fatalerrstr
|
|
|
|
{R"(
|
|
|
|
***
|
|
|
|
*** A fatal error has occurred. Please contact the developer with the message below.
|
|
|
|
*** Create a coredump by reproducing the error using the -debug command-line option.
|
|
|
|
***
|
|
|
|
|
|
|
|
%s
|
|
|
|
)"};
|
|
|
|
|
|
|
|
const char *const usererrstr
|
|
|
|
{R"(
|
|
|
|
***
|
2019-05-10 01:49:19 +02:00
|
|
|
*** A fatal startup error has occurred:
|
2019-03-02 20:58:40 +01:00
|
|
|
***
|
|
|
|
|
|
|
|
%s
|
2019-05-10 01:49:19 +02:00
|
|
|
|
|
|
|
***
|
|
|
|
*** Please fix the problem to continue.
|
|
|
|
***
|
2019-03-02 20:58:40 +01:00
|
|
|
)"};
|
2016-09-10 03:35:44 +02:00
|
|
|
|
2019-05-10 01:49:19 +02:00
|
|
|
static bool startup_checks();
|
|
|
|
static void applyargs();
|
|
|
|
static void enable_coredumps();
|
|
|
|
static int print_version();
|
|
|
|
|
2019-05-04 03:13:01 +02:00
|
|
|
int
|
|
|
|
main(int _argc, char *const *_argv, char *const *const _envp)
|
2019-04-23 10:51:21 +02:00
|
|
|
noexcept try
|
2016-08-13 05:05:54 +02:00
|
|
|
{
|
2016-08-31 10:03:12 +02:00
|
|
|
umask(077); // better safe than sorry --SRB
|
2018-08-13 23:36:12 +02:00
|
|
|
|
|
|
|
// '-' switched arguments come first; this function incs argv and decs argc
|
2019-03-02 21:25:51 +01:00
|
|
|
auto argc(_argc);
|
|
|
|
auto argv(_argv), envp(_envp);
|
2019-06-29 07:03:55 +02:00
|
|
|
const char *const progname(_argv[0]);
|
2016-08-31 10:03:12 +02:00
|
|
|
parseargs(&argc, &argv, opts);
|
2019-10-13 04:17:31 +02:00
|
|
|
matrix &= !nomatrix;
|
|
|
|
nomatrix |= !matrix;
|
2016-08-31 10:03:12 +02:00
|
|
|
|
2018-01-10 09:56:33 +01:00
|
|
|
// cores are not dumped without consent of the user to maintain the privacy
|
2019-04-11 06:17:45 +02:00
|
|
|
// of cryptographic key material in memory at the time of the crash. Note
|
|
|
|
// that on systems that support MADV_DONTDUMP such material will be excluded
|
|
|
|
// from the coredump. Nevertheless, other sensitive material such as user
|
|
|
|
// data may still be present in the core.
|
2018-01-10 09:56:33 +01:00
|
|
|
if(RB_DEBUG_LEVEL || ircd::debugmode)
|
|
|
|
enable_coredumps();
|
|
|
|
|
2018-08-13 23:36:12 +02:00
|
|
|
if(!startup_checks())
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2016-08-31 10:03:12 +02:00
|
|
|
if(printversion)
|
2018-08-13 23:36:12 +02:00
|
|
|
return print_version();
|
2016-08-31 10:03:12 +02:00
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
// Sets various other conf items based on the program options captured into
|
|
|
|
// the globals preceding this frame.
|
|
|
|
applyargs();
|
|
|
|
|
|
|
|
// The network name (matrix origin) is the first positional argument after
|
|
|
|
// any switched arguments. The matrix origin is the hostpart of MXID's for
|
|
|
|
// the server.
|
2018-12-01 01:46:34 +01:00
|
|
|
const ircd::string_view origin
|
|
|
|
{
|
|
|
|
argc > 0?
|
|
|
|
argv[0]:
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
// The server_name is the unique name for this specific server. This is
|
2018-12-01 01:46:34 +01:00
|
|
|
// generally the same as origin; but if origin is example.org with an
|
2019-10-01 05:50:58 +02:00
|
|
|
// SRV record redirecting to matrix.example.org then server_name is
|
2018-12-01 01:46:34 +01:00
|
|
|
// matrix.example.org. In clusters serving a single origin, all
|
2019-10-01 05:50:58 +02:00
|
|
|
// server_names must be different.
|
|
|
|
const ircd::string_view server_name
|
2017-08-23 23:46:35 +02:00
|
|
|
{
|
2019-10-01 05:50:58 +02:00
|
|
|
argc > 1? // server_name given on command line
|
2018-12-01 01:46:34 +01:00
|
|
|
argv[1]:
|
2019-10-01 05:50:58 +02:00
|
|
|
argc > 0? // server_name matches origin
|
2018-12-01 01:46:34 +01:00
|
|
|
argv[0]:
|
|
|
|
nullptr
|
2017-08-23 23:46:35 +02:00
|
|
|
};
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
// at least one server_name argument is required for now.
|
2019-10-13 04:17:31 +02:00
|
|
|
if(!server_name && matrix)
|
2018-08-13 23:36:12 +02:00
|
|
|
throw ircd::user_error
|
|
|
|
{
|
2019-06-29 07:03:55 +02:00
|
|
|
"usage :%s <origin> [servername]", progname
|
2018-08-13 23:36:12 +02:00
|
|
|
};
|
|
|
|
|
2019-04-24 10:01:48 +02:00
|
|
|
// The smoketest uses this ircd::run::level callback to set a flag when
|
2019-09-25 21:48:00 +02:00
|
|
|
// each ircd::run::level is reached. All flags must be set to pass. The
|
2019-10-01 05:50:58 +02:00
|
|
|
// smoketest is inert unless the -smoketest program option is used. Note
|
|
|
|
// the special case for run::level::RUN, which initiates the transition
|
|
|
|
// to QUIT; the ircd::post allows any operations queued in the io_context
|
|
|
|
// to run in case the smoketest isn't the only callback being invoked.
|
|
|
|
const ircd::run::changed smoketester
|
2019-04-24 10:01:48 +02:00
|
|
|
{
|
2019-10-01 05:50:58 +02:00
|
|
|
[](const auto &level)
|
|
|
|
{
|
|
|
|
smoketest.at(size_t(level) + 1) = true;
|
|
|
|
if(smoketest[0] && level == ircd::run::level::RUN)
|
|
|
|
ircd::post {[] { ircd::quit(); }};
|
|
|
|
}
|
|
|
|
};
|
2019-04-24 10:01:48 +02:00
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
// Setup synchronization primitives on this stack for starting and stopping
|
|
|
|
// the application (matrix homeserver). Note this stack cannot actually use
|
|
|
|
// these; they'll be used to synchronize the closures below running in
|
|
|
|
// different contexts.
|
|
|
|
ircd::ctx::latch start(2), quit(2);
|
2019-10-07 23:47:43 +02:00
|
|
|
std::exception_ptr eptr;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
|
|
|
// Setup the matrix homeserver application. This will be executed on an
|
|
|
|
// ircd::context (dedicated stack). We construct several objects on the
|
|
|
|
// stack which are the basis for our matrix homeserver. When the stack
|
|
|
|
// unwinds, the homeserver will go out of service.
|
2019-10-07 23:47:43 +02:00
|
|
|
const auto homeserver{[&origin, &server_name, &start, &quit, &eptr]
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-07 23:47:43 +02:00
|
|
|
try
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-07 23:47:43 +02:00
|
|
|
// 5 Load the matrix library dynamic shared object
|
|
|
|
ircd::matrix matrix;
|
|
|
|
|
|
|
|
// 6 Run a primary homeserver based on the program options given.
|
|
|
|
struct ircd::m::homeserver::opts opts;
|
|
|
|
opts.origin = origin;
|
|
|
|
opts.server_name = server_name;
|
|
|
|
const ircd::custom_ptr<ircd::m::homeserver> homeserver
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-07 23:47:43 +02:00
|
|
|
// 6.1
|
|
|
|
matrix.init(&opts), [&matrix]
|
|
|
|
(ircd::m::homeserver *const homeserver)
|
|
|
|
{
|
|
|
|
// 11.1
|
|
|
|
matrix.fini(homeserver);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 7 Notify the loader the homeserver is ready for service.
|
|
|
|
start.count_down_and_wait();
|
|
|
|
|
|
|
|
// 9 Yield until the loader notifies us; this stack will then unwind.
|
|
|
|
quit.count_down_and_wait();
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2020-02-18 18:56:21 +01:00
|
|
|
// ctx::exception_handler allows us to yield an ircd::ctx (stack
|
|
|
|
// switch) inside a catch block, which we'll need in this scope.
|
2019-10-07 23:47:43 +02:00
|
|
|
const ircd::ctx::exception_handler eh;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2020-02-18 18:56:21 +01:00
|
|
|
// Copy a reference to the current exception which was saved by eh.
|
|
|
|
// Note it is not safe to call std::current_exception() here.
|
|
|
|
eptr = eh;
|
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 7' Notify the loader the homeserver failed to start
|
|
|
|
start.count_down_and_wait();
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 9' Yield until the loader notifies us; this stack will then unwind.
|
|
|
|
quit.count_down_and_wait();
|
|
|
|
}
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 11
|
2019-10-01 05:50:58 +02:00
|
|
|
}};
|
|
|
|
|
|
|
|
// This object registers a callback for a specific event in libircd; the
|
|
|
|
// closure is called from the main context (#1) running ircd::main().
|
2020-03-16 20:24:58 +01:00
|
|
|
// after libircd is ready for service in runlevel LOAD but before entering
|
2019-10-01 05:50:58 +02:00
|
|
|
// runlevel RUN. It is called again immediately after entering runlevel
|
|
|
|
// QUIT, but before any functionality of libircd destructs. This cues us
|
|
|
|
// to start and stop the homeserver.
|
2019-10-03 01:49:30 +02:00
|
|
|
const ircd::run::changed loader
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-07 23:47:43 +02:00
|
|
|
[&homeserver, &start, &quit, &eptr](const auto &level)
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
|
|
|
static ircd::context context;
|
|
|
|
|
|
|
|
// 2 This branch is taken the first time this function is called,
|
|
|
|
// and not taken the second time.
|
2020-03-16 20:24:58 +01:00
|
|
|
if(level == ircd::run::level::LOAD && !context && !nomatrix)
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
|
|
|
// 3 Launch the homeserver context (asynchronous).
|
2019-10-04 01:08:00 +02:00
|
|
|
context = { "matrix", ircd::context::POST, homeserver };
|
2019-10-01 05:50:58 +02:00
|
|
|
|
|
|
|
// 4 Yield until the homeserver function notifies `start`; waiting
|
|
|
|
// here prevents ircd::main() from entering runlevel RUN.
|
|
|
|
start.count_down_and_wait();
|
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 8 Check if error on start; rethrowing that here propagates
|
|
|
|
// to ircd::main() and triggers a runlevel QUIT sequence.
|
|
|
|
if(!!eptr)
|
|
|
|
std::rethrow_exception(eptr);
|
|
|
|
|
|
|
|
// 8.1
|
2019-10-01 05:50:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-03 22:21:50 +02:00
|
|
|
if(level != ircd::run::level::QUIT || !context)
|
2019-10-03 01:49:30 +02:00
|
|
|
return;
|
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 10 Notify the waiting homeserver context to quit; this will
|
2019-10-01 05:50:58 +02:00
|
|
|
// start shutting down the homeserver.
|
|
|
|
quit.count_down_and_wait();
|
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 12 Wait for the homeserver context to finish before we return.
|
2019-10-01 05:50:58 +02:00
|
|
|
context.join();
|
|
|
|
}
|
|
|
|
};
|
2019-09-29 01:45:36 +02:00
|
|
|
|
2019-10-03 01:49:30 +02:00
|
|
|
// This is the sole io_context for Construct, and the ios.run() below is the
|
|
|
|
// the only place where the program actually blocks.
|
|
|
|
boost::asio::io_context ios;
|
|
|
|
|
|
|
|
// libircd does no signal handling (or at least none that you ever have to
|
|
|
|
// care about); reaction to all signals happens out here instead. Handling
|
|
|
|
// is done properly through the io_context which registers the handler for
|
|
|
|
// the platform and then safely posts the received signal to the io_context
|
|
|
|
// event loop. This means we lose the true instant hardware-interrupt gratitude
|
|
|
|
// of signals but with the benefit of unconditional safety and cross-
|
|
|
|
// platformness with windows etc.
|
|
|
|
const construct::signals signals{ios};
|
|
|
|
|
|
|
|
// Associates libircd with our io_context and posts the initial routines
|
|
|
|
// to that io_context. Execution of IRCd will then occur during ios::run()
|
2020-02-27 19:11:59 +01:00
|
|
|
ircd::init(ios.get_executor());
|
2019-10-03 01:49:30 +02:00
|
|
|
|
2019-04-03 19:49:33 +02:00
|
|
|
// If the user wants to immediately drop to an interactive command line
|
|
|
|
// without having to send a ctrl-c for it, that is provided here. This does
|
|
|
|
// not actually take effect until it's processed in the ios.run() below.
|
2020-04-25 01:42:15 +02:00
|
|
|
if(cmdline || !execute.empty())
|
2018-12-11 23:55:40 +01:00
|
|
|
construct::console::spawn();
|
2016-09-03 18:16:04 +02:00
|
|
|
|
2019-04-03 19:49:33 +02:00
|
|
|
// If the user wants to immediately process console commands
|
|
|
|
// non-interactively from a program argument input, that is enqueued here.
|
2020-04-25 01:42:15 +02:00
|
|
|
for(auto &&cmd : execute)
|
|
|
|
construct::console::queue.emplace_back(std::move(cmd));
|
2017-11-16 02:33:43 +01:00
|
|
|
|
2019-04-03 19:49:07 +02:00
|
|
|
// For developer debugging and testing this branch from a "-norun" argument
|
|
|
|
// will exit before committing to the ios.run().
|
|
|
|
if(norun)
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
// 1
|
2017-08-23 23:46:35 +02:00
|
|
|
// Execution.
|
2018-02-22 10:33:25 +01:00
|
|
|
// Blocks until a clean exit from a quit() or an exception comes out of it.
|
2020-01-24 18:49:50 +01:00
|
|
|
const size_t handled
|
|
|
|
{
|
|
|
|
ios.run()
|
|
|
|
};
|
2019-03-02 21:25:51 +01:00
|
|
|
|
2019-10-07 23:47:43 +02:00
|
|
|
// 13
|
2019-04-24 10:01:48 +02:00
|
|
|
// The smoketest is enabled if the first value is true; then all of the
|
|
|
|
// values must be true for the smoketest to pass.
|
|
|
|
if(smoketest[0])
|
|
|
|
return std::count(begin(smoketest), end(smoketest), true) == smoketest.size()?
|
|
|
|
EXIT_SUCCESS:
|
|
|
|
EXIT_FAILURE;
|
|
|
|
|
2019-03-02 21:25:51 +01:00
|
|
|
// The restart flag can be set by the console command "restart" which
|
|
|
|
// calls ircd::quit() to clean break from the run() loop.
|
|
|
|
if(ircd::restart)
|
|
|
|
ircd::syscall(::execve, _argv[0], _argv, _envp);
|
2019-05-10 01:56:42 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2016-08-13 05:05:54 +02:00
|
|
|
}
|
2016-11-29 16:23:38 +01:00
|
|
|
catch(const ircd::user_error &e)
|
2016-09-08 22:29:02 +02:00
|
|
|
{
|
|
|
|
if(ircd::debugmode)
|
2019-06-24 07:09:41 +02:00
|
|
|
ircd::terminate{e};
|
2016-09-08 22:29:02 +02:00
|
|
|
|
|
|
|
fprintf(stderr, usererrstr, e.what());
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-08-31 10:03:12 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
if(ircd::debugmode)
|
2019-06-24 07:09:41 +02:00
|
|
|
ircd::terminate{e};
|
2012-02-18 04:54:44 +01:00
|
|
|
|
2016-08-31 12:55:27 +02:00
|
|
|
/*
|
|
|
|
* Why EXIT_FAILURE here?
|
|
|
|
* Because if ircd_die_cb() is called it's because of a fatal
|
|
|
|
* error inside libcharybdis, and we don't know how to handle the
|
|
|
|
* exception, so it is logical to return a FAILURE exit code here.
|
|
|
|
* --nenolod
|
|
|
|
*
|
|
|
|
* left the comment but the code is gone -jzk
|
|
|
|
*/
|
2016-08-31 10:03:12 +02:00
|
|
|
fprintf(stderr, fatalerrstr, e.what());
|
2016-08-31 12:55:27 +02:00
|
|
|
return EXIT_FAILURE;
|
2016-08-31 10:03:12 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 23:36:12 +02:00
|
|
|
int
|
2018-05-08 04:21:21 +02:00
|
|
|
print_version()
|
2016-08-31 10:03:12 +02:00
|
|
|
{
|
|
|
|
printf("VERSION :%s\n",
|
2018-02-22 22:33:53 +01:00
|
|
|
RB_VERSION);
|
2016-08-31 10:03:12 +02:00
|
|
|
|
|
|
|
#ifdef CUSTOM_BRANDING
|
|
|
|
printf("VERSION :based on %s-%s\n",
|
|
|
|
PACKAGE_NAME,
|
|
|
|
PACKAGE_VERSION);
|
|
|
|
#endif
|
2018-08-13 23:36:12 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2016-08-31 10:03:12 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 04:21:21 +02:00
|
|
|
bool
|
|
|
|
startup_checks()
|
2016-08-31 10:03:12 +02:00
|
|
|
try
|
|
|
|
{
|
2019-04-23 10:30:52 +02:00
|
|
|
if(RB_VERSION != ircd::info::version)
|
|
|
|
ircd::log::warning
|
|
|
|
{
|
|
|
|
"Header version '%s' mismatch library '%s'",
|
|
|
|
RB_VERSION,
|
|
|
|
ircd::info::version,
|
|
|
|
};
|
|
|
|
|
|
|
|
if(RB_VERSION_TAG != ircd::info::tag)
|
|
|
|
ircd::log::warning
|
|
|
|
{
|
|
|
|
"Header version tag '%s' mismatch library '%s'",
|
|
|
|
RB_VERSION_TAG,
|
|
|
|
ircd::info::tag,
|
|
|
|
};
|
|
|
|
|
2019-08-18 07:23:24 +02:00
|
|
|
if(RB_TIME_CONFIGURED != ircd::info::configured_time)
|
2019-04-23 10:30:52 +02:00
|
|
|
ircd::log::warning
|
|
|
|
{
|
2019-06-19 22:32:40 +02:00
|
|
|
"Header configuration time:%ld (%s) %s than library configuration time:%ld (%s).",
|
|
|
|
RB_TIME_CONFIGURED,
|
2019-04-23 10:30:52 +02:00
|
|
|
RB_VERSION_TAG,
|
2019-06-13 22:33:22 +02:00
|
|
|
RB_TIME_CONFIGURED > ircd::info::configured_time? "newer" : "older",
|
2019-08-18 07:23:24 +02:00
|
|
|
ircd::info::configured_time,
|
2019-04-23 10:30:52 +02:00
|
|
|
ircd::info::tag,
|
|
|
|
};
|
|
|
|
|
2016-08-31 10:03:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2016-07-01 05:04:00 +02:00
|
|
|
{
|
2016-08-31 10:03:12 +02:00
|
|
|
fprintf(stderr, usererrstr, e.what());
|
|
|
|
return false;
|
2016-07-01 05:04:00 +02:00
|
|
|
}
|
2016-08-31 12:55:27 +02:00
|
|
|
|
2018-01-10 09:56:33 +01:00
|
|
|
void
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
enable_coredumps()
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Setup corefile size immediately after boot -kre
|
|
|
|
//
|
|
|
|
|
|
|
|
rlimit rlim; // resource limits
|
|
|
|
ircd::syscall(getrlimit, RLIMIT_CORE, &rlim);
|
|
|
|
|
|
|
|
// Set corefilesize to maximum
|
|
|
|
rlim.rlim_cur = rlim.rlim_max;
|
|
|
|
ircd::syscall(setrlimit, RLIMIT_CORE, &rlim);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to adjust rlimit: " << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
enable_coredumps()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
/// These operations are safe to call before ircd::init() and anytime after
|
|
|
|
/// static initialization.
|
2018-12-09 00:17:13 +01:00
|
|
|
void
|
|
|
|
applyargs()
|
|
|
|
{
|
2020-01-13 03:22:47 +01:00
|
|
|
if(single)
|
|
|
|
{
|
|
|
|
nolisten = true;
|
|
|
|
write_avoid = true;
|
|
|
|
cmdline = true;
|
|
|
|
}
|
|
|
|
|
2020-04-25 06:26:06 +02:00
|
|
|
if(defaults)
|
|
|
|
ircd::defaults.set("true");
|
|
|
|
|
2019-04-15 20:08:40 +02:00
|
|
|
if(read_only)
|
|
|
|
ircd::read_only.set("true");
|
|
|
|
|
|
|
|
// read_only implies write_avoid.
|
|
|
|
if(write_avoid || read_only)
|
|
|
|
ircd::write_avoid.set("true");
|
|
|
|
|
2018-12-09 00:17:13 +01:00
|
|
|
if(debugmode)
|
|
|
|
ircd::debugmode.set("true");
|
|
|
|
else
|
|
|
|
ircd::debugmode.set("false");
|
|
|
|
|
|
|
|
if(nolisten)
|
|
|
|
ircd::net::listen.set("false");
|
|
|
|
else
|
|
|
|
ircd::net::listen.set("true");
|
|
|
|
|
|
|
|
if(noautomod)
|
|
|
|
ircd::mods::autoload.set("false");
|
|
|
|
else
|
|
|
|
ircd::mods::autoload.set("true");
|
|
|
|
|
|
|
|
if(checkdb)
|
|
|
|
ircd::db::open_check.set("true");
|
|
|
|
else
|
|
|
|
ircd::db::open_check.set("false");
|
|
|
|
|
|
|
|
if(pitrecdb)
|
|
|
|
ircd::db::open_recover.set("point");
|
|
|
|
else
|
|
|
|
ircd::db::open_recover.set("absolute");
|
|
|
|
|
2020-01-12 04:14:32 +01:00
|
|
|
if(repairdb)
|
|
|
|
ircd::db::open_repair.set("true");
|
|
|
|
else
|
|
|
|
ircd::db::open_repair.set("false");
|
|
|
|
|
2018-12-09 00:17:13 +01:00
|
|
|
if(nodirect)
|
|
|
|
ircd::fs::fd::opts::direct_io_enable.set("false");
|
|
|
|
else
|
|
|
|
ircd::fs::fd::opts::direct_io_enable.set("true");
|
|
|
|
|
|
|
|
if(noaio)
|
|
|
|
ircd::fs::aio::enable.set("false");
|
2019-08-11 07:06:08 +02:00
|
|
|
|
|
|
|
if(noiou)
|
|
|
|
ircd::fs::iou::enable.set("false");
|
2019-03-25 23:17:09 +01:00
|
|
|
|
2019-06-23 02:39:25 +02:00
|
|
|
if(yes6)
|
|
|
|
ircd::net::enable_ipv6.set("true");
|
|
|
|
else if(no6)
|
|
|
|
ircd::net::enable_ipv6.set("false");
|
|
|
|
else
|
2019-03-25 23:17:09 +01:00
|
|
|
ircd::net::enable_ipv6.set("false");
|
2019-06-01 11:02:37 +02:00
|
|
|
|
|
|
|
if(soft_assert)
|
|
|
|
ircd::soft_assert.set("true");
|
2019-09-25 21:48:00 +02:00
|
|
|
|
|
|
|
if(quietmode)
|
|
|
|
ircd::log::console_disable();
|
2018-12-09 00:17:13 +01:00
|
|
|
}
|