|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 by Jonathan Naylor G4KLX
|
|
|
|
* Copyright (C) 2016,2018 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
|
|
|
@ -93,33 +93,27 @@ void CYSFReflector::run()
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
|
|
|
|
::fprintf(stderr, "YSFReflector: unable to open the log file\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
bool m_daemon = m_conf.getDaemon();
|
|
|
|
bool m_daemon = m_conf.getDaemon();
|
|
|
|
if (m_daemon) {
|
|
|
|
if (m_daemon) {
|
|
|
|
// Create new process
|
|
|
|
// Create new process
|
|
|
|
pid_t pid = ::fork();
|
|
|
|
pid_t pid = ::fork();
|
|
|
|
if (pid == -1) {
|
|
|
|
if (pid == -1) {
|
|
|
|
::LogWarning("Couldn't fork() , exiting");
|
|
|
|
::fprintf(stderr, "Couldn't fork() , exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (pid != 0) {
|
|
|
|
else if (pid != 0)
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create new session and process group
|
|
|
|
// Create new session and process group
|
|
|
|
if (::setsid() == -1) {
|
|
|
|
if (::setsid() == -1) {
|
|
|
|
::LogWarning("Couldn't setsid(), exiting");
|
|
|
|
::fprintf(stderr, "Couldn't setsid(), exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the working directory to the root directory
|
|
|
|
// Set the working directory to the root directory
|
|
|
|
if (::chdir("/") == -1) {
|
|
|
|
if (::chdir("/") == -1) {
|
|
|
|
::LogWarning("Couldn't cd /, exiting");
|
|
|
|
::fprintf(stderr, "Couldn't cd /, exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -131,7 +125,7 @@ void CYSFReflector::run()
|
|
|
|
if (getuid() == 0) {
|
|
|
|
if (getuid() == 0) {
|
|
|
|
struct passwd* user = ::getpwnam("mmdvm");
|
|
|
|
struct passwd* user = ::getpwnam("mmdvm");
|
|
|
|
if (user == NULL) {
|
|
|
|
if (user == NULL) {
|
|
|
|
::LogError("Could not get the mmdvm user, exiting");
|
|
|
|
::fprintf(stderr, "Could not get the mmdvm user, exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -140,24 +134,30 @@ void CYSFReflector::run()
|
|
|
|
|
|
|
|
|
|
|
|
// Set user and group ID's to mmdvm:mmdvm
|
|
|
|
// Set user and group ID's to mmdvm:mmdvm
|
|
|
|
if (setgid(mmdvm_gid) != 0) {
|
|
|
|
if (setgid(mmdvm_gid) != 0) {
|
|
|
|
::LogWarning("Could not set mmdvm GID, exiting");
|
|
|
|
::fprintf(stderr, "Could not set mmdvm GID, exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (setuid(mmdvm_uid) != 0) {
|
|
|
|
if (setuid(mmdvm_uid) != 0) {
|
|
|
|
::LogWarning("Could not set mmdvm UID, exiting");
|
|
|
|
::fprintf(stderr, "Could not set mmdvm UID, exiting\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Double check it worked (AKA Paranoia)
|
|
|
|
// Double check it worked (AKA Paranoia)
|
|
|
|
if (setuid(0) != -1) {
|
|
|
|
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;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
|
|
|
|
::fprintf(stderr, "YSFReflector: unable to open the log file\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CNetwork network(m_conf.getNetworkPort(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug());
|
|
|
|
CNetwork network(m_conf.getNetworkPort(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug());
|
|
|
|
|
|
|
|
|
|
|
|
ret = network.open();
|
|
|
|
ret = network.open();
|
|
|
|