shithub: riscv

Download patch

ref: 8b19c4f273613b0477b13d6579e59396084671fc
parent: e80c7eb50b65ff7bc864fe551c24ac26c15f3e8d
author: cinap_lenrek <[email protected]>
date: Fri Jan 5 02:10:58 EST 2024

9nfs: fix rfork() race with shared pid variable

--- a/sys/src/cmd/9nfs/chat.c
+++ b/sys/src/cmd/9nfs/chat.c
@@ -26,7 +26,7 @@
 void
 chatsrv(char *name)
 {
-	int n, sfd, pfd[2];
+	int n, sfd, pid, pfd[2];
 	char *p, buf[256];
 
 	if(name && *name)
@@ -44,13 +44,14 @@
 	sfd = create(nbuf, OWRITE, 0600);
 	if(sfd < 0)
 		panic("chatsrv create %s", nbuf);
-	chatpid = rfork(RFPROC|RFMEM);
-	switch(chatpid){
+	pid = rfork(RFPROC|RFMEM);
+	switch(pid){
 	case -1:
 		panic("chatsrv fork");
 	case 0:
 		break;
 	default:
+		chatpid = pid;
 		atexit(killchat);
 		return;
 	}