[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] pkd_daemon.c: force close pkd_state.server_fd upon stop


There's a race window between the accept loop's call to
accept(2) and it checking `ctx.keep_going`.  Forcefully
close the server socket such that any raced `accept` ends
up failing.

Signed-off-by: Jon Simons <jon@xxxxxxxxxxxxx>
---
 tests/pkd/pkd_daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/pkd/pkd_daemon.c b/tests/pkd/pkd_daemon.c
index 3a530793..9860ca56 100644
--- a/tests/pkd/pkd_daemon.c
+++ b/tests/pkd/pkd_daemon.c
@@ -498,6 +498,7 @@ void pkd_stop(struct pkd_result *out) {
     int rc = 0;
 
     ctx.keep_going = 0;
+    close(pkd_state.server_fd);
 
     rc = pthread_kill(ctx.tid, SIGUSR1);
     assert_int_equal(rc, 0);
-- 
2.14.1


References:
[PATCH 0/3] pkd: fix return code check and some racesJon Simons <jon@xxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org