Only call setgroups as root

setgroups fails when already running as a user.
This commit is contained in:
C. McEnroe 2020-08-16 22:20:14 -04:00
parent daac7db044
commit f9cfab1e0d

View File

@ -187,8 +187,10 @@ void serviceStart(struct Service *service) {
error = setgid(serviceGID);
if (error) err(ExitNoExec, "setgid");
error = setgroups(1, &serviceGID);
if (error) err(ExitNoExec, "setgroups");
if (!getuid()) {
error = setgroups(1, &serviceGID);
if (error) err(ExitNoExec, "setgroups");
}
error = setuid(serviceUID);
if (error) err(ExitNoExec, "setuid");