aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2016-01-01 08:39:41 +0100
committerMattias Andrée <maandree@member.fsf.org>2016-01-01 08:39:51 +0100
commit04a2637f23a9d2b1aee83e364450a02377b44cbc (patch)
tree99716598a1990112e2476abd5f0aec2c8440ee6d /src/daemon.h
parentfix the last bit (diff)
downloadsat-04a2637f23a9d2b1aee83e364450a02377b44cbc.tar.gz
sat-04a2637f23a9d2b1aee83e364450a02377b44cbc.tar.bz2
sat-04a2637f23a9d2b1aee83e364450a02377b44cbc.tar.xz
small improvements and cleanup
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/daemon.h')
-rw-r--r--src/daemon.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/daemon.h b/src/daemon.h
index 5aaa1c6..d860d1f 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -1,5 +1,5 @@
/**
- * Copyright © 2015 Mattias Andrée <maandree@member.fsf.org>
+ * Copyright © 2015, 2016 Mattias Andrée <maandree@member.fsf.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -89,18 +89,29 @@
*
* @param ... The statement.
*/
-# ifdef DEBUG
+# ifndef DEBUG
+# define t(...) do { if (__VA_ARGS__) goto fail; } while (0)
+# else
# define t(...) do { if ((__VA_ARGS__) ? (failed__ = #__VA_ARGS__) : 0) { (perror)(failed__); goto fail; } } while (0)
static const char *failed__ = NULL;
# define perror(_) ((void)(_))
-# else
-# define t(...) do { if (__VA_ARGS__) goto fail; } while (0)
# endif
#endif
/**
+ * `dup2(OLD, NEW)` and, on success, `close(OLD)`.
+ *
+ * @param OLD:int The file descriptor to duplicate and close.
+ * @param NEW:int The new file descriptor.
+ * @return 0 on success, -1 on error.
+ */
+#define DUP2_AND_CLOSE(OLD, NEW) (dup2(OLD, NEW) == -1 ? -1 : (close(OLD), 0))
+
+
+
+/**
* Macro to put directly after the variable definitions in `main`.
*/
#define DAEMON_PROLOGUE \
@@ -194,8 +205,6 @@ ssize_t pwriten(int fildes, const void *buf, size_t nbyte, size_t offset);
/**
* Wrapper for `read` that reads all available data.
*
- * Sets `errno` to `EBADMSG` on success.
- *
* @param fd The file descriptor from which to to read.
* @param buf Output parameter for the data.
* @param n Output parameter for the number of read bytes.