Skip to content

Commit

Permalink
bfstd: New xwaitpid() wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed Oct 31, 2023
1 parent 06ee53d commit 8aaf670
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/bfstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/bfstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

/**
Expand Down
2 changes: 1 addition & 1 deletion src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
}

int wstatus;
if (waitpid(pid, &wstatus, 0) < 0) {
if (xwaitpid(pid, &wstatus, 0) < 0) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/xspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8aaf670

Please sign in to comment.