shithub: svcfs

Download patch

ref: f7c354bfa6b8cffe2ce4880712decd29a4f22106
parent: 7f4c8f0736d52d4bff3fb0aefda9cf58bc39b5e6
author: Michael Misch <michaelmisch1985@gmail.com>
date: Sun Aug 4 07:54:30 EDT 2024

Stash changes

--- a/TODO
+++ b/TODO
@@ -12,6 +12,7 @@
 ## Client
 
 - Add in command to toggle markup
+- Reads on feed do not close cleanly when buffers change
 
 ## Notifications:
 
--- a/client.c
+++ b/client.c
@@ -234,9 +234,9 @@
 		b = f->cl->current;
 Again:
 		// Check if we have a tag here, abort early if so.
-		if(b->tag != flushtag){	
+		if(b->tag != flushtag){
 			n = pread(f->cl->fd, buf, sizeof(buf), r->ifcall.offset);
-			if(n){
+			if(n > 0){
 				// cut off the EOF
 				r->ofcall.count = n;
 				memmove(r->ofcall.data, buf, n);
@@ -329,8 +329,6 @@
 		t = strtok(s, " ");
 		s = strtok(nil, "\n");
 		if(strcmp(t, "buffer") == 0){
-			if(f->cl->fd)
-				close(f->cl->fd);
 			b = bufferSearch(root, s);
 			if(!b){
 				respond(r, "No buffers available");
@@ -337,6 +335,11 @@
 				return;
 			}
 			qlock(&b->l);
+			if(f->cl->fd){
+				b->tag = flushtag = 1;
+				rwakeupall(&b->rz);
+				close(f->cl->fd);
+			}
 			f->cl->current = b;
 			b->tag = r->tag;
 			qunlock(&b->l);
@@ -409,6 +412,7 @@
 void
 clstart(Srv *s)
 {
+	// TODO: Set up note handler
 	root = emalloc(sizeof(*root));
 	USED(root);
 	root = (Buffer*)s->aux;
--- a/service.c
+++ b/service.c
@@ -80,7 +80,7 @@
 
 	// NOTE: If you're sending more commands than this before they are processed, up this number
 	// But also it might be time to question your design, because commands really should not be taking long
-	svc->cmds = chancreate(1024, 16);
+	svc->cmds = chancreate(1024, 32);
 	svc->base = bufferCreate(svc->cmds);
 	svc->isInitialized = 0;
 	
@@ -330,11 +330,11 @@
 
 	cmd = strtok(s, " ");
 	targ = strtok(nil, "\n");
-	if(strcmp(cmd, "feed")==0) {
+	if(strcmp(cmd, "feed")==0) { 
 		if(b = bufferSearch(svc->base, targ)) {
+print("%s %s %s\n", cmd, targ, data);
 			qlock(&b->l);
 			d = dirfstat(b->fd);
-			data[strlen(data)] = '\n';
 			pwrite(b->fd, data, strlen(data), d->length);
 			free(d);
 			if(rwakeupall(&b->rz) == 0)
@@ -399,10 +399,11 @@
 		s[n] = 0;
 		if(f->svc->isInitialized){
 			t = s;
+print("s in: %s\n", s);
 			while(*t && strchr("\t\r\n", *t)==0)
 				t++;
-			while(*t && strchr("\t\r\n", *t))
-				*t++ = 0;
+			//while(*t && strchr("\t\r\n", *t))
+			//	*t++ = 0;
 			t = svcctl(f->svc, s, t);
 			respond(r, t);
 		} else {
@@ -447,7 +448,7 @@
 
 	if(f = fid->aux){
 		if(f->svc && f->svc->childpid)
-			postnote(PNGROUP, f->svc->childpid, "shutdown");
+			postnote(PNPROC, f->svc->childpid, "done");
 		// TODO: Uncomment this after we are good to go, this is our keepalive roughly
 		//fid->aux = nil;
 		//if(f->svc)
@@ -473,9 +474,8 @@
 		unmount(nil, mtpt);
 	for(i = 0; i < nservice; i++)
 		if(service[i].ref){
-			print("Killing %d\n", service[i].childpid);
-			postnote(PNGROUP, service[i].childpid, "shutdown");
+			postnote(PNPROC, service[i].childpid, "done");
 		}
-	postnote(PNGROUP, getpid(), "shutdown");
+	postnote(PNPROC, getpid(), "done");
 	threadexitsall(nil);
 }
--