@@ -48,7 +48,6 @@ static void SignalHandler(int signo, siginfo_t *info, void *) {
4848 // Set the flag before writing to the pipe!
4949 g_signal_info[signo].flag = 1 ;
5050
51- char c = ' .' ;
5251 int fd = g_signal_info[signo].pipe_fd ;
5352 if (fd < 0 ) {
5453 // This can happen with the following (unlikely) sequence of events:
@@ -60,9 +59,11 @@ static void SignalHandler(int signo, siginfo_t *info, void *) {
6059 return ;
6160 }
6261
62+ // Write a(ny) character to the pipe to wake up from the poll syscall.
63+ char c = ' .' ;
6364 ssize_t bytes_written = llvm::sys::RetryAfterSignal (-1 , ::write, fd, &c, 1 );
64- // We're only using the pipe to wake up the reader, so we can safely ignore
65- // EAGAIN (pipe full)
65+ // We can safely ignore EAGAIN ( pipe full), as that means poll will definitely
66+ // return.
6667 assert (bytes_written == 1 || (bytes_written == -1 && errno == EAGAIN));
6768}
6869
@@ -167,9 +168,14 @@ void MainLoopPosix::RunImpl::ProcessReadEvents() {
167168MainLoopPosix::MainLoopPosix () : m_triggering(false ) {
168169 Status error = m_trigger_pipe.CreateNew (/* child_process_inherit=*/ false );
169170 assert (error.Success ());
170- assert (fcntl (m_trigger_pipe.GetWriteFileDescriptor (), F_SETFL,
171- O_NONBLOCK | fcntl (m_trigger_pipe.GetWriteFileDescriptor (),
172- F_GETFL)) == 0 );
171+
172+ // Make the write end of the pipe non-blocking.
173+ int result = fcntl (m_trigger_pipe.GetWriteFileDescriptor (), F_SETFL,
174+ fcntl (m_trigger_pipe.GetWriteFileDescriptor (), F_GETFL) |
175+ O_NONBLOCK);
176+ assert (result == 0 );
177+ UNUSED_IF_ASSERT_DISABLED (result);
178+
173179 const int trigger_pipe_fd = m_trigger_pipe.GetReadFileDescriptor ();
174180 m_read_fds.insert ({trigger_pipe_fd, [trigger_pipe_fd](MainLoopBase &loop) {
175181 char c;
0 commit comments