summaryrefslogtreecommitdiff
path: root/src/shared/varlink.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-21 17:29:48 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-10-22 21:37:31 +0900
commit7c26a631ad8bf91016db156b7d299ca68fd7866e (patch)
tree17786eae3d2145864c7182ec28498174ee5ae02a /src/shared/varlink.c
parente0e914eaf86e2d10454f7b9dae1295d3f3213a49 (diff)
downloadsystemd-7c26a631ad8bf91016db156b7d299ca68fd7866e.tar.gz
varlink: disconnect varlink link in one more case
Previously we'd possibly see POLLHUP on a varlink link, and continue to run epoll on it even though we have nothing to read nor write anymore. Let's fix that, and once we know that there's nothing to write anymore (or we saw a write error already) we'll disconnect after POLLHUP. Fixes: #20062
Diffstat (limited to 'src/shared/varlink.c')
-rw-r--r--src/shared/varlink.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
index c34a08cf57..b31ca108fe 100644
--- a/src/shared/varlink.c
+++ b/src/shared/varlink.c
@@ -416,9 +416,10 @@ static int varlink_test_disconnect(Varlink *v) {
if (IN_SET(v->state, VARLINK_IDLE_CLIENT) && (v->write_disconnected || v->got_pollhup))
goto disconnect;
- /* The server is still expecting to write more, but its write end is disconnected and it got a POLLHUP
- * (i.e. from a disconnected client), so disconnect. */
- if (IN_SET(v->state, VARLINK_PENDING_METHOD, VARLINK_PENDING_METHOD_MORE) && v->write_disconnected && v->got_pollhup)
+ /* We are on the server side and still want to send out more replies, but we saw POLLHUP already, and
+ * either got no buffered bytes to write anymore or already saw a write error. In that case we should
+ * shut down the varlink link. */
+ if (IN_SET(v->state, VARLINK_PENDING_METHOD, VARLINK_PENDING_METHOD_MORE) && (v->write_disconnected || v->output_buffer_size == 0) && v->got_pollhup)
goto disconnect;
return 0;