NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: cannot start detached sessions (with -m -d) back to back



On Fri, 31 Dec 2021, Valery Ushakov wrote:

I think screen is racing against the child process in MakeWindow.


I think something else might also be going on:

On NetBSD 9.2_STABLE:

$ screen -S ses -d -m -p 0 sh		# create
$ ps -Au				# check for screen & sh
...
root    1802  0.0  0.0  27148  1992 ?     Is    1:34am 0:00.00 SCREEN -S ses -d -m -p 0 sh (screen)
...
rvp     1085  0.0  0.1  23488  2252 pts/4 Ss+   1:34am 0:00.00 sh
...
$ screen -S ses -X quit			# quit
$ screen -S ses -X quit			# confirm
No screen session found.
$ ls -l /dev/pts/			# check for pts/4 used by sh
total 0
crw--w----  1 rvp  tty  5, 0 Dec 31 01:38 0
crw--w----  1 rvp  tty  5, 1 Dec 31 01:38 1
crw--w----  1 rvp  tty  5, 2 Dec 31 01:33 2
crw--w----  1 rvp  tty  5, 3 Dec 31 01:38 3
$ ps -Au				# but sh still exists!
...
rvp     1085  0.0  0.1  23488  2252 pts/4 Is+   1:34am 0:00.00 sh
...
$ fstat -p 1085				#  and still holding on to pts/4
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
rvp sh 1085 wd /tmp 85400958320606835 drwxrwxrwt 192 r rvp sh 1085 0 /dev/pts 11 crw-rw-rw- pts/4 rw
rvp      sh          1085    1  /dev/pts       11 crw-rw-rw-   pts/4 rw
rvp      sh          1085    2  /dev/pts       11 crw-rw-rw-   pts/4 rw
rvp      sh          1085   12  /         1405459 crw-rw-rw-     tty rw
$ ls -l /dev/pts/			# no pts/4
total 0
crw--w----  1 rvp  tty  5, 0 Dec 31 01:41 0
crw--w----  1 rvp  tty  5, 1 Dec 31 01:40 1
crw--w----  1 rvp  tty  5, 2 Dec 31 01:33 2
crw--w----  1 rvp  tty  5, 3 Dec 31 01:41 3
$ screen -S ses -d -m -p 0 sh		# other sh instances won't start
	 				# running bash(1), however, closes
					# the older instance on the same PTY
$ kill -HUP 1085			# kill still running sh
$ screen -S ses -d -m -p 0 sh		# now screen will run

1. I don't use screen, but, it seems to me that `-X quit' should kill off all
   programs upon termination.

2. For some reason, on NetBSD, closing the master PTY-fd in screen does not
   cause programs on the slave side to exit (on EOF).

OP: Try this patch:

---START---
diff -u screen-4.8.0{.orig,}/screen.c --- screen-4.8.0.orig/screen.c 2020-02-05 20:09:38.000000000 +0000
+++ screen-4.8.0/screen.c       2021-12-31 01:56:30.470670972 +0000
@@ -1801,6 +1801,10 @@
     struct win *p = windows;
     windows = windows->w_next;
     FreeWindow(p);
+    if (p->w_pid > 0) {
+      debug1("Hangup(%d);\n", p->w_pid);
+      killpg(p->w_pid, SIGHUP);
+    }
   }

   if (ServerSocket != -1) {
---END---

Hope this helps...

-RVP


Home | Main Index | Thread Index | Old Index