code: plan9front

Download patch

ref: ee2174eb6d33da8eea7d1f68101b70deb12a2a4c
parent: 8d2b84747b1cbc54d6f23cc461d3ef838c1dfec9
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Jan 5 02:02:25 EST 2024

telco: fix rfork() race for pid

--- a/sys/src/cmd/telco/telco.c
+++ b/sys/src/cmd/telco/telco.c
@@ -72,7 +72,6 @@
 	char	rbuf[Nrbuf];
 	char	*rp;
 	char	*wp;
-	long	pid;
 };
 
 enum
@@ -1159,7 +1158,7 @@
 	int n;
 	char *p;
 	char file[256];
-	int background;
+	int background, pid;
 
 	background = 0;
 	d->ctl = d->data = -1;
@@ -1178,12 +1177,13 @@
 
 		if(!background){
 			background = 1;
-			switch(d->pid = rfork(RFPROC|RFMEM)){
+			switch(pid = rfork(RFPROC|RFMEM)){
 			case -1:
 				error("out of processes");
 			case 0:
 				break;
 			default:
+				d->monitoring = pid;
 				return;
 			}
 		}