Skip to content

Commit c22bca1

Browse files
committed
Processing (Linux): blocks SIGCHLD and simplify poll error handling
Partially reverts e9ab67b Fixes #2056 & unfixes #1418
1 parent e04cc9c commit c22bca1

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

src/common/init.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ static void exitSignalHandler(FF_MAYBE_UNUSED int signal)
9292
resetConsole();
9393
exit(0);
9494
}
95-
static void chldSignalHandler(FF_MAYBE_UNUSED int signal)
96-
{
97-
// empty; used to interrupt the poll and read syscalls
98-
}
9995
#endif
10096

10197
void ffStart(void)
@@ -121,7 +117,10 @@ void ffStart(void)
121117
sigaction(SIGINT, &action, NULL);
122118
sigaction(SIGTERM, &action, NULL);
123119
sigaction(SIGQUIT, &action, NULL);
124-
sigaction(SIGCHLD, &(struct sigaction) { .sa_handler = chldSignalHandler }, NULL);
120+
sigset_t newmask;
121+
sigemptyset(&newmask);
122+
sigaddset(&newmask, SIGCHLD);
123+
sigprocmask(SIG_BLOCK, &newmask, NULL);
125124
#endif
126125

127126
//reset everything to default before we start printing

src/common/processing_linux.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,30 +184,13 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer)
184184
waitpid(childPid, NULL, 0);
185185
return "poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)";
186186
}
187-
else if (pollret < 0)
188-
{
189-
if (errno == EINTR)
190-
{
191-
// The child process has been terminated. See `chldSignalHandler` in `common/init.c`
192-
if (waitpid(childPid, NULL, WNOHANG) == childPid)
193-
{
194-
// Read remaining data from the pipe
195-
fcntl(childPipeFd, F_SETFL, O_CLOEXEC | O_NONBLOCK);
196-
childPid = -1;
197-
}
198-
}
199-
else
200-
{
201-
kill(childPid, SIGTERM);
202-
waitpid(childPid, NULL, 0);
203-
return "poll(&pollfd, 1, timeout) error: not EINTR";
204-
}
205-
}
206-
else if (pollfd.revents & POLLERR)
187+
else if (pollret < 0 || (pollfd.revents & POLLERR))
207188
{
208189
kill(childPid, SIGTERM);
209190
waitpid(childPid, NULL, 0);
210-
return "poll(&pollfd, 1, timeout) error: POLLERR";
191+
return pollret < 0
192+
? "poll(&pollfd, 1, timeout) error: pollret < 0"
193+
: "poll(&pollfd, 1, timeout) error: pollfd.revents & POLLERR";
211194
}
212195
}
213196

@@ -229,12 +212,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer)
229212
return NULL;
230213
}
231214
else if (nRead < 0)
232-
{
233-
if (errno == EAGAIN)
234-
return NULL;
235-
else
236-
break;
237-
}
215+
break;
238216
}
239217

240218
return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed";

0 commit comments

Comments
 (0)