From: Alan T. DeKok Date: Thu, 19 Feb 2026 19:31:10 +0000 (-0500) Subject: better handle pipe full X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b375fc51a41fd1d7f7e24f51da4e4b2bc38870b;p=thirdparty%2Ffreeradius-server.git better handle pipe full --- diff --git a/src/lib/io/control.c b/src/lib/io/control.c index 947de3f4a4d..71cf13a2e50 100644 --- a/src/lib/io/control.c +++ b/src/lib/io/control.c @@ -339,8 +339,6 @@ int fr_control_message_push(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, */ int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size) { - ssize_t ret; - int delay = 0; (void) talloc_get_type_abort(c, fr_control_t); if (c->same_thread) { @@ -352,24 +350,25 @@ int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, if (fr_control_message_push(c, rb, id, data, data_size) < 0) return -1; -again: - if ((ret = write(c->pipe[1], ".", 1)) == 1) return 0; +redo: + if (write(c->pipe[1], ".", 1) >= 0) return 0; + + if (errno == EINTR) goto redo; + + /* + * EAGAIN means that the pipe is full, which means that the other end will eventually + * read from it. + */ + if (errno == EAGAIN) return 0; - if ((ret < 0) && (errno != EAGAIN) #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN) - && (errno != EWOULDBLOCK) + if (errno == EWOULDBLOCK) return 0; #endif - ) { - return -1; - } /* - * @todo - this is pretty crap. We should instead have a better way to deal with things when the - * pipe gets full. + * Other error, that's an issue. */ - delay += 10; - usleep(delay); - goto again; + return -1; }