shithub: mq

Download patch

ref: 41c3ba6e0a21f385552bd9c5d506dc1aa3e9a7a0
parent: cae6aebb8f31e359fc872d4364962935bae703b7
author: kvik <kvik@a-b.xyz>
date: Sun Sep 13 09:38:48 EDT 2020

pin: implement 'quit' command

--- a/rc/pin
+++ b/rc/pin
@@ -36,6 +36,7 @@
 fn detach {
 	echo creating $mq >[1=2]
 
+	mq = $1
 	mkdir -p $mq
 	echo replay on >$mq/ctl
 	touch $mq/^(0 1 2 note)
@@ -43,16 +44,35 @@
 	cat $mq/note >/proc/$apid/notepg &
 }
 
+fn term {
+	for(p in $killem)
+		echo -n kill >/proc/$p/note
+}
+
+fn input {
+	while(){
+	syscall -o read 0 buf 8192 >/env/buf >[2]/dev/null \
+	|| {term; exit 'read error'}
+	switch(`{cat /env/buf}){
+	case q
+		term; exit
+	case *
+		cat /env/buf
+	}}
+}
+
 fn attach {
 	echo attaching $mq >[1=2]
 
 	rfork e
+	mq = $1
 	fn sigint {
 		echo -n interrupt >>$mq/note
 		status = interrupted
 	}
 	mq-cat $mq 0 1 2 &
-	cat </fd/0 >>$mq/0 &
+	killem = ($killem $apid)
+	input </fd/0 >>$mq/0 &
 	wait $apid
 	while(~ $status interrupted)
 		wait $apid
@@ -59,6 +79,6 @@
 }
 
 if(! test -d $mq)
-	detach
+	detach $mq
 if(~ $#noattach 0)
-	attach
+	attach $mq