Skip to content

Commit

Permalink
Fix SocketServer control EOF handling (#106)
Browse files Browse the repository at this point in the history
Handle EOF on the control pipe. This sometimes seems to happen in slow
test environments even though neither end of the control pipe got
closed.

Now close them properly, and use the EOF event as notification instead
of this.running and sending a control byte.

Fixes #105
  • Loading branch information
martinpitt authored Aug 7, 2020
1 parent 1121f53 commit b5cf0a5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/umockdev.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1765,12 +1765,9 @@ private class SocketServer {
if (!this.running)
return;

this.running = false;

// wake up the select() in our thread
debug ("Stopping SocketServer: signalling thread");
char b = '1';
assert (Posix.write (this.ctrl_w, &b, 1) == 1);
Posix.close (this.ctrl_w);

// merely calling remove_all() does not invoke ScriptRunner dtor, so stop manually
foreach (unowned ScriptRunner r in this.script_runners.get_values())
Expand Down Expand Up @@ -1832,7 +1829,14 @@ private class SocketServer {
if (Posix.FD_ISSET (this.ctrl_r, fds) > 0) {
debug ("socket server thread: woken up by control fd");
char buf;
assert (Posix.read (this.ctrl_r, &buf, 1) == 1);
ssize_t r = Posix.read (this.ctrl_r, &buf, 1);
if (r == 0) {
/* EOF on ctrl_w, stop */
this.running = false;
Posix.close (this.ctrl_r);
} else {
assert (r == 1);
}
continue;
}

Expand Down

0 comments on commit b5cf0a5

Please sign in to comment.