]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
better handle pipe full
authorAlan T. DeKok <aland@freeradius.org>
Thu, 19 Feb 2026 19:31:10 +0000 (14:31 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 19 Feb 2026 22:38:24 +0000 (17:38 -0500)
src/lib/io/control.c

index 947de3f4a4d97e35c05f1922dd34fd18c8e85a72..71cf13a2e50615e1ec34edba37388963c5458173 100644 (file)
@@ -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;
 }