From c7e02fecd0467954d9cb0110b569103825990b6b Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sat, 21 Jul 2018 23:31:57 -0400 Subject: [PATCH] Move log LogInitialise() --- DMR2NXDN/DMR2NXDN.cpp | 32 ++++++++++++++++---------------- DMR2YSF/DMR2YSF.cpp | 32 ++++++++++++++++---------------- NXDN2DMR/NXDN2DMR.cpp | 32 ++++++++++++++++---------------- YSF2DMR/YSF2DMR.cpp | 32 ++++++++++++++++---------------- YSF2NXDN/YSF2NXDN.cpp | 26 +++++++++++++------------- YSF2P25/YSF2P25.cpp | 32 ++++++++++++++++---------------- 6 files changed, 93 insertions(+), 93 deletions(-) diff --git a/DMR2NXDN/DMR2NXDN.cpp b/DMR2NXDN/DMR2NXDN.cpp index d81e95d..67cb14f 100644 --- a/DMR2NXDN/DMR2NXDN.cpp +++ b/DMR2NXDN/DMR2NXDN.cpp @@ -132,32 +132,26 @@ int CDMR2NXDN::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "DMR2NXDN: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -165,37 +159,43 @@ int CDMR2NXDN::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "DMR2NXDN: unable to open the log file\n"); + return 1; + } + m_defsrcid = m_conf.getDMRId(); std::string gatewayAddress = m_conf.getDstAddress(); diff --git a/DMR2YSF/DMR2YSF.cpp b/DMR2YSF/DMR2YSF.cpp index eaec6ad..38194d8 100644 --- a/DMR2YSF/DMR2YSF.cpp +++ b/DMR2YSF/DMR2YSF.cpp @@ -135,32 +135,26 @@ int CDMR2YSF::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "DMR2YSF: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -168,37 +162,43 @@ int CDMR2YSF::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "DMR2YSF: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_defsrcid = m_conf.getDMRId(); diff --git a/NXDN2DMR/NXDN2DMR.cpp b/NXDN2DMR/NXDN2DMR.cpp index b3d22b4..74cb426 100644 --- a/NXDN2DMR/NXDN2DMR.cpp +++ b/NXDN2DMR/NXDN2DMR.cpp @@ -136,32 +136,26 @@ int CNXDN2DMR::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "NXDN2DMR: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -169,37 +163,43 @@ int CNXDN2DMR::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "NXDN2DMR: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_nxdnTG = m_conf.getTG(); diff --git a/YSF2DMR/YSF2DMR.cpp b/YSF2DMR/YSF2DMR.cpp index f01fe23..8c8a5b0 100644 --- a/YSF2DMR/YSF2DMR.cpp +++ b/YSF2DMR/YSF2DMR.cpp @@ -141,32 +141,26 @@ int CYSF2DMR::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "YSF2DMR: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -174,37 +168,43 @@ int CYSF2DMR::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "YSF2DMR: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_suffix = m_conf.getSuffix(); diff --git a/YSF2NXDN/YSF2NXDN.cpp b/YSF2NXDN/YSF2NXDN.cpp index f094ca3..2560fbb 100644 --- a/YSF2NXDN/YSF2NXDN.cpp +++ b/YSF2NXDN/YSF2NXDN.cpp @@ -134,32 +134,26 @@ int CYSF2NXDN::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "YSF2NXDN: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -171,7 +165,7 @@ int CYSF2NXDN::run() if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } @@ -180,24 +174,30 @@ int CYSF2NXDN::run() //Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } //Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "YSF2NXDN: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_suffix = m_conf.getSuffix(); m_defsrcid = m_conf.getNXDNId(); diff --git a/YSF2P25/YSF2P25.cpp b/YSF2P25/YSF2P25.cpp index 84eaec4..e2b049b 100644 --- a/YSF2P25/YSF2P25.cpp +++ b/YSF2P25/YSF2P25.cpp @@ -186,32 +186,26 @@ int CYSF2P25::run() logDisplayLevel = 0U; #endif - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); - if (!ret) { - ::fprintf(stderr, "YSF2P25: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } else if (pid != 0) exit(EXIT_SUCCESS); // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -219,37 +213,43 @@ int CYSF2P25::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), logDisplayLevel); + if (!ret) { + ::fprintf(stderr, "YSF2P25: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_defsrcid = m_conf.getP25Id(); m_dstid = m_conf.getP25DstId();