Просмотр исходного кода

Issue #359: closing a JUCE web-view plugin's editor (Xfer Shrub) no longer hangs LYNX; plugins' child processes get a clean start

Shrub 1.07 runs JUCE 8's WebBrowserComponent. On editor close, JUCE's GtkChildProcess::killChild waits 1.5 s for its web-view
helper, then loops kill(SIGTERM) + waitpid until WIFEXITED. A helper that died of the signal never counts as exited, waitpid
fails with ECHILD and leaves the old status, so the loop spun forever (100 % CPU in wait4 inside Shrub.so, the reporter's
stack). Reproduced with the real Shrub 1.07 and the 0.1.32 AppImage (helper slowed past the grace), and with a test plugin.

- LYNX's executable exports its own waitpid (wait4; on ECHILD for one pid it sets *status to 0, as if zeroed by the caller),
  which plugins bind to: JUCE's loop now ends on its second turn (src/platform/ChildHygiene.cpp, Linux only, not in
  LYNX's plugin build).
- A forked copy (fork without exec) of LYNX no longer keeps LYNX's handlers: pthread_atfork resets SIGSEGV/BUS/ILL/FPE/
  ABRT/SYS/TERM/HUP/PIPE handlers to the default, and the fault / end-signal handlers act as default outside LYNX's pid.
  Before, a plugin's forked child sent SIGTERM wrote into LYNX's end-signal pipe: LYNX ended and the child lived on.
- SIGPIPE is caught by a no-op handler instead of SIG_IGN (windows inbox, video export): an ignored SIGPIPE was inherited
  across exec by every program a plugin started.
- Close-on-exec for LYNX's descriptors: the end-signal pipe, the windows inbox wake pipe, the video encoder's pipe and log,
  and a sweep at start-up of everything opened before plugins load (JUCE's message socket pair), except fds LYNX was
  started with.
- Checked: no LYNX thread blocks signals; the AppImage's AppRun sets no LD_LIBRARY_PATH and LYNX changes no environment.

Tests: --selftest "children190th" / --children190thtest (export bound, JUCE's loop, a child's signals and descriptors, a
forked copy's dispositions and SIGTERM); tools/testplugin/lynx_test_child.c (CLAP: children started as its editor closes)
with a Linux CI step through --editortest.
Ka1-S 5 дней назад
Родитель
Сommit
cd2e1e2edb

+ 15 - 0
.github/workflows/tests.yml

@@ -232,6 +232,21 @@ jobs:
           cat crash.txt
           grep -q 'blacklisted: .*crash.clap' crash.txt
 
+      # Issue #359 (round 190th): what a hosted plugin's child processes get from LYNX. Xfer Shrub's JUCE web view hung
+      # LYNX as its editor closed (JUCE's killChild loop spun once its helper died of SIGTERM). The test plugin starts
+      # children as its editor closes: their signals and descriptors, SIGTERM and end of input, a forked copy, JUCE's loop.
+      # (descriptors 3+ of the runner closed first: the probe lists every one a child inherits)
+      - name: Plugin child processes (CLAP)
+        if: runner.os == 'Linux'
+        shell: bash
+        run: |
+          mkdir -p child-plugin
+          cc -shared -fPIC -O2 -Ithird_party/clap/include tools/testplugin/lynx_test_child.c -o "child-plugin/LYNX Test Child.clap"
+          LYNX_TEST_CHILD_REPORT="$PWD/child.txt" LYNX_PROFILE_DIR="$PWD/child-profile" xvfb-run -a perl -e 'use POSIX (); POSIX::close($_) for 3..1023; alarm 120; exec @ARGV' \
+            build/LYNX_artefacts/Release/LYNX --editortest "$PWD/child-plugin/LYNX Test Child.clap" "$PWD/child-editor.txt" || true
+          cat child-editor.txt child.txt || true
+          grep -q '^result=OK' child-editor.txt && grep -q '^done=1' child.txt && ! grep -q '=FAIL' child.txt
+
       # Issue #155: a VST3 that ignores bus activation (as every nih-plug plugin does) reads its sidechain bus while LYNX
       # keeps that bus off; JUCE passed null sample pointers there (nih-plug: memcpy from null, LYNX crashed). The test
       # plugin goes silent on a null pointer, so this fails (peak=0) unless the off bus holds silence (cmake fix 24).

+ 6 - 0
CMakeLists.txt

@@ -862,6 +862,12 @@ if(LYNX_BUILD_APP)
         src/ui/AudioToMidi.cpp
         src/ui/PolyEditor.cpp)
     target_sources(LYNX PRIVATE src/Main.cpp ${LYNX_APP_SOURCES})
+    # issue #359 (round 190th): LYNX's own waitpid, exported for the plugins it hosts (src/platform/ChildHygiene.h). In the
+    # executable only, never in LYNX's plugin build (it must not reach another host's process)
+    target_sources(LYNX PRIVATE src/platform/ChildHygiene.cpp)
+    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+        target_link_options(LYNX PRIVATE "LINKER:--export-dynamic-symbol=waitpid")
+    endif()
     # Ableton Link 4.1.1 (GPL-2.0-or-later, used under the GPLv3; third_party/link, round 190gl) with its bundled Asio
     # (Boost licence): header-only, used by src/engine/AbletonLink.cpp alone (it sets Link's and Asio's macros itself)
     set_source_files_properties(src/engine/AbletonLink.cpp PROPERTIES COMPILE_OPTIONS

+ 205 - 0
src/Children190thCheck.inc

@@ -0,0 +1,205 @@
+    // Round 190th (issue #359: closing Xfer Shrub's editor hung LYNX). Included in the app class of Main.cpp;
+    // --children190thtest <report> and --selftest "children190th". What a hosted plugin's child processes get from LYNX
+    // (Linux; "OK" elsewhere), checked the way a plugin does it (waitpid looked up as a plugin binds to it):
+    // - waitpid: plugins get LYNX's exported one, and JUCE 8's killChild loop (juce::WebBrowserComponent's web-view
+    //   helper, built into Shrub) ends once the helper died of SIGTERM (it spun for ever: 100 % CPU in kill + wait4);
+    // - a child (fork + exec) gets no blocked or ignored signal of the watched ones (SIGPIPE: LYNX catches it now, it
+    //   ignored it) and no descriptor LYNX opened (only the ones LYNX was started with);
+    // - a forked copy (no exec) starts with the default action for SIGSEGV / SIGABRT / SIGTERM / SIGHUP / SIGPIPE, and
+    //   SIGTERM ends it (it ran LYNX's handler, which wrote into LYNX's pipe: LYNX ended, the copy lived on).
+    juce::String children190thCheck (juce::String& log)
+    {
+        juce::String result = "OK";
+        const auto check = [&] (const juce::String& what, bool ok, const juce::String& detail = {}) {
+            log << (ok ? "ok   " : "FAIL ") << what << (detail.isNotEmpty() ? "  [" + detail + "]" : juce::String()) << "\n";
+            if (! ok && result == "OK")
+                result = "ERROR " + what + " " + detail;
+        };
+#if JUCE_LINUX
+        using Wait = pid_t (*) (pid_t, int*, int);
+        const auto bound = reinterpret_cast<Wait> (dlsym (RTLD_DEFAULT, "waitpid"));
+        check ("plugins bind waitpid to LYNX's", bound != nullptr && reinterpret_cast<const void*> (bound) == lynx::childhygiene::exportedWaitpid());
+        if (bound == nullptr)
+            return result;
+
+        const auto nowMs = [] { return juce::Time::getMillisecondCounterHiRes(); };
+        const auto spawn = [] (const char* script, int out) -> pid_t {
+            const auto pid = ::fork();
+            if (pid == 0)
+            {
+                if (out >= 0)
+                    ::dup2 (out, 1);
+                ::execl ("/bin/sh", "sh", "-c", script, (char*) nullptr);
+                ::_exit (127);
+            }
+            return pid;
+        };
+        const auto waitFor = [&] (pid_t pid, int& status, double ms) {
+            const auto until = nowMs() + ms;
+            for (;;)
+            {
+                const auto r = bound (pid, &status, WNOHANG);
+                if (r == pid)
+                    return true;
+                if ((r < 0 && errno != EINTR) || nowMs() > until)
+                    return false;
+                juce::Thread::sleep (5);
+            }
+        };
+        const auto reapHard = [&] (pid_t pid) {
+            int status = 0;
+            ::kill (pid, SIGKILL);
+            waitFor (pid, status, 3000.0);
+        };
+
+        // JUCE 8.0's GtkChildProcess::killChild with a helper that outlives the grace (3 x 20 ms here, 15 x 100 ms in JUCE)
+        {
+            const auto rescuedBefore = lynx::childhygiene::rescuedWaits();
+            const auto childProcess = spawn ("exec sleep 30", -1);
+            const auto t0 = nowMs();
+            int status = 0, waited = 0;
+            waited = bound (childProcess, &status, WNOHANG);
+            for (int i = 0; i < 3 && (! WIFEXITED (status) || waited != childProcess); ++i)
+            {
+                juce::Thread::sleep (20);
+                waited = bound (childProcess, &status, WNOHANG);
+            }
+            status = 0;
+            bool spun = false;
+            long loops = 0;
+            if (childProcess > 0 && (! WIFEXITED (status) || waited != childProcess))
+                for (;;)
+                {
+                    ::kill (childProcess, SIGTERM);
+                    bound (childProcess, &status, 0);
+                    if (WIFEXITED (status))
+                        break;
+                    if ((++loops & 1023) == 0 && nowMs() - t0 > 4000.0)
+                    {
+                        spun = true;
+                        break;
+                    }
+                }
+            check ("JUCE's killChild loop ends after its helper died of SIGTERM", childProcess > 0 && ! spun && loops <= 2,
+                   juce::String (loops) + " turns, " + juce::String (nowMs() - t0, 0) + " ms, rescued "
+                       + juce::String (lynx::childhygiene::rescuedWaits() - rescuedBefore));
+        }
+
+        // a child's signals and descriptors (SIGPIPE as LYNX's windows inbox and the video export set it)
+        lynx::crashguard::quietBrokenPipes();
+        {
+            int fds[2] = { -1, -1 };
+            std::string out;
+            int status = 0;
+            pid_t pid = -1;
+            if (::pipe2 (fds, O_CLOEXEC) == 0)
+            {
+                pid = spawn ("grep -E '^Sig(Blk|Ign):' /proc/$$/status; ls -l /proc/$$/fd", fds[1]);
+                ::close (fds[1]);
+                char buffer[1024];
+                for (;;)
+                {
+                    const auto n = ::read (fds[0], buffer, sizeof (buffer));
+                    if (n > 0)
+                        out.append (buffer, (std::size_t) n);
+                    else if (! (n < 0 && errno == EINTR))
+                        break;
+                }
+                ::close (fds[0]);
+            }
+            const auto finished = pid > 0 && waitFor (pid, status, 3000.0);
+            if (pid > 0 && ! finished)
+                reapHard (pid);
+            check ("the probe child ran", finished && WIFEXITED (status), juce::String (out).substring (0, 200));
+            const auto field = [&out] (const char* name) {
+                const auto at = out.find (name);
+                return at == std::string::npos ? ~0ULL : std::strtoull (out.c_str() + at + std::strlen (name), nullptr, 16);
+            };
+            const auto blocked = field ("SigBlk:"), ignored = field ("SigIgn:");
+            juce::String badBlocked, badIgnored;
+            for (const auto sig : { SIGHUP, SIGPIPE, SIGTERM, SIGCHLD, SIGALRM, SIGUSR1, SIGUSR2, SIGPROF, SIGCONT, SIGWINCH })
+            {
+                const auto bit = 1ULL << (sig - 1);
+                if (blocked != ~0ULL && (blocked & bit) != 0)
+                    badBlocked << " " << sig;
+                if (ignored != ~0ULL && (ignored & bit) != 0)
+                    badIgnored << " " << sig;
+            }
+            check ("a child gets no blocked signal", blocked != ~0ULL && badBlocked.isEmpty(), badBlocked.trim());
+            check ("a child gets no ignored signal (SIGPIPE ...)", ignored != ~0ULL && badIgnored.isEmpty(), badIgnored.trim());
+            // "lrwx------ 1 user user 64 date 3 -> socket:[123]": the number before " -> "
+            juce::StringArray leaked;
+            for (const auto& line : juce::StringArray::fromLines (juce::String (out)))
+                if (const auto arrow = line.indexOf (" -> "); arrow > 0)
+                {
+                    const auto fd = line.substring (0, arrow).fromLastOccurrenceOf (" ", false, false).getIntValue();
+                    if (fd > 2 && ! lynx::childhygiene::startedWith (fd))
+                        leaked.add (juce::String (fd) + " " + line.substring (arrow + 4));
+                }
+            check ("a child gets no descriptor LYNX opened", leaked.isEmpty(), leaked.joinIntoString ("; "));
+        }
+
+        if (! sanitizerOwnsSignals())
+        {
+            // a forked copy's dispositions (pthread_atfork's child handler): bit k set = signal k of the list kept a handler
+            const auto pid = ::fork();
+            if (pid == 0)
+            {
+                int bits = 0, k = 0;
+                for (const auto sig : { SIGSEGV, SIGBUS, SIGABRT, SIGTERM, SIGHUP, SIGPIPE })
+                {
+                    struct sigaction current {};
+                    if (::sigaction (sig, nullptr, &current) == 0 && current.sa_handler != SIG_DFL && current.sa_handler != SIG_IGN)
+                        bits |= 1 << k;
+                    ++k;
+                }
+                ::_exit (bits);
+            }
+            int status = 0;
+            const auto finished = pid > 0 && waitFor (pid, status, 3000.0);
+            if (pid > 0 && ! finished)
+                reapHard (pid);
+            check ("a forked copy starts with the default actions", finished && WIFEXITED (status) && WEXITSTATUS (status) == 0,
+                   "kept (SEGV BUS ABRT TERM HUP PIPE bits): " + juce::String (finished && WIFEXITED (status) ? WEXITSTATUS (status) : -1));
+
+            // SIGTERM ends a forked copy, and only the copy (LYNX goes on: this check returns)
+            const auto copy = ::fork();
+            if (copy == 0)
+                for (;;)
+                    ::pause();
+            juce::Thread::sleep (100);
+            ::kill (copy, SIGTERM);
+            status = 0;
+            const auto ended = copy > 0 && waitFor (copy, status, 3000.0);
+            if (copy > 0 && ! ended)
+                reapHard (copy);
+            check ("SIGTERM ends a forked copy (LYNX goes on)", ended && WIFSIGNALED (status) && WTERMSIG (status) == SIGTERM,
+                   ended ? (WIFSIGNALED (status) ? "signal " + juce::String (WTERMSIG (status)) : "exit " + juce::String (WEXITSTATUS (status))) : juce::String ("still running"));
+        }
+
+        // the threads LYNX has now: none with a watched signal blocked (a plugin's child gets its thread's mask)
+        {
+            juce::StringArray masked;
+            for (const auto& task : juce::File ("/proc/self/task").findChildFiles (juce::File::findDirectories, false))
+            {
+                const auto status = task.getChildFile ("status").loadFileAsString();
+                const auto at = status.indexOf ("SigBlk:");
+                if (at < 0)
+                    continue;
+                const auto mask = std::strtoull (status.substring (at + 7).trim().toRawUTF8(), nullptr, 16);
+                const auto watched = (1ULL << (SIGTERM - 1)) | (1ULL << (SIGCHLD - 1)) | (1ULL << (SIGPIPE - 1)) | (1ULL << (SIGHUP - 1));
+                if ((mask & watched) != 0)
+                    masked.add (status.fromFirstOccurrenceOf ("Name:", false, false).upToFirstOccurrenceOf ("\n", false, false).trim() + " "
+                                + juce::String::toHexString ((juce::int64) mask));
+            }
+            const auto self = juce::File ("/proc/thread-self/status").loadFileAsString();
+            const auto at = self.indexOf ("SigBlk:");
+            check ("the message thread blocks no signal", at >= 0 && std::strtoull (self.substring (at + 7).trim().toRawUTF8(), nullptr, 16) == 0);
+            log << "info threads with SIGTERM / SIGCHLD / SIGPIPE / SIGHUP blocked: " << masked.size()
+                << (masked.isEmpty() ? juce::String() : " (" + masked.joinIntoString (", ") + ")") << "\n";
+        }
+#else
+        check ("Linux only", true);
+#endif
+        return result;
+    }

+ 24 - 1
src/Main.cpp

@@ -181,6 +181,9 @@ namespace juce { extern bool lynxXdndRelayOn; unsigned long lynxXdndRelayTargetF
 #endif
  #include <sys/prctl.h> // (round 190ou: --multieditor255test LYNX_ME_PTRACE=1)
  #include <sys/socket.h> // (round 190rf: --qa190rfchild display)
+ #include <fcntl.h> // (round 190th: src/Children190thCheck.inc)
+ #include <signal.h>
+ #include <sys/wait.h>
  #include <unistd.h>
 #endif
 #include "engine/HostingTests.h"
@@ -405,6 +408,7 @@ namespace juce::detail { bool dispatchNextMessageOnSystemQueue (bool returnIfNoP
 #include "ui/ToolWindow.h"
 #include "core/Details190mv.h" // (round 190mv)
 #include "platform/CrashGuard.h"
+#include "platform/ChildHygiene.h"
 #include "ui/CrashReporter.h"
 #include "ui/Updater.h"
 #include "ui/AudioCheck.h"
@@ -1079,6 +1083,9 @@ public:
         }
         if (! sanitizerOwnsSignals())
             lynx::crashguard::hardenSignals(); // issue #115: stack overflows and SIGTERM / SIGHUP leave a trace (Linux / macOS)
+        // issue #359 (round 190th): what LYNX opened so far (JUCE's message socket pair, the end-signal pipe, ...) is not
+        // handed on to the programs plugins start (Linux)
+        lynx::childhygiene::closeOnExecForOwnDescriptors();
 
         // SFZ instruments (round 167o): their FLAC / OGG / AIFF / MP3 samples through JUCE's readers
         lynx::sfz::setDecoder ([] (const std::string& path, lynx::sfz::Audio& out) {
@@ -2613,6 +2620,17 @@ public:
             runKeyRoute190sj (args[args.indexOf ("--keyroute190sjtest") + 1].unquoted());
             return;
         }
+        if (args.contains ("--children190thtest"))
+        {
+            // LYNX --children190thtest report.txt (round 190th, issue #359; also in --selftest): src/Children190thCheck.inc
+            juce::String log;
+            const auto i = args.indexOf ("--children190thtest");
+            const auto result = children190thCheck (log);
+            juce::File (args[i + 1].unquoted()).replaceWithText (log + "children190th=" + result + "\n");
+            setApplicationReturnValue (result == "OK" ? 0 : 1);
+            quit();
+            return;
+        }
         if (args.contains ("--details190tbtest"))
         {
             // LYNX --details190tbtest report.txt (round 190tb, 0.1.33 details pass; also in --selftest): src/Details190tbCheck.inc
@@ -11018,6 +11036,9 @@ private:
         // round 190tb (0.1.33 details pass): FL's hint readouts, pointers and arrows (src/Details190tbCheck.inc)
         juce::String details190tbLog;
         const auto details190tbResult = details190tbCheck (details190tbLog);
+        // round 190th (issue #359): what a plugin's child processes get from LYNX (src/Children190thCheck.inc)
+        juce::String children190thLog;
+        const auto children190thResult = children190thCheck (children190thLog);
         // round 190rp (0.1.32 Q4, stability): src/Stab190rpCheck.inc
         juce::String stab190rpLog;
         const auto stab190rpResult = stab190rpCheck (stab190rpLog);
@@ -12442,7 +12463,7 @@ private:
                         && sidechainResult == "OK" && lanesResult == "OK" && arrange190cgResult == "OK" && livescr190drResult == "OK" && livewf190efResult == "OK" && livewf190emResult == "OK" && trackclips190neResult == "OK" && tracker190nwResult == "OK" && tracker190obResult == "OK" && rackauto190ooResult == "OK" && tracker190omResult == "OK" && rackauto190owResult == "OK" && versionsResult == "OK" && pluginsOffResult == "OK" && missingFilesResult == "OK"
                         && midigen190fmResult == "OK" && clipenv190giResult == "OK" && beatslaw190gxResult == "OK" && warplaw190ikResult == "OK" && editorScale190heResult == "OK" && sfModBase190heResult == "OK" && trackauto190gzResult == "OK" && community190hqResult == "OK" && rollup030Result == "OK" && rollup031Result == "OK" && rollup031s2Result == "OK"
                         && keys190nuResult == "OK" && rollup031s3Result == "OK"
-                        && helix4khs190ocResult == "OK" && rollup031s4Result == "OK" && sections190olResult == "OK" && rollup031s5Result == "OK" && simpleDuck190otResult == "OK" && tracks190peResult == "OK" && issue258Result == "OK" && issues190qrResult == "OK" && backlog190rcResult == "OK" && community190riResult == "OK" && q1a190rwResult == "OK" && iox190rmResult == "OK" && issues190rtResult == "OK" && perf190rnResult == "OK" && perf190sbResult == "OK" && undo190spResult == "OK" && menuwindows190skResult == "OK" && issues330skResult == "OK" && audioedit190stResult == "OK" && drumsynth190syResult == "OK" && smallbugs190srResult == "OK" && quickwins190srResult == "OK" && batch292_190swResult == "OK" && yannik190sqResult == "OK" && batch334svResult == "OK" && qa190rbResult == "OK" && bugs190rvResult == "OK" && q6190saResult == "OK" && issue325Result == "OK" && keysheet190sjResult == "OK" && details190tbResult == "OK" && stab190rpResult == "OK" && repeats190pmResult == "OK" && mixerqol190qhResult == "OK" && autolive190qpResult == "OK" && issue282Result == "OK" && feel190qeResult == "OK" && toolbar190qgResult == "OK" && extras190qkResult == "OK" && extras190roResult == "OK" && playlistview190soResult == "OK" && custom190ssResult == "OK" && discord190quResult == "OK" && trialmark190qtResult == "OK" && optionsux190qxResult == "OK" && chordlane190pfResult == "OK" && nofl190rhResult == "OK" && autolinks190ovResult == "OK"
+                        && helix4khs190ocResult == "OK" && rollup031s4Result == "OK" && sections190olResult == "OK" && rollup031s5Result == "OK" && simpleDuck190otResult == "OK" && tracks190peResult == "OK" && issue258Result == "OK" && issues190qrResult == "OK" && backlog190rcResult == "OK" && community190riResult == "OK" && q1a190rwResult == "OK" && iox190rmResult == "OK" && issues190rtResult == "OK" && perf190rnResult == "OK" && perf190sbResult == "OK" && undo190spResult == "OK" && menuwindows190skResult == "OK" && issues330skResult == "OK" && audioedit190stResult == "OK" && drumsynth190syResult == "OK" && smallbugs190srResult == "OK" && quickwins190srResult == "OK" && batch292_190swResult == "OK" && yannik190sqResult == "OK" && batch334svResult == "OK" && qa190rbResult == "OK" && bugs190rvResult == "OK" && q6190saResult == "OK" && issue325Result == "OK" && keysheet190sjResult == "OK" && details190tbResult == "OK" && children190thResult == "OK" && stab190rpResult == "OK" && repeats190pmResult == "OK" && mixerqol190qhResult == "OK" && autolive190qpResult == "OK" && issue282Result == "OK" && feel190qeResult == "OK" && toolbar190qgResult == "OK" && extras190qkResult == "OK" && extras190roResult == "OK" && playlistview190soResult == "OK" && custom190ssResult == "OK" && discord190quResult == "OK" && trialmark190qtResult == "OK" && optionsux190qxResult == "OK" && chordlane190pfResult == "OK" && nofl190rhResult == "OK" && autolinks190ovResult == "OK"
                         && trackstates190opResult == "OK" && rollup031s6Result == "OK" // (round 190op's item, reported but not counted in its branch: rollup 0.1.31 step 6)
                         && rollup031s7Result == "OK" && rollup031s8Result == "OK" && rollup032Result == "OK" && headerGearResult == "OK" && perTab259Result == "OK" && slots260Result == "OK" && hotfixPlacesResult == "OK" && startPageScrollResult.startsWith ("OK") // (round 190qf: slots260) (rollup 0.1.31 step 7, round 190pw; and the three rounds' items its branches reported but did not count:)
                         && slides190piResult == "OK" && automodes190paResult == "OK" && heldSteps190ozResult == "OK"
@@ -12590,6 +12611,7 @@ private:
                << "issue325=" << issue325Result << (issue325Result == "OK" ? juce::String() : " | " + issue325Log.replace ("\n", "; ")) << "\n"
                << "keysheet190sj=" << keysheet190sjResult << (keysheet190sjResult == "OK" ? juce::String() : " | " + keysheet190sjLog.replace ("\n", "; ")) << "\n"
                << "details190tb=" << details190tbResult << (details190tbResult == "OK" ? juce::String() : " | " + details190tbLog.replace ("\n", "; ")) << "\n"
+               << "children190th=" << children190thResult << (children190thResult == "OK" ? juce::String() : " | " + children190thLog.replace ("\n", "; ")) << "\n"
                << "stab190rp=" << stab190rpResult << (stab190rpResult == "OK" ? juce::String() : " | " + stab190rpLog.replace ("\n", "; ")) << "\n"
                << "repeats190pm=" << repeats190pmResult << "\n"
                << "mixerqol190qh=" << mixerqol190qhResult << "\n"
@@ -23041,6 +23063,7 @@ private:
 #include "Q6Check190sa.inc" // round 190sa: 0.1.32 Q6 (files) + the Simple layout's sound drop
 #include "KeySheetCheck190sj.inc" // round 190sj: issue #327, every key of the F1 shortcut sheet runs its action
 #include "Details190tbCheck.inc" // round 190tb: 0.1.33 details pass (hint readouts, FL's pointers and arrows)
+#include "Children190thCheck.inc" // round 190th: issue #359, what a plugin's child processes get from LYNX (Shrub's hang)
 #include "Uhe190sjTest.inc" // round 190sj: issues #329 / #255, u-he editors opened, closed and removed (--uhe190sjtest)
 #include "Issue325Check190sg.inc" // round 190sg: issue #325, a sample dropped on an audio clip replaces its channel's sample (FL)
 #include "Qa190rbCheck.inc" // round 190rb: the 0.1.32 quality round's crash / memory fixes, checked

+ 88 - 0
src/platform/ChildHygiene.cpp

@@ -0,0 +1,88 @@
+#include "platform/ChildHygiene.h"
+
+#include <atomic>
+
+#if defined(__linux__)
+ #include <cerrno>
+ #include <cstdlib>
+ #include <dirent.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/wait.h>
+ #include <unistd.h>
+
+namespace
+{
+std::atomic<int> rescued { 0 };
+
+// the descriptors open when the process started (before main): fds 0-1023, one bit each
+constexpr int trackedFds = 1024;
+unsigned long long startFds[trackedFds / 64] = {};
+
+template <typename Fn>
+void forEachOpenFd (Fn&& fn) noexcept
+{
+    if (auto* dir = ::opendir ("/proc/self/fd"))
+    {
+        const auto own = ::dirfd (dir);
+        while (auto* entry = ::readdir (dir))
+        {
+            char* end = nullptr;
+            const auto fd = std::strtol (entry->d_name, &end, 10);
+            if (end != entry->d_name && *end == 0 && fd != own)
+                fn ((int) fd);
+        }
+        ::closedir (dir);
+    }
+}
+
+__attribute__ ((constructor)) void recordStartFds() noexcept
+{
+    forEachOpenFd ([] (int fd) {
+        if (fd >= 0 && fd < trackedFds)
+            startFds[fd / 64] |= 1ULL << (fd % 64);
+    });
+}
+} // namespace
+
+// See ChildHygiene.h. Exported from the executable (CMakeLists.txt: --export-dynamic-symbol=waitpid).
+extern "C" __attribute__ ((visibility ("default"))) pid_t waitpid (pid_t pid, int* status, int options)
+{
+    const auto result = ::wait4 (pid, status, options, nullptr);
+    if (result < 0 && errno == ECHILD && pid > 0 && status != nullptr)
+    {
+        *status = 0; // (errno stays ECHILD)
+        rescued.fetch_add (1, std::memory_order_relaxed);
+    }
+    return result;
+}
+
+namespace lynx::childhygiene
+{
+void closeOnExecForOwnDescriptors() noexcept
+{
+    forEachOpenFd ([] (int fd) {
+        if (fd <= 2 || startedWith (fd))
+            return;
+        const auto flags = ::fcntl (fd, F_GETFD);
+        if (flags >= 0 && (flags & FD_CLOEXEC) == 0)
+            ::fcntl (fd, F_SETFD, flags | FD_CLOEXEC);
+    });
+}
+
+int rescuedWaits() noexcept { return rescued.load (std::memory_order_relaxed); }
+const void* exportedWaitpid() noexcept { return reinterpret_cast<const void*> (&::waitpid); }
+bool startedWith (int fd) noexcept { return fd >= 0 && fd < trackedFds && (startFds[fd / 64] & (1ULL << (fd % 64))) != 0; }
+} // namespace lynx::childhygiene
+
+#else
+
+namespace lynx::childhygiene
+{
+void closeOnExecForOwnDescriptors() noexcept {}
+int rescuedWaits() noexcept { return 0; }
+const void* exportedWaitpid() noexcept { return nullptr; }
+bool startedWith (int) noexcept { return false; }
+} // namespace lynx::childhygiene
+
+#endif

+ 25 - 0
src/platform/ChildHygiene.h

@@ -0,0 +1,25 @@
+#pragma once
+
+// Issue #359 (round 190th): what the child processes of hosted plugins get from LYNX (Linux; nothing elsewhere).
+// Compiled into the LYNX executable only (not into LYNX's own plugin build: the waitpid below must never be exported
+// from a plugin into another host's process).
+//
+// - waitpid: LYNX's executable exports its own waitpid, which plugins bind to (the executable comes first in the global
+//   symbol scope). It is the C library's (wait4), except that a call for one child that fails with ECHILD (no such
+//   child, or reaped already) sets *status to 0, as if the caller had zeroed it. Callers that look at the return value
+//   see no difference. The one that does not is JUCE 8's GtkChildProcess::killChild (juce::WebBrowserComponent on
+//   Linux, built into Xfer Shrub 1.07 and other JUCE web-view plugins): a web-view helper still there 1.5 s after
+//   "quit" is sent SIGTERM in a loop that ends only on WIFEXITED (status); once the helper died of the signal, waitpid
+//   kept failing and left the old "killed by SIGTERM" status there, so the loop never ended: LYNX's interface thread
+//   spun at 100 % CPU in kill + wait4 inside the plugin as its editor closed (and as LYNX quit). Now the second turn
+//   ends it.
+// - closeOnExecForOwnDescriptors: every descriptor LYNX (JUCE's message socket pair, the libraries) opened before the
+//   first plugin loads gets FD_CLOEXEC, so a plugin's helper does not inherit them. The ones LYNX was started with are
+//   left as they are.
+namespace lynx::childhygiene
+{
+void closeOnExecForOwnDescriptors() noexcept; // once, on the message thread, before any plugin is loaded
+int rescuedWaits() noexcept;                    // waitpid calls whose status was set as above (only grows)
+const void* exportedWaitpid() noexcept;         // LYNX's own waitpid (the selftest compares it with what plugins get)
+bool startedWith (int fd) noexcept;             // the descriptor was open when the process started
+} // namespace lynx::childhygiene

+ 72 - 1
src/platform/CrashGuard.cpp

@@ -114,6 +114,21 @@ void setCurrentFrame (GuardFrame* f) noexcept { tlsFrame = f; }
 std::atomic<int> guardState { 0 }; // 0 = not installed, 1 = being installed, 2 = installed
 struct sigaction previousAction[guardedCount];
 const void* ownImage = nullptr; // where LYNX's executable (LYNX's and JUCE's code) is loaded
+// Issue #359 (round 190th): the process that installed the handlers. A plugin's child process that does not exec (JUCE's
+// web view run in the forked copy) keeps LYNX's handlers: there a fault must not reach LYNX's crash handler (or jump back
+// into the guarded call: two LYNXes) and SIGTERM must not go into LYNX's own end-signal pipe (which the parent reads:
+// LYNX took the child's SIGTERM as its own and ended, and the child lived on, its parent waiting for it).
+pid_t ownerPid = 0;
+bool inForkedCopy() noexcept { return ownerPid != 0 && ::getpid() != ownerPid; } // (async-signal-safe)
+void defaultActionInChild (int sig, const siginfo_t* info) noexcept
+{
+    struct sigaction fallback {};
+    fallback.sa_handler = SIG_DFL;
+    sigemptyset (&fallback.sa_mask);
+    sigaction (sig, &fallback, nullptr);
+    if (info == nullptr || info->si_code <= 0)
+        raise (sig); // (sent, not a fault of an instruction: a fault happens again on return)
+}
 
 // A fault the kernel raised for an instruction of this thread (not a signal sent by kill / raise / sigqueue)
 bool synchronousFault (const siginfo_t* info) noexcept
@@ -411,6 +426,11 @@ void passOn (int sig, siginfo_t* info, void* context) noexcept
 
 void onFault (int sig, siginfo_t* info, void* context)
 {
+    if (inForkedCopy())
+    {
+        defaultActionInChild (sig, info);
+        return;
+    }
     const auto savedErrno = errno;
     if (auto* frame = currentFrame(); frame != nullptr && frame->handling == 0 && synchronousFault (info))
     {
@@ -442,6 +462,7 @@ void installFaultGuard() noexcept
             sched_yield();
         return;
     }
+    ownerPid = ::getpid();
     Dl_info self {};
     if (dladdr (reinterpret_cast<const void*> (&installFaultGuard), &self) != 0)
         ownImage = self.dli_fbase;
@@ -1752,12 +1773,37 @@ int endSignalPipe[2] = { -1, -1 };
 
 void onEndSignal (int sig)
 {
+    if (inForkedCopy())
+    {
+        defaultActionInChild (sig, nullptr); // (a plugin's forked copy ends as it would have without LYNX)
+        return;
+    }
     // async-signal-safe: only write(); the thread below notes it (the note takes a lock and allocates)
     const auto byte = (unsigned char) sig;
     if (endSignalPipe[1] >= 0)
         (void) ::write (endSignalPipe[1], &byte, 1);
 }
 
+// pthread_atfork's child handler (issue #359, round 190th): a plugin's child process that does not exec at once (JUCE's
+// web view in the forked copy, a helper thread of a library) has LYNX's crash handler, LYNX's plugin-call guard and
+// LYNX's SIGTERM / SIGHUP / SIGPIPE handlers: back to the default action there, as in a process LYNX did not start.
+// (exec resets them anyway; async-signal-safe: sigaction only)
+void resetHandlersInForkedChild()
+{
+    for (const auto sig : { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT, SIGSYS, SIGTERM, SIGHUP, SIGPIPE })
+    {
+        struct sigaction current {};
+        if (sigaction (sig, nullptr, &current) != 0 || current.sa_handler == SIG_DFL || current.sa_handler == SIG_IGN)
+            continue;
+        struct sigaction fallback {};
+        fallback.sa_handler = SIG_DFL;
+        sigemptyset (&fallback.sa_mask);
+        sigaction (sig, &fallback, nullptr);
+    }
+}
+
+void brokenPipe (int) {} // (quietBrokenPipes)
+
 std::string endSignalStep (int sig)
 {
     return sig == SIGTERM ? "ended by SIGTERM (the system or another program asked LYNX to close)"
@@ -1797,7 +1843,17 @@ void hardenSignals() noexcept
         // round 190dt: the plugin-call guard (call()), on top of the crash handler it passes LYNX's own faults to
         installFaultGuard();
 
-        if (endSignalPipe[0] < 0 && ::pipe (endSignalPipe) == 0)
+        // issue #359: the forked copies of plugins (and LYNX's own) start without LYNX's crash and end-signal handlers
+        static std::once_flag atFork;
+        std::call_once (atFork, [] { pthread_atfork (nullptr, nullptr, resetHandlersInForkedChild); });
+
+        // (close-on-exec: a plugin's helper program must not hold LYNX's end-signal pipe, round 190th)
+ #if defined(__APPLE__)
+        if (endSignalPipe[0] < 0 && ::pipe (endSignalPipe) == 0 && ::fcntl (endSignalPipe[0], F_SETFD, FD_CLOEXEC) == 0
+            && ::fcntl (endSignalPipe[1], F_SETFD, FD_CLOEXEC) == 0)
+ #else
+        if (endSignalPipe[0] < 0 && ::pipe2 (endSignalPipe, O_CLOEXEC) == 0)
+ #endif
         {
             std::thread ([] {
                 unsigned char byte = 0;
@@ -1826,6 +1882,21 @@ void hardenSignals() noexcept
 #endif
 }
 
+void quietBrokenPipes() noexcept
+{
+#if ! defined(_WIN32)
+    struct sigaction current {};
+    if (::sigaction (SIGPIPE, nullptr, &current) == 0 && current.sa_handler == SIG_DFL)
+    {
+        struct sigaction action {};
+        action.sa_handler = brokenPipe;
+        sigemptyset (&action.sa_mask);
+        action.sa_flags = SA_RESTART;
+        ::sigaction (SIGPIPE, &action, nullptr);
+    }
+#endif
+}
+
 void startHangWatch (const std::string& folderUtf8, int stallMs) noexcept
 {
     try

+ 7 - 0
src/platform/CrashGuard.h

@@ -243,7 +243,14 @@ void startHangWatch (const std::string& folderUtf8, int stallMs = 2000) noexcept
 // - SIGTERM / SIGHUP (the session logging out, the terminal that started LYNX closed, `kill`) leave a session step
 //   ("ended by SIGTERM ...") before LYNX ends as it did before. Without them the report could only say "closed".
 // - round 190dt: the plugin-call guard of call() (see the top of this file), on top of the crash handler.
+// - issue #359 (round 190th): the child of every fork() starts with the default action for the signals LYNX (or JUCE's
+//   crash handler) catches, and LYNX's handlers do nothing of LYNX's in a forked copy (a plugin's child process).
 void hardenSignals() noexcept;
+// Issue #359 (round 190th; Linux / macOS, nothing on Windows): SIGPIPE answered by a handler that does nothing, instead
+// of SIG_IGN. A write to a reader that went away fails with EPIPE either way, but an ignored signal stays ignored across
+// exec in every child process (a plugin's helper, xdg-open, ...), where a caught one goes back to its default action.
+// Only when SIGPIPE has its default action (left as it is when LYNX was started with it ignored or caught).
+void quietBrokenPipes() noexcept;
 void heartbeat() noexcept;
 void stopHangWatch() noexcept;
 // Round 190rf (Linux / BSD; nothing elsewhere): the X server went away (the session ended, Xwayland crashed). Xlib calls

+ 9 - 4
src/ui/LynxWindows.cpp

@@ -3,6 +3,7 @@
 
 #include <juce_events/juce_events.h>
 
+#include "platform/CrashGuard.h"
 #include "platform/Paths.h"
 
 #if JUCE_WINDOWS
@@ -127,10 +128,15 @@ public:
         if (::mkfifo (path.toRawUTF8(), 0600) != 0)
             return false;
         fd = ::open (path.toRawUTF8(), O_RDWR | O_NONBLOCK | O_CLOEXEC); // (read-write: no end of file when a writer closes)
+  #if defined(__APPLE__)
         if (fd < 0 || ::pipe (wake) != 0)
             return false;
         for (auto w : wake)
             ::fcntl (w, F_SETFD, FD_CLOEXEC);
+  #else
+        if (fd < 0 || ::pipe2 (wake, O_CLOEXEC) != 0) // (close-on-exec at once: another thread may fork meanwhile)
+            return false;
+  #endif
 #endif
         return startThread (juce::Thread::Priority::low);
     }
@@ -265,10 +271,9 @@ bool start (Entry me, Receiver receiver)
     if (s.inbox != nullptr || ! enabled())
         return s.inbox != nullptr;
 #if ! JUCE_WINDOWS
-    // a window that goes away between our open and write must not end this one (SIGPIPE's default)
-    struct sigaction current {};
-    if (::sigaction (SIGPIPE, nullptr, &current) == 0 && current.sa_handler == SIG_DFL)
-        ::signal (SIGPIPE, SIG_IGN);
+    // a window that goes away between our open and write must not end this one (SIGPIPE's default); caught, not ignored
+    // (issue #359: an ignored SIGPIPE was handed on to every program a plugin started)
+    crashguard::quietBrokenPipes();
 #endif
     me.pid = processId();
     me.started = (double) juce::Time::currentTimeMillis() / 1000.0;

+ 11 - 7
src/ui/VisualEditors.cpp

@@ -14,6 +14,7 @@
 #include "core/Effects.h"
 #include "core/Patcher.h"
 #include "engine/Exporter.h"
+#include "platform/CrashGuard.h"
 #include "platform/Paths.h"
 #include "ui/ColourPicker.h"
 #include "ui/FileChoosers.h"
@@ -1902,13 +1903,21 @@ public:
         process = pi.hProcess;
         return true;
 #else
+        // issue #359 (round 190th): close-on-exec, so that no other program started meanwhile (a plugin's helper) holds the
+        // encoder's input open (it would never see its end); dup2 below clears it on the encoder's own 0 / 1 / 2
         int fds[2];
         if (pipe (fds) != 0)
             return false;
-        const auto logFd = ::open (log.getFullPathName().toRawUTF8(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
+        for (const auto h : fds)
+            ::fcntl (h, F_SETFD, FD_CLOEXEC);
+        const auto logFd = ::open (log.getFullPathName().toRawUTF8(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
         std::vector<std::string> argv { exe.getFullPathName().toStdString() };
         for (const auto& a : args)
             argv.push_back (a.toStdString());
+        std::vector<char*> raw; // (made before fork: the child may only call async-signal-safe functions)
+        for (auto& s : argv)
+            raw.push_back (s.data());
+        raw.push_back (nullptr);
         child = fork();
         if (child == 0)
         {
@@ -1918,11 +1927,6 @@ public:
                 dup2 (logFd, 1);
                 dup2 (logFd, 2);
             }
-            ::close (fds[1]);
-            std::vector<char*> raw;
-            for (auto& s : argv)
-                raw.push_back (s.data());
-            raw.push_back (nullptr);
             execv (raw[0], raw.data());
             _exit (127);
         }
@@ -1934,7 +1938,7 @@ public:
             ::close (fds[1]);
             return false;
         }
-        signal (SIGPIPE, SIG_IGN);
+        crashguard::quietBrokenPipes(); // (an encoder that quits must not end LYNX; caught, not ignored: issue #359)
         fd = fds[1];
         return true;
 #endif

+ 339 - 0
tools/testplugin/lynx_test_child.c

@@ -0,0 +1,339 @@
+/* A CLAP effect whose editor starts child processes as it closes, for testing what LYNX hands to the child processes
+ * of the plugins it hosts (issue #359, round 190th; Linux):
+ *   cc -shared -fPIC -O2 -Ithird_party/clap/include tools/testplugin/lynx_test_child.c -o "LYNX Test Child.clap"
+ *   LYNX_TEST_CHILD_REPORT=/abs/child.txt LYNX --editortest "LYNX Test Child.clap" report.txt
+ * Otherwise a 0.5 gain (in -> out). Its editor (CLAP gui, X11) draws nothing. When the host destroys the editor, on the
+ * thread that does it, it runs these and appends one line each to $LYNX_TEST_CHILD_REPORT:
+ *   probe=      a child (fork + exec of /bin/sh) reports its blocked signals, its ignored signals and the descriptors it
+ *               inherited (it should get an empty mask, default dispositions and only 0 / 1 / 2)
+ *   term=       a child that waits for SIGTERM and exits 0 on it: it must have exited within 3 s of the kill
+ *   eof=        a child that reads its stdin (a pipe) until the end: it must end within 3 s of our closing the pipe
+ *   nofork=     a child that does not exec (fork only, as JUCE's web view when it runs in the forked copy): SIGTERM must
+ *               end it within 3 s (in LYNX it ran LYNX's own SIGTERM handler, which wrote to LYNX's pipe: the child
+ *               lived on and the host process took the signal as its own and ended)
+ *   juce=       JUCE 8's GtkChildProcess::killChild (juce_WebBrowserComponent_linux.cpp), as Xfer Shrub 1.07 runs it
+ *               when its editor closes: a web-view helper that is still there after 1.5 s is sent SIGTERM in a loop
+ *               that ends only on WIFEXITED, so once the helper died of the signal the loop spun for ever (100 % CPU in
+ *               kill + waitpid, the #359 hang). Here the loop is cut after 3 s and reported as "spin".
+ * Each line is "<name>=OK ..." or "<name>=FAIL ...". LYNX_TEST_CHILD=<name> runs only that one.
+ */
+#define _GNU_SOURCE
+#include <clap/clap.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
+
+static const char* const features[] = { CLAP_PLUGIN_FEATURE_AUDIO_EFFECT, CLAP_PLUGIN_FEATURE_UTILITY, NULL };
+
+static const clap_plugin_descriptor_t descriptor = {
+    CLAP_VERSION_INIT, "org.lynx.test-child", "LYNX Test Child", "LYNX", "https://github.com/Ka1-S/LYNX-SHARE", "", "", "1.0.0",
+    "Starts child processes as its editor closes (host signal / descriptor hygiene tests)", features
+};
+
+static double now_ms (void)
+{
+    struct timespec t;
+    clock_gettime (CLOCK_MONOTONIC, &t);
+    return t.tv_sec * 1000.0 + t.tv_nsec / 1.0e6;
+}
+static void sleep_ms (int ms)
+{
+    struct timespec t = { ms / 1000, (long) (ms % 1000) * 1000000L };
+    while (nanosleep (&t, &t) != 0 && errno == EINTR) {}
+}
+static int wanted (const char* name)
+{
+    const char* only = getenv ("LYNX_TEST_CHILD");
+    return only == NULL || *only == 0 || strcmp (only, name) == 0;
+}
+static void report (const char* line)
+{
+    const char* path = getenv ("LYNX_TEST_CHILD_REPORT");
+    if (path == NULL || *path == 0)
+        return;
+    const int fd = open (path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644);
+    if (fd < 0)
+        return;
+    (void) ! write (fd, line, strlen (line));
+    (void) ! write (fd, "\n", 1);
+    close (fd);
+}
+/* fork + exec /bin/sh -c script, with stdin / stdout from the given descriptors (-1: inherited as they are) */
+static pid_t spawn_sh (const char* script, int in, int out)
+{
+    const pid_t pid = fork();
+    if (pid == 0)
+    {
+        if (in >= 0 && in != 0) dup2 (in, 0);
+        if (out >= 0 && out != 1) dup2 (out, 1);
+        execl ("/bin/sh", "sh", "-c", script, (char*) NULL);
+        _exit (127);
+    }
+    return pid;
+}
+/* waits up to ms for the child; 1 = reaped (status set), 0 = still there, -1 = error */
+static int wait_for (pid_t pid, int* status, int ms)
+{
+    const double until = now_ms() + ms;
+    for (;;)
+    {
+        const pid_t r = waitpid (pid, status, WNOHANG);
+        if (r == pid) return 1;
+        if (r < 0 && errno != EINTR) return -1;
+        if (now_ms() > until) return 0;
+        sleep_ms (10);
+    }
+}
+static void reap_hard (pid_t pid)
+{
+    int status = 0;
+    kill (pid, SIGKILL);
+    (void) wait_for (pid, &status, 3000);
+}
+
+/* signals whose state a host must not hand on (SIGINT / SIGQUIT: a shell's background job gets them ignored) */
+static const int watched[] = { SIGHUP, SIGPIPE, SIGTERM, SIGCHLD, SIGALRM, SIGUSR1, SIGUSR2, SIGPROF, SIGCONT, SIGWINCH };
+
+static void run_probe (void)
+{
+    char out[4096] = { 0 }, line[600];
+    int fds[2];
+    if (pipe2 (fds, O_CLOEXEC) != 0) { report ("probe=FAIL pipe"); return; }
+    /* (ls lists the shell's descriptors from a child of its own: no pipe of a command substitution among them) */
+    const pid_t pid = spawn_sh ("grep -E '^Sig(Blk|Ign):' /proc/$$/status; ls -l /proc/$$/fd; exit 0", -1, fds[1]);
+    close (fds[1]);
+    size_t used = 0;
+    for (;;)
+    {
+        const ssize_t n = read (fds[0], out + used, sizeof (out) - 1 - used);
+        if (n > 0) { used += (size_t) n; continue; }
+        if (n < 0 && errno == EINTR) continue;
+        break;
+    }
+    close (fds[0]);
+    int status = 0;
+    if (pid < 0 || wait_for (pid, &status, 3000) != 1) { if (pid > 0) reap_hard (pid); report ("probe=FAIL the probe did not finish"); return; }
+    unsigned long long blocked = 0, ignored = 0;
+    const char* b = strstr (out, "SigBlk:");
+    const char* i = strstr (out, "SigIgn:");
+    if (b == NULL || i == NULL) { report ("probe=FAIL no /proc status"); return; }
+    blocked = strtoull (b + 7, NULL, 16);
+    ignored = strtoull (i + 7, NULL, 16);
+    char bad[400] = { 0 };
+    for (size_t k = 0; k < sizeof (watched) / sizeof (watched[0]); ++k)
+    {
+        const unsigned long long bit = 1ULL << (watched[k] - 1);
+        char one[40];
+        if (blocked & bit) { snprintf (one, sizeof (one), " blocked:%d", watched[k]); strncat (bad, one, sizeof (bad) - strlen (bad) - 1); }
+        if (ignored & bit) { snprintf (one, sizeof (one), " ignored:%d", watched[k]); strncat (bad, one, sizeof (bad) - strlen (bad) - 1); }
+    }
+    /* the inherited descriptors: "lrwx------ 1 user user 64 date N -> target" lines, N > 2 */
+    char fdlist[2000] = { 0 };
+    int leaked = 0;
+    for (const char* arrow = strstr (out, " -> "); arrow != NULL; arrow = strstr (arrow + 4, " -> "))
+    {
+        const char* num = arrow;
+        while (num > out && num[-1] != ' ' && num[-1] != '\n')
+            --num;
+        const int fd = atoi (num);
+        const char* e = strchr (arrow, '\n');
+        const size_t len = e != NULL ? (size_t) (e - arrow - 4) : strlen (arrow + 4);
+        if (fd <= 2)
+            continue;
+        char one[300];
+        snprintf (one, sizeof (one), " [%d %.*s]", fd, (int) (len < 250 ? len : 250), arrow + 4);
+        if (strlen (fdlist) + strlen (one) + 1 < sizeof (fdlist))
+            strcat (fdlist, one);
+        ++leaked;
+    }
+    snprintf (line, sizeof (line), "probe=%s blocked=%llx ignored=%llx%s inherited_fds=%d%s", (bad[0] == 0 && leaked == 0) ? "OK" : "FAIL",
+              blocked, ignored, bad, leaked, fdlist);
+    report (line);
+}
+
+static void run_term (void)
+{
+    char line[200];
+    const pid_t pid = spawn_sh ("trap 'exit 0' TERM; while :; do sleep 0.05; done", -1, -1);
+    if (pid < 0) { report ("term=FAIL fork"); return; }
+    sleep_ms (300);
+    kill (pid, SIGTERM);
+    const double t0 = now_ms();
+    int status = 0;
+    const int r = wait_for (pid, &status, 3000);
+    if (r != 1) { reap_hard (pid); report ("term=FAIL the child did not end on SIGTERM within 3 s"); return; }
+    snprintf (line, sizeof (line), "term=%s exited=%d code=%d signal=%d ms=%.0f", WIFEXITED (status) && WEXITSTATUS (status) == 0 ? "OK" : "FAIL",
+              WIFEXITED (status) ? 1 : 0, WIFEXITED (status) ? WEXITSTATUS (status) : -1, WIFSIGNALED (status) ? WTERMSIG (status) : 0, now_ms() - t0);
+    report (line);
+}
+
+static void run_eof (void)
+{
+    char line[200];
+    int fds[2];
+    if (pipe2 (fds, O_CLOEXEC) != 0) { report ("eof=FAIL pipe"); return; }
+    const pid_t pid = spawn_sh ("cat > /dev/null; exit 0", fds[0], -1);
+    close (fds[0]);
+    if (pid < 0) { close (fds[1]); report ("eof=FAIL fork"); return; }
+    (void) ! write (fds[1], "x\n", 2);
+    sleep_ms (100);
+    close (fds[1]);
+    const double t0 = now_ms();
+    int status = 0;
+    if (wait_for (pid, &status, 3000) != 1) { reap_hard (pid); report ("eof=FAIL the child did not see the end of its stdin within 3 s"); return; }
+    snprintf (line, sizeof (line), "eof=%s code=%d ms=%.0f", WIFEXITED (status) && WEXITSTATUS (status) == 0 ? "OK" : "FAIL",
+              WIFEXITED (status) ? WEXITSTATUS (status) : -1, now_ms() - t0);
+    report (line);
+}
+
+static void run_nofork (void)
+{
+    char line[200];
+    const pid_t pid = fork();
+    if (pid == 0)
+    {
+        for (;;)
+            pause();
+    }
+    if (pid < 0) { report ("nofork=FAIL fork"); return; }
+    sleep_ms (200);
+    kill (pid, SIGTERM);
+    int status = 0;
+    if (wait_for (pid, &status, 3000) != 1) { reap_hard (pid); report ("nofork=FAIL a forked copy lived on after SIGTERM (it ran the host's handler)"); return; }
+    snprintf (line, sizeof (line), "nofork=%s signal=%d", WIFSIGNALED (status) && WTERMSIG (status) == SIGTERM ? "OK" : "FAIL",
+              WIFSIGNALED (status) ? WTERMSIG (status) : 0);
+    report (line);
+}
+
+/* JUCE 8.0's killChild, as compiled into the plugins that use juce::WebBrowserComponent on Linux, with a 3 s cut-off */
+static void run_juce (void)
+{
+    char line[200];
+    /* a "web view helper" that takes longer than JUCE's 1.5 s to quit, and dies of SIGTERM (its default action) */
+    const pid_t childProcess = spawn_sh ("exec sleep 30", -1, -1);
+    if (childProcess < 0) { report ("juce=FAIL fork"); return; }
+    const double t0 = now_ms();
+    int status = 0, result = 0;
+    result = waitpid (childProcess, &status, WNOHANG);
+    for (int i = 0; i < 15 && (! WIFEXITED (status) || result != childProcess); ++i)
+    {
+        sleep_ms (100);
+        result = waitpid (childProcess, &status, WNOHANG);
+    }
+    status = 0;
+    long loops = 0;
+    int spun = 0;
+    if (! WIFEXITED (status) || result != childProcess)
+    {
+        for (;;)
+        {
+            kill (childProcess, SIGTERM);
+            waitpid (childProcess, &status, 0);
+            if (WIFEXITED (status))
+                break;
+            if ((++loops & 1023) == 0 && now_ms() - t0 > 4500) { spun = 1; break; }
+        }
+    }
+    snprintf (line, sizeof (line), "juce=%s loops=%ld ms=%.0f", spun ? "FAIL spin (kill + waitpid for ever, issue #359)" : "OK", loops, now_ms() - t0);
+    report (line);
+}
+
+static void on_editor_closed (void)
+{
+    if (wanted ("probe"))  run_probe();
+    if (wanted ("term"))   run_term();
+    if (wanted ("eof"))    run_eof();
+    if (wanted ("nofork")) run_nofork();
+    if (wanted ("juce"))   run_juce();
+    report ("done=1");
+}
+
+static uint32_t ports_count (const clap_plugin_t* p, bool in) { (void) p; (void) in; return 1; }
+static bool ports_get (const clap_plugin_t* p, uint32_t index, bool in, clap_audio_port_info_t* info)
+{
+    (void) p;
+    if (index != 0) return false;
+    memset (info, 0, sizeof (*info));
+    info->id = in ? 0 : 1;
+    strcpy (info->name, in ? "In" : "Out");
+    info->flags = CLAP_AUDIO_PORT_IS_MAIN;
+    info->channel_count = 2;
+    info->port_type = CLAP_PORT_STEREO;
+    info->in_place_pair = CLAP_INVALID_ID;
+    return true;
+}
+static const clap_plugin_audio_ports_t audio_ports = { ports_count, ports_get };
+
+static bool p_init (const clap_plugin_t* p) { (void) p; return true; }
+static void p_destroy (const clap_plugin_t* p) { free ((void*) p); }
+static bool p_activate (const clap_plugin_t* p, double r, uint32_t a, uint32_t b) { (void) p; (void) r; (void) a; (void) b; return true; }
+static void p_deactivate (const clap_plugin_t* p) { (void) p; }
+static bool p_start (const clap_plugin_t* p) { (void) p; return true; }
+static void p_stop (const clap_plugin_t* p) { (void) p; }
+static void p_reset (const clap_plugin_t* p) { (void) p; }
+static clap_process_status p_process (const clap_plugin_t* p, const clap_process_t* proc)
+{
+    (void) p;
+    if (proc->audio_inputs_count < 1 || proc->audio_outputs_count < 1) return CLAP_PROCESS_CONTINUE;
+    for (uint32_t c = 0; c < 2 && c < proc->audio_inputs[0].channel_count && c < proc->audio_outputs[0].channel_count; ++c)
+        for (uint32_t i = 0; i < proc->frames_count; ++i)
+            proc->audio_outputs[0].data32[c][i] = 0.5f * proc->audio_inputs[0].data32[c][i];
+    return CLAP_PROCESS_CONTINUE;
+}
+
+static bool g_api (const clap_plugin_t* p, const char* api, bool floating) { (void) p; return ! floating && strcmp (api, CLAP_WINDOW_API_X11) == 0; }
+static bool g_preferred (const clap_plugin_t* p, const char** api, bool* floating) { (void) p; *api = CLAP_WINDOW_API_X11; *floating = false; return true; }
+static bool g_create (const clap_plugin_t* p, const char* api, bool floating) { return g_api (p, api, floating); }
+static void g_destroy (const clap_plugin_t* p) { (void) p; on_editor_closed(); }
+static bool g_scale (const clap_plugin_t* p, double s) { (void) p; (void) s; return true; }
+static bool g_size (const clap_plugin_t* p, uint32_t* w, uint32_t* h) { (void) p; *w = 240; *h = 120; return true; }
+static bool g_can_resize (const clap_plugin_t* p) { (void) p; return false; }
+static bool g_hints (const clap_plugin_t* p, clap_gui_resize_hints_t* h) { (void) p; (void) h; return false; }
+static bool g_adjust (const clap_plugin_t* p, uint32_t* w, uint32_t* h) { (void) p; *w = 240; *h = 120; return true; }
+static bool g_set_size (const clap_plugin_t* p, uint32_t w, uint32_t h) { (void) p; (void) w; (void) h; return true; }
+static bool g_parent (const clap_plugin_t* p, const clap_window_t* window) { (void) p; (void) window; return true; }
+static bool g_transient (const clap_plugin_t* p, const clap_window_t* w) { (void) p; (void) w; return false; }
+static void g_title (const clap_plugin_t* p, const char* t) { (void) p; (void) t; }
+static bool g_show (const clap_plugin_t* p) { (void) p; return true; }
+static bool g_hide (const clap_plugin_t* p) { (void) p; return true; }
+static const clap_plugin_gui_t gui = { g_api, g_preferred, g_create, g_destroy, g_scale, g_size, g_can_resize, g_hints, g_adjust,
+                                       g_set_size, g_parent, g_transient, g_title, g_show, g_hide };
+
+static const void* p_extension (const clap_plugin_t* p, const char* id)
+{
+    (void) p;
+    if (strcmp (id, CLAP_EXT_GUI) == 0)
+        return &gui;
+    return strcmp (id, CLAP_EXT_AUDIO_PORTS) == 0 ? &audio_ports : NULL;
+}
+static void p_main_thread (const clap_plugin_t* p) { (void) p; }
+
+static uint32_t f_count (const clap_plugin_factory_t* f) { (void) f; return 1; }
+static const clap_plugin_descriptor_t* f_descriptor (const clap_plugin_factory_t* f, uint32_t i) { (void) f; return i == 0 ? &descriptor : NULL; }
+static const clap_plugin_t* f_create (const clap_plugin_factory_t* f, const clap_host_t* host, const char* id)
+{
+    (void) f; (void) host;
+    if (strcmp (id, descriptor.id) != 0) return NULL;
+    clap_plugin_t* p = (clap_plugin_t*) calloc (1, sizeof (clap_plugin_t));
+    p->desc = &descriptor;
+    p->init = p_init; p->destroy = p_destroy; p->activate = p_activate; p->deactivate = p_deactivate;
+    p->start_processing = p_start; p->stop_processing = p_stop; p->reset = p_reset; p->process = p_process;
+    p->get_extension = p_extension; p->on_main_thread = p_main_thread;
+    return p;
+}
+static const clap_plugin_factory_t factory = { f_count, f_descriptor, f_create };
+
+static bool e_init (const char* path) { (void) path; return true; }
+static void e_deinit (void) {}
+static const void* e_factory (const char* id) { return strcmp (id, CLAP_PLUGIN_FACTORY_ID) == 0 ? &factory : NULL; }
+
+CLAP_EXPORT const clap_plugin_entry_t clap_entry = { CLAP_VERSION_INIT, e_init, e_deinit, e_factory };