util: Add a wrapper for dup() and pipe2()

The wrappers take care of blocking the SIGALRM signal.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
This commit is contained in:
Olivier Fourdan 2022-12-06 14:23:01 +01:00 committed by Peter Hutterer
parent 0ac9b1b02d
commit 0d3a398fee

View file

@ -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.