diff options
-rw-r--r-- | src/bfstd.c | 9 | ||||
-rw-r--r-- | src/bfstd.h | 7 | ||||
-rw-r--r-- | src/exec.c | 2 | ||||
-rw-r--r-- | src/parse.c | 2 | ||||
-rw-r--r-- | 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 <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <sys/wait.h> #include <unistd.h> #include <wchar.h> #include <wctype.h> @@ -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 <sys/wait.h> + +/** + * waitpid() wrapper that handles EINTR. + */ +pid_t xwaitpid(pid_t pid, int *status, int flags); + // #include <unistd.h> /** @@ -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; } |