From 0d3a398fee2d084d26a92db1dce28fdebf128cfe Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Tue, 6 Dec 2022 14:23:01 +0100 Subject: [PATCH] util: Add a wrapper for dup() and pipe2() The wrappers take care of blocking the SIGALRM signal. Signed-off-by: Olivier Fourdan --- src/util-io.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/util-io.h b/src/util-io.h index ab42d1c..718e2f5 100644 --- a/src/util-io.h +++ b/src/util-io.h @@ -152,6 +152,32 @@ xsend(int fd, const void *buf, size_t len) return n; } +/** + * Wrapper around pipe2() that always blocks the SIGALRM signal. + */ +static inline int +xpipe2(int pipefd[2], int flags) +{ + sigset_t old_mask = signals_block(); + int n = pipe2(pipefd, flags); + signals_release(old_mask); + + return n; +} + +/** + * Wrapper around dup() that always blocks the SIGALRM signal. + */ +static inline int +xdup(int fd) +{ + sigset_t old_mask = signals_block(); + int n = dup(fd); + signals_release(old_mask); + + return n; +} + /** * Wrapper around send() that always sets MSG_NOSIGNAL and allows appending * file descriptors to the message.