commit 4f653341476e7bd81475ea29316d59254d8b957e
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Aug 22 01:19:45 2022 +0200

    term: Prevent new master while some slaves are still there
    
    The previous master may have gone before all previous slaves have gone. If a
    slave gets stuck, TTY_OPEN will kept set, and there would be no reset performed
    in open_hook, thus leaking tty state and data.

diff --git a/term/ptyio.c b/term/ptyio.c
index fadddc16..928ae0ac 100644
--- a/term/ptyio.c
+++ b/term/ptyio.c
@@ -72,7 +72,7 @@ pty_open_hook (struct trivfs_control *cntl,
 
   pthread_mutex_lock (&global_lock);
 
-  if (ptyopen)
+  if (ptyopen || nperopens)
     {
       pthread_mutex_unlock (&global_lock);
       return EBUSY;
diff --git a/term/term.h b/term/term.h
index 162ed49d..efe27ffa 100644
--- a/term/term.h
+++ b/term/term.h
@@ -31,6 +31,8 @@
 #include <features.h>
 #include <hurd/hurd_types.h>
 
+extern int nperopens;
+
 #ifdef TERM_DEFINE_EI
 #define TERM_EI
 #else
