ARC SDK
Public Member Functions
Arc::UserSwitch Class Reference

Class for temporary switching of user id. More...

#include <arc/User.h>

Public Member Functions

 UserSwitch (int uid, int gid)
 Switch uid and gid. More...
 
 ~UserSwitch (void)
 Switch back to old uid and gid and release lock on this class. More...
 
 operator bool (void)
 Returns true if switching user succeeded. More...
 
void resetPostFork (void)
 

Detailed Description

Class for temporary switching of user id.

If this class is created, the user identity is switched to the provided uid and gid. Due to an internal lock there will be only one valid instance of this class. Any attempt to create another instance will block until the first one is destroyed. If uid and gid are set to 0 then the user identity is not switched, but the lock is applied anyway. The lock has a dual purpose. The first and most important is to protect communication with the underlying operating system which may depend on user identity. For that it is advisable for code which talks to the operating system to acquire a valid instance of this class. Care must be taken not to hold that instance too long as that may block other code in a multithreaded environment. The other purpose of this lock is to provide a workaround for a glibc bug in __nptl_setxid. This bug causes lockup of seteuid() function if racing with fork. To avoid this problem the lock mentioned above is used by the Run class while spawning a new process.

Constructor & Destructor Documentation

◆ UserSwitch()

Arc::UserSwitch::UserSwitch ( int  uid,
int  gid 
)

Switch uid and gid.

◆ ~UserSwitch()

Arc::UserSwitch::~UserSwitch ( void  )

Switch back to old uid and gid and release lock on this class.

Member Function Documentation

◆ operator bool()

Arc::UserSwitch::operator bool ( void  )
inline

Returns true if switching user succeeded.

◆ resetPostFork()

void Arc::UserSwitch::resetPostFork ( void  )

This method to be called after fork in child process to avoid deadlock on global condition.


The documentation for this class was generated from the following file: