Cleaning up indenting.
This commit is contained in:
parent
4b72c936ce
commit
e9e8745aa7
125
MMDVMHost.cpp
125
MMDVMHost.cpp
|
@ -66,8 +66,8 @@ static int m_signal = 0;
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
static void sigHandler(int signum)
|
static void sigHandler(int signum)
|
||||||
{
|
{
|
||||||
m_killed = true;
|
m_killed = true;
|
||||||
m_signal = signum;
|
m_signal = signum;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,47 +78,47 @@ const char* HEADER4 = "Copyright(C) 2015-2017 by Jonathan Naylor, G4KLX and othe
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
const char* iniFile = DEFAULT_INI_FILE;
|
const char* iniFile = DEFAULT_INI_FILE;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
for (int currentArg = 1; currentArg < argc; ++currentArg) {
|
for (int currentArg = 1; currentArg < argc; ++currentArg) {
|
||||||
std::string arg = argv[currentArg];
|
std::string arg = argv[currentArg];
|
||||||
if ((arg == "-v") || (arg == "--version")) {
|
if ((arg == "-v") || (arg == "--version")) {
|
||||||
::fprintf(stdout, "MMDVMHost version %s git #%.7s\n", VERSION, gitversion);
|
::fprintf(stdout, "MMDVMHost version %s git #%.7s\n", VERSION, gitversion);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (arg.substr(0,1) == "-") {
|
} else if (arg.substr(0,1) == "-") {
|
||||||
::fprintf(stderr, "Usage: MMDVMHost [-v|--version] [filename]\n");
|
::fprintf(stderr, "Usage: MMDVMHost [-v|--version] [filename]\n");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
iniFile = argv[currentArg];
|
iniFile = argv[currentArg];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
::signal(SIGTERM, sigHandler);
|
::signal(SIGTERM, sigHandler);
|
||||||
::signal(SIGHUP, sigHandler);
|
::signal(SIGHUP, sigHandler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
m_signal = 0;
|
m_signal = 0;
|
||||||
|
|
||||||
CMMDVMHost* host = new CMMDVMHost(std::string(iniFile));
|
CMMDVMHost* host = new CMMDVMHost(std::string(iniFile));
|
||||||
ret = host->run();
|
ret = host->run();
|
||||||
|
|
||||||
delete host;
|
delete host;
|
||||||
|
|
||||||
if (m_signal == 15)
|
if (m_signal == 15)
|
||||||
::LogInfo("Caught SIGTERM, exiting");
|
::LogInfo("Caught SIGTERM, exiting");
|
||||||
|
|
||||||
if (m_signal == 1)
|
if (m_signal == 1)
|
||||||
::LogInfo("Caught SIGHUP, restarting");
|
::LogInfo("Caught SIGHUP, restarting");
|
||||||
} while (m_signal == 1);
|
} while (m_signal == 1);
|
||||||
|
|
||||||
::LogFinalise();
|
::LogFinalise();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMMDVMHost::CMMDVMHost(const std::string& confFile) :
|
CMMDVMHost::CMMDVMHost(const std::string& confFile) :
|
||||||
|
@ -173,61 +173,58 @@ int CMMDVMHost::run()
|
||||||
// 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");
|
LogWarning("Couldn't fork() , exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} 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");
|
LogWarning("Couldn't setsid(), exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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");
|
LogWarning("Couldn't cd /, exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
::close(STDIN_FILENO);
|
::close(STDIN_FILENO);
|
||||||
::close(STDOUT_FILENO);
|
::close(STDOUT_FILENO);
|
||||||
::close(STDERR_FILENO);
|
::close(STDERR_FILENO);
|
||||||
|
|
||||||
#if !defined(HD44780) && !defined(OLED)
|
#if !defined(HD44780) && !defined(OLED)
|
||||||
//If we are currently root...
|
//If we are currently root...
|
||||||
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");
|
LogError("Could not get the mmdvm user, exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uid_t mmdvm_uid = user->pw_uid;
|
uid_t mmdvm_uid = user->pw_uid;
|
||||||
gid_t mmdvm_gid = user->pw_gid;
|
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) {
|
if (::setgid(mmdvm_gid) != 0) {
|
||||||
::LogWarning("Could not set mmdvm GID, exiting");
|
LogWarning("Could not set mmdvm GID, exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setuid(mmdvm_uid) != 0) {
|
if (::setuid(mmdvm_uid) != 0) {
|
||||||
::LogWarning("Could not set mmdvm UID, exiting");
|
LogWarning("Could not set mmdvm UID, exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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");
|
LogWarning("It's possible to regain root - something is wrong!, exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
::LogWarning("Dropping root permissions in daemon mode is disabled with HD44780 display");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue