Merge branch 'master' into pocsag
This commit is contained in:
commit
5cf86578fc
|
@ -182,19 +182,13 @@ int CMMDVMHost::run()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
|
||||||
if (!ret) {
|
|
||||||
::fprintf(stderr, "MMDVMHost: unable to open the log file\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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 -1;
|
return -1;
|
||||||
} else if (pid != 0) {
|
} else if (pid != 0) {
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
@ -202,13 +196,13 @@ int CMMDVMHost::run()
|
||||||
|
|
||||||
// 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 -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");
|
::fprintf(stderr, "Couldn't cd /, exiting\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,41 +211,48 @@ int CMMDVMHost::run()
|
||||||
::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");
|
::fprintf(stderr, "Could not get the mmdvm user, exiting\n");
|
||||||
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");
|
::fprintf(stderr, "Could not set mmdvm GID, exiting\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 -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");
|
::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
LogWarning("Dropping root permissions in daemon mode is disabled with HD44780 display");
|
::fprintf(stderr, "Dropping root permissions in daemon mode is disabled with HD44780 display\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
||||||
|
if (!ret) {
|
||||||
|
::fprintf(stderr, "MMDVMHost: unable to open the log file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LogInfo(HEADER1);
|
LogInfo(HEADER1);
|
||||||
LogInfo(HEADER2);
|
LogInfo(HEADER2);
|
||||||
LogInfo(HEADER3);
|
LogInfo(HEADER3);
|
||||||
|
|
Loading…
Reference in a new issue