acme: add -m option and avoid looking in the mirror

This commit is contained in:
Russ Cox 2008-04-17 16:04:19 -04:00
parent e63025d094
commit cd5a73785d
6 changed files with 25 additions and 2 deletions

View file

@ -28,6 +28,7 @@ Reffont *reffonts[2];
int snarffd = -1; int snarffd = -1;
int mainpid; int mainpid;
int swapscrollbuttons = FALSE; int swapscrollbuttons = FALSE;
char *mtpt;
enum{ enum{
NSnarf = 1000 /* less than 1024, I/O buffer size */ NSnarf = 1000 /* less than 1024, I/O buffer size */
@ -106,6 +107,11 @@ threadmain(int argc, char *argv[])
if(loadfile == nil) if(loadfile == nil)
goto Usage; goto Usage;
break; break;
case 'm':
mtpt = ARGF();
if(mtpt == nil)
goto Usage;
break;
case 'r': case 'r':
swapscrollbuttons = TRUE; swapscrollbuttons = TRUE;
break; break;
@ -1056,3 +1062,13 @@ acmegetsnarf(void)
free(r); free(r);
free(s); free(s);
} }
int
ismtpt(char *file)
{
int n;
/* This is not foolproof, but it will stop a lot of them. */
n = strlen(mtpt);
return strncmp(file, mtpt, n) == 0 && ((n > 0 && mtpt[n-1] == '/') || file[n] == '/' || file[n] == 0);
}

View file

@ -542,6 +542,7 @@ int erroutfd;
int messagesize; /* negotiated in 9P version setup */ int messagesize; /* negotiated in 9P version setup */
int globalautoindent; int globalautoindent;
int dodollarsigns; int dodollarsigns;
char* mtpt;
enum enum
{ {

View file

@ -102,3 +102,5 @@ int abbrevenv(Rune**, uint*);
#define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune)) #define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune))
#define runerealloc(a, b) (Rune*)erealloc((a), (b)*sizeof(Rune)) #define runerealloc(a, b) (Rune*)erealloc((a), (b)*sizeof(Rune))
#define runemove(a, b, c) memmove((a), (b), (c)*sizeof(Rune)) #define runemove(a, b, c) memmove((a), (b), (c)*sizeof(Rune))
int ismtpt(char*);

View file

@ -121,7 +121,7 @@ fsysinit(void)
initfcall(); initfcall();
if(pipe(p) < 0) if(pipe(p) < 0)
error("can't create pipe"); error("can't create pipe");
if(post9pservice(p[0], "acme") < 0) if(post9pservice(p[0], "acme", mtpt) < 0)
error("can't post service"); error("can't post service");
sfd = p[1]; sfd = p[1];
fmtinstall('F', fcallfmt); fmtinstall('F', fcallfmt);

View file

@ -620,7 +620,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
if(w != nil) if(w != nil)
goto Isfile; goto Isfile;
/* if it's the name of a file, it's a file */ /* if it's the name of a file, it's a file */
if(access(e->bname, 0) < 0){ if(ismtpt(e->bname) || access(e->bname, 0) < 0){
free(e->bname); free(e->bname);
e->bname = nil; e->bname = nil;
goto Isntfile; goto Isntfile;

View file

@ -200,6 +200,10 @@ textload(Text *t, uint q0, char *file, int setqid)
warning(nil, "empty directory name"); warning(nil, "empty directory name");
return 0; return 0;
} }
if(ismtpt(file)){
warning(nil, "will not open self mount point %s\n", file);
return 0;
}
fd = open(file, OREAD); fd = open(file, OREAD);
if(fd < 0){ if(fd < 0){
warning(nil, "can't open %s: %r\n", file); warning(nil, "can't open %s: %r\n", file);