setegid()

Set the effective group ID for a process

Synopsis:

#include <unistd.h>

int setegid( gid_t gid );

Since:

BlackBerry 10.0.0

Arguments:

gid
The effective group ID that you want to use for the process.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The setegid() function lets the calling process set the effective group ID based on the following:

  • If the process has the PROCMGR_AID_SETGID ability enabled (see procmgr_ability()), the setegid() function sets the effective group ID to gid.
  • If the process doesn't have the PROCMGR_AID_SETGID ability enabled, but gid is equal to the real group ID or saved set-group ID, setegid() sets the effective group ID to gid.

The real and saved group ID aren't changed.

If a set-group ID process sets its effective group ID to its real group ID, it can still set its effective group ID back to the saved set-group ID.

Returns:

Zero for success, or -1 if an error occurs ( errno is set).

Errors:

EINVAL
The value of gid is out of range.
EPERM
The process doesn't have the PROCMGR_AID_SETGID ability enabled, and gid doesn't match the real group ID or the saved set-group ID.

Examples:

/*
 * This process sets its effective group ID to 2
 */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main( void )
{
    gid_t oegid;

    oegid = getegid();
    if( setegid( 2 ) == -1 ) {
        perror( "setegid" );
        return EXIT_FAILURE;
    }

    printf( "Was effective group %d, is 2\n", oegid );
    return EXIT_SUCCESS;
}

Classification:

POSIX 1003.1

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

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus