2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
2018-01-14 03:03:04 +01:00
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2018-02-04 03:22:01 +01:00
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
2018-01-14 03:03:04 +01:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
2018-02-04 03:22:01 +01:00
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-09-06 22:11:55 +02:00
|
|
|
namespace ircd
|
|
|
|
{
|
2019-09-30 23:41:15 +02:00
|
|
|
// Fundamental context #1; all subsystems live as objects on this stack.
|
|
|
|
// This is created by ircd::init(), and it executes ircd::main(), it then
|
|
|
|
// deletes itself and nulls this pointer when finished.
|
2019-09-25 21:48:00 +02:00
|
|
|
extern ctx::ctx *main_context;
|
2019-09-30 23:41:15 +02:00
|
|
|
|
|
|
|
// Main function. This frame anchors the initialization and destruction of
|
|
|
|
// all non-static assets provided by the library.
|
2020-12-19 01:37:05 +01:00
|
|
|
static void main(user_main) noexcept;
|
2016-09-06 22:11:55 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 19:39:40 +01:00
|
|
|
// internal interface to ircd::run (see ircd/run.h, ircd/run.cc)
|
|
|
|
namespace ircd::run
|
|
|
|
{
|
|
|
|
// change the current runlevel
|
|
|
|
bool set(const enum level &);
|
|
|
|
}
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// Records compile-time header version information.
|
2019-09-07 23:03:09 +02:00
|
|
|
decltype(ircd::version_api)
|
|
|
|
ircd::version_api
|
|
|
|
{
|
|
|
|
"IRCd", info::versions::API, 0, {0, 0, 0}, RB_VERSION
|
|
|
|
};
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// Records runtime linked library (this library) version information.
|
2019-09-07 23:03:09 +02:00
|
|
|
decltype(ircd::version_abi)
|
|
|
|
ircd::version_abi
|
|
|
|
{
|
|
|
|
"IRCd", info::versions::ABI, 0, {0, 0, 0}, ircd::info::version
|
|
|
|
};
|
|
|
|
|
2020-10-01 07:01:21 +02:00
|
|
|
/// This item allows the library to indicate to the embedder that they should
|
|
|
|
/// restart their application (or reload this library if available). The
|
|
|
|
/// use-case here is for features like the `restart` command in the console
|
|
|
|
/// module. Such a command triggers a normal quit and the application may exit
|
|
|
|
/// normally; therefor the embedder should check this item to perform a restart
|
|
|
|
/// rather than exiting.
|
|
|
|
///
|
|
|
|
/// This item is a string to allow for different program options at restart.
|
|
|
|
/// For now this is limited to space-separated arguments without respect for
|
|
|
|
/// quoting (for now), so no arguments can have spaces.
|
|
|
|
///
|
|
|
|
/// Empty string disables restart. The name of the executable should not be
|
|
|
|
/// prefixed to the string.
|
2020-09-16 03:01:40 +02:00
|
|
|
decltype(ircd::restart)
|
|
|
|
ircd::restart
|
|
|
|
{
|
|
|
|
{ "name", "ircd.restart" },
|
2020-10-01 07:01:21 +02:00
|
|
|
{ "default", std::string{} },
|
2020-09-16 03:01:40 +02:00
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Coarse mode indicator for debug/developer behavior when and if possible.
|
|
|
|
/// For example: additional log messages may be enabled by this mode. This
|
|
|
|
/// option is technically effective in both release builds and debug builds
|
|
|
|
/// but it controls far less in non-debug builds. This item may be toggled
|
|
|
|
/// at any time. It doesn't change operational functionality.
|
|
|
|
decltype(ircd::debugmode)
|
|
|
|
ircd::debugmode
|
|
|
|
{
|
|
|
|
{ "name", "ircd.debugmode" },
|
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// When assertions are enabled this further softens runtime behavior to be
|
|
|
|
/// non-disruptive/non-terminating for diagnostic purposes. Debugging/developer
|
|
|
|
/// use only. This item may be toggled at any time.
|
2019-06-01 11:02:37 +02:00
|
|
|
decltype(ircd::soft_assert)
|
|
|
|
ircd::soft_assert
|
|
|
|
{
|
2019-09-07 23:03:09 +02:00
|
|
|
{ "name", "ircd.soft_assert" },
|
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
2019-06-01 11:02:37 +02:00
|
|
|
};
|
|
|
|
|
2020-09-16 03:01:40 +02:00
|
|
|
/// Coarse mode declaration for "maintenance mode" a.k.a. "single user mode"
|
|
|
|
/// which is intended to be similar to normal operating mode but without
|
|
|
|
/// services to clients or some background tasks. It is implied and set when
|
|
|
|
/// write_avoid=true which is itself implied and set by read_only.
|
|
|
|
decltype(ircd::maintenance)
|
|
|
|
ircd::maintenance
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.maintenance" },
|
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!maintenance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
net::listen.set("false");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// Coarse mode indicator for degraded operation known as "write-avoid" which
|
|
|
|
/// is similar to read_only but not hard-enforced. Writes may still occur,
|
|
|
|
/// such as those manually triggered by an admin. All subsystems and background
|
|
|
|
/// tasks otherwise depart from normal operation to avoid writes.
|
2019-04-15 20:08:40 +02:00
|
|
|
decltype(ircd::write_avoid)
|
|
|
|
ircd::write_avoid
|
|
|
|
{
|
2020-09-16 03:01:40 +02:00
|
|
|
{
|
|
|
|
{ "name", "ircd.write_avoid" },
|
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!write_avoid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
maintenance.set("true");
|
|
|
|
}
|
2019-04-15 20:08:40 +02:00
|
|
|
};
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// Coarse mode declaration for read-only behavior. All subsystems and feature
|
|
|
|
/// modules respect this indicator by preventing any writes and persistence
|
|
|
|
/// during execution. This item should be set before ircd::init() to be most
|
|
|
|
/// effective.
|
2019-04-15 20:08:40 +02:00
|
|
|
decltype(ircd::read_only)
|
|
|
|
ircd::read_only
|
|
|
|
{
|
2020-09-16 03:01:40 +02:00
|
|
|
{
|
|
|
|
{ "name", "ircd.read_only" },
|
|
|
|
{ "default", false },
|
|
|
|
{ "persist", false },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!read_only)
|
|
|
|
return;
|
2018-12-09 00:17:13 +01:00
|
|
|
|
2020-09-16 03:01:40 +02:00
|
|
|
write_avoid.set("true");
|
|
|
|
}
|
2019-03-02 21:25:51 +01:00
|
|
|
};
|
|
|
|
|
2020-09-27 23:44:33 +02:00
|
|
|
/// Diagnostic options selection. This indicates whether any tests or special
|
|
|
|
/// behavior should occur rather than normal operation; also allowing for
|
|
|
|
/// fine-grained options to be conveyed to such tests/diagnostics. While this
|
|
|
|
/// appears here as coarse library-wide option it does not on its own affect
|
|
|
|
/// normal server operations just by being set. It affect things only if
|
|
|
|
/// specific functionality checks and alters its behavior based on the value
|
|
|
|
/// of this string contextually.
|
|
|
|
decltype(ircd::diagnostic)
|
|
|
|
ircd::diagnostic
|
|
|
|
{
|
|
|
|
{ "name", "ircd.diagnostic" },
|
|
|
|
{ "default", string_view{} },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2020-02-27 18:17:09 +01:00
|
|
|
/// Main context pointer placement.
|
2019-09-25 21:48:00 +02:00
|
|
|
decltype(ircd::main_context)
|
|
|
|
ircd::main_context;
|
|
|
|
|
2017-09-26 03:43:33 +02:00
|
|
|
/// Sets up the IRCd and its main context, then returns without blocking.
|
2020-02-27 19:11:59 +01:00
|
|
|
///
|
|
|
|
/// Pass the executor obtained from your io_context instance.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
|
|
|
/// This function will setup the main program loop of libircd. The execution will
|
2017-12-29 23:53:39 +01:00
|
|
|
/// occur when your io_context.run() or poll() is further invoked.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
2019-01-18 17:55:06 +01:00
|
|
|
/// init() can only be called from a run::level::HALT state
|
2017-09-26 03:43:33 +02:00
|
|
|
void
|
2020-12-19 01:37:05 +01:00
|
|
|
ircd::init(boost::asio::executor &&executor,
|
|
|
|
user_main user)
|
2017-09-30 08:04:41 +02:00
|
|
|
try
|
2016-09-06 22:11:55 +02:00
|
|
|
{
|
2019-05-10 01:47:47 +02:00
|
|
|
// This function must only be called from a HALT state.
|
2019-01-18 17:55:06 +01:00
|
|
|
if(run::level != run::level::HALT)
|
2018-01-22 09:25:08 +01:00
|
|
|
throw error
|
|
|
|
{
|
2019-01-18 17:55:06 +01:00
|
|
|
"Cannot init() IRCd from runlevel %s", reflect(run::level)
|
2018-01-22 09:25:08 +01:00
|
|
|
};
|
2017-11-06 21:14:50 +01:00
|
|
|
|
2019-05-10 01:47:47 +02:00
|
|
|
// Setup the core event loop system starting with the user's supplied ios.
|
2020-02-27 19:11:59 +01:00
|
|
|
ios::init(std::move(executor));
|
2019-05-10 01:47:47 +02:00
|
|
|
|
2018-03-02 09:35:02 +01:00
|
|
|
// The log is available. but it is console-only until conf opens files.
|
2016-09-06 22:11:55 +02:00
|
|
|
log::init();
|
2018-05-08 01:13:16 +02:00
|
|
|
log::mark("DEADSTART"); // 6600
|
2016-09-06 22:11:55 +02:00
|
|
|
|
2018-01-17 12:55:36 +01:00
|
|
|
// This starts off the log with library information.
|
2018-04-20 21:41:03 +02:00
|
|
|
info::dump();
|
2017-11-30 19:26:13 +01:00
|
|
|
|
2017-11-06 21:14:50 +01:00
|
|
|
// Setup the main context, which is a new stack executing the function
|
|
|
|
// ircd::main(). The main_context is the first ircd::ctx to be spawned
|
|
|
|
// and will be the last to finish.
|
|
|
|
//
|
2017-12-29 23:53:39 +01:00
|
|
|
// The context::POST will delay this spawn until the next io_context
|
2017-11-06 21:14:50 +01:00
|
|
|
// event slice, so no context switch will occur here. Note that POST has
|
|
|
|
// to be used here because: A. This init() function is executing on the
|
|
|
|
// main stack, and context switches can only occur between context stacks,
|
2017-12-29 23:53:39 +01:00
|
|
|
// not between contexts and the main stack. B. The user's io_context may or
|
2017-11-06 21:14:50 +01:00
|
|
|
// may not even be running yet anyway.
|
|
|
|
//
|
2018-12-14 01:21:54 +01:00
|
|
|
// (debug compilation) The context::SLICE_EXEMPT flag exempts the context
|
|
|
|
// from assertions that it's not blocking the process with excessive CPU
|
|
|
|
// usage or long syscall. Main context can't meet this requirement.
|
|
|
|
//
|
2019-01-18 17:55:06 +01:00
|
|
|
context main_context
|
2017-09-26 03:43:33 +02:00
|
|
|
{
|
2020-12-19 01:37:05 +01:00
|
|
|
"main",
|
|
|
|
512_KiB,
|
|
|
|
std::bind(&ircd::main, std::move(user)),
|
|
|
|
context::POST | context::SLICE_EXEMPT
|
2017-09-26 03:43:33 +02:00
|
|
|
};
|
|
|
|
|
2017-11-06 21:14:50 +01:00
|
|
|
// The default behavior for ircd::context is to join the ctx on dtor. We
|
|
|
|
// can't have that here because this is strictly an asynchronous function
|
|
|
|
// on the main stack. Under normal circumstances, the mc will be entered
|
|
|
|
// and be able to delete this pointer itself when it finishes. Otherwise
|
|
|
|
// this must be manually deleted with assurance that mc will never enter.
|
2017-09-26 03:43:33 +02:00
|
|
|
ircd::main_context = main_context.detach();
|
2017-11-06 21:14:50 +01:00
|
|
|
|
2019-01-18 17:55:06 +01:00
|
|
|
// Finally, without prior exception, the commitment to run::level::READY
|
2017-11-06 21:14:50 +01:00
|
|
|
// is made here. The user can now invoke their ios.run(), or, if they
|
|
|
|
// have already, IRCd will begin main execution shortly...
|
2019-01-18 17:55:06 +01:00
|
|
|
run::set(run::level::READY);
|
2016-09-06 22:11:55 +02:00
|
|
|
}
|
2017-09-30 08:04:41 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2016-09-06 22:11:55 +02:00
|
|
|
|
2017-09-26 03:43:33 +02:00
|
|
|
/// Notifies IRCd to shutdown. A shutdown will occur asynchronously and this
|
2017-11-06 21:14:50 +01:00
|
|
|
/// function will return immediately. A runlevel change to HALT will be
|
|
|
|
/// indicated when IRCd has no more work for the ios. When the HALT state
|
|
|
|
/// is observed the user is free to destruct all resources related to libircd.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
|
|
|
/// This function is the proper way to shutdown libircd after an init(), and while
|
2017-12-29 23:53:39 +01:00
|
|
|
/// your io_context.run() is invoked without stopping your io_context shared by
|
|
|
|
/// other activities unrelated to libircd. If your io_context has no other activities
|
2017-11-06 21:14:50 +01:00
|
|
|
/// the run() will then return immediately after IRCd posts its transition to
|
|
|
|
/// the HALT state.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
2022-05-26 21:00:07 +02:00
|
|
|
[[gnu::cold]]
|
2017-09-26 03:43:33 +02:00
|
|
|
bool
|
2017-11-06 21:14:50 +01:00
|
|
|
ircd::quit()
|
2017-09-26 03:43:33 +02:00
|
|
|
noexcept
|
2016-10-26 08:25:04 +02:00
|
|
|
{
|
2020-12-01 05:26:21 +01:00
|
|
|
log::logf
|
2018-08-28 23:04:43 +02:00
|
|
|
{
|
2020-12-01 05:26:21 +01:00
|
|
|
log::star, log::level::DEBUG,
|
2018-08-28 23:04:43 +02:00
|
|
|
"IRCd quit requested from runlevel:%s ctx:%p main_context:%p",
|
2019-01-18 17:55:06 +01:00
|
|
|
reflect(run::level),
|
2018-08-28 23:04:43 +02:00
|
|
|
(const void *)ctx::current,
|
|
|
|
(const void *)main_context
|
|
|
|
};
|
2017-09-26 03:43:33 +02:00
|
|
|
|
2019-01-18 17:55:06 +01:00
|
|
|
if(main_context) switch(run::level)
|
2018-08-28 23:04:43 +02:00
|
|
|
{
|
2019-01-18 17:55:06 +01:00
|
|
|
case run::level::READY:
|
2018-08-28 23:04:43 +02:00
|
|
|
{
|
|
|
|
ctx::terminate(*main_context);
|
|
|
|
main_context = nullptr;
|
2019-01-18 17:55:06 +01:00
|
|
|
ircd::run::set(run::level::HALT);
|
2018-08-28 23:04:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-26 08:25:04 +02:00
|
|
|
|
2019-01-18 17:55:06 +01:00
|
|
|
case run::level::START:
|
2018-08-28 23:04:43 +02:00
|
|
|
{
|
|
|
|
ctx::terminate(*main_context);
|
|
|
|
main_context = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 17:55:06 +01:00
|
|
|
case run::level::RUN:
|
2018-08-28 23:04:43 +02:00
|
|
|
{
|
|
|
|
ctx::notify(*main_context);
|
|
|
|
main_context = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 17:55:06 +01:00
|
|
|
case run::level::QUIT:
|
2020-06-13 03:37:16 +02:00
|
|
|
case run::level::HALT:
|
2019-01-18 17:55:06 +01:00
|
|
|
case run::level::FAULT:
|
2018-08-28 23:04:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-10-26 08:25:04 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 00:06:16 +02:00
|
|
|
/// Notifies IRCd that execution is being resumed after a significant gap.
|
|
|
|
/// Basically this is connected to a SIGCONT handler and beneficial after
|
|
|
|
/// user stops, debugging and ACPI suspensions, etc. It is not required at
|
|
|
|
/// this time, but its connection is advised for best behavior.
|
|
|
|
void
|
|
|
|
ircd::cont()
|
|
|
|
noexcept
|
|
|
|
{
|
2020-12-01 05:26:21 +01:00
|
|
|
log::logf
|
2019-06-06 00:06:16 +02:00
|
|
|
{
|
2020-12-01 05:26:21 +01:00
|
|
|
log::star, log::level::DEBUG,
|
2019-06-06 00:06:16 +02:00
|
|
|
"IRCd cont requested from runlevel:%s ctx:%p main_context:%p",
|
|
|
|
reflect(run::level),
|
|
|
|
(const void *)ctx::current,
|
|
|
|
(const void *)main_context
|
|
|
|
};
|
|
|
|
|
|
|
|
switch(run::level)
|
|
|
|
{
|
|
|
|
case run::level::RUN:
|
|
|
|
break;
|
2020-06-13 09:02:27 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2019-06-06 00:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
log::notice
|
|
|
|
{
|
2020-12-01 05:26:21 +01:00
|
|
|
log::star, "IRCd resuming service in runlevel %s.",
|
2019-06-06 00:06:16 +02:00
|
|
|
reflect(run::level),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:33:25 +01:00
|
|
|
/// Main context; Main program. Do not call this function directly.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
|
|
|
/// This function manages the lifetime for all resources and subsystems
|
|
|
|
/// that don't/can't have their own static initialization. When this
|
|
|
|
/// function is entered, subsystem init objects are constructed on the
|
|
|
|
/// frame. The lifetime of those objects is the handle to the lifetime
|
|
|
|
/// of the subsystem, so destruction will shut down that subsystem.
|
|
|
|
///
|
|
|
|
/// The status of this function and IRCd overall can be observed through
|
2019-01-18 17:55:06 +01:00
|
|
|
/// the ircd::runlevel. The ircd::run::changed callback can be set
|
2017-09-26 03:43:33 +02:00
|
|
|
/// to be notified on a runlevel change. The user should wait for a runlevel
|
2017-11-06 21:14:50 +01:00
|
|
|
/// of HALT before destroying IRCd related resources and stopping their
|
2017-12-29 23:53:39 +01:00
|
|
|
/// io_context from running more jobs.
|
2017-09-26 03:43:33 +02:00
|
|
|
///
|
2016-09-06 22:11:55 +02:00
|
|
|
void
|
2020-12-19 01:37:05 +01:00
|
|
|
ircd::main(user_main user)
|
2018-03-16 23:16:14 +01:00
|
|
|
noexcept try
|
2016-09-06 22:11:55 +02:00
|
|
|
{
|
2020-12-19 01:37:05 +01:00
|
|
|
// When this function completes without exception, subsystems are done
|
|
|
|
// shutting down and IRCd transitions to HALT.
|
2019-12-03 22:05:32 +01:00
|
|
|
const unwind_defer halted{[]
|
2017-09-30 08:04:41 +02:00
|
|
|
{
|
2019-01-18 17:55:06 +01:00
|
|
|
run::set(run::level::HALT);
|
2017-09-30 08:04:41 +02:00
|
|
|
}};
|
2017-09-26 03:43:33 +02:00
|
|
|
|
2020-12-19 01:37:05 +01:00
|
|
|
// We block interruption/termination of the main context by default;
|
|
|
|
// this covers most of the functionality performed by this function and
|
|
|
|
// its callees. This provides consistent and complete runlevel transitions.
|
|
|
|
const ctx::uninterruptible::nothrow disable_interruption {true};
|
|
|
|
|
2018-08-28 23:04:43 +02:00
|
|
|
// When this function is entered IRCd will transition to START indicating
|
|
|
|
// that subsystems are initializing.
|
2020-12-19 01:37:05 +01:00
|
|
|
run::set(run::level::START);
|
2018-08-28 23:04:43 +02:00
|
|
|
|
2017-09-26 03:43:33 +02:00
|
|
|
// These objects are the init()'s and fini()'s for each subsystem.
|
|
|
|
// Appearing here ties their life to the main context. Initialization can
|
|
|
|
// also occur in ircd::init() or static initialization itself if either are
|
|
|
|
// more appropriate.
|
2017-08-23 23:13:57 +02:00
|
|
|
|
2021-03-11 18:11:57 +01:00
|
|
|
ctx::ole::init _ole_; // Thread OffLoad Engine
|
2019-04-03 22:16:05 +02:00
|
|
|
fs::init _fs_; // Local filesystem
|
2021-01-05 23:50:53 +01:00
|
|
|
cl::init _cl_; // OpenCL
|
2018-03-17 07:13:37 +01:00
|
|
|
magic::init _magic_; // libmagic
|
2020-08-24 10:35:15 +02:00
|
|
|
magick::init _magick_; // ImageMagick
|
2017-10-25 18:35:23 +02:00
|
|
|
openssl::init _ossl_; // openssl crypto
|
2017-09-30 08:04:41 +02:00
|
|
|
net::init _net_; // Networking
|
2017-09-08 11:19:26 +02:00
|
|
|
db::init _db_; // RocksDB
|
2018-02-14 05:38:55 +01:00
|
|
|
client::init _client_; // Client related
|
2019-10-06 01:21:06 +02:00
|
|
|
server::init _server_; // Server related
|
2017-08-23 23:13:57 +02:00
|
|
|
js::init _js_; // SpiderMonkey
|
2017-09-26 03:43:33 +02:00
|
|
|
|
2020-12-19 01:37:05 +01:00
|
|
|
// Continuation passed to the user's main function.
|
|
|
|
const auto continuation{[]
|
2019-09-30 23:41:15 +02:00
|
|
|
{
|
2020-12-19 01:37:05 +01:00
|
|
|
// Transition to the QUIT state on unwind.
|
|
|
|
const unwind quit{[]
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow disable_interruption {true};
|
|
|
|
ircd::run::set(run::level::QUIT);
|
|
|
|
}};
|
2019-09-30 23:41:15 +02:00
|
|
|
|
2020-12-19 01:37:05 +01:00
|
|
|
// Block interruptions again for runlevel transitions.
|
|
|
|
const ctx::uninterruptible disable_interruption {true};
|
2019-10-03 01:49:30 +02:00
|
|
|
|
2020-12-19 01:37:05 +01:00
|
|
|
// IRCd will now transition to the RUN state indicating full functionality.
|
2020-10-18 00:10:22 +02:00
|
|
|
run::set(run::level::RUN);
|
2019-10-03 01:49:30 +02:00
|
|
|
|
2020-12-19 01:37:05 +01:00
|
|
|
// Allow interrupts while running so we can be notified to quit.
|
|
|
|
const ctx::uninterruptible reenable_interruption {false};
|
|
|
|
|
|
|
|
// wait() blocks until the main context is notified or interrupted etc.
|
|
|
|
// Waiting here will hold open this stack with all of the above objects
|
|
|
|
// living on it.
|
|
|
|
ctx::wait();
|
|
|
|
}};
|
|
|
|
|
|
|
|
if(!user)
|
|
|
|
return continuation();
|
|
|
|
|
|
|
|
// Allow interrupts again by default for the duration of the user.
|
|
|
|
const ctx::uninterruptible reenable_interruption {false};
|
|
|
|
|
|
|
|
// Call user.
|
|
|
|
user(continuation);
|
2017-09-26 03:43:33 +02:00
|
|
|
}
|
2018-12-16 02:13:35 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"IRCd main :%s", e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const ctx::terminated &)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-05-07 00:11:59 +02:00
|
|
|
catch(...)
|
2016-09-06 22:11:55 +02:00
|
|
|
{
|
2018-01-22 09:25:08 +01:00
|
|
|
log::critical
|
|
|
|
{
|
2018-12-16 02:13:35 +01:00
|
|
|
"IRCd main error."
|
2018-01-22 09:25:08 +01:00
|
|
|
};
|
2016-09-06 22:11:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 01:19:15 +02:00
|
|
|
/// IRCd uptime in seconds
|
|
|
|
ircd::seconds
|
|
|
|
ircd::uptime()
|
|
|
|
{
|
|
|
|
return seconds(ircd::time() - info::startup_time);
|
|
|
|
}
|