fix: handle SIGPIPE

This commit is contained in:
Sebastian Ullrich 2020-08-29 22:47:05 +02:00 committed by Leonardo de Moura
parent 9f40e46043
commit cc909e20e1
3 changed files with 14 additions and 0 deletions

View file

@ -15,6 +15,9 @@ Author: Leonardo de Moura
#include <unistd.h> // NOLINT
#include <sys/mman.h>
#endif
#ifndef LEAN_WINDOWS
#include <csignal>
#endif
#include <fcntl.h>
#include <iostream>
#include <chrono>
@ -653,6 +656,10 @@ void initialize_io() {
mark_persistent(g_stream_stderr);
g_stream_stdin = lean_stream_of_handle(io_wrap_handle(stdin));
mark_persistent(g_stream_stdin);
#ifndef LEAN_WINDOWS
// We want to handle SIGPIPE ourselves
lean_always_assert(signal(SIGPIPE, SIG_IGN) != SIG_ERR);
#endif
}
void finalize_io() {

View file

@ -15,3 +15,9 @@ open IO.Process
child.stdin.flush;
child.wait;
child.stdout.readToEnd
#eval do
child ← spawn { cmd := "true", stdin := Stdio.piped };
child.wait;
child.stdin.putStrLn "ha!";
child.stdin.flush <|> IO.println "flush of broken pipe failed"

View file

@ -2,3 +2,4 @@ hi!
0
"ho!\n"
"hu!\n"
flush of broken pipe failed