Move the position of LogInitialise.

This commit is contained in:
Jonathan Naylor 2018-06-18 18:53:56 +01:00
parent 12a87b6897
commit f1e6db8db7

View file

@ -102,33 +102,27 @@ int CDAPNETGateway::run()
setlocale(LC_ALL, "C");
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
if (!ret) {
::fprintf(stderr, "DAPNETGateway: 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)
} 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;
}
@ -136,37 +130,43 @@ int CDAPNETGateway::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(), m_conf.getLogDisplayLevel());
if (!ret) {
::fprintf(stderr, "DAPNETGateway: unable to open the log file\n");
return 1;
}
bool debug = m_conf.getDAPNETDebug();
std::string rptAddress = m_conf.getRptAddress();