13 #include <sys/types.h> 24 #include <condition_variable> 33 void TerminateSignal(
int signum)
35 std::cout <<
"terminating.." << std::endl;
40 DaemonInstance =
nullptr;
50 if (signal(SIGTERM, TerminateSignal) == SIG_ERR)
52 std::cerr <<
"unable to set SIGTERM handler" << std::endl;
55 if (signal(SIGINT, TerminateSignal) == SIG_ERR)
57 std::cerr <<
"unable to set SIGINT handler" << std::endl;
60 if (signal(SIGSTOP, TerminateSignal) == SIG_ERR)
62 std::cerr <<
"unable to set SIGSTOP handler" << std::endl;
65 DaemonInstance =
this;
76 std::cerr <<
"Failed to fork: " << strerror(errno) << std::endl;
91 std::cerr <<
"setsid() failed: " << strerror(errno) << std::endl;
97 std::cerr <<
"Cannot change dir. " << strerror(errno) << std::endl;
101 if (!logFile.empty())
103 FILE * tmp = fopen(logFile.c_str(),
"w");
107 std::cerr <<
"Cannot open log file " << logFile <<
". " << strerror(errno) << std::endl;
112 close(STDOUT_FILENO);
113 close(STDERR_FILENO);
115 dup2(fileno(tmp), STDOUT_FILENO);
116 dup2(fileno(tmp), STDERR_FILENO);
OPC UA Address space part. GNU LGPL.
void Daemonize(const std::string &str)
void SetTerminateHandlers()