[Previous] [Contents] [Index] [Next]

setgid()

Set the real, effective and saved group IDs

Synopsis:

#include <unistd.h>

int setgid( gid_t gid );

Library:

libc

Description:

The setgid() function allows the calling process to set the real, effective and saved group IDs, based on the following:

This function doesn't change any supplementary group IDs of the calling process.

If you wish to change only the effective group ID, even if you have appropriate privileges, you should consider using the setegid() function.

Returns:

0
Success.
-1
An error occurred; errno is set to indicate the error.

Errors:

EINVAL
The value of gid is invalid.
EPERM
The process doesn't have appropriate privileges, and gid doesn't match the real group ID.

Examples:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main( void )
  {
    gid_t ogid;

    ogid = getgid();
    if( setgid( 2 ) == -1 ) {
       perror( "setgid" );
       return EXIT_FAILURE;
    }
    printf( "group id is now 2, was %d\n", ogid );
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, setegid(), seteuid(), setuid()


[Previous] [Contents] [Index] [Next]