mirror of
https://github.com/g4klx/DAPNETGateway.git
synced 2026-08-26 12:32:45 -04:00
Upgrade the version and signal handling.
This commit is contained in:
parent
e677d6a954
commit
f0a271ae53
3 changed files with 57 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@ Debug
|
|||
Release
|
||||
x64
|
||||
DAPNETGateway
|
||||
GitVersion.h
|
||||
*.o
|
||||
*.opendb
|
||||
*.bak
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
#include "Timer.h"
|
||||
#include "Log.h"
|
||||
#include "REGEX.h"
|
||||
#include "GitVersion.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
|
@ -77,6 +79,17 @@ const unsigned char FUNCTIONAL_ALPHANUMERIC = 3U;
|
|||
|
||||
const unsigned int MAX_TIME_TO_HOLD_TIME_MESSAGES = 15000U; // 15s
|
||||
|
||||
static bool m_killed = false;
|
||||
static int m_signal = 0;
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
static void sigHandler(int signum)
|
||||
{
|
||||
m_killed = true;
|
||||
m_signal = signum;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* iniFile = DEFAULT_INI_FILE;
|
||||
|
|
@ -84,7 +97,7 @@ int main(int argc, char** argv)
|
|||
for (int currentArg = 1; currentArg < argc; ++currentArg) {
|
||||
std::string arg = argv[currentArg];
|
||||
if ((arg == "-v") || (arg == "--version")) {
|
||||
::fprintf(stdout, "DAPNETGateway version %s\n", VERSION);
|
||||
::fprintf(stdout, "DAPNETGateway version %s git #%.7s\n", VERSION, gitversion);
|
||||
return 0;
|
||||
} else if (arg.substr(0, 1) == "-") {
|
||||
::fprintf(stderr, "Usage: DAPNETGateway [-v|--version] [filename]\n");
|
||||
|
|
@ -95,11 +108,33 @@ int main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
CDAPNETGateway* gateway = new CDAPNETGateway(std::string(iniFile));
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
::signal(SIGINT, sigHandler);
|
||||
::signal(SIGTERM, sigHandler);
|
||||
::signal(SIGHUP, sigHandler);
|
||||
#endif
|
||||
|
||||
int ret = gateway->run();
|
||||
int ret = 0;
|
||||
|
||||
delete gateway;
|
||||
do {
|
||||
m_signal = 0;
|
||||
|
||||
CDAPNETGateway* gateway = new CDAPNETGateway(std::string(iniFile));
|
||||
ret = gateway->run();
|
||||
delete gateway;
|
||||
|
||||
if (m_signal == 2)
|
||||
::LogInfo("DAPNETGateway-%s exited on receipt of SIGINT", VERSION);
|
||||
|
||||
if (m_signal == 15)
|
||||
::LogInfo("DAPNETGateway-%s exited on receipt of SIGTERM", VERSION);
|
||||
|
||||
if (m_signal == 1)
|
||||
::LogInfo("DAPNETGateway-%s restarted on receipt of SIGHUP", VERSION);
|
||||
|
||||
} while (m_signal == 1);
|
||||
|
||||
::LogFinalise();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -255,8 +290,6 @@ int CDAPNETGateway::run()
|
|||
return 1;
|
||||
}
|
||||
|
||||
LogMessage("Starting DAPNETGateway-%s", VERSION);
|
||||
|
||||
ret = m_dapnetNetwork->login();
|
||||
if (!ret) {
|
||||
m_pocsagNetwork->close();
|
||||
|
|
@ -286,6 +319,8 @@ int CDAPNETGateway::run()
|
|||
if (m_regexWhitelist->load())
|
||||
regexWhitelist = m_regexWhitelist->get();
|
||||
|
||||
LogMessage("DAPNETGateway-%s is starting", VERSION);
|
||||
LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
|
||||
|
||||
for (;;) {
|
||||
unsigned char buffer[200U];
|
||||
|
|
|
|||
15
Makefile
15
Makefile
|
|
@ -15,8 +15,23 @@ DAPNETGateway: $(OBJECTS)
|
|||
%.o: %.cpp
|
||||
$(CXX) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
DAPNETGateway.o: GitVersion.h FORCE
|
||||
|
||||
.PHONY: GitVersion.h
|
||||
|
||||
FORCE:
|
||||
|
||||
install:
|
||||
install -m 755 DAPNETGateway /usr/local/bin/
|
||||
|
||||
clean:
|
||||
$(RM) DAPNETGateway *.o *.d *.bak *~
|
||||
|
||||
# Export the current git version if the index file exists, else 000...
|
||||
GitVersion.h:
|
||||
ifneq ("$(wildcard .git/index)","")
|
||||
echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > $@
|
||||
else
|
||||
echo "const char *gitversion = \"0000000000000000000000000000000000000000\";" > $@
|
||||
endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue