1
0
Fork 0

Add optional diabling of file rotation and UDP socket bug fixing.

ycs232-kbc
Jonathan Naylor 4 years ago
parent c9c7705628
commit 81170f53ee

@ -65,6 +65,7 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U), m_logFileLevel(0U),
m_logFilePath(), m_logFilePath(),
m_logFileRoot(), m_logFileRoot(),
m_logFileRotate(true),
m_aprsEnabled(false), m_aprsEnabled(false),
m_aprsAddress(), m_aprsAddress(),
m_aprsPort(0U), m_aprsPort(0U),
@ -216,6 +217,8 @@ bool CConf::read()
m_logFileLevel = (unsigned int)::atoi(value); m_logFileLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayLevel") == 0) else if (::strcmp(key, "DisplayLevel") == 0)
m_logDisplayLevel = (unsigned int)::atoi(value); m_logDisplayLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "FileRotate") == 0)
m_logFileRotate = ::atoi(value) == 1;
} else if (section == SECTION_APRS) { } else if (section == SECTION_APRS) {
if (::strcmp(key, "Enable") == 0) if (::strcmp(key, "Enable") == 0)
m_aprsEnabled = ::atoi(value) == 1; m_aprsEnabled = ::atoi(value) == 1;
@ -417,6 +420,11 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot; return m_logFileRoot;
} }
bool CConf::getLogFileRotate() const
{
return m_logFileRotate;
}
bool CConf::getAPRSEnabled() const bool CConf::getAPRSEnabled() const
{ {
return m_aprsEnabled; return m_aprsEnabled;

@ -76,6 +76,7 @@ public:
unsigned int getLogFileLevel() const; unsigned int getLogFileLevel() const;
std::string getLogFilePath() const; std::string getLogFilePath() const;
std::string getLogFileRoot() const; std::string getLogFileRoot() const;
bool getLogFileRotate() const;
// The APRS section // The APRS section
bool getAPRSEnabled() const; bool getAPRSEnabled() const;
@ -122,6 +123,7 @@ private:
unsigned int m_logFileLevel; unsigned int m_logFileLevel;
std::string m_logFilePath; std::string m_logFilePath;
std::string m_logFileRoot; std::string m_logFileRoot;
bool m_logFileRotate;
bool m_aprsEnabled; bool m_aprsEnabled;
std::string m_aprsAddress; std::string m_aprsAddress;

@ -169,9 +169,9 @@ int CDGIdGateway::run()
#endif #endif
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#else #else
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#endif #endif
if (!ret) { if (!ret) {
::fprintf(stderr, "DGIdGateway: unable to open the log file\n"); ::fprintf(stderr, "DGIdGateway: unable to open the log file\n");

@ -28,6 +28,7 @@ DisplayLevel=1
FileLevel=1 FileLevel=1
FilePath=. FilePath=.
FileRoot=DGIdGateway FileRoot=DGIdGateway
FileRotate=1
[APRS] [APRS]
Enable=0 Enable=0

@ -35,6 +35,7 @@
static unsigned int m_fileLevel = 2U; static unsigned int m_fileLevel = 2U;
static std::string m_filePath; static std::string m_filePath;
static std::string m_fileRoot; static std::string m_fileRoot;
static bool m_fileRotate = true;
static FILE* m_fpLog = NULL; static FILE* m_fpLog = NULL;
static bool m_daemon = false; static bool m_daemon = false;
@ -45,7 +46,7 @@ static struct tm m_tm;
static char LEVELS[] = " DMIWEF"; static char LEVELS[] = " DMIWEF";
static bool LogOpen() static bool logOpenRotate()
{ {
bool status = false; bool status = false;
@ -86,13 +87,51 @@ static bool LogOpen()
return status; return status;
} }
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) static bool logOpenNoRotate()
{
bool status = false;
if (m_fileLevel == 0U)
return true;
if (m_fpLog != NULL)
return true;
char filename[200U];
#if defined(_WIN32) || defined(_WIN64)
::sprintf(filename, "%s\\%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#else
::sprintf(filename, "%s/%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
status = true;
#if !defined(_WIN32) && !defined(_WIN64)
if (m_daemon)
dup2(fileno(m_fpLog), fileno(stderr));
#endif
}
return status;
}
bool LogOpen()
{
if (m_fileRotate)
return logOpenRotate();
else
return logOpenNoRotate();
}
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate)
{ {
m_filePath = filePath; m_filePath = filePath;
m_fileRoot = fileRoot; m_fileRoot = fileRoot;
m_fileLevel = fileLevel; m_fileLevel = fileLevel;
m_displayLevel = displayLevel; m_displayLevel = displayLevel;
m_daemon = daemon; m_daemon = daemon;
m_fileRotate = rotate;
if (m_daemon) if (m_daemon)
m_displayLevel = 0U; m_displayLevel = 0U;

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -30,7 +30,7 @@
extern void Log(unsigned int level, const char* fmt, ...); extern void Log(unsigned int level, const char* fmt, ...);
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate);
extern void LogFinalise(); extern void LogFinalise();
#endif #endif

@ -289,6 +289,12 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %lu", ::GetLastError()); LogError("Error returned from recvfrom, err: %lu", ::GetLastError());
#else #else
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port);
close();
open();
}
#endif #endif
return -1; return -1;
} }

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20201029"; const char* VERSION = "20201101";
#endif #endif

@ -64,6 +64,7 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U), m_logFileLevel(0U),
m_logFilePath(), m_logFilePath(),
m_logFileRoot(), m_logFileRoot(),
m_logFileRotate(true),
m_aprsEnabled(false), m_aprsEnabled(false),
m_aprsAddress(), m_aprsAddress(),
m_aprsPort(0U), m_aprsPort(0U),
@ -221,6 +222,8 @@ bool CConf::read()
m_logFileLevel = (unsigned int)::atoi(value); m_logFileLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayLevel") == 0) else if (::strcmp(key, "DisplayLevel") == 0)
m_logDisplayLevel = (unsigned int)::atoi(value); m_logDisplayLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "FileRotate") == 0)
m_logFileRotate = ::atoi(value) == 1;
} else if (section == SECTION_APRS) { } else if (section == SECTION_APRS) {
if (::strcmp(key, "Enable") == 0) if (::strcmp(key, "Enable") == 0)
m_aprsEnabled = ::atoi(value) == 1; m_aprsEnabled = ::atoi(value) == 1;
@ -410,6 +413,11 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot; return m_logFileRoot;
} }
bool CConf::getLogFileRotate() const
{
return m_logFileRotate;
}
bool CConf::getAPRSEnabled() const bool CConf::getAPRSEnabled() const
{ {
return m_aprsEnabled; return m_aprsEnabled;

@ -57,6 +57,7 @@ public:
unsigned int getLogFileLevel() const; unsigned int getLogFileLevel() const;
std::string getLogFilePath() const; std::string getLogFilePath() const;
std::string getLogFileRoot() const; std::string getLogFileRoot() const;
bool getLogFileRotate() const;
// The APRS section // The APRS section
bool getAPRSEnabled() const; bool getAPRSEnabled() const;
@ -127,6 +128,7 @@ private:
unsigned int m_logFileLevel; unsigned int m_logFileLevel;
std::string m_logFilePath; std::string m_logFilePath;
std::string m_logFileRoot; std::string m_logFileRoot;
bool m_logFileRotate;
bool m_aprsEnabled; bool m_aprsEnabled;
std::string m_aprsAddress; std::string m_aprsAddress;

@ -35,6 +35,7 @@
static unsigned int m_fileLevel = 2U; static unsigned int m_fileLevel = 2U;
static std::string m_filePath; static std::string m_filePath;
static std::string m_fileRoot; static std::string m_fileRoot;
static bool m_fileRotate = true;
static FILE* m_fpLog = NULL; static FILE* m_fpLog = NULL;
static bool m_daemon = false; static bool m_daemon = false;
@ -45,7 +46,7 @@ static struct tm m_tm;
static char LEVELS[] = " DMIWEF"; static char LEVELS[] = " DMIWEF";
static bool LogOpen() static bool logOpenRotate()
{ {
bool status = false; bool status = false;
@ -86,13 +87,51 @@ static bool LogOpen()
return status; return status;
} }
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) static bool logOpenNoRotate()
{
bool status = false;
if (m_fileLevel == 0U)
return true;
if (m_fpLog != NULL)
return true;
char filename[200U];
#if defined(_WIN32) || defined(_WIN64)
::sprintf(filename, "%s\\%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#else
::sprintf(filename, "%s/%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
status = true;
#if !defined(_WIN32) && !defined(_WIN64)
if (m_daemon)
dup2(fileno(m_fpLog), fileno(stderr));
#endif
}
return status;
}
bool LogOpen()
{
if (m_fileRotate)
return logOpenRotate();
else
return logOpenNoRotate();
}
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate)
{ {
m_filePath = filePath; m_filePath = filePath;
m_fileRoot = fileRoot; m_fileRoot = fileRoot;
m_fileLevel = fileLevel; m_fileLevel = fileLevel;
m_displayLevel = displayLevel; m_displayLevel = displayLevel;
m_daemon = daemon; m_daemon = daemon;
m_fileRotate = rotate;
if (m_daemon) if (m_daemon)
m_displayLevel = 0U; m_displayLevel = 0U;

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -30,7 +30,7 @@
extern void Log(unsigned int level, const char* fmt, ...); extern void Log(unsigned int level, const char* fmt, ...);
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate);
extern void LogFinalise(); extern void LogFinalise();
#endif #endif

@ -289,6 +289,12 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %lu", ::GetLastError()); LogError("Error returned from recvfrom, err: %lu", ::GetLastError());
#else #else
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port);
close();
open();
}
#endif #endif
return -1; return -1;
} }

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20200921"; const char* VERSION = "20201101";
#endif #endif

@ -171,9 +171,9 @@ int CYSFGateway::run()
#endif #endif
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#else #else
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#endif #endif
if (!ret) { if (!ret) {
::fprintf(stderr, "YSFGateway: unable to open the log file\n"); ::fprintf(stderr, "YSFGateway: unable to open the log file\n");

@ -28,6 +28,7 @@ DisplayLevel=1
FileLevel=1 FileLevel=1
FilePath=. FilePath=.
FileRoot=YSFGateway FileRoot=YSFGateway
FileRotate=1
[APRS] [APRS]
Enable=0 Enable=0

@ -289,6 +289,12 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %lu", ::GetLastError()); LogError("Error returned from recvfrom, err: %lu", ::GetLastError());
#else #else
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port);
close();
open();
}
#endif #endif
return -1; return -1;
} }

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20200920"; const char* VERSION = "20201101";
#endif #endif

@ -44,6 +44,7 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U), m_logFileLevel(0U),
m_logFilePath(), m_logFilePath(),
m_logFileRoot(), m_logFileRoot(),
m_logFileRotate(true),
m_networkPort(0U), m_networkPort(0U),
m_networkDebug(false) m_networkDebug(false)
{ {
@ -127,6 +128,8 @@ bool CConf::read()
m_logFileLevel = (unsigned int)::atoi(value); m_logFileLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayLevel") == 0) else if (::strcmp(key, "DisplayLevel") == 0)
m_logDisplayLevel = (unsigned int)::atoi(value); m_logDisplayLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "FileRotate") == 0)
m_logFileRotate = ::atoi(value) == 1;
} else if (section == SECTION_NETWORK) { } else if (section == SECTION_NETWORK) {
if (::strcmp(key, "Port") == 0) if (::strcmp(key, "Port") == 0)
m_networkPort = (unsigned int)::atoi(value); m_networkPort = (unsigned int)::atoi(value);
@ -180,6 +183,11 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot; return m_logFileRoot;
} }
bool CConf::getLogFileRotate() const
{
return m_logFileRotate;
}
unsigned int CConf::getNetworkPort() const unsigned int CConf::getNetworkPort() const
{ {
return m_networkPort; return m_networkPort;

@ -43,6 +43,7 @@ public:
unsigned int getLogFileLevel() const; unsigned int getLogFileLevel() const;
std::string getLogFilePath() const; std::string getLogFilePath() const;
std::string getLogFileRoot() const; std::string getLogFileRoot() const;
bool getLogFileRotate() const;
// The Network section // The Network section
unsigned int getNetworkPort() const; unsigned int getNetworkPort() const;
@ -60,6 +61,7 @@ private:
unsigned int m_logFileLevel; unsigned int m_logFileLevel;
std::string m_logFilePath; std::string m_logFilePath;
std::string m_logFileRoot; std::string m_logFileRoot;
bool m_logFileRotate;
unsigned int m_networkPort; unsigned int m_networkPort;
bool m_networkDebug; bool m_networkDebug;

@ -35,6 +35,7 @@
static unsigned int m_fileLevel = 2U; static unsigned int m_fileLevel = 2U;
static std::string m_filePath; static std::string m_filePath;
static std::string m_fileRoot; static std::string m_fileRoot;
static bool m_fileRotate = true;
static FILE* m_fpLog = NULL; static FILE* m_fpLog = NULL;
static bool m_daemon = false; static bool m_daemon = false;
@ -45,7 +46,7 @@ static struct tm m_tm;
static char LEVELS[] = " DMIWEF"; static char LEVELS[] = " DMIWEF";
static bool LogOpen() static bool logOpenRotate()
{ {
bool status = false; bool status = false;
@ -86,13 +87,51 @@ static bool LogOpen()
return status; return status;
} }
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) static bool logOpenNoRotate()
{
bool status = false;
if (m_fileLevel == 0U)
return true;
if (m_fpLog != NULL)
return true;
char filename[200U];
#if defined(_WIN32) || defined(_WIN64)
::sprintf(filename, "%s\\%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#else
::sprintf(filename, "%s/%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
status = true;
#if !defined(_WIN32) && !defined(_WIN64)
if (m_daemon)
dup2(fileno(m_fpLog), fileno(stderr));
#endif
}
return status;
}
bool LogOpen()
{
if (m_fileRotate)
return logOpenRotate();
else
return logOpenNoRotate();
}
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate)
{ {
m_filePath = filePath; m_filePath = filePath;
m_fileRoot = fileRoot; m_fileRoot = fileRoot;
m_fileLevel = fileLevel; m_fileLevel = fileLevel;
m_displayLevel = displayLevel; m_displayLevel = displayLevel;
m_daemon = daemon; m_daemon = daemon;
m_fileRotate = rotate;
if (m_daemon) if (m_daemon)
m_displayLevel = 0U; m_displayLevel = 0U;

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -30,7 +30,7 @@
extern void Log(unsigned int level, const char* fmt, ...); extern void Log(unsigned int level, const char* fmt, ...);
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate);
extern void LogFinalise(); extern void LogFinalise();
#endif #endif

@ -289,6 +289,12 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %lu", ::GetLastError()); LogError("Error returned from recvfrom, err: %lu", ::GetLastError());
#else #else
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port);
close();
open();
}
#endif #endif
return -1; return -1;
} }

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20200920"; const char* VERSION = "20201101";
#endif #endif

@ -151,9 +151,9 @@ void CYSFReflector::run()
#endif #endif
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#else #else
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
#endif #endif
if (!ret) { if (!ret) {
::fprintf(stderr, "YSFReflector: unable to open the log file\n"); ::fprintf(stderr, "YSFReflector: unable to open the log file\n");

@ -14,6 +14,7 @@ DisplayLevel=1
FileLevel=1 FileLevel=1
FilePath=. FilePath=.
FileRoot=YSFReflector FileRoot=YSFReflector
FileRotate=1
[Network] [Network]
Port=42000 Port=42000

Loading…
Cancel
Save