The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
sem.h File Reference

Functions for establishing and managing low level sockets. More...

Go to the source code of this file.

Macros

#define HAVE_SEMAPHORES
 

Functions

int fr_sem_cgid (gid_t *gid, int sem_id)
 
int fr_sem_close (int sem_id, char const *file)
 Remove the semaphore, this helps with permissions issues. More...
 
int fr_sem_cuid (uid_t *uid, int sem_id)
 Return the UID that created the semaphore. More...
 
int fr_sem_get (char const *file, int proj_id, uid_t uid, gid_t gid, bool check_perm, bool must_exist)
 Returns a semid for the semaphore associated with the file. More...
 
int fr_sem_gid (uid_t *gid, int sem_id)
 Return the GID that last operated on the semaphore. More...
 
int fr_sem_pid (pid_t *pid, int sem_id)
 Return the PID of the process that last operated on the semaphore. More...
 
int fr_sem_post (int sem_id, char const *file, bool undo_on_exit)
 Decrement the semaphore by 1. More...
 
int fr_sem_take (int sem_id, char const *file, bool undo_on_exit)
 Increment the semaphore by 1. More...
 
int fr_sem_uid (uid_t *uid, int sem_id)
 Return the UID that last operated on the semaphore. More...
 
int fr_sem_wait (int sem_id, char const *file, bool undo_on_exit, bool nonblock)
 Wait for a semaphore to reach 0, then increment it by 1. More...
 

Detailed Description

Functions for establishing and managing low level sockets.

Definition in file sem.h.

Macro Definition Documentation

◆ HAVE_SEMAPHORES

#define HAVE_SEMAPHORES

Definition at line 32 of file sem.h.

Function Documentation

◆ fr_sem_cgid()

int fr_sem_cgid ( gid_t *  gid,
int  sem_id 
)

◆ fr_sem_close()

int fr_sem_close ( int  sem_id,
char const *  file 
)

Remove the semaphore, this helps with permissions issues.

Parameters
[in]sem_idto close.
[in]fileto use in error messages.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 329 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_cuid()

int fr_sem_cuid ( uid_t *  uid,
int  sem_id 
)

Return the UID that created the semaphore.

Parameters
[out]uidthe last modified the semaphore.
[in]sem_idsemaphore ID.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 128 of file sem.c.

+ Here is the call graph for this function:

◆ fr_sem_get()

int fr_sem_get ( char const *  file,
int  proj_id,
uid_t  uid,
gid_t  gid,
bool  check_perm,
bool  must_exist 
)

Returns a semid for the semaphore associated with the file.

Parameters
[in]fileto get or create semaphore from.
[in]proj_idif 0 will default to '0xf4ee4a31'.
[in]uidthat should own the semaphore.
[in]gidthat should own the semaphore.
[in]check_permVerify the semaphore is owned by the specified uid/gid, and that it was created by the specified uid/gid or root. Also verify that it is not world writable.
[in]must_existsemaphore must already exist.
Returns
  • >= 0 the semaphore id.
  • -1 the file specified does not exist, or there is a permissions error.
  • -2 failed getting semaphore.
  • -3 failed creating semaphore.
  • -4 must_exist was true, and the semaphore does not exist.

Definition at line 421 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_gid()

int fr_sem_gid ( uid_t *  gid,
int  sem_id 
)

Return the GID that last operated on the semaphore.

Parameters
[out]gidthe last modified the semaphore.
[in]sem_idsemaphore ID.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 102 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_pid()

int fr_sem_pid ( pid_t *  pid,
int  sem_id 
)

Return the PID of the process that last operated on the semaphore.

Parameters
[out]pidthat last modified the semaphore.
[in]sem_idsemaphore ID.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 53 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_post()

int fr_sem_post ( int  sem_id,
char const *  file,
bool  undo_on_exit 
)

Decrement the semaphore by 1.

Parameters
[in]sem_idto take.
[in]fileto use in error messages.
[in]undo_on_exitdecrement the semaphore on exit.
Returns
  • 1 already at 0.
  • 0 on success.
  • -1 on failure.

Definition at line 182 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_take()

int fr_sem_take ( int  sem_id,
char const *  file,
bool  undo_on_exit 
)

Increment the semaphore by 1.

Parameters
[in]sem_idto take.
[in]fileto use in error messages.
[in]undo_on_exitdecrement the semaphore on exit.
Returns
  • -1 on failure.
  • 0 on success.

Definition at line 221 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_uid()

int fr_sem_uid ( uid_t *  uid,
int  sem_id 
)

Return the UID that last operated on the semaphore.

Parameters
[out]uidthe last modified the semaphore.
[in]sem_idsemaphore ID.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 76 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sem_wait()

int fr_sem_wait ( int  sem_id,
char const *  file,
bool  undo_on_exit,
bool  nonblock 
)

Wait for a semaphore to reach 0, then increment it by 1.

Parameters
[in]sem_idto operate on.
[in]fileto use in error messages.
[in]undo_on_exitIf true, semaphore will be decremented if this process exits.
[in]nonblockIf true, don't wait and return 1 if the semaphore is not at 0.
Returns
  • 1 would have blocked waiting for semaphore.
  • 0 incremented the semaphore.
  • -1 permissions error (EACCES).
  • -2 another error occurred.

Definition at line 252 of file sem.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: