mirror of
https://github.com/matrix-construct/construct
synced 2024-06-03 02:28:55 +02:00
charybdis: Establish main entry point.
This commit is contained in:
parent
4399c1e2c3
commit
4b62a704bf
|
@ -19,15 +19,98 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rb/rb.h>
|
|
||||||
#include <ircd/ircd.h>
|
#include <ircd/ircd.h>
|
||||||
|
|
||||||
namespace ircd
|
using namespace ircd;
|
||||||
|
|
||||||
|
bool printversion;
|
||||||
|
lgetopt opts[] =
|
||||||
{
|
{
|
||||||
extern int charybdis_main(int argc, char *const argv[]);
|
{ "help", NULL, lgetopt::USAGE, "Print this text" },
|
||||||
|
{ "version", &printversion, lgetopt::BOOL, "Print version and exit" },
|
||||||
|
{ "configfile", &ConfigFileEntry.configfile, lgetopt::STRING, "File to use for ircd.conf" },
|
||||||
|
{ "conftest", &testing_conf, lgetopt::YESNO, "Test the configuration files and exit" },
|
||||||
|
{ "debug", &ircd::debugmode, lgetopt::BOOL, "Enable options for debugging" },
|
||||||
|
{ NULL, NULL, lgetopt::STRING, NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
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"(
|
||||||
|
***
|
||||||
|
*** A fatal startup error has occurred. Please fix the problem to continue. ***
|
||||||
|
***
|
||||||
|
%s
|
||||||
|
)"};
|
||||||
|
|
||||||
|
static void print_version();
|
||||||
|
static bool startup_checks();
|
||||||
|
|
||||||
|
int main(int argc, char *const *argv)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
umask(077); // better safe than sorry --SRB
|
||||||
|
|
||||||
|
ConfigFileEntry.dpath = path::get(path::PREFIX);
|
||||||
|
ConfigFileEntry.configfile = path::get(path::IRCD_CONF); // Server configuration file
|
||||||
|
ConfigFileEntry.connect_timeout = 30; // Default to 30
|
||||||
|
|
||||||
|
parseargs(&argc, &argv, opts);
|
||||||
|
if(!startup_checks())
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if(printversion)
|
||||||
|
{
|
||||||
|
print_version();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ircd::run();
|
||||||
|
}
|
||||||
|
catch(const std::exception &e)
|
||||||
|
{
|
||||||
|
if(ircd::debugmode)
|
||||||
|
throw;
|
||||||
|
|
||||||
|
fprintf(stderr, fatalerrstr, e.what());
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
void print_version()
|
||||||
{
|
{
|
||||||
return ircd::charybdis_main(argc, argv);
|
printf("VERSION :%s\n",
|
||||||
|
info::version.c_str());
|
||||||
|
|
||||||
|
#ifdef CUSTOM_BRANDING
|
||||||
|
printf("VERSION :based on %s-%s\n",
|
||||||
|
PACKAGE_NAME,
|
||||||
|
PACKAGE_VERSION);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("VERSION :%s\n", rb_lib_version());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool startup_checks()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
if(geteuid() == 0)
|
||||||
|
throw error("Don't run ircd as root!!!");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
path::chdir(ConfigFileEntry.dpath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(const std::exception &e)
|
||||||
|
{
|
||||||
|
fprintf(stderr, usererrstr, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
namespace ircd {
|
namespace ircd {
|
||||||
|
|
||||||
|
extern bool debugmode;
|
||||||
|
|
||||||
struct SetOptions
|
struct SetOptions
|
||||||
{
|
{
|
||||||
int maxclients; /* max clients allowed */
|
int maxclients; /* max clients allowed */
|
||||||
|
@ -61,7 +63,6 @@ struct Counter
|
||||||
|
|
||||||
extern struct SetOptions GlobalSetOptions; /* defined in ircd.c */
|
extern struct SetOptions GlobalSetOptions; /* defined in ircd.c */
|
||||||
|
|
||||||
extern const char *logFileName;
|
|
||||||
extern volatile sig_atomic_t dorehash;
|
extern volatile sig_atomic_t dorehash;
|
||||||
extern volatile sig_atomic_t dorehashbans;
|
extern volatile sig_atomic_t dorehashbans;
|
||||||
extern volatile sig_atomic_t doremotd;
|
extern volatile sig_atomic_t doremotd;
|
||||||
|
@ -104,5 +105,7 @@ void server_reboot(void) __attribute__((noreturn));
|
||||||
void setup_signals();
|
void setup_signals();
|
||||||
void ircd_shutdown(const char *reason) __attribute__((noreturn));
|
void ircd_shutdown(const char *reason) __attribute__((noreturn));
|
||||||
|
|
||||||
|
int run();
|
||||||
|
|
||||||
} // namespace ircd
|
} // namespace ircd
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
|
@ -38,9 +38,7 @@ struct lgetopt
|
||||||
const char *desc; /* description of the argument, usage for printing help */
|
const char *desc; /* description of the argument, usage for printing help */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct lgetopt myopts[];
|
void usage(const char *, struct lgetopt *opts) __attribute__((noreturn));
|
||||||
|
|
||||||
void usage(const char *) __attribute__((noreturn));
|
|
||||||
void parseargs(int *, char * const **, struct lgetopt *);
|
void parseargs(int *, char * const **, struct lgetopt *);
|
||||||
|
|
||||||
} // namespace ircd
|
} // namespace ircd
|
||||||
|
|
|
@ -72,7 +72,7 @@ parseargs(int *argc, char * const **argv, struct lgetopt *opts)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: option '%c%s' requires an argument\n",
|
"Error: option '%c%s' requires an argument\n",
|
||||||
OPTCHAR, opts[i].opt);
|
OPTCHAR, opts[i].opt);
|
||||||
usage(progname);
|
usage(progname, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
*((int *) opts[i].argloc) = atoi((*argv)[1]);
|
*((int *) opts[i].argloc) = atoi((*argv)[1]);
|
||||||
|
@ -86,7 +86,7 @@ parseargs(int *argc, char * const **argv, struct lgetopt *opts)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"error: option '%c%s' requires an argument\n",
|
"error: option '%c%s' requires an argument\n",
|
||||||
OPTCHAR, opts[i].opt);
|
OPTCHAR, opts[i].opt);
|
||||||
usage(progname);
|
usage(progname, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
*((char **) opts[i].argloc) =
|
*((char **) opts[i].argloc) =
|
||||||
|
@ -98,7 +98,7 @@ parseargs(int *argc, char * const **argv, struct lgetopt *opts)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case argtype::USAGE:
|
case argtype::USAGE:
|
||||||
usage(progname);
|
usage(progname, opts);
|
||||||
/*NOTREACHED*/ default:
|
/*NOTREACHED*/ default:
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: internal error in parseargs() at %s:%d\n",
|
"Error: internal error in parseargs() at %s:%d\n",
|
||||||
|
@ -110,13 +110,13 @@ parseargs(int *argc, char * const **argv, struct lgetopt *opts)
|
||||||
if(!found)
|
if(!found)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, &(*argv)[0][1]);
|
fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, &(*argv)[0][1]);
|
||||||
usage(progname);
|
usage(progname, opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(const char *name)
|
usage(const char *name, struct lgetopt *myopts)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
71
ircd/ircd.cc
71
ircd/ircd.cc
|
@ -23,6 +23,8 @@
|
||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool ircd::debugmode;
|
||||||
|
|
||||||
|
|
||||||
namespace ircd {
|
namespace ircd {
|
||||||
|
|
||||||
|
@ -77,8 +79,6 @@ int split_users;
|
||||||
int split_servers;
|
int split_servers;
|
||||||
int eob_count;
|
int eob_count;
|
||||||
|
|
||||||
const char *logFileName = NULL;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd_shutdown(const char *reason)
|
ircd_shutdown(const char *reason)
|
||||||
{
|
{
|
||||||
|
@ -146,21 +146,6 @@ init_sys(void)
|
||||||
maxconnections = MAXCONNECTIONS;
|
maxconnections = MAXCONNECTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printVersion = 0;
|
|
||||||
|
|
||||||
struct lgetopt myopts[] = {
|
|
||||||
{"configfile", &ConfigFileEntry.configfile,
|
|
||||||
lgetopt::STRING, "File to use for ircd.conf"},
|
|
||||||
{"logfile", &logFileName,
|
|
||||||
lgetopt::STRING, "File to use for ircd.log"},
|
|
||||||
{"version", &printVersion,
|
|
||||||
lgetopt::YESNO, "Print version and exit"},
|
|
||||||
{"conftest", &testing_conf,
|
|
||||||
lgetopt::YESNO, "Test the configuration files and exit"},
|
|
||||||
{"help", NULL, lgetopt::USAGE, "Print this text"},
|
|
||||||
{NULL, NULL, lgetopt::STRING, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_rehash(void *unused)
|
check_rehash(void *unused)
|
||||||
{
|
{
|
||||||
|
@ -363,38 +348,9 @@ seed_random(void *unused)
|
||||||
* Side Effects - this is where the ircd gets going right now
|
* Side Effects - this is where the ircd gets going right now
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
charybdis_main(int argc, char * const argv[])
|
run()
|
||||||
{
|
{
|
||||||
int fd;
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
/* Check to see if the user is running us as root, which is a nono */
|
|
||||||
if(geteuid() == 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Don't run ircd as root!!!\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
logFileName = path::get(path::IRCD_LOG);
|
|
||||||
|
|
||||||
ConfigFileEntry.dpath = path::get(path::PREFIX);
|
|
||||||
ConfigFileEntry.configfile = path::get(path::IRCD_CONF); // Server configuration file
|
|
||||||
ConfigFileEntry.connect_timeout = 30; /* Default to 30 */
|
|
||||||
|
|
||||||
init_sys();
|
init_sys();
|
||||||
|
|
||||||
umask(077); /* better safe than sorry --SRB */
|
|
||||||
|
|
||||||
myargv = argv;
|
|
||||||
parseargs(&argc, &argv, myopts);
|
|
||||||
|
|
||||||
if(chdir(ConfigFileEntry.dpath))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_set_time();
|
rb_set_time();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -405,18 +361,7 @@ charybdis_main(int argc, char * const argv[])
|
||||||
/* initialise operhash fairly early. */
|
/* initialise operhash fairly early. */
|
||||||
init_operhash();
|
init_operhash();
|
||||||
|
|
||||||
memset(&me, 0, sizeof(me));
|
|
||||||
memset(&meLocalUser, 0, sizeof(meLocalUser));
|
|
||||||
me.localClient = &meLocalUser;
|
me.localClient = &meLocalUser;
|
||||||
|
|
||||||
/* Make sure all lists are zeroed */
|
|
||||||
memset(&unknown_list, 0, sizeof(unknown_list));
|
|
||||||
memset(&lclient_list, 0, sizeof(lclient_list));
|
|
||||||
memset(&serv_list, 0, sizeof(serv_list));
|
|
||||||
memset(&global_serv_list, 0, sizeof(global_serv_list));
|
|
||||||
memset(&local_oper_list, 0, sizeof(local_oper_list));
|
|
||||||
memset(&oper_list, 0, sizeof(oper_list));
|
|
||||||
|
|
||||||
rb_dlinkAddTail(&me, &me.node, &global_client_list);
|
rb_dlinkAddTail(&me, &me.node, &global_client_list);
|
||||||
|
|
||||||
memset(&Count, 0, sizeof(Count));
|
memset(&Count, 0, sizeof(Count));
|
||||||
|
@ -424,16 +369,6 @@ charybdis_main(int argc, char * const argv[])
|
||||||
memset(&AdminInfo, 0, sizeof(AdminInfo));
|
memset(&AdminInfo, 0, sizeof(AdminInfo));
|
||||||
memset(&ServerStats, 0, sizeof(struct ServerStatistics));
|
memset(&ServerStats, 0, sizeof(struct ServerStatistics));
|
||||||
|
|
||||||
if(printVersion)
|
|
||||||
{
|
|
||||||
printf("ircd: version %s(%s)\n", info::version.c_str(), info::serno.c_str());
|
|
||||||
#ifdef CUSTOM_BRANDING
|
|
||||||
printf("ircd: based on %s-%s\n", PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
#endif
|
|
||||||
printf("ircd: %s\n", rb_lib_version());
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_signals();
|
setup_signals();
|
||||||
|
|
||||||
server_state_foreground = true;
|
server_state_foreground = true;
|
||||||
|
|
Loading…
Reference in a new issue