Functions for establishing and managing low level sockets.
More...
Go to the source code of this file.
|
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...
|
|
Functions for establishing and managing low level sockets.
- Copyright
- 2021 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
Definition in file sem.h.
◆ HAVE_SEMAPHORES
Definition at line 32 of file sem.h.
◆ 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_id | to close. |
[in] | file | to use in error messages. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 329 of file sem.c.
◆ fr_sem_cuid()
int fr_sem_cuid |
( |
uid_t * |
uid, |
|
|
int |
sem_id |
|
) |
| |
Return the UID that created the semaphore.
- Parameters
-
[out] | uid | the last modified the semaphore. |
[in] | sem_id | semaphore ID. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 128 of file sem.c.
◆ 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] | file | to get or create semaphore from. |
[in] | proj_id | if 0 will default to '0xf4ee4a31'. |
[in] | uid | that should own the semaphore. |
[in] | gid | that should own the semaphore. |
[in] | check_perm | Verify 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_exist | semaphore 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.
◆ fr_sem_gid()
int fr_sem_gid |
( |
uid_t * |
gid, |
|
|
int |
sem_id |
|
) |
| |
Return the GID that last operated on the semaphore.
- Parameters
-
[out] | gid | the last modified the semaphore. |
[in] | sem_id | semaphore ID. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 102 of file sem.c.
◆ 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] | pid | that last modified the semaphore. |
[in] | sem_id | semaphore ID. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 53 of file sem.c.
◆ 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_id | to take. |
[in] | file | to use in error messages. |
[in] | undo_on_exit | decrement the semaphore on exit. |
- Returns
- 1 already at 0.
- 0 on success.
- -1 on failure.
Definition at line 182 of file sem.c.
◆ 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_id | to take. |
[in] | file | to use in error messages. |
[in] | undo_on_exit | decrement the semaphore on exit. |
- Returns
- -1 on failure.
- 0 on success.
Definition at line 221 of file sem.c.
◆ fr_sem_uid()
int fr_sem_uid |
( |
uid_t * |
uid, |
|
|
int |
sem_id |
|
) |
| |
Return the UID that last operated on the semaphore.
- Parameters
-
[out] | uid | the last modified the semaphore. |
[in] | sem_id | semaphore ID. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 76 of file sem.c.
◆ 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_id | to operate on. |
[in] | file | to use in error messages. |
[in] | undo_on_exit | If true, semaphore will be decremented if this process exits. |
[in] | nonblock | If 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.