From 8aaf670c13ade259f7bcdd50332968c1c6290b34 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 31 Oct 2023 13:25:04 -0400 Subject: bfstd: New xwaitpid() wrapper --- src/bfstd.c | 9 +++++++++ src/bfstd.h | 7 +++++++ src/exec.c | 2 +- src/parse.c | 2 +- src/xspawn.c | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/bfstd.c b/src/bfstd.c index eee02b8..06226a2 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -391,6 +392,14 @@ int xminor(dev_t dev) { #endif } +pid_t xwaitpid(pid_t pid, int *status, int flags) { + pid_t ret; + do { + ret = waitpid(pid, status, flags); + } while (ret < 0 && errno == EINTR); + return ret; +} + int dup_cloexec(int fd) { #ifdef F_DUPFD_CLOEXEC return fcntl(fd, F_DUPFD_CLOEXEC, 0); diff --git a/src/bfstd.h b/src/bfstd.h index db558c6..4e36aca 100644 --- a/src/bfstd.h +++ b/src/bfstd.h @@ -213,6 +213,13 @@ int xminor(dev_t dev); # define st_birthtim st_birthtimespec #endif +// #include + +/** + * waitpid() wrapper that handles EINTR. + */ +pid_t xwaitpid(pid_t pid, int *status, int flags); + // #include /** diff --git a/src/exec.c b/src/exec.c index 0e0d585..97cfafa 100644 --- a/src/exec.c +++ b/src/exec.c @@ -390,7 +390,7 @@ fail: } int wstatus; - if (waitpid(pid, &wstatus, 0) < 0) { + if (xwaitpid(pid, &wstatus, 0) < 0) { return -1; } diff --git a/src/parse.c b/src/parse.c index fafd787..3f32021 100644 --- a/src/parse.c +++ b/src/parse.c @@ -2980,7 +2980,7 @@ static struct bfs_expr *parse_help(struct parser_state *state, int arg1, int arg if (pager > 0) { cfclose(cout); - waitpid(pager, NULL, 0); + xwaitpid(pager, NULL, 0); } state->just_info = true; diff --git a/src/xspawn.c b/src/xspawn.c index 7fb63e0..64759e0 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -234,7 +234,7 @@ pid_t bfs_spawn(const char *exe, const struct bfs_spawn *ctx, char **argv, char xclose(pipefd[0]); if (nbytes == sizeof(error)) { int wstatus; - waitpid(pid, &wstatus, 0); + xwaitpid(pid, &wstatus, 0); errno = error; return -1; } -- cgit v1.2.3