MCPcopy Create free account
hub / github.com/cppla/ServerStatus / main

Function main

server/src/main.cpp:1065–1120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1063}
1064
1065int main(int argc, const char *argv[])
1066{
1067 int RetVal;
1068 dbg_logger_stdout();
1069
1070 #if defined(CONF_FAMILY_UNIX)
1071 signal(SIGINT, ExitFunc);
1072 signal(SIGTERM, ExitFunc);
1073 signal(SIGQUIT, ExitFunc);
1074 signal(SIGHUP, ReloadFunc);
1075 #endif
1076
1077 char aUsage[128];
1078 CConfig Config;
1079 str_format(aUsage, sizeof(aUsage), "%s [options]", argv[0]);
1080 const char *pConfigFile = 0;
1081 const char *pWebDir = 0;
1082 const char *pBindAddr = 0;
1083
1084 struct argparse_option aOptions[] = {
1085 OPT_HELP(),
1086 OPT_BOOLEAN('v', "verbose", &Config.m_Verbose, "Verbose output", 0),
1087 OPT_STRING('c', "config", &pConfigFile, "Config file to use", 0),
1088 OPT_STRING('d', "web-dir", &pWebDir, "Location of the web directory", 0),
1089 OPT_STRING('b', "bind", &pBindAddr, "Bind to address", 0),
1090 OPT_INTEGER('p', "port", &Config.m_Port, "Listen on port", 0),
1091 OPT_END(),
1092 };
1093 struct argparse Argparse;
1094 argparse_init(&Argparse, aOptions, aUsage, 0);
1095 argc = argparse_parse(&Argparse, argc, argv);
1096
1097 if(pConfigFile)
1098 str_copy(Config.m_aConfigFile, pConfigFile, sizeof(Config.m_aConfigFile));
1099 if(pWebDir)
1100 str_copy(Config.m_aWebDir, pWebDir, sizeof(Config.m_aWebDir));
1101 if(pBindAddr)
1102 str_copy(Config.m_aBindAddr, pBindAddr, sizeof(Config.m_aBindAddr));
1103
1104 if(Config.m_aWebDir[strlen(Config.m_aWebDir)-1] != '/')
1105 str_append(Config.m_aWebDir, "/", sizeof(Config.m_aWebDir));
1106 if(!fs_is_dir(Config.m_aWebDir))
1107 {
1108 dbg_msg("main", "ERROR: Can't find web directory: %s", Config.m_aWebDir);
1109 return 1;
1110 }
1111
1112 char aTmp[1024];
1113 str_format(aTmp, sizeof(aTmp), "%s%s", Config.m_aWebDir, Config.m_aJSONFile);
1114 str_copy(Config.m_aJSONFile, aTmp, sizeof(Config.m_aJSONFile));
1115
1116 CMain Main(Config);
1117 RetVal = Main.Run();
1118
1119 return RetVal;
1120}
1121

Callers

nothing calls this directly

Calls 9

dbg_logger_stdoutFunction · 0.85
str_formatFunction · 0.85
argparse_initFunction · 0.85
argparse_parseFunction · 0.85
str_copyFunction · 0.85
str_appendFunction · 0.85
fs_is_dirFunction · 0.85
dbg_msgFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected