fricas in pipe, and SIGPIPE

9 views
Skip to first unread message

Qian Yun

unread,
Apr 29, 2026, 8:35:01 AMApr 29
to fricas-devel
If we use FriCAS inside a pipe, and does not take all of its output,
such as:

echo '1+1' | fricas -nosman | head -n 4

Then we will be sent to debugger:

debugger invoked on a SB-INT:BROKEN-PIPE in thread
#<THREAD tid=847801 "main thread" RUNNING {1200038003}>:
Couldn't write to #<SB-SYS:FD-STREAM for "standard output" {12010AC3E3}>:
Broken pipe

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit from the current thread.

(SB-IMPL::FLUSH-OUTPUT-BUFFER #<SB-SYS:FD-STREAM for "standard output"
{12010AC3E3}>)


=====

What's the right thing to do here? Terminate the whole process
on SIGPIPE?

To achieve, we can use
(sb-sys:enable-interrupt sb-unix:sigpipe :default)
in "fricas_init".

- Qian

Waldek Hebisch

unread,
May 12, 2026, 1:13:16 PMMay 12
to fricas...@googlegroups.com
For non-interactive use this is right thing. But AFAICS we use
pipes in other contexts, so it is more tricky.

--
Waldek Hebisch

Qian Yun

unread,
May 12, 2026, 6:17:21 PMMay 12
to fricas...@googlegroups.com
No other Lisps have this issue.

For the "use pipes in other contexts", you mean SIGPIPE was used
by sbcl for Ctrl-C handling?

- Qian

Waldek Hebisch

unread,
May 12, 2026, 9:58:45 PMMay 12
to fricas...@googlegroups.com
That is another thing. I mean that our C code uses pipes. Also
when we run programs communitation is via pipes. This may be
not a problem now as IIRC FRICASsys is using mainly sockets,
but we should think about this.

--
Waldek Hebisch

Qian Yun

unread,
May 12, 2026, 10:15:09 PMMay 12
to fricas...@googlegroups.com
On 5/13/26 9:58 AM, Waldek Hebisch wrote:
>
> That is another thing. I mean that our C code uses pipes. Also
> when we run programs communitation is via pipes. This may be
> not a problem now as IIRC FRICASsys is using mainly sockets,
> but we should think about this.
>

When we use fricas interactively via sman, FRICASsys is managed
by PTY. When we use fricas non-interactively via pipe,
there was no problem, the following patch will fix this one.

- Qian

diff --git a/src/interp/util.lisp b/src/interp/util.lisp
index bb2ae3d6..4f9de407 100644
--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -147,6 +147,12 @@
#+:GCL (setq compiler::*suppress-compiler-notes* t)
#+:GCL (si::break-on-floating-point-exceptions :floating-point-overflow t
:division-by-zero t)
+
+ #+(and :sbcl :unix)
+ (if (and (ignore-errors (sb-ext:assert-version->= 2 0 9) t)
+ (eq :fifo (sb-unix:fd-type 1)))
+ (sb-sys:enable-interrupt sb-unix:sigpipe :default))
+
(in-package "BOOT")
(|initroot|)
#+:poplog (setf POPLOG:*READ-PROMPT* "") ;; Turn off Poplog read prompts

Waldek Hebisch

unread,
May 12, 2026, 10:55:42 PMMay 12
to fricas...@googlegroups.com
On Wed, May 13, 2026 at 10:15:04AM +0800, Qian Yun wrote:
> On 5/13/26 9:58 AM, Waldek Hebisch wrote:
> >
> > That is another thing. I mean that our C code uses pipes. Also
> > when we run programs communitation is via pipes. This may be
> > not a problem now as IIRC FRICASsys is using mainly sockets,
> > but we should think about this.
> >
>
> When we use fricas interactively via sman, FRICASsys is managed
> by PTY. When we use fricas non-interactively via pipe,
> there was no problem, the following patch will fix this one.

OK, please commit.

> diff --git a/src/interp/util.lisp b/src/interp/util.lisp
> index bb2ae3d6..4f9de407 100644
> --- a/src/interp/util.lisp
> +++ b/src/interp/util.lisp
> @@ -147,6 +147,12 @@
> #+:GCL (setq compiler::*suppress-compiler-notes* t)
> #+:GCL (si::break-on-floating-point-exceptions :floating-point-overflow t
> :division-by-zero t)
> +
> + #+(and :sbcl :unix)
> + (if (and (ignore-errors (sb-ext:assert-version->= 2 0 9) t)
> + (eq :fifo (sb-unix:fd-type 1)))
> + (sb-sys:enable-interrupt sb-unix:sigpipe :default))
> +
> (in-package "BOOT")
> (|initroot|)
> #+:poplog (setf POPLOG:*READ-PROMPT* "") ;; Turn off Poplog read prompts
>
> --
> 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...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/8c2e981f-0f79-4675-b0ce-54a6d53907d2%40gmail.com.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages