Sfoglia il codice sorgente

Initial shell startup and console output are working.

now for stdin.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 8 anni fa
parent
commit
3db7fe787d

+ 1 - 0
sys/src/cmd/cmux/build.json

@@ -8,6 +8,7 @@
 		"SourceFiles": [
 			"cmux.c",
 			"fsys.c",
+			"kdebug.c",
 			"time.c",
 			"util.c",
 			"wctl.c",

+ 65 - 15
sys/src/cmd/cmux/cmux.c

@@ -31,8 +31,6 @@ void		delete(void);
 void		hide(void);
 void		unhide(int);
 void		newtile(int);
-Image	*sweep(void);
-Image	*bandsize(Window*);
 void		resized(void);
 Channel	*exitchan;	/* chan(int) */
 Channel	*winclosechan; /* chan(Window*); */
@@ -76,11 +74,18 @@ char *kbdargv[] = { "rc", "-c", nil, nil };
 
 int errorshouldabort = 0;
 
+Console HardwareConsole = {
+	.in = 0,
+	.out = 1,
+};
+
 void
 usage(void)
 {
+	print_func_entry();
 	fprint(2, "usage: cmux [-k kbdcmd]\n");
 	exits("usage");
+	print_func_exit();
 }
 
 void
@@ -100,8 +105,9 @@ threadmain(int argc, char *argv[])
 			usage();
 		break;
 		break;
-	}ARGEND
-
+	}ARGEND;
+	fmtinstall('W', winfmt);
+	fmtinstall('f', fidfmt);
 	mainpid = getpid();
 	if(getwd(buf, sizeof buf) == nil)
 		startdir = estrdup(".");
@@ -143,7 +149,8 @@ threadmain(int argc, char *argv[])
 		fprint(2, "cmux: can't create file system server: %r\n");
 	else{
 		errorshouldabort = 1;	/* suicide if there's trouble after this */
-		proccreate(initcmd, nil, STACK);
+#if 0
+//		proccreate(initcmd, nil, STACK);
 		if(kbdin){
 			kbdargv[2] = kbdin;
 			//i = allocwindow(wscreen, r, Refbackup, DWhite);
@@ -151,6 +158,10 @@ threadmain(int argc, char *argv[])
 			if(wkeyboard == nil)
 				error("can't create keyboard window");
 		}
+#endif
+		wkeyboard = new(&HardwareConsole, 0, nil, "/bin/rc", nil);
+		if(wkeyboard == nil)
+			error("can't create session leader console");
 		threadnotify(shutdown, 1);
 		recv(exitchan, nil);
 	}
@@ -165,13 +176,18 @@ threadmain(int argc, char *argv[])
 void
 putsnarf(void)
 {
+	print_func_entry();
 	int fd, i, n;
 
-	if(snarffd<0 || nsnarf==0)
+	if(snarffd<0 || nsnarf==0) {
+		print_func_exit();
 		return;
+	}
 	fd = open("/dev/snarf", OWRITE);
-	if(fd < 0)
+	if(fd < 0) {
+		print_func_exit();
 		return;
+	}
 	/* snarf buffer could be huge, so fprint will truncate; do it in blocks */
 	for(i=0; i<nsnarf; i+=n){
 		n = nsnarf-i;
@@ -181,16 +197,20 @@ putsnarf(void)
 			break;
 	}
 	close(fd);
+	print_func_exit();
 }
 
 void
 getsnarf(void)
 {
+	print_func_entry();
 	int i, n, nb, nulls;
 	char *sn, buf[1024];
 
-	if(snarffd < 0)
+	if(snarffd < 0) {
+		print_func_exit();
 		return;
+	}
 	sn = nil;
 	i = 0;
 	seek(snarffd, 0, 0);
@@ -205,16 +225,19 @@ getsnarf(void)
 		cvttorunes(sn, i, snarf, &nb, &nsnarf, &nulls);
 		free(sn);
 	}
+	print_func_exit();
 }
 
 void
 initcmd(void *arg)
 {
+	print_func_entry();
 
 	rfork(RFENVG|RFFDG|RFNOTEG|RFNAMEG);
 	procexecl(nil, "/bin/rc", "rc", "-i", nil);
 	fprint(2, "cmux: exec failed: %r\n");
 	exits("exec");
+	print_func_exit();
 }
 
 char *oknotes[] =
@@ -229,6 +252,7 @@ char *oknotes[] =
 int
 shutdown(void * vacio, char *msg)
 {
+	print_func_entry();
 	int i;
 	static Lock shutdownlk;
 	
@@ -241,21 +265,25 @@ shutdown(void * vacio, char *msg)
 	fprint(2, "cmux %d: abort: %s\n", getpid(), msg);
 	abort();
 	exits(msg);
+	print_func_exit();
 	return 0;
 }
 
 void
 killprocs(void)
 {
+	print_func_entry();
 	int i;
 
 	for(i=0; i<nwindow; i++)
 		postnote(PNGROUP, window[i]->pid, "hangup");
+		print_func_exit();
 }
 
 void
 keyboardthread(void* v)
 {
+	print_func_entry();
 	Rune buf[2][20], *rp;
 	int n, i;
 
@@ -272,6 +300,7 @@ keyboardthread(void* v)
 		if(input != nil)
 			sendp(input->ck, rp);
 	}
+	print_func_exit();
 }
 
 /*
@@ -280,6 +309,7 @@ keyboardthread(void* v)
 void
 keyboardsend(char *s, int cnt)
 {
+	print_func_entry();
 	Rune *r;
 	int i, nb, nr;
 
@@ -289,17 +319,24 @@ keyboardsend(char *s, int cnt)
 	for(i=0; i<nr; i++)
 		send(keyboardctl->c, &r[i]);
 	free(r);
+	print_func_exit();
 }
 
 int
 portion(int x, int lo, int hi)
 {
+	print_func_entry();
 	x -= lo;
 	hi -= lo;
-	if(x < 20)
+	if(x < 20) {
+		print_func_exit();
 		return 0;
-	if(x > hi-20)
+	}
+	if(x > hi-20) {
+		print_func_exit();
 		return 2;
+	}
+	print_func_exit();
 	return 1;
 }
 
@@ -307,6 +344,7 @@ portion(int x, int lo, int hi)
 void
 winclosethread(void* v)
 {
+	print_func_entry();
 	Window *w;
 
 	threadsetname("winclosethread");
@@ -314,12 +352,14 @@ winclosethread(void* v)
 		w = recvp(winclosechan);
 		wclose(w);
 	}
+	print_func_exit();
 }
 
 /* thread to make Deleted windows that the client still holds disappear offscreen after an interval */
 void
 deletethread(void* v)
 {
+	print_func_entry();
 	char *s;
 
 
@@ -330,38 +370,46 @@ deletethread(void* v)
 //		freeimage(i);
 		free(s);
 	}
+	print_func_exit();
 }
 
 void
 deletetimeoutproc(void *v)
 {
+	print_func_entry();
 	char *s;
 
 	s = v;
 	sleep(750);	/* remove window from screen after 3/4 of a second */
 	sendp(deletechan, s);
+	print_func_exit();
 }
 
 void
 delete(void)
 {
+	print_func_entry();
 //	Window *w;
 	fprint(2, "can't delete!\n");
 //	w = nil; //pointto(TRUE);
 //	if(w)
 //		wsendctlmesg(w, Deleted, ZR, nil);
+	print_func_exit();
 }
 
 Window*
-new(Image *i, int pid, char *dir, char *cmd, char **argv)
+new(Console *i, int pid, char *dir, char *cmd, char **argv)
 {
+	print_func_entry();
 	Window *w;
 	Mousectl *mc = nil; // someday.
 	Channel *cm, *ck, *cctl, *cpid;
 	void **arg;
 
-	if(i == nil)
+	if(i == nil) {
+		print_func_exit();
 		return nil;
+	}
 	cm = chancreate(sizeof(Mouse), 0);
 	ck = chancreate(sizeof(Rune*), 0);
 	cctl = chancreate(sizeof(Wctlmesg), 4);
@@ -369,12 +417,12 @@ new(Image *i, int pid, char *dir, char *cmd, char **argv)
 	if(cm==nil || ck==nil || cctl==nil)
 		error("new: channel alloc failed");
 	mc = emalloc(sizeof(Mousectl));
-	*mc = *mousectl;
-	mc->c = cm;
+	// NO. *mc = *mousectl;
+	// NO. mc->c = cm;
 	w = wmk(mc, ck, cctl);
-	w = nil;
 	free(mc);	/* wmk copies *mc */
 	window = erealloc(window, ++nwindow*sizeof(Window*));
+fprint(2, "-----------> Set Window  %d to %p\n", nwindow-1, w);
 	window[nwindow-1] = w;
 	threadcreate(winctl, w, 8192);
 	if(pid == 0){
@@ -395,6 +443,7 @@ new(Image *i, int pid, char *dir, char *cmd, char **argv)
 		/* window creation failed */
 		fprint(2, "not killing it\n"); //wsendctlmesg(w, Deleted, ZR, nil);
 		chanfree(cpid);
+		print_func_exit();
 		return nil;
 	}
 	wsetpid(w, pid, 1);
@@ -402,5 +451,6 @@ new(Image *i, int pid, char *dir, char *cmd, char **argv)
 	if(dir)
 		w->dir = estrdup(dir);
 	chanfree(cpid);
+	print_func_exit();
 	return w;
 }

+ 25 - 7
sys/src/cmd/cmux/dat.h

@@ -18,7 +18,7 @@
  * ptyx
  * ttyx
  * pty0 and tty0 are special
- * The Window struct will be redefined; Image structs go away.
+ * The Window struct will be redefined
  */
 enum
 {
@@ -68,7 +68,7 @@ typedef	struct	Timer Timer;
 typedef	struct	Wctlmesg Wctlmesg;
 typedef	struct	Window Window;
 typedef	struct	Xfid Xfid;
-typedef void *Image;
+typedef struct  Console Console;
 
 enum
 {
@@ -100,6 +100,14 @@ enum	/* control messages */
 	Exited,
 };
 
+/* The Console contains info about the physical console, i.e. the /dev/console we open
+ * on startup.
+ */
+struct Console {
+	int in;
+	int out;
+};
+
 struct Wctlmesg
 {
 	int		type;
@@ -132,7 +140,7 @@ struct Mousectl
 	int		mfd;		/* to mouse file */
 	int		cfd;		/* to cursor file */
 	int		pid;		/* of slave proc */
-	Image*	image;	/* of associated window/display */
+	Console*	image;	/* of associated window/display */
 };
 
 struct Mousereadmesg
@@ -219,8 +227,8 @@ char*	wcontents(Window*, int*);
 int		wbswidth(Window*, Rune);
 int		wclickmatch(Window*, int, int, int, uint*);
 int		wclose(Window*);
-//int		wctlmesg(Window*, int, Rectangle, Image*);
-//int		wctlmesg(Window*, int, Rectangle, Image*);
+//int		wctlmesg(Window*, int, Rectangle, Console*);
+//int		wctlmesg(Window*, int, Rectangle, Console*);
 uint		wbacknl(Window*, uint, uint);
 uint		winsert(Window*, Rune*, int, uint);
 void		waddraw(Window*, Rune*, int);
@@ -239,11 +247,11 @@ void		wpaste(Window*);
 void		wplumb(Window*);
 //void		wrefresh(Window*, Rectangle);
 void		wrepaint(Window*);
-void		wresize(Window*, Image*, int);
+void		wresize(Window*, Console*, int);
 void		wscrdraw(Window*);
 void		wscroll(Window*, int);
 void		wselect(Window*);
-//void		wsendctlmesg(Window*, int, Rectangle, Image*);
+//void		wsendctlmesg(Window*, int, Rectangle, Console*);
 void		wsetcursor(Window*, int);
 void		wsetname(Window*);
 void		wsetorigin(Window*, uint, int);
@@ -361,3 +369,13 @@ int		errorshouldabort;
 int		menuing;		/* menu action is pending; waiting for window to be indicated */
 int		snarfversion;	/* updated each time it is written */
 int		messagesize;		/* negotiated in 9P version setup */
+
+/* special formats.  */
+int fidfmt(Fmt *f);
+int winfmt(Fmt *f);
+
+/* For a poor-mans function tracer (can add these with spatch) */
+void __print_func_entry(const char *func, const char *file);
+void __print_func_exit(const char *func, const char *file);
+#define print_func_entry() __print_func_entry(__FUNCTION__, __FILE__)
+#define print_func_exit() __print_func_exit(__FUNCTION__, __FILE__)

+ 2 - 2
sys/src/cmd/cmux/fns.h

@@ -23,7 +23,7 @@ void	freescrtemps(void);
 // /dev/ttyfs/ctl
 int	parsewctl(char**, int*, int*, char**, char*, char*);
 int	writewctl(Xfid*, char*);
-Window *new(Image*, int, char*, char*, char**);
+Window *new(Console*, int, char*, char*, char**);
 
 int	min(int, int);
 int	max(int, int);
@@ -51,6 +51,6 @@ void	cvttorunes(char*, int, Rune*, int*, int*, int*);
 
 // ??
 void
-wsendctlmesg(Window *w, int m, Image *i);
+wsendctlmesg(Window *w, int m, Console *i);
 char*
 runetobyte(Rune *r, int n, int *ip);

+ 115 - 12
sys/src/cmd/cmux/fsys.c

@@ -90,6 +90,7 @@ Xfid* 	(*fcall[Tmax])(Filsys*, Xfid*, Fid*) =
 void
 post(char *name, char *envname, int srvfd)
 {
+	print_func_entry();
 	int fd;
 	char buf[32];
 
@@ -100,6 +101,7 @@ post(char *name, char *envname, int srvfd)
 	if(write(fd, buf, strlen(buf)) != strlen(buf))
 		error("srv write");
 	putenv(envname, name);
+	print_func_exit();
 }
 
 /*
@@ -109,20 +111,27 @@ post(char *name, char *envname, int srvfd)
 int
 cexecpipe(int *p0, int *p1)
 {
+	print_func_entry();
 	/* pipe the hard way to get close on exec */
-	if(bind("#|", "/mnt/temp", MREPL) < 0)
+	if(bind("#|", "/mnt/temp", MREPL) < 0) {
+		print_func_exit();
 		return -1;
+	}
 	*p0 = open("/mnt/temp/data", ORDWR);
 	*p1 = open("/mnt/temp/data1", ORDWR|OCEXEC);
 	unmount(nil, "/mnt/temp");
-	if(*p0<0 || *p1<0)
+	if(*p0<0 || *p1<0) {
+		print_func_exit();
 		return -1;
+	}
+	print_func_exit();
 	return 0;
 }
 
 Filsys*
 filsysinit(Channel *cxfidalloc)
 {
+	print_func_entry();
 	int n, fd, pid, p0;
 	Filsys *fs;
 	Channel *c;
@@ -170,10 +179,12 @@ filsysinit(Channel *cxfidalloc)
 	sprint(srvpipe, "/srv/rio.%s.%d", fs->user, pid);
 	post(srvpipe, "wsys", fs->cfd);
 
+	print_func_exit();
 	return fs;
 
 Rescue:
 	free(fs);
+	print_func_exit();
 	return nil;
 }
 
@@ -181,6 +192,7 @@ static
 void
 filsysproc(void *arg)
 {
+	print_func_entry();
 	int n;
 	Xfid *x;
 	Fid *f;
@@ -223,6 +235,7 @@ filsysproc(void *arg)
 		}
 		firstmessage = 0;
 	}
+	print_func_exit();
 }
 
 /*
@@ -231,24 +244,30 @@ filsysproc(void *arg)
 int
 filsysmount(Filsys *fs, int id)
 {
+	print_func_entry();
 	char buf[32];
 
 	close(fs->sfd);	/* close server end so mount won't hang if exiting */
 	sprint(buf, "%d", id);
+fprint(2, "mount %s\n", buf);
 	if(mount(fs->cfd, -1, "/mnt/wsys", MREPL, buf, 'M') < 0){
 		fprint(2, "mount failed: %r\n");
+		print_func_exit();
 		return -1;
 	}
 	if(bind("/mnt/wsys", "/dev", MBEFORE) < 0){
 		fprint(2, "bind failed: %r\n");
+		print_func_exit();
 		return -1;
 	}
+	print_func_exit();
 	return 0;
 }
 
 Xfid*
 filsysrespond(Filsys *fs, Xfid *x, Fcall *t, char *err)
 {
+	print_func_entry();
 	int n;
 
 	if(err){
@@ -269,33 +288,44 @@ filsysrespond(Filsys *fs, Xfid *x, Fcall *t, char *err)
 		fprint(2, "rio:->%F\n", t);
 	free(x->buf);
 	x->buf = nil;
+	print_func_exit();
 	return x;
 }
 
 void
 filsyscancel(Xfid *x)
 {
+	print_func_entry();
 	if(x->buf){
 		free(x->buf);
 		x->buf = nil;
 	}
+	print_func_exit();
 }
 
 static 
 Xfid*
 filsysversion(Filsys *fs, Xfid *x, Fid* f)
 {
+	print_func_entry();
 	Fcall t;
 
-	if(!firstmessage)
+	if(!firstmessage) {
+		print_func_exit();
 		return filsysrespond(x->fs, x, &t, "version request not first message");
-	if(x->msize < 256)
+	}
+	if(x->msize < 256) {
+		print_func_exit();
 		return filsysrespond(x->fs, x, &t, "version: message size too small");
+	}
 	messagesize = x->msize;
 	t.msize = messagesize;
-	if(strncmp(x->version, "9P2000", 6) != 0)
+	if(strncmp(x->version, "9P2000", 6) != 0) {
+		print_func_exit();
 		return filsysrespond(x->fs, x, &t, "unrecognized 9P version");
+	}
 	t.version = "9P2000";
+	print_func_exit();
 	return filsysrespond(fs, x, &t, nil);
 }
 
@@ -303,8 +333,10 @@ static
 Xfid*
 filsysauth(Filsys *fs, Xfid *x, Fid* f)
 {
+	print_func_entry();
 	Fcall t;
 
+		print_func_exit();
 		return filsysrespond(fs, x, &t, "rio: authentication not required");
 }
 
@@ -312,7 +344,9 @@ static
 Xfid*
 filsysflush(Filsys* fs, Xfid *x, Fid* f)
 {
+	print_func_entry();
 	sendp(x->c, xfidflush);
+	print_func_exit();
 	return nil;
 }
 
@@ -320,10 +354,13 @@ static
 Xfid*
 filsysattach(Filsys * fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 
-	if(strcmp(x->uname, x->fs->user) != 0)
+	if(strcmp(x->uname, x->fs->user) != 0) {
+		print_func_exit();
 		return filsysrespond(x->fs, x, &t, Eperm);
+	}
 	f->busy = TRUE;
 	f->open = FALSE;
 	f->qid.path = Qdir;
@@ -332,6 +369,7 @@ filsysattach(Filsys * fs, Xfid *x, Fid *f)
 	f->dir = dirtab;
 	f->nrpart = 0;
 	sendp(x->c, xfidattach);
+	print_func_exit();
 	return nil;
 }
 
@@ -339,9 +377,13 @@ static
 int
 numeric(char *s)
 {
+	print_func_entry();
 	for(; *s!='\0'; s++)
-		if(*s<'0' || '9'<*s)
+		if(*s<'0' || '9'<*s) {
+			print_func_exit();
 			return 0;
+		}
+	print_func_exit();
 	return 1;
 }
 
@@ -349,6 +391,7 @@ static
 Xfid*
 filsyswalk(Filsys *fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 	Fid *nf;
 	int i, id;
@@ -359,14 +402,28 @@ filsyswalk(Filsys *fs, Xfid *x, Fid *f)
 	char *err;
 	Qid qid;
 
-	if(f->open)
+	if (DEBUG)
+		fprint(2, "f %p\n", f);
+	if (! f) {
+		print_func_exit();
+		return filsysrespond(fs, x, &t, "NO FID!");
+	}
+
+	if (DEBUG)
+		fprint(2, "FID %f\n", f);
+
+	if(f->open) {
+		print_func_exit();
 		return filsysrespond(fs, x, &t, "walk of open file");
+	}
 	nf = nil;
 	if(x->fid  != x->newfid){
 		/* BUG: check exists */
 		nf = newfid(fs, x->newfid);
-		if(nf->busy)
+		if(nf->busy) {
+			print_func_exit();
 			return filsysrespond(fs, x, &t, "clone to busy fid");
+		}
 		nf->busy = TRUE;
 		nf->open = FALSE;
 		nf->dir = f->dir;
@@ -463,6 +520,7 @@ filsyswalk(Filsys *fs, Xfid *x, Fid *f)
 		f->qid = qid;
 	}
 
+	print_func_exit();
 	return filsysrespond(fs, x, &t, err);
 }
 
@@ -470,6 +528,7 @@ static
 Xfid*
 filsysopen(Filsys *fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 	int m;
 
@@ -495,9 +554,11 @@ filsysopen(Filsys *fs, Xfid *x, Fid *f)
 		goto Deny;
 		
 	sendp(x->c, xfidopen);
+	print_func_exit();
 	return nil;
 
     Deny:
+	print_func_exit();
 	return filsysrespond(fs, x, &t, Eperm);
 }
 
@@ -505,8 +566,10 @@ static
 Xfid*
 filsyscreate(Filsys *fs, Xfid *x, Fid*f)
 {
+	print_func_entry();
 	Fcall t;
 
+	print_func_exit();
 	return filsysrespond(fs, x, &t, Eperm);
 }
 
@@ -514,6 +577,8 @@ static
 int
 idcmp(const void *a, const void *b)
 {
+	print_func_entry();
+	print_func_exit();
 	return *(int*)a - *(int*)b;
 }
 
@@ -521,6 +586,7 @@ static
 Xfid*
 filsysread(Filsys *fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 	uint8_t *b;
 	int i, n, o, e, len, j, k, *ids;
@@ -530,14 +596,17 @@ filsysread(Filsys *fs, Xfid *x, Fid *f)
 
 	if((f->qid.type & QTDIR) == 0){
 		sendp(x->c, xfidread);
+		print_func_exit();
 		return nil;
 	}
 	o = x->offset;
 	e = x->offset+x->count;
 	clock = getclock();
 	b = malloc(messagesize-IOHDRSZ);	/* avoid memset of emalloc */
-	if(b == nil)
-		return filsysrespond(fs, x, &t, "out of memory");
+	if(b == nil) {
+	print_func_exit();
+	return filsysrespond(fs, x, &t, "out of memory");
+	}
 	n = 0;
 	switch(FILE(f->qid)){
 	case Qdir:
@@ -581,6 +650,7 @@ filsysread(Filsys *fs, Xfid *x, Fid *f)
 	t.count = n;
 	filsysrespond(fs, x, &t, nil);
 	free(b);
+	print_func_exit();
 	return x;
 }
 
@@ -588,7 +658,9 @@ static
 Xfid*
 filsyswrite(Filsys* fs, Xfid *x, Fid*f)
 {
+	print_func_entry();
 	sendp(x->c, xfidwrite);
+	print_func_exit();
 	return nil;
 }
 
@@ -596,18 +668,21 @@ static
 Xfid*
 filsysclunk(Filsys *fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 
 	if(f->open){
 		f->busy = FALSE;
 		f->open = FALSE;
 		sendp(x->c, xfidclose);
+		print_func_exit();
 		return nil;
 	}
 	if(f->w)
 		sendp(winclosechan, f->w);
 	f->busy = FALSE;
 	f->open = FALSE;
+	print_func_exit();
 	return filsysrespond(fs, x, &t, nil);
 }
 
@@ -615,8 +690,10 @@ static
 Xfid*
 filsysremove(Filsys *fs, Xfid *x, Fid*f)
 {
+	print_func_entry();
 	Fcall t;
 
+	print_func_exit();
 	return filsysrespond(fs, x, &t, Eperm);
 }
 
@@ -624,12 +701,14 @@ static
 Xfid*
 filsysstat(Filsys *fs, Xfid *x, Fid *f)
 {
+	print_func_entry();
 	Fcall t;
 
 	t.stat = emalloc(messagesize-IOHDRSZ);
 	t.nstat = dostat(fs, WIN(x->f->qid), f->dir, t.stat, messagesize-IOHDRSZ, getclock());
 	x = filsysrespond(fs, x, &t, nil);
 	free(t.stat);
+	print_func_exit();
 	return x;
 }
 
@@ -637,8 +716,10 @@ static
 Xfid*
 filsyswstat(Filsys *fs, Xfid *x, Fid*f)
 {
+	print_func_entry();
 	Fcall t;
 
+	print_func_exit();
 	return filsysrespond(fs, x, &t, Eperm);
 }
 
@@ -646,23 +727,28 @@ static
 Fid*
 newfid(Filsys *fs, int fid)
 {
+	print_func_entry();
 	Fid *f, *ff, **fh;
 
 	ff = nil;
 	fh = &fs->fids[fid&(Nhash-1)];
 	for(f=*fh; f; f=f->next)
-		if(f->fid == fid)
+		if(f->fid == fid) {
+			print_func_exit();
 			return f;
+		}
 		else if(ff==nil && f->busy==FALSE)
 			ff = f;
 	if(ff){
 		ff->fid = fid;
+		print_func_exit();
 		return ff;
 	}
 	f = emalloc(sizeof *f);
 	f->fid = fid;
 	f->next = *fh;
 	*fh = f;
+	print_func_exit();
 	return f;
 }
 
@@ -670,10 +756,12 @@ static
 uint
 getclock(void)
 {
+	print_func_entry();
 	char buf[32];
 
 	seek(clockfd, 0, 0);
 	read(clockfd, buf, sizeof buf);
+	print_func_exit();
 	return atoi(buf);
 }
 
@@ -681,6 +769,7 @@ static
 int
 dostat(Filsys *fs, int id, Dirtab *dir, uint8_t *buf, int nbuf, uint clock)
 {
+	print_func_entry();
 	Dir d;
 
 	d.qid.path = QID(id, dir->qid);
@@ -697,5 +786,19 @@ dostat(Filsys *fs, int id, Dirtab *dir, uint8_t *buf, int nbuf, uint clock)
 	d.muid = fs->user;
 	d.atime = clock;
 	d.mtime = clock;
+	print_func_exit();
 	return convD2M(&d, buf, nbuf);
 }
+int
+fidfmt(Fmt *f)
+{
+	Fid *fid;
+
+	fid = va_arg(f->args, Fid*);
+	if (! fid)
+		return fmtprint(f, "<NULL>");
+	return fmtprint(f, "fid %d, %s%s, %W\n", 
+			fid->fid, fid->busy ? "busy," : "",
+			fid->open ? "open, " : "",
+			fid->w);
+}

+ 12 - 0
sys/src/cmd/cmux/time.c

@@ -22,26 +22,33 @@ static
 uint
 msec(void)
 {
+	print_func_entry();
+	print_func_exit();
 	return nsec()/1000000;
 }
 
 void
 timerstop(Timer *t)
 {
+	print_func_entry();
 	t->next = timer;
 	timer = t;
+	print_func_exit();
 }
 
 void
 timercancel(Timer *t)
 {
+	print_func_entry();
 	t->cancel = TRUE;
+	print_func_exit();
 }
 
 static
 void
 timerproc(void* vacio)
 {
+	print_func_entry();
 	int i, nt, na, dt, del;
 	Timer **t, *x;
 	uint old, new;
@@ -95,13 +102,16 @@ timerproc(void* vacio)
 		if(nbrecv(ctimer, &x) > 0)
 			goto gotit;
 	}
+	print_func_exit();
 }
 
 void
 timerinit(void)
 {
+	print_func_entry();
 	ctimer = chancreate(sizeof(Timer*), 100);
 	proccreate(timerproc, nil, STACK);
+	print_func_exit();
 }
 
 /*
@@ -112,6 +122,7 @@ timerinit(void)
 Timer*
 timerstart(int dt)
 {
+	print_func_entry();
 	Timer *t;
 
 	t = timer;
@@ -125,5 +136,6 @@ timerstart(int dt)
 	t->dt = dt;
 	t->cancel = FALSE;
 	sendp(ctimer, t);
+	print_func_exit();
 	return t;
 }

+ 39 - 6
sys/src/cmd/cmux/util.c

@@ -18,6 +18,7 @@
 void
 cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
 {
+	print_func_entry();
 	uint8_t *q;
 	Rune *s;
 	int j, w;
@@ -46,109 +47,141 @@ cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
 	}
 	*nb = (char*)q-p;
 	*nr = s-r;
+	print_func_exit();
 }
 
 void
 error(char *s)
 {
+	print_func_entry();
 	fprint(2, "rio: %s: %r\n", s);
 	if(errorshouldabort)
 		abort();
 	threadexitsall("error");
+	print_func_exit();
 }
 
 void*
 erealloc(void *p, uint n)
 {
+	print_func_entry();
 	p = realloc(p, n);
 	if(p == nil)
 		error("realloc failed");
+	print_func_exit();
 	return p;
 }
 
 void*
 emalloc(uint n)
 {
+	print_func_entry();
 	void *p;
 
 	p = malloc(n);
 	if(p == nil)
 		error("malloc failed");
 	memset(p, 0, n);
+	print_func_exit();
 	return p;
 }
 
 char*
 estrdup(char *s)
 {
+	print_func_entry();
 	char *p;
 
 	p = malloc(strlen(s)+1);
 	if(p == nil)
 		error("strdup failed");
 	strcpy(p, s);
+	print_func_exit();
 	return p;
 }
 
 int
 isalnum(Rune c)
 {
+	print_func_entry();
 	/*
 	 * Hard to get absolutely right.  Use what we know about ASCII
 	 * and assume anything above the Latin control characters is
 	 * potentially an alphanumeric.
 	 */
-	if(c <= ' ')
+	if(c <= ' ') {
+		print_func_exit();
 		return FALSE;
-	if(0x7F<=c && c<=0xA0)
+	}
+	if(0x7F<=c && c<=0xA0) {
+		print_func_exit();
 		return FALSE;
-	if(utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", c))
+	}
+	if(utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", c)) {
+		print_func_exit();
 		return FALSE;
+	}
+	print_func_exit();
 	return TRUE;
 }
 
 Rune*
 strrune(Rune *s, Rune c)
 {
+	print_func_entry();
 	Rune c1;
 
 	if(c == 0) {
 		while(*s++)
 			;
+		print_func_exit();
 		return s-1;
 	}
 
 	while(c1 = *s++)
-		if(c1 == c)
+		if(c1 == c) {
+			print_func_exit();
 			return s-1;
+		}
+	print_func_exit();
 	return nil;
 }
 
 int
 min(int a, int b)
 {
-	if(a < b)
+	print_func_entry();
+	if(a < b) {
+		print_func_exit();
 		return a;
+	}
+	print_func_exit();
 	return b;
 }
 
 int
 max(int a, int b)
 {
-	if(a > b)
+	print_func_entry();
+	if(a > b) {
+		print_func_exit();
 		return a;
+	}
+	print_func_exit();
 	return b;
 }
 
 char*
 runetobyte(Rune *r, int n, int *ip)
 {
+	print_func_entry();
 	char *s;
 	int m;
 
 	s = emalloc(n*UTFmax+1);
 	m = snprint(s, n*UTFmax+1, "%.*S", n, r);
 	*ip = m;
+	print_func_exit();
 	return s;
 }
 

+ 38 - 4
sys/src/cmd/cmux/wctl.c

@@ -91,6 +91,7 @@ static
 int
 word(char **sp, char *tab[])
 {
+	print_func_entry();
 	char *s, *t;
 	int i;
 
@@ -103,24 +104,33 @@ word(char **sp, char *tab[])
 	for(i=0; tab[i]!=nil; i++)
 		if(strncmp(tab[i], t, strlen(tab[i])) == 0){
 			*sp = s;
+			print_func_exit();
 			return i;
 	}
+	print_func_exit();
 	return -1;
 }
 
 int
 set(int sign, int neg, int abs, int pos)
 {
-	if(sign < 0)
+	print_func_entry();
+	if(sign < 0) {
+		print_func_exit();
 		return neg;
-	if(sign > 0)
+	}
+	if(sign > 0) {
+		print_func_exit();
 		return pos;
+	}
+	print_func_exit();
 	return abs;
 }
 
 void
 shift(int *minp, int *maxp, int min, int max)
 {
+	print_func_entry();
 	if(*minp < min){
 		*maxp += min-*minp;
 		*minp = min;
@@ -129,6 +139,7 @@ shift(int *minp, int *maxp, int min, int max)
 		*minp += max-*maxp;
 		*maxp = max;
 	}
+	print_func_exit();
 }
 
 
@@ -136,6 +147,7 @@ shift(int *minp, int *maxp, int min, int max)
 int
 riostrtol(char *s, char **t)
 {
+	print_func_entry();
 	int n;
 
 	while(*s!='\0' && (*s==' ' || *s=='\t' || *s=='['))
@@ -146,6 +158,7 @@ riostrtol(char *s, char **t)
 	if(*t != s)
 		while((*t)[0] == ']')
 			(*t)++;
+	print_func_exit();
 	return n;
 }
 
@@ -155,6 +168,7 @@ parsewctl(char **argp, int *pidp, int *idp,
 	  char **cdp, char *s,
 	  char *err)
 {
+	print_func_entry();
 	int cmd, param, xy = 0;
 
 	*pidp = 0;
@@ -162,6 +176,7 @@ parsewctl(char **argp, int *pidp, int *idp,
 	cmd = word(&s, cmds);
 	if(cmd < 0){
 		strcpy(err, "unrecognized wctl command");
+		print_func_exit();
 		return -1;
 	}
 	strcpy(err, "missing or bad wctl parameter");
@@ -182,20 +197,23 @@ parsewctl(char **argp, int *pidp, int *idp,
 		s++;
 	if(cmd!=New && *s!='\0'){
 		strcpy(err, "extraneous text in wctl message");
+		print_func_exit();
 		return -1;
 	}
 
 	if(argp)
 		*argp = s;
 
+	print_func_exit();
 	return cmd;
 }
 
 int
 wctlnew(char *arg, int pid, char *dir, char *err)
 {
+	print_func_entry();
 	char **argv;
-	Image *i = nil;
+	Console *i = nil;
 
 	argv = emalloc(4*sizeof(char*));
 	argv[0] = "rc";
@@ -211,17 +229,20 @@ wctlnew(char *arg, int pid, char *dir, char *err)
 	}
 	if(i == nil){
 		strcpy(err, Ewalloc);
+		print_func_exit();
 		return -1;
 	}
 	//new(i, hideit, scrollit, pid, dir, "/bin/rc", argv);
 
 	free(argv);	/* when new() returns, argv and args have been copied */
+	print_func_exit();
 	return 1;
 }
 
 int
 writewctl(Xfid *x, char *err)
 {
+	print_func_entry();
 	int cnt, cmd, j, id, pid;
 	char *arg, *dir;
 	Window *w;
@@ -232,8 +253,10 @@ writewctl(Xfid *x, char *err)
 	id = 0;
 
 	cmd = parsewctl(&arg, &pid, &id, &dir, x->data, err);
-	if(cmd < 0)
+	if(cmd < 0) {
+		print_func_exit();
 		return -1;
+	}
 
 	if(id != 0){
 		for(j=0; j<nwindow; j++)
@@ -241,36 +264,44 @@ writewctl(Xfid *x, char *err)
 				break;
 		if(j == nwindow){
 			strcpy(err, "no such window id");
+			print_func_exit();
 			return -1;
 		}
 		w = window[j];
 		if(w->deleted){
 			strcpy(err, "window deleted");
+			print_func_exit();
 			return -1;
 		}
 	}
 
 	switch(cmd){
 	case New:
+		print_func_exit();
 		return wctlnew(arg, pid, dir, err);
 	case Set:
 		if(pid > 0)
 			wsetpid(w, pid, 0);
+		print_func_exit();
 		return 1;
 	case Current:
 		wcurrent(w);
+		print_func_exit();
 		return 1;
 	case Delete:
 		//wsendctlmesg(w, Deleted, ZR, nil);
+		print_func_exit();
 		return 1;
 	}
 	strcpy(err, "invalid wctl message");
+	print_func_exit();
 	return -1;
 }
 
 void
 wctlthread(void *v)
 {
+	print_func_entry();
 	char *buf, *arg, *dir;
 	int cmd, id, pid;
 	char err[ERRMAX];
@@ -290,11 +321,13 @@ wctlthread(void *v)
 		}
 		free(buf);
 	}
+	print_func_exit();
 }
 
 void
 wctlproc(void *v)
 {
+	print_func_entry();
 	char *buf;
 	int n, eofs;
 	Channel *c;
@@ -318,4 +351,5 @@ wctlproc(void *v)
 		buf[n] = '\0';
 		sendp(c, buf);
 	}
+	print_func_exit();
 }

+ 67 - 42
sys/src/cmd/cmux/wind.c

@@ -31,10 +31,11 @@ static	int		id;
 Window*
 wmk(Mousectl *mc, Channel *ck, Channel *cctl)
 {
+	print_func_entry();
 	Window *w;
 
 	w = emalloc(sizeof(Window));
-	w->mc = *mc;
+	// NO. w->mc = nil; // *mc;
 	w->ck = ck;
 	w->cctl = cctl;
 	w->conswrite = chancreate(sizeof(Conswritemesg), 0);
@@ -46,12 +47,14 @@ wmk(Mousectl *mc, Channel *ck, Channel *cctl)
 	w->dir = estrdup(startdir);
 	w->label = estrdup("<unnamed>");
 	incref(w);	/* ref will be removed after mounting; avoids delete before ready to be deleted */
+	print_func_exit();
 	return w;
 }
 
 void
 wsetname(Window *w)
 {
+	print_func_entry();
 	int i, n;
 	char err[ERRMAX];
 	
@@ -67,21 +70,26 @@ wsetname(Window *w)
 	}
 	w->name[0] = 0;
 	fprint(2, "rio: setname failed: %s\n", err);
+	print_func_exit();
 }
 
 int
 wclose(Window *w)
 {
+	print_func_entry();
 	int i;
 
 	i = decref(w);
-	if(i > 0)
+	if(i > 0) {
+		print_func_exit();
 		return 0;
+	}
 	if(i < 0)
 		error("negative ref count");
 	if(!w->deleted)
 		wclosewin(w);
 	wsendctlmesg(w, Exited, nil);
+	print_func_exit();
 	return 1;
 }
 
@@ -89,13 +97,14 @@ wclose(Window *w)
 void
 winctl(void *arg)
 {
+	print_func_entry();
 	Rune *rp, *bp, *tp, *up, *kbdr;
 	uint qh;
 	int nr, nb, c, wid, i, npart, initial, lastb;
 	char *s, *t, part[3];
 	Window *w;
 	Mousestate *mp, m;
-	enum { WKey, WMouse, WMouseread, WCtl, WCwrite, WCread, WWread, NWALT };
+	enum { WKey, /*WMouse, WMouseread, */WCtl, WCwrite, WCread, WWread, NWALT };
 	Alt alts[NWALT+1];
 	Mousereadmesg mrm;
 	Conswritemesg cwm;
@@ -104,7 +113,6 @@ winctl(void *arg)
 	Stringpair pair;
 	Wctlmesg wcm;
 	char buf[4*12+1];
-
 	w = arg;
 	snprint(buf, sizeof buf, "winctl-id%d", w->id);
 	threadsetname(buf);
@@ -120,12 +128,14 @@ winctl(void *arg)
 	alts[WKey].c = w->ck;
 	alts[WKey].v = &kbdr;
 	alts[WKey].op = CHANRCV;
+#if 0
 	alts[WMouse].c = w->mc.c;
 	alts[WMouse].v = &w->mc.Mouse;
 	alts[WMouse].op = CHANRCV;
 	alts[WMouseread].c = w->mouseread;
 	alts[WMouseread].v = &mrm;
 	alts[WMouseread].op = CHANSND;
+#endif
 	alts[WCtl].c = w->cctl;
 	alts[WCtl].v = &wcm;
 	alts[WCtl].op = CHANRCV;
@@ -143,10 +153,12 @@ winctl(void *arg)
 	npart = 0;
 	lastb = -1;
 	for(;;){
+#if 0
 		if(w->mouseopen && w->mouse.counter != w->mouse.lastcounter)
 			alts[WMouseread].op = CHANSND;
 		else
 			alts[WMouseread].op = CHANNOP;
+#endif
 		if(w->deleted || !w->wctlready)
 			alts[WWread].op = CHANNOP;
 		else
@@ -171,6 +183,7 @@ winctl(void *arg)
 ///			while(nbrecv(w->ck, &r))
 //				wkeyctl(w, r);
 			break;
+#if 0
 		case WMouse:
 			if(w->mouseopen) {
 				w->mouse.counter++;
@@ -204,6 +217,7 @@ winctl(void *arg)
 			w->mouse.lastcounter = m.counter;
 			send(mrm.cm, &m.Mouse);
 			continue;
+#endif
 		case WCtl:
 			exits("WCtl can't do");
 #if 0
@@ -223,43 +237,15 @@ winctl(void *arg)
 			rp = pair.s;
 			nr = pair.ns;
 			bp = rp;
-			for(i=0; i<nr; i++)
-				if(*bp++ == '\b'){
-					--bp;
-					initial = 0;
-					tp = runemalloc(nr);
-					runemove(tp, rp, i);
-					up = tp+i;
-					for(; i<nr; i++){
-						*up = *bp++;
-						if(*up == '\b')
-							if(up == tp)
-								initial++;
-							else
-								--up;
-						else
-							up++;
-					}
-					if(initial){
-						if(initial > w->qh)
-							initial = w->qh;
-						qh = w->qh-initial;
-						fprint(2, "WDELETE\n");
-						//wdelete(w, qh, qh+initial);
-						w->qh = qh;
-					}
-					free(rp);
-					rp = tp;
-					nr = up-tp;
-					rp[nr] = 0;
-					break;
-				}
-			fprint(2, "winsert!\n");
-//			w->qh = winsert(w, rp, nr, w->qh)+nr;
-//			wsetselect(w, w->q0, w->q1);
+			for(i=0; i<nr; i++) {
+				// See rio for the run conversion crap. For now, I'm not going to
+				// worry about it. This is designed to target Akaros too.
+				fprint(/*w->Console->out*/1, "%c", *bp++);
+			}
 			free(rp);
 			break;
 		case WCread:
+fprint(2, "Console read\n");
 			recv(crm.c1, &pair);
 			t = pair.s;
 			nb = pair.ns;
@@ -314,14 +300,17 @@ winctl(void *arg)
 			continue;
 		}
 	}
+	print_func_exit();
 }
 
 void
 waddraw(Window *w, Rune *r, int nr)
 {
+	print_func_entry();
 	w->raw = runerealloc(w->raw, w->nraw+nr);
 	runemove(w->raw+w->nraw, r, nr);
 	w->nraw += nr;
+	print_func_exit();
 }
 
 /*
@@ -331,11 +320,13 @@ waddraw(Window *w, Rune *r, int nr)
 void
 interruptproc(void *v)
 {
+	print_func_entry();
 	int *notefd;
 
 	notefd = v;
 	write(*notefd, "interrupt", 9);
 	free(notefd);
+	print_func_exit();
 }
 
 
@@ -345,17 +336,20 @@ interruptproc(void *v)
 //static uint	selectq;
 
 void
-wsendctlmesg(Window *w, int type, Image *image)
+wsendctlmesg(Window *w, int type, Console *image)
 {
+	print_func_entry();
 	Wctlmesg wcm;
 
 	wcm.type = type;
 	send(w->cctl, &wcm);
+	print_func_exit();
 }
 
 int
-wctlmesg(Window *w, int m, Image *i)
+wctlmesg(Window *w, int m, Console *i)
 {
+	print_func_entry();
 	switch(m){
 	default:
 		error("unknown control message");
@@ -401,16 +395,20 @@ wctlmesg(Window *w, int m, Image *i)
 		free(w);
 		break;
 	}
+	print_func_exit();
 	return m;
 }
 
 void
 wcurrent(Window *w)
 {
+	print_func_entry();
 	Window *oi;
 
-	if(wkeyboard!=nil && w==wkeyboard)
+	if(wkeyboard!=nil && w==wkeyboard) {
+		print_func_exit();
 		return;
+	}
 	oi = input;
 	input = w;
 	if(w != oi){
@@ -423,11 +421,13 @@ wcurrent(Window *w)
 			wsendctlmesg(w, Wakeup, nil);
 		}
 	}
+	print_func_exit();
 }
 
 Window*
 wtop(void)
 {
+	print_func_entry();
 	exits("wtop!");
 #if 0
 	Window *w;
@@ -441,6 +441,7 @@ wtop(void)
 		w->topped = ++topped;
 	}
 #endif
+	print_func_exit();
 	return nil;
 }
 
@@ -448,17 +449,25 @@ wtop(void)
 Window*
 wlookid(int id)
 {
+	print_func_entry();
 	int i;
 
+	fprint(2, "%d:", id);
 	for(i=0; i<nwindow; i++)
-		if(window[i]->id == id)
+		if(window[i]->id == id) {
+			fprint(2, "FOUND @%p", window[i]);
+			print_func_exit();
 			return window[i];
+		}
+	fprint(2, "NOT FOUND;");
+	print_func_exit();
 	return nil;
 }
 
 void
 wclosewin(Window *w)
 {
+	print_func_entry();
 	int i;
 
 	w->deleted = TRUE;
@@ -479,14 +488,17 @@ wclosewin(Window *w)
 			--nwindow;
 			memmove(window+i, window+i+1, (nwindow-i)*sizeof(Window*));
 			w->deleted = TRUE;
+			print_func_exit();
 			return;
 		}
 	error("unknown window in closewin");
+	print_func_exit();
 }
 
 void
 wsetpid(Window *w, int pid, int dolabel)
 {
+	print_func_entry();
 	char buf[128];
 	int fd;
 
@@ -501,11 +513,13 @@ wsetpid(Window *w, int pid, int dolabel)
 	if(w->notefd > 0)
 		close(w->notefd);
 	w->notefd = fd;
+	print_func_exit();
 }
 
 void
 winshell(void *args)
 {
+	print_func_entry();
 	Window *w;
 	Channel *pidc;
 	void **arg;
@@ -544,5 +558,16 @@ winshell(void *args)
 		procexec(pidc, cmd, argv);
 		_exits("exec failed");
 	}
+	print_func_exit();
 }
 
+int
+winfmt(Fmt *f)
+{
+	Window *w;
+
+	w = va_arg(f->args, Window*);
+	if (w < (void *)4096)
+		return fmtprint(f, "BOGUS w!: %p", w);
+	return fmtprint(f, "%p: %s", w, w->label);
+}

+ 50 - 8
sys/src/cmd/cmux/xfid.c

@@ -45,6 +45,7 @@ static	int	ntsnarf;
 void
 xfidallocthread(void* vacio)
 {
+	print_func_entry();
 	Xfid *x;
 	enum { Alloc, Free, N };
 	static Alt alts[N+1];
@@ -92,20 +93,24 @@ xfidallocthread(void* vacio)
 			break;
 		}
 	}
+	print_func_exit();
 }
 
 Channel*
 xfidinit(void)
 {
+	print_func_entry();
 	cxfidalloc = chancreate(sizeof(Xfid*), 0);
 	cxfidfree = chancreate(sizeof(Xfid*), 0);
 	threadcreate(xfidallocthread, nil, STACK);
+	print_func_exit();
 	return cxfidalloc;
 }
 
 void
 xfidctl(void *arg)
 {
+	print_func_entry();
 	Xfid *x;
 	void (*f)(Xfid*);
 	char buf[64];
@@ -119,11 +124,13 @@ xfidctl(void *arg)
 		if(decref(x) == 0)
 			sendp(cxfidfree, x);
 	}
+	print_func_exit();
 }
 
 void
 xfidflush(Xfid *x)
 {
+	print_func_entry();
 	Fcall t;
 	Xfid *xf;
 
@@ -147,17 +154,19 @@ xfidflush(Xfid *x)
 			break;
 		}
 	filsysrespond(x->fs, x, &t, nil);
+	print_func_exit();
 }
 
 void
 xfidattach(Xfid *x)
 {
+	extern Console HardwareConsole;
+	print_func_entry();
 	Fcall t;
 	int id;
 	Window *w;
 	char *err = nil;
 	int pid = -1, newlymade;
-	Image *i = (void *)1;
 
 	t.qid = x->f->qid;
 	qlock(&all);
@@ -166,13 +175,10 @@ xfidattach(Xfid *x)
 	newlymade = FALSE;
 
 	if(x->aname[0] == 'N'){	/* N  */
-		if(i){
-			if(pid == 0)
-				pid = -1;	/* make sure we don't pop a shell! - UGH */
-			w = new(i, pid, nil, nil, nil);
-			newlymade = TRUE;
-		}else
-			err = Ewindow;
+		if(pid == 0)
+			pid = -1;	/* make sure we don't pop a shell! - UGH */
+		w = new(&HardwareConsole, pid, nil, nil, nil);
+		newlymade = TRUE;
 	}else{
 		id = atoi(x->aname);
 		w = wlookid(id);
@@ -182,29 +188,34 @@ xfidattach(Xfid *x)
 		qunlock(&all);
 		x->f->busy = FALSE;
 		filsysrespond(x->fs, x, &t, err);
+		print_func_exit();
 		return;
 	}
 	if(!newlymade)	/* counteract dec() in winshell() */
 		incref(w);
 	qunlock(&all);
 	filsysrespond(x->fs, x, &t, nil);
+	print_func_exit();
 }
 
 void
 xfidopen(Xfid *x)
 {
+	print_func_entry();
 	Fcall t;
 	Window *w;
 
 	w = x->f->w;
 	if(w->deleted){
 		filsysrespond(x->fs, x, &t, Edeleted);
+		print_func_exit();
 		return;
 	}
 	switch(FILE(x->f->qid)){
 	case Qconsctl:
 		if(w->ctlopen){
 			filsysrespond(x->fs, x, &t, Einuse);
+			print_func_exit();
 			return;
 		}
 		w->ctlopen = TRUE;
@@ -212,12 +223,14 @@ xfidopen(Xfid *x)
 	case Qkbdin:
 		if(w !=  wkeyboard){
 			filsysrespond(x->fs, x, &t, Eperm);
+			print_func_exit();
 			return;
 		}
 		break;
 	case Qmouse:
 		if(w->mouseopen){
 			filsysrespond(x->fs, x, &t, Einuse);
+			print_func_exit();
 			return;
 		}
 		/*
@@ -251,6 +264,7 @@ xfidopen(Xfid *x)
 			 */
 			if(w->wctlopen){
 				filsysrespond(x->fs, x, &t, Einuse);
+				print_func_exit();
 				return;
 			}
 			w->wctlopen = TRUE;
@@ -264,11 +278,13 @@ xfidopen(Xfid *x)
 	x->f->open = TRUE;
 	x->f->mode = x->mode;
 	filsysrespond(x->fs, x, &t, nil);
+	print_func_exit();
 }
 
 void
 xfidclose(Xfid *x)
 {
+	print_func_entry();
 	Fcall t;
 	Window *w;
 	int nb, nulls;
@@ -311,11 +327,13 @@ xfidclose(Xfid *x)
 	}
 	wclose(w);
 	filsysrespond(x->fs, x, &t, nil);
+	print_func_exit();
 }
 
 void
 xfidwrite(Xfid *x)
 {
+	print_func_entry();
 	Fcall fc;
 	int c, cnt, qid, nb, off, nr;
 	char buf[256], *p;
@@ -329,6 +347,7 @@ xfidwrite(Xfid *x)
 	w = x->f->w;
 	if(w->deleted){
 		filsysrespond(x->fs, x, &fc, Edeleted);
+		print_func_exit();
 		return;
 	}
 	qid = FILE(x->f->qid);
@@ -337,6 +356,7 @@ xfidwrite(Xfid *x)
 	x->data[cnt] = 0;
 	switch(qid){
 	case Qcons:
+fprint(2, "Qcons wirte\n");
 		nr = x->f->nrpart;
 		if(nr > 0){
 			memmove(x->data+nr, x->data, cnt);	/* there's room: see malloc in filsysproc */
@@ -372,6 +392,7 @@ xfidwrite(Xfid *x)
 			break;
 		case CWflush:
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
 
@@ -383,15 +404,20 @@ xfidwrite(Xfid *x)
 			pair.ns = 0;
 			send(cwm.cw, &pair);		/* wake up window with empty data */
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
+fprint(2, "OK send\n");
 		qlock(&x->active);
+fprint(2, "locked send\n");
 		pair.s = r;
 		pair.ns = nr;
 		send(cwm.cw, &pair);
 		fc.count = x->count;
+fprint(2, "POK send done\n");
 		filsysrespond(x->fs, x, &fc, nil);
 		qunlock(&x->active);
+		print_func_exit();
 		return;
 
 	case Qconsctl:
@@ -420,11 +446,13 @@ xfidwrite(Xfid *x)
 			break;
 		}
 		filsysrespond(x->fs, x, &fc, "unknown control message");
+		print_func_exit();
 		return;
 
 	case Qlabel:
 		if(off != 0){
 			filsysrespond(x->fs, x, &fc, "non-zero offset writing label");
+			print_func_exit();
 			return;
 		}
 		free(w->label);
@@ -438,11 +466,13 @@ xfidwrite(Xfid *x)
 			break;
 		if(x->data[0] != 'm'){
 			filsysrespond(x->fs, x, &fc, Ebadmouse);
+			print_func_exit();
 			return;
 		}
 		p = nil;
 		if(p == nil){
 			filsysrespond(x->fs, x, &fc, Eshort);
+			print_func_exit();
 			return;
 		}
 		break;
@@ -451,6 +481,7 @@ xfidwrite(Xfid *x)
 		/* always append only */
 		if(ntsnarf > MAXSNARF){	/* avoid thrashing when people cut huge text */
 			filsysrespond(x->fs, x, &fc, Elong);
+			print_func_exit();
 			return;
 		}
 		tsnarf = erealloc(tsnarf, ntsnarf+cnt+1);	/* room for NUL */
@@ -491,6 +522,7 @@ xfidwrite(Xfid *x)
 	case Qwctl:
 		if(writewctl(x, buf) < 0){
 			filsysrespond(x->fs, x, &fc, buf);
+			print_func_exit();
 			return;
 		}
 		break;
@@ -499,15 +531,18 @@ xfidwrite(Xfid *x)
 		fprint(2, buf, "unknown qid %d in write\n", qid);
 		sprint(buf, "unknown qid in write");
 		filsysrespond(x->fs, x, &fc, buf);
+		print_func_exit();
 		return;
 	}
 	fc.count = cnt;
 	filsysrespond(x->fs, x, &fc, nil);
+	print_func_exit();
 }
 
 void
 xfidread(Xfid *x)
 {
+	print_func_entry();
 	Fcall fc;
 	int n, off, cnt, c;
 	uint qid;
@@ -527,6 +562,7 @@ xfidread(Xfid *x)
 	w = x->f->w;
 	if(w->deleted){
 		filsysrespond(x->fs, x, &fc, Edeleted);
+		print_func_exit();
 		return;
 	}
 	qid = FILE(x->f->qid);
@@ -542,6 +578,7 @@ xfidread(Xfid *x)
 		fc.count = 0;
 		filsysrespond(x->fs, x, &fc, nil);
 		qunlock(&x->active);
+		print_func_exit();
 		return;
 	}
 	switch(qid){
@@ -561,6 +598,7 @@ xfidread(Xfid *x)
 			break;
 		case CRflush:
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
 
@@ -577,6 +615,7 @@ xfidread(Xfid *x)
 			recv(c2, nil);			/* wake up window and toss data */
 			free(t);
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
 		qlock(&x->active);
@@ -615,6 +654,7 @@ xfidread(Xfid *x)
 			break;
 		case MRflush:
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
 
@@ -624,6 +664,7 @@ xfidread(Xfid *x)
 			recv(x->flushc, nil);		/* wake up flushing xfid */
 			recv(mrm.cm, nil);			/* wake up window and toss data */
 			filsyscancel(x);
+			print_func_exit();
 			return;
 		}
 		qlock(&x->active);
@@ -693,4 +734,5 @@ xfidread(Xfid *x)
 		filsysrespond(x->fs, x, &fc, buf);
 		break;
 	}
+	print_func_exit();
 }

+ 2 - 0
sys/src/cmd/rio/rio.c

@@ -221,6 +221,7 @@ threadmain(int argc, char *argv[])
 		fprint(2, "rio: can't create file system server: %r\n");
 	else{
 		errorshouldabort = 1;	/* suicide if there's trouble after this */
+#if 0
 		if(initstr)
 			proccreate(initcmd, initstr, STACK);
 		if(kbdin){
@@ -233,6 +234,7 @@ threadmain(int argc, char *argv[])
 			if(wkeyboard == nil)
 				error("can't create keyboard window");
 		}
+#endif
 		threadnotify(shutdown, 1);
 		recv(exitchan, nil);
 	}

+ 2 - 1
usr/glenda/lib/profile

@@ -5,6 +5,7 @@ if(! syscall create /tmp/xxx 1 0666 >[2]/dev/null)
 	ramfs	# in case we're running off a cd
 font = /lib/font/bit/pelm/euro.9.font
 fn cd { builtin cd $* && awd }  # for acme
+
 switch($service){
 case terminal
 	# plumber
@@ -26,7 +27,7 @@ case cpu
 	fn cpu%{ $* }
 	if (! test -e /mnt/term/mnt/wsys) {	# cpu call from drawterm
 		font=/lib/font/bit/pelm/latin1.8.font
-		exec rio
+		#exec rio
 	}
 case con
 	prompt=('cpu% ' '	')