Updated: April 19, 2023 |
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.
If the process has the PROCMGR_AID_SETGID ability for the supplied group ID, setgid() sets the real, effective, and saved set-group IDs to the value passed in.
If the process does not have the ability but the group ID matches that of the process's current real, effective, or saved set-group IDs, then only the effective group ID is set to the value passed in.
This function doesn't change any supplementary group IDs of the calling process.
Due to the subtle behavior of setgid(), QNX recommends that you instead use setregid() with both group IDs set to the same value unless it is intended that only the effective group ID be changed, in which case setegid() should be used. It is recommended that you do not use a negative value for a group ID.
#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 |