git: 9front

Download patch

ref: 82827fb704deabedd160cfd04df67efc9623847d
parent: f2ba4fb36684ecdd3e1989b1934ac332e3a7bda4
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Dec 21 02:45:30 EST 2011

page, mothra: corral rogue note groups

--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -204,13 +204,17 @@
 		alttext=pltextview(alt, PACKE|EXPAND, Pt(0, 0), 0, dolink);
 		plscroll(alttext, 0, bar);
 }
+int cohort = -1;
 void killcohort(void){
 	int i;
 	for(i=0;i!=3;i++){	/* It's a long way to the kitchen */
-		postnote(PNGROUP, getpid(), "kill\n");
+		postnote(PNGROUP, cohort, "kill\n");
 		sleep(1);
 	}
 }
+void catch(void*, char*){
+	noted(NCONT);
+}
 void dienow(void*, char*){
 	noted(NDFLT);
 }
@@ -272,8 +276,15 @@
 	 * so that we can stop all subprocesses with a note,
 	 * and to isolate rendezvous from other processes
 	 */
-	rfork(RFNOTEG|RFNAMEG|RFREND);
+	if(cohort = rfork(RFPROC|RFNOTEG|RFNAMEG|RFREND)){
+		atexit(killcohort);
+		notify(catch);
+		waitpid();
+		exits(0);
+	}
+	cohort = getpid();
 	atexit(killcohort);
+
 	switch(argc){
 	default:
 	Usage:
@@ -677,7 +688,6 @@
 		save(urlopen(selection, GET, 0), s);
 		break;
 	case 'q':
-		draw(screen, screen->r, display->white, 0, ZP);
 		exits(0);
 	}
 	plinitentry(cmd, EXPAND, 0, "", docmd);
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -1160,11 +1160,12 @@
 	unlockdisplay(display);
 }
 
+int cohort = -1;
 void killcohort(void)
 {
 	int i;
 	for(i=0;i!=3;i++){	/* It's a long way to the kitchen */
-		postnote(PNGROUP, getpid(), "kill");
+		postnote(PNGROUP, cohort, "kill");
 		sleep(1);
 	}
 }
@@ -1219,9 +1220,15 @@
 	 * so that we can stop all subprocesses with a note,
 	 * and to isolate rendezvous from other processes
 	 */
-	rfork(RFNOTEG|RFNAMEG|RFREND);
-	atexit(killcohort);
 	atnotify(catchnote, 1);
+	if(cohort = rfork(RFPROC|RFNOTEG|RFNAMEG|RFREND)){
+		atexit(killcohort);
+		waitpid();
+		exits(0);
+	}
+	cohort = getpid();
+	atexit(killcohort);
+
 	if(newwin > 0){
 		s = smprint("-pid %d", getpid());
 		if(newwindow(s) < 0)
--