shithub: riscv

Download patch

ref: 24d1fbde273f30422d852811d3724ede789acd0d
parent: f8de863602cfbb957733297cdaa2ee2e19a36f8b
author: cinap_lenrek <[email protected]>
date: Wed Sep 18 22:07:46 EDT 2019

kernel: simplify pgrpnote(); moving the note string copying to procwrite()

keeps handling of devproc's note and notepg files similar and in the
same place and reduces stack usage.

--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -1164,7 +1164,11 @@
 	 * than the process pgrpid
 	 */
 	if(QID(c->qid) == Qnotepg) {
-		pgrpnote(NOTEID(c->pgrpid), va, n, NUser);
+		if(n >= ERRMAX-1)
+			error(Etoobig);
+		memmove(buf, va, n);
+		buf[n] = 0;
+		pgrpnote(NOTEID(c->pgrpid), buf, NUser);
 		return n;
 	}
 
--- a/sys/src/9/port/pgrp.c
+++ b/sys/src/9/port/pgrp.c
@@ -13,16 +13,10 @@
 static Ref mountid;
 
 void
-pgrpnote(ulong noteid, char *a, long n, int flag)
+pgrpnote(ulong noteid, char *n, int flag)
 {
 	Proc *p, *ep;
-	char buf[ERRMAX];
 
-	if(n >= ERRMAX-1)
-		error(Etoobig);
-
-	memmove(buf, a, n);
-	buf[n] = 0;
 	p = proctab(0);
 	for(ep = p+conf.nproc; p < ep; p++) {
 		if(p->state == Dead)
@@ -30,7 +24,7 @@
 		if(up != p && p->noteid == noteid && p->kp == 0) {
 			qlock(&p->debug);
 			if(p->noteid == noteid)
-				postnote(p, 0, buf, flag);
+				postnote(p, 0, n, flag);
 			qunlock(&p->debug);
 		}
 	}
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -214,7 +214,7 @@
 ulong		perfticks(void);
 void		pexit(char*, int);
 void		pgrpcpy(Pgrp*, Pgrp*);
-void		pgrpnote(ulong, char*, long, int);
+void		pgrpnote(ulong, char*, int);
 int		pidalloc(Proc*);
 #define		poperror()		up->nerrlab--
 void		portcountpagerefs(ulong*, int);