shithub: riscv

Download patch

ref: 8791baf8b3a34e8bace2f6242153fbdf2812765c
parent: e614ab1d7f82b17b9a921280792ecbfb3a8d67d3
author: cinap_lenrek <[email protected]>
date: Tue May 8 19:53:46 EDT 2012

rio: dont list files we dont serve when reading directory

--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -322,6 +322,7 @@
 Window	*wkeyboard;	/* window of simulated keyboard */
 int		nwindow;
 int		snarffd;
+int		gotscreen;
 Window	*input;
 QLock	all;			/* BUG */
 Filsys	*filsys;
--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -346,6 +346,18 @@
 }
 
 static
+int
+skipdir(char *name)
+{
+	/* don't serve these if it's provided in the environment */
+	if(snarffd>=0 && strcmp(name, "snarf")==0)
+		return 1;
+	if(gotscreen && strcmp(name, "screen")==0)
+		return 1;
+	return 0;
+}
+
+static
 Xfid*
 filsyswalk(Filsys *fs, Xfid *x, Fid *f)
 {
@@ -430,13 +442,8 @@
 				dir = dirtab;
 				goto Accept;
 			}
-
-			/* don't serve these if it's provided in the environment */
-			if(snarffd>=0 && strcmp(x->wname[i], "snarf")==0)
-				break;	
-			if(strcmp(x->wname[i], "screen")==0 && access("/dev/screen", AEXIST)==0)
+			if(skipdir(x->wname[i]))
 				break;
-
 			id = WIN(f->qid);
 			d = dirtab;
 			d++;	/* skip '.' */
@@ -548,13 +555,15 @@
 	case Qwsysdir:
 		d = dirtab;
 		d++;	/* first entry is '.' */
-		for(i=0; d->name!=nil && i<e; i+=len){
+		for(i=0; d->name!=nil && i<e; d++){
+			if(skipdir(d->name))
+				continue;
 			len = dostat(fs, WIN(x->f->qid), d, b+n, x->count-n, clock);
 			if(len <= BIT16SZ)
 				break;
 			if(i >= o)
 				n += len;
-			d++;
+			i += len;
 		}
 		break;
 	case Qwsys:
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -184,6 +184,7 @@
 	}
 
 	snarffd = open("/dev/snarf", OREAD|OCEXEC);
+	gotscreen = access("/dev/screen", AEXIST)==0;
 
 	if(geninitdraw(nil, derror, nil, "rio", nil, Refnone) < 0){
 		fprint(2, "rio: can't open display: %r\n");