fix: reopen FIFO on EOF to prevent blocking on subsequent writes
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
14
src/pipe.c
14
src/pipe.c
@@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -19,12 +20,15 @@ extern spsc_queue_t cmd_queue_main_fifo;
|
||||
|
||||
static void *pipe_thread_func(void *arg) {
|
||||
(void)arg;
|
||||
char line[LINE_MAX];
|
||||
|
||||
while (1) {
|
||||
FILE *fifo = fopen(FIFO_PATH, "r");
|
||||
if (!fifo) {
|
||||
perror("fopen fifo");
|
||||
return NULL;
|
||||
}
|
||||
char line[LINE_MAX];
|
||||
|
||||
while (fgets(line, sizeof(line), fifo)) {
|
||||
/* strip newline */
|
||||
size_t len = strlen(line);
|
||||
@@ -69,8 +73,14 @@ static void *pipe_thread_func(void *arg) {
|
||||
}
|
||||
/* ignore unknown lines */
|
||||
}
|
||||
/* EOF – all writers closed, reopen for next connection */
|
||||
fclose(fifo);
|
||||
return NULL;
|
||||
{
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 50000000};
|
||||
nanosleep(&ts, NULL);
|
||||
} /* small pause before retrying */
|
||||
}
|
||||
return NULL; /* unreachable */
|
||||
}
|
||||
|
||||
int pipe_start_reader(void) {
|
||||
|
||||
Reference in New Issue
Block a user