diff options
Diffstat (limited to '')
-rw-r--r-- | src/daemon.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/daemon.h b/src/daemon.h index 562ec52..e2a3f40 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -80,6 +80,37 @@ /** + * Macro to put directly after the variable definitions in `main`. + */ +#define DAEMON_PROLOGUE \ + int rc = 0; \ + assert(argc == 3); \ + t (reopen(STATE_FILENO, O_RDWR)) \ + +/** + * Macro to put before the cleanup code in `main`. + */ +#define DAEMON_CLEANUP_START \ +done: \ + shutdown(SOCK_FILENO, SHUT_WR); \ + close(SOCK_FILENO); \ + close(STATE_FILENO) + +/** + * Macro to put after the cleanup code in `main`. + */ +#define DAEMON_CLEANUP_END \ + return rc; \ +fail: \ + if (send_string(SOCK_FILENO, STDERR_FILENO, argv[0], ": ", strerror(errno), "\n", NULL)) \ + perror(argv[0]); \ + rc = 1; \ + goto done; \ + (void) argc + + + +/** * A queued job. */ struct job { |