diff options
Diffstat (limited to 'src/daemon.h')
-rw-r--r-- | src/daemon.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/daemon.h b/src/daemon.h index cb6736a..dc8a355 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -125,6 +125,20 @@ fail: \ goto done; \ (void) argc +/** + * Call `CALL` which returns a file descriptor. + * Than make sure that the file descriptor's + * number is `WANT`. Go to `fail' on error. + * + * @param FD:int variable The variable where the file descriptor shall be stored. + * @param WANT:int The file descriptor the file should have. + * @parma CALL:int call Call to function that creates and returns the file descriptor. + */ +#define GET_FD(FD, WANT, CALL) \ + t (FD = CALL, FD == -1); \ + t (dup2_and_null(FD, WANT) == -1); \ + FD = WANT + /** @@ -238,3 +252,27 @@ int remove_job(const char *jobno, int runjob); */ struct job **get_jobs(void); +/** + * Duplicate a file descriptor, and + * open /dev/null to the old file descriptor. + * However, if `old` is 3 or greater, it will + * be closed rather than /dev/null. + * + * @param old The old file descriptor. + * @param new The new file descriptor. + * @return `new`, -1 on error. + */ +int dup2_and_null(int old, int new); + +/** + * Create or open the state file. + * + * @param open_flags Flags (the second parameter) for `open`. + * @param state_path Output parameter for the state file's pathname. + * May be `NULL`; + * @return A file descriptor to the state file, -1 on error. + * + * @throws 0 `!(open_flags & O_CREAT)` and the file does not exist. + */ +int open_state(int open_flags, char **state_path); + |