0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd: Move sys/resource / coredump related out of libircd.

This commit is contained in:
Jason Volk 2018-01-10 00:56:33 -08:00
parent 8acdf52443
commit 84bbeecc83
3 changed files with 44 additions and 45 deletions

View file

@ -21,6 +21,7 @@
#include <ircd/ircd.h>
#include <ircd/asio.h>
#include <RB_INC_SYS_RESOURCE_H
#include "lgetopt.h"
#include "charybdis.h"
@ -28,6 +29,7 @@ namespace fs = ircd::fs;
static void sigfd_handler(const boost::system::error_code &, int);
static bool startup_checks();
static void enable_coredumps();
static void print_version();
const char *const fatalerrstr
@ -90,6 +92,11 @@ try
if(!startup_checks())
return 1;
// cores are not dumped without consent of the user to maintain the privacy
// of cryptographic key material in memory at the time of the crash.
if(RB_DEBUG_LEVEL || ircd::debugmode)
enable_coredumps();
if(printversion)
{
print_version();
@ -213,6 +220,32 @@ catch(const std::exception &e)
static void handle_usr2();
static void handle_usr1();
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
static void handle_quit();
static void handle_interruption();
static void handle_termstop();

View file

@ -45,21 +45,19 @@
// Generated by ./configure
#include "config.h"
extern "C" {
#include <RB_INC_ASSERT_H
#include <RB_INC_STDARG_H
#include <RB_INC_SYS_TIME_H
#include <RB_INC_SYS_RESOURCE_H
} // extern "C"
extern "C"
{
#include <RB_INC_ASSERT_H
#include <RB_INC_STDARG_H
#include <RB_INC_SYS_TIME_H
}
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <RB_INC_WINDOWS_H
#include <RB_INC_WINSOCK2_H
#include <RB_INC_WS2TCPIP_H
#include <RB_INC_IPHLPAPI_H
#define WIN32_LEAN_AND_MEAN 1
#include <RB_INC_WINDOWS_H
#include <RB_INC_WINSOCK2_H
#include <RB_INC_WS2TCPIP_H
#include <RB_INC_IPHLPAPI_H
#endif
#include <RB_INC_CSTDDEF

View file

@ -44,7 +44,6 @@ namespace ircd
ctx::ctx *main_context; // Main program loop
bool debugmode; // meaningful ifdef RB_DEBUG
void enable_coredumps();
std::string read_conf(std::string file);
void set_runlevel(const enum runlevel &);
void at_main_exit() noexcept;
@ -114,11 +113,6 @@ try
throw error("Cannot init() IRCd from runlevel %s",
reflect(runlevel));
// cores are not dumped without consent of the user to maintain the privacy
// of cryptographic key material in memory at the time of the crash.
if(RB_DEBUG_LEVEL || debugmode)
enable_coredumps();
// Samples the thread this context was executed on which should be where
// the user ran ios.run(). The user may have invoked ios.run() on multiple
// threads, but we consider this one thread a main thread for now...
@ -443,32 +437,6 @@ catch(const std::exception &e)
throw;
}
void
#ifdef HAVE_SYS_RESOURCE_H
ircd::enable_coredumps()
try
{
//
// Setup corefile size immediately after boot -kre
//
rlimit rlim; // resource limits
syscall(getrlimit, RLIMIT_CORE, &rlim);
// Set corefilesize to maximum
rlim.rlim_cur = rlim.rlim_max;
syscall(setrlimit, RLIMIT_CORE, &rlim);
}
catch(const std::exception &e)
{
std::cerr << "Failed to adjust rlimit: " << e.what() << std::endl;
}
#else
ircd::enable_coredumps()
{
}
#endif
// namespace ircd {
/* /quote set variables */