Skip to content

Commit

Permalink
Merge pull request #2706 from gdt/fix/select-eintr
Browse files Browse the repository at this point in the history
core ipc: Handle select returning EINTR
  • Loading branch information
jimklimov authored Dec 4, 2024
2 parents 2d64030 + 30e4ea6 commit ff08e87
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions include/nutipc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,22 @@ void * Signal::HandlerThread<H>::main(void * comm_pipe_read_end) {
FD_SET(rfd, &rfds);

// Poll on signal pipe
// Note that direct blocking read could be also used;
// however, select allows timeout specification
// which might come handy...
// Note that a straightforward blocking read could be
// also used. However, select allows specifying a
// timeout, which could be useful in the future (but
// is not used in the current code).
int fdno = ::select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr);

// TBD: Die or recover on error?
// -1 is an error, but EINTR means the system call was
// interrupted. System calls are expected to be
// interrupted on signal delivery; some systems
// restart them, and some don't. Getting EINTR is
// therefore not actually an error, and the standard
// approach is to retry.
if (-1 == fdno) {
if (errno == EINTR)
continue;

std::stringstream e;

e << "Poll on communication pipe read end ";
Expand All @@ -633,6 +642,12 @@ void * Signal::HandlerThread<H>::main(void * comm_pipe_read_end) {
throw std::runtime_error(e.str());
}

// POSIX probably does not prohibit reading some but
// not all of the multibyte message. However, it is
// unlikely that an implementation using write and
// read on int-sized or smaller objects will split
// them. For now our strategy is to hope this does
// not happen.
assert(sizeof(word) == read_out);

command_t command = static_cast<command_t>(word);
Expand Down

0 comments on commit ff08e87

Please sign in to comment.