From 0cfada604d9c87c43c12d461ae3e4daebf05771d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 26 Oct 2014 00:52:46 +0200 Subject: 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. --- player/lua.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'player/lua.c') 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 -- cgit v1.2.3