shithub: rc

Download patch

ref: 24deadf3d2ae91c3fe687dc6af9122aae6bd9563
parent: f3f162f18ce9f782b1675ba03e566d9cdffeff59
author: qwx <qwx@sciops.net>
date: Sat May 13 11:07:08 EDT 2023

wircrc: fix incorrect handling of wmk race

old bug; unlike original version which wrote cmsg's to all windows at
once, we spawn a window for that channel or user if it doesn't exist,
but we almost always end up sending more text for the window wmk
hasn't registered yet.  the stupid wins2 array was used for it, the
intent apparently being to just resend the message until wmk has
called wname and is done, but wins2 is never updated, so this spins at
100% cpu.  instead, use a pointer variable and background a proc which
at least sleeps while trying to resend the data, instead of slowing
down the main rc thread, and doesn't loop.

--- a/bin/wircrc
+++ b/bin/wircrc
@@ -121,7 +121,7 @@
 	if not{
 		aux/trampoline $1 <>$c/data1 >[1=0] &
 	}
-	<>/$c/data >[1=0]{
+	<>$c/data >[1=0]{
 		$*(3-) $c $apid
 		exit
 	}
@@ -217,7 +217,8 @@
 			wd$id=$a(3)
 			wp$id=$a(4)
 			wins=($id $wins)
-			#wio $id '---' $id '---'
+			x=wip$id
+			$x=()
 		case wclose
 			d=wd$id
 			p=wp$id
@@ -249,13 +250,15 @@
 				}
 			}
 		case cmsg
+			x=wip$id
 			if(~ $id $wins)
 				wio $id $a(3) '⇒' $a(4-)
-			if not if(~ $id $wins2)
-				echo $a >/n/wircrc/data1
+			if not if(! ~ $#$x 0){
+				{ sleep 1; echo $a >/n/wircrc/data1 } &
+			}
 			if not if(! ~ $id *!'#'*){
+				$x=1
 				wmk $id $a(3-) &
-				wins2=($id $wins2)
 			}
 		case wtype
 			switch($a(3)){