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.

- 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.

Reply via email to