Set the real, effective and saved set-group IDs
#include <unistd.h> int setgid( gid_t gid );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The setgid() function lets the calling process set its real and effective group IDs and its saved set-group ID to its real or effective group ID, its saved set-group ID, or one of the group IDs identified by the PROCMGR_AID_SETGID ability (see procmgr_ability()).
This function doesn't change any supplementary group IDs of the calling process.
QNX recommends that you use setegid() or setregid() instead of setgid().
#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; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |