osdep: fix infinite loop when cancelling subprocess

Due to the state of the other fds/pipes it cannot safely be assumed
that the loop breaks on its own.
This commit is contained in:
sfan5 2024-02-10 19:16:16 +01:00
parent 71598ca07e
commit ca5f7d2b4b
1 changed files with 3 additions and 1 deletions

View File

@ -281,7 +281,7 @@ void mp_subprocess2(struct mp_subprocess_opts *opts,
if (pid) if (pid)
kill(pid, SIGKILL); kill(pid, SIGKILL);
killed_by_us = true; killed_by_us = true;
break; goto break_poll;
} }
struct mp_subprocess_fd *fd = &opts->fds[n]; struct mp_subprocess_fd *fd = &opts->fds[n];
if (fd->on_read) { if (fd->on_read) {
@ -316,6 +316,8 @@ void mp_subprocess2(struct mp_subprocess_opts *opts,
} }
} }
break_poll:
// Note: it can happen that a child process closes the pipe, but does not // Note: it can happen that a child process closes the pipe, but does not
// terminate yet. In this case, we would have to run waitpid() in // terminate yet. In this case, we would have to run waitpid() in
// a separate thread and use pthread_cancel(), or use other weird // a separate thread and use pthread_cancel(), or use other weird