On Tue, Oct 08, 2024 at 07:52:11PM +0800, Qian Yun wrote: > You can observe that 'spadclient' takes 100% CPU when running > in pipe: > > echo ')lisp (progn (sleep 14) (sb-ext:quit))' | fricas -noclef > > When the input from pipe drains, 'read' will return 0, > our current code interprets it as CTRL-D instead of EOF, > causing the process to enter into endless loop.
Yes, there is a problem in usage as above. But I am unsure if this change solves the problem or merely moves it to a different place. Namely, it looks to me that sometimes current handling is appropriate. To put differently, by passing info trough the pipe there seem to be information loss. You try to compensate using 'isatty', at best this is fragile, but potentially may fail in other use cases. > - Qian > > diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c > index d8a62999..ee545c19 100644 > --- a/src/lib/sockio-c.c > +++ b/src/lib/sockio-c.c > @@ -796,10 +796,12 @@ remote_stdio(Sock *sock) > char buf[1024]; > fd_set rd; > int len; > + int stdin_is_terminal = isatty(0); > + int stdin_available = 1; > while (1) { > FD_ZERO(&rd); > FD_SET(sock->socket,&rd); > - FD_SET(0, &rd); > + if (stdin_available) FD_SET(0, &rd); > len = sselect(FD_SETSIZE, (fd_set *)&rd, (fd_set *)0, (fd_set *)0, > NULL); > if (len == -1) { > perror("stdio select"); > @@ -812,7 +814,12 @@ remote_stdio(Sock *sock) > return; > } > if (len == 0) { > + if (stdin_is_terminal) { > /* EOF (CTRL-D) received, ignore it for now */ > + } else { > + /* stdin is connected to a pipe and it is closed. */ > + stdin_available = 0; > + } > } else { > swrite(sock, buf, len, "writing to remote stdin"); > } > > -- > You received this message because you are subscribed to the Google Groups > "FriCAS - computer algebra system" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to fricas-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/fricas-devel/a6220d52-3b0e-4c2f-9abb-fc98ee224393%40gmail.com. -- Waldek Hebisch -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/Z2wT8lMGraHmUkzI%40fricas.org.