From a7c382683ea6ed2b0c4284d2999c9aae2643ca02 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 18 Jun 2018 18:50:47 +0100 Subject: [PATCH] Move the location of LogInitialise. --- NXDNGateway/NXDNGateway.cpp | 36 ++++++++++++++++----------------- NXDNReflector/NXDNReflector.cpp | 36 ++++++++++++++++----------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/NXDNGateway/NXDNGateway.cpp b/NXDNGateway/NXDNGateway.cpp index 71e4722..b1ed1fe 100644 --- a/NXDNGateway/NXDNGateway.cpp +++ b/NXDNGateway/NXDNGateway.cpp @@ -103,33 +103,27 @@ void CNXDNGateway::run() return; } - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), 1U, 1U); - if (!ret) { - ::fprintf(stderr, "NXDNGateway: unable to open the log file\n"); - return; - } - #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; - } - else if (pid != 0) + } 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; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return; } @@ -137,37 +131,43 @@ void CNXDNGateway::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; } 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; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return; } - //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; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), 1U, 1U); + if (!ret) { + ::fprintf(stderr, "NXDNGateway: unable to open the log file\n"); + return; + } + in_addr rptAddr = CUDPSocket::lookup(m_conf.getRptAddress()); unsigned int rptPort = m_conf.getRptPort(); diff --git a/NXDNReflector/NXDNReflector.cpp b/NXDNReflector/NXDNReflector.cpp index ae980ac..31ab8ec 100644 --- a/NXDNReflector/NXDNReflector.cpp +++ b/NXDNReflector/NXDNReflector.cpp @@ -96,33 +96,27 @@ void CNXDNReflector::run() return; } - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); - if (!ret) { - ::fprintf(stderr, "NXDNReflector: unable to open the log file\n"); - return; - } - #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; - } - else if (pid != 0) + } 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; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return; } @@ -130,37 +124,43 @@ void CNXDNReflector::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; } 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; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return; } - //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; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); + if (!ret) { + ::fprintf(stderr, "NXDNReflector: unable to open the log file\n"); + return; + } + unsigned short tg = m_conf.getTG(); CNXDNNetwork nxdnNetwork(m_conf.getNetworkPort(), m_conf.getNetworkDebug());