shithub: drawcpu

Download patch

ref: b527faa7af4f7198fd12acc67de845c0bb4c437f
parent: a25a94e8f04e1d852c4ac2e8924f243e2fb70cbb
author: halfwit <michaelmisch1985@gmail.com>
date: Mon Jan 12 19:51:41 EST 2026

Use internal seconds for cap, various other fixes

--- a/drawcpu.h
+++ b/drawcpu.h
@@ -1,3 +1,2 @@
 extern char *getuser(void);
-extern int aanclient(char*, int);
-extern void mntgen(char*, char*);
\ No newline at end of file
+extern int aanclient(char*, int);
\ No newline at end of file
--- a/kern/chan.c
+++ b/kern/chan.c
@@ -1152,7 +1152,7 @@
 	int len, n, t, nomount;
 	Chan *c;
 	Chan * cnew;
-	Path */*volatile*/ path;
+	Path *volatile path;
 	Elemlist e;
 	Rune r;
 	Mhead *m;
--- a/kern/devcap.c
+++ b/kern/devcap.c
@@ -110,8 +110,8 @@
 	Caphash *t;
     return; 
 	while((t = capalloc.first) != nil){
-		//if(capalloc.nhash < Maxhash && TK2SEC(MACHP(0)->ticks - t->ticks) < Timeout)
-		//	break;
+		if(capalloc.nhash < Maxhash && ((ulong)time(0) - t->ticks) < Timeout)
+			break;
 		capalloc.nhash--;
 		capalloc.first = t->next;
 		secfree(t);
@@ -154,7 +154,7 @@
 	p = secalloc(sizeof *p);
 	memmove(p->hash, hash, Hashlen);
 	p->next = nil;
-	//p->ticks = MACHP(0)->ticks;
+	p->ticks = (ulong)time(0);
 
 	qlock(&capalloc.lk);
 
@@ -248,9 +248,9 @@
 			error(err);
 		}
 		secfree(p);
-        strcpy(up->user, to);
-		//procsetuser(to);
-
+		qlock(&up->debug);
+		kstrcpy(up->user, to, sizeof up->user);
+		qunlock(&up->debug);
 		secfree(cp);
 		poperror();
 		break;
--- a/kern/error.c
+++ b/kern/error.c
@@ -13,7 +13,6 @@
 char Ebadchar[] = "bad character in file name";
 char Efilename[] = "file name syntax";
 char Eperm[] = "permission denied";
-char Enoswap[] = "unable to toggle swap on Drawcpu";
 char Ebadusefd[] = "inappropriate use of fd";
 char Ebadarg[] = "bad arg in system call";
 char Einuse[] = "device or object already in use";
--- a/kern/postnote.c
+++ b/kern/postnote.c
@@ -122,7 +122,7 @@
 			continue;
 		qlock(&p->debug);
 		if(p->noteid == noteid && !p->kp){
-			incref(n);
+			incref(&n->ref);
 			pushnote(p, n);
 		}
 		qunlock(&p->debug);
--- a/kern/seg.c
+++ b/kern/seg.c
@@ -12,11 +12,11 @@
 	int i;
 	for(i = 0; i < NSEG; i++){
 		s = up->seg[i];
-		qlock(&s->rw);
+		rlock(&s->rw);
 		print("start %ul, end %ul, offset %ul", s->start, s->start + s->size, offset);
 		if(s->start <= offset && s->start + s->size >= offset)
 			return s;
-		qunlock(&s->rw);
+		runlock(&s->rw);
 	}
 	return nil;
 }
--- a/kern/syscall.c
+++ b/kern/syscall.c
@@ -907,7 +907,7 @@
 		//[_READ]			= _sys_read,
 		//[OSEEK]			= _sysoseek,
 		[SLEEP]			= _syssleep,
-		[_STAT]			= _sysstat,
+		//[_STAT]			= _sys_stat,
 		[RFORK]			= _sysrfork,
 		//[_WRITE]			= _sys_write,
 		[PIPE]			= _syspipe,
--- a/main.c
+++ b/main.c
@@ -94,8 +94,6 @@
 		
 	if(!auth || !fs)
 		usage();
-	/* We don't use argv for the root loadtext */
-	argv[0] = "";
 
 	sizebug();
 	osinit();
@@ -106,7 +104,8 @@
 	chandevinit();
 	quotefmtinstall();
 
-	/* This ordering is based on /lib/namespace 
+	/* 
+	 * This ordering is based on /lib/namespace 
 	 * - Our host fs connection lives in /srv/boot
 	 * - Everything else should eventually get a /srv
 	 */
@@ -120,6 +119,18 @@
 	bind("#I", "/net", MAFTER);
 	bind("#a", "/net", MAFTER);
 
+	/* Environment */
+	ksetenv("home", smprint("/usr/%s", eve), 0);
+	ksetenv("cputype", "arm", 0); // cputype being anything but arm should fail for now
+	ksetenv("objtype", "arm", 0);
+	ksetenv("rootdir", "/root", 0);
+	ksetenv("auth", auth, 0);
+	ksetenv("user", eve, 0);
+	ksetenv("service", "unix", 0);
+	ksetenv("sysname", sysname, 0);
+	ksetenv("prompt", "unix\% ", 0);
+	ksetenv("nvram", "/tmp/nvram", 0); /* Set up in the host /tmp */
+
 	open(cons, OREAD);
 	open(cons, OWRITE);
 	open(cons, OWRITE);
@@ -134,29 +145,16 @@
 	mount(sfd, -1, "/root", MREPL|MCREATE|MCACHE, "");
 	close(sfd);
 
-	/* Used for `os` */
-	bind("#C", "/mnt/term/", MAFTER);
-	bind("#U", "/mnt/cpu", MAFTER);
-	bind("/mnt/cpu/tmp", "/tmp", MCREATE|MAFTER);
-	bind("/root", "/", MCREATE|MAFTER);
-
 	/* Build our /bin directory */
+	bind("/root", "/", MAFTER);
 	if(bind("/arm/bin", "/bin", MCREATE|MREPL) < 0 || bind("/rc/bin", "/bin", MAFTER) < 0)
 		panic("bind bin: %r");
 
-	loadtext("/bin/rc", 1, argv);
-	ksetenv("home", smprint("/usr/%s", eve), 0);
-	ksetenv("cputype", "arm", 0); // cputype being anything but arm should fail for now
-	ksetenv("objtype", "arm", 0);
-	ksetenv("rootdir", "/root", 0);
-	ksetenv("auth", auth, 0);
-	ksetenv("user", eve, 0);
-	ksetenv("service", "unix", 0);
-	ksetenv("sysname", sysname, 0);
-	ksetenv("prompt", "unix\% ", 0);
-	ksetenv("nvram", "/tmp/nvram", 0); /* Set up in the host /tmp */
-
 	/* Run machine */
+	loadtext(argv[0], argc, argv);
 	procrun(0);
+
+	/* Clean up */
+	close(fd);
 	exits(0);
 }
--