diff options
author | wm4 <wm4@nowhere> | 2014-10-26 00:52:46 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-10-26 01:40:36 +0200 |
commit | 0cfada604d9c87c43c12d461ae3e4daebf05771d (patch) | |
tree | 269d01e7cdf752e8c98cd2a6e21719116b3bb9d5 /player/lua.c | |
parent | 90e3e990217081691aa0f89e712dd2ae771be876 (diff) | |
download | mpv-0cfada604d9c87c43c12d461ae3e4daebf05771d.tar.bz2 mpv-0cfada604d9c87c43c12d461ae3e4daebf05771d.tar.xz |
lua: subprocess: don't distinguish pipe errors/EOF
What was the purpose of that? Probably none.
Also simplify another thing: if we get the cancel signal through FD,
there's no reason to check it separately.
Diffstat (limited to 'player/lua.c')
-rw-r--r-- | player/lua.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/player/lua.c b/player/lua.c index 561ba37487..66240f9975 100644 --- a/player/lua.c +++ b/player/lua.c @@ -1246,16 +1246,17 @@ static int script_subprocess(lua_State *L) close(pipes[1]); pipes[1] = -1; - bool eof = false; - while (!eof) { + while (1) { struct pollfd fds[] = { {.events = POLLIN, .fd = pipes[0]}, {.events = POLLIN, .fd = cancel ? mp_cancel_get_fd(cancel) : -1}, }; if (poll(fds, fds[1].fd >= 0 ? 2 : 1, -1) < 0 && errno != EINTR) break; - if (fds[1].revents) + if (fds[1].revents) { + kill(pid, SIGKILL); break; + } if (fds[0].revents) { char buf[4096]; ssize_t r = read(pipes[0], buf, sizeof(buf)); @@ -1263,7 +1264,6 @@ static int script_subprocess(lua_State *L) continue; if (r > 0) bstr_xappend(tmp, &output, (bstr){buf, r}); - eof = r == 0; if (r <= 0) break; } @@ -1271,9 +1271,6 @@ static int script_subprocess(lua_State *L) break; } - if (!eof || (cancel && mp_cancel_test(cancel))) - kill(pid, SIGKILL); - // 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 // a separate thread and use pthread_cancel(), or use other weird |