shithub: mq

Download patch

ref: cae6aebb8f31e359fc872d4364962935bae703b7
parent: 2d7d9916d34ceeaef920d1f1e00aed6d215d7ca1
author: kvik <kvik@a-b.xyz>
date: Sat Sep 12 17:20:58 EDT 2020

pin: forward interrupt note to the pinned proc

Prior to this patch we used the interrupt note to detach from a session.
This was only mildly convenient but left no nice way to interrupt the
pinned proc itself.  It also broke user's expectation that pressing the
interrupt (delete) key would kill the thing that appears to be running
in foreground.

We now ignore the interrupt note on the client side and instead forward
it to the pinned proc.  This matches the behaviour of programs running
inside the usual rio window context.

--- a/rc/pin
+++ b/rc/pin
@@ -32,16 +32,33 @@
 	if not
 		exec echo $cmd >>$mq/0
 }
-if(! test -d $mq){
+
+fn detach {
 	echo creating $mq >[1=2]
+
 	mkdir -p $mq
 	echo replay on >$mq/ctl
-	touch $mq/^(0 1 2)
+	touch $mq/^(0 1 2 note)
 	$cmd <$mq/0 >>$mq/1 >>[2]$mq/2 &
+	cat $mq/note >/proc/$apid/notepg &
 }
-if(~ $#noattach 1)
-	exit
-echo attaching $mq >[1=2]
-mq-cat $mq 0 1 2 &
-cat /proc/$pid/noteid >/proc/$apid/noteid
-exec cat >>$mq/0
+
+fn attach {
+	echo attaching $mq >[1=2]
+
+	rfork e
+	fn sigint {
+		echo -n interrupt >>$mq/note
+		status = interrupted
+	}
+	mq-cat $mq 0 1 2 &
+	cat </fd/0 >>$mq/0 &
+	wait $apid
+	while(~ $status interrupted)
+		wait $apid
+}
+
+if(! test -d $mq)
+	detach
+if(~ $#noattach 0)
+	attach