modify init setgid

Signed-off-by: zhong_ning <zhong_ning@hoperun.com>
This commit is contained in:
zhong_ning 2021-08-10 22:40:20 +08:00
parent a3f82ef4e6
commit 1401f9c0fa

View File

@ -77,13 +77,13 @@ static int SetAllAmbientCapability()
static int SetPerms(const Service *service)
{
if (KeepCapability() != 0) {
return SERVICE_FAILURE;
}
if (setgroups(service->servPerm.gIDCnt, service->servPerm.gIDArray) != 0) {
INIT_LOGE("SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt);
return SERVICE_FAILURE;
INIT_CHECK_RETURN_VALUE(KeepCapability() == 0, SERVICE_FAILURE);
if (service->servPerm.gIDCnt == 1) {
INIT_ERROR_CHECK(setgid(service->servPerm.gIDArray[0]) == 0, return SERVICE_FAILURE,
"SetPerms, setgid for %s failed. %d", service->name, errno);
} else if (service->servPerm.gIDCnt > 1){
INIT_ERROR_CHECK(setgroups(service->servPerm.gIDCnt, service->servPerm.gIDArray) == 0, return SERVICE_FAILURE,
"SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt);
}
if (service->servPerm.uID != 0) {