Pádraig Brady <[email protected]> writes:
> Oh interesting. I usually do a test run with SIGPIPE ignored
> before doing a release. It's interesting github CI also
> ignores SIGPIPE. That seems generally problematic, especially
> for a CI framework where you don't want to inadvertently spin CPU.
>
> Anyway, yes I can repro with:
>
> $ (trap '' PIPE && make check SUBDIRS=. TESTS=tests/tee/tee.sh)
> The fix looks good to me.
FWIW, I looked into it a bit more, and it seems like more of a
consequence of the actions runner being written in C# than a conscious
choice they made [1].
Using the following program, we can see that C# ignores SIGPIPE and
doesn't restore it to the state it inherited from the parent process
when executing child programs:
$ cat Program.cs
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
class Program
{
[DllImport ("libc")]
private static extern int sigaction (int signum, IntPtr act, IntPtr
oldact);
static void
Main ()
{
if (OperatingSystem.IsWindows ())
{
Console.WriteLine (false);
return;
}
IntPtr oldact = Marshal.AllocHGlobal (256);
try
{
const int SIGPIPE = 13;
bool ignored = (sigaction (SIGPIPE, IntPtr.Zero, oldact) == 0
&& Marshal.ReadIntPtr (oldact) == new IntPtr (1));
Console.WriteLine (ignored);
}
finally
{
Marshal.FreeHGlobal (oldact);
}
var psi = new ProcessStartInfo { FileName = "/bin/bash",
RedirectStandardOutput = true,
UseShellExecute = false };
psi.ArgumentList.Add ("-c");
psi.ArgumentList.Add ("yes | :; echo \"${PIPESTATUS[@]}\"");
using var process = Process.Start (psi)!;
string output = process.StandardOutput.ReadToEnd ();
process.WaitForExit ();
Console.WriteLine (output);
}
}
Here is what we see when running it:
$ yes | :; echo "${PIPESTATUS[@]}"
141 0
$ dotnet run
True
yes: standard output: Broken pipe
1 0
Unfortunately, this feels more common than not with programming
languages, as shown on your page [2].
I'll push that patch, thanks.
Collin
[1] https://github.com/actions/runner
[2] https://www.pixelbeat.org/programming/sigpipe_handling.html