9.78 getgroups/setgroups

int getgroups(size_t size, gid_t list[]);
int setgroups(size_t size, const gid_t *list);

This syscall gets and sets the supplementary user groups of the caller process. The stored group IDs, along with the effective GID, will be used to check permission for file access. among others permission checks.

getgroups does not return the effective GID of the caller process on the list. POSIX leaves whether the effective GID is included on this list as an implementation detail, so portable programs should be ready for that scenario.

Init starts with an empty array of supplementary group IDs.

Passing 0 and NULL to setgroups will empty the supplementary group list.

getgroups returns the number of supplementary groups or -1 on failure, setgroups returns 0 on success and -1 on failure, both with the following errno:

EINVAL

getgroups size is less than the number of supplementary group IDs.