代码拉取完成,页面将自动刷新
#include "daemon.hpp"
int main()
{
try
{
WORD wLastMs = 0;
Yaml::Node conf;
locale::global(locale(""));
system("title daemon - main");
EnableDebugPrivilege();
bool mainDaemon = true;
DWORD dwChildPid = 0;
BASEINFO baseInfo = { 0 };
list<PROCINFO> procInfoList = EnumProcInfo();
InitBaseInfo(baseInfo, procInfoList);
while (true)
{
SYSTEMTIME stLastWrite = GetLastWriteTime("conf.yml");
if (wLastMs == 0)
wLastMs = stLastWrite.wMilliseconds;
else if (wLastMs != stLastWrite.wMilliseconds) {
Log(L"conf.yml has been changed");
conf.Clear();
wLastMs = stLastWrite.wMilliseconds;
Log(L"empty configuration, need to reload conf.yml");
}
if (conf.IsNone())
{
Log(L"loading conf.yml");
Yaml::Parse(conf, "conf.yml");
Log(L"loading conf.yml completed");
}
bool become2child = baseInfo.wsName == baseInfo.wsPname && IsProcessAlive(baseInfo.dwPpid);
if (become2child && mainDaemon)
{
mainDaemon = false;
system("title daemon - child");
Log(L"main process exist, election become to child process");
}
else if (!become2child && !mainDaemon)
{
mainDaemon = true;
system("title daemon - main");
Log(L"main process not exist, election become to main process");
}
if (mainDaemon)
{
if (!dwChildPid || !IsProcessAlive(dwChildPid))
{
Log(L"child daemon not exist, try create child daemon");
dwChildPid = StartupProcess(baseInfo.wsName, conf["daemon"]["hide"].As<bool>() ? CREATE_NO_WINDOW : CREATE_NEW_CONSOLE);
if (!dwChildPid)
Log(L"create child daemon fail, something was wrong");
}
bool keepAlive = conf["keep-alive"].IsNone();
bool timingShutdown = conf["timing-shutdown"].IsNone();
bool intervalShutdown = conf["interval-shutdown"].IsNone();
bool windowMessage = conf["window-message"].IsNone();
if (!keepAlive || !timingShutdown || !intervalShutdown)
procInfoList = EnumProcInfo(timingShutdown || intervalShutdown);
if (!keepAlive)
KeepAlive(conf["keep-alive"], procInfoList);
if (!timingShutdown)
TimingShutdown(conf["timing-shutdown"], procInfoList);
if (!intervalShutdown)
IntervalShutdown(conf["interval-shutdown"], procInfoList);
if (!windowMessage)
WindowMessage(conf["window-message"]);
}
Sleep(conf["daemon"]["interval"].As<int>());
}
}
catch (runtime_error e)
{
Log(L"runtime error, " + ansi2unicode(string(e.what())) + L", abort");
}
catch (...)
{
Log(L"unknown error, abort");
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。