Fix Linux compile error.

This commit is contained in:
Jonathan Naylor
2016-05-05 18:06:05 +01:00
parent 07f8d26b17
commit 06825ca502

View File

@@ -36,6 +36,7 @@
#include <vector> #include <vector>
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
#include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h> #include <fcntl.h>
@@ -161,25 +162,22 @@ int CMMDVMHost::run()
#if !defined(HD44780) #if !defined(HD44780)
//If we are currently root... //If we are currently root...
if (getuid() == 0) { if (getuid() == 0) {
//get UID for mmdvm user struct passwd* user = ::getpwnam("mmdvm");
uid_t mmdvm_uid = getpwnam("mmdvm")->pw_uid; if (user == NULL) {
if (mmdvm_uid == NULL) { ::LogError("Could not get the mmdvm user, exiting");
::LogWarning("Could not get mmdvm UID, exiting"); return -1;
return -1; }
}
//get GID for mmdvm user uid_t mmdvm_uid = user->pw_uid;
gid_t mmdvm_gid = getpwnam("mmdvm")->pw_gid; gid_t mmdvm_gid = user->pw_gid;
if (mmdvm_gid == NULL) {
::LogWarning("Could not get mmdvm GID, exiting");
return -1;
}
//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;
} }