From cd5a73785d8f7533f1438a955daf23159d09a352 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 17 Apr 2008 16:04:19 -0400 Subject: acme: add -m option and avoid looking in the mirror --- src/cmd/acme/acme.c | 16 ++++++++++++++++ src/cmd/acme/dat.h | 1 + src/cmd/acme/fns.h | 2 ++ src/cmd/acme/fsys.c | 2 +- src/cmd/acme/look.c | 2 +- src/cmd/acme/text.c | 4 ++++ 6 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c index 87673cdb..07ce503a 100644 --- a/src/cmd/acme/acme.c +++ b/src/cmd/acme/acme.c @@ -28,6 +28,7 @@ Reffont *reffonts[2]; int snarffd = -1; int mainpid; int swapscrollbuttons = FALSE; +char *mtpt; enum{ NSnarf = 1000 /* less than 1024, I/O buffer size */ @@ -106,6 +107,11 @@ threadmain(int argc, char *argv[]) if(loadfile == nil) goto Usage; break; + case 'm': + mtpt = ARGF(); + if(mtpt == nil) + goto Usage; + break; case 'r': swapscrollbuttons = TRUE; break; @@ -1056,3 +1062,13 @@ acmegetsnarf(void) free(r); 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); +} diff --git a/src/cmd/acme/dat.h b/src/cmd/acme/dat.h index a0d5cef3..93af258d 100644 --- a/src/cmd/acme/dat.h +++ b/src/cmd/acme/dat.h @@ -542,6 +542,7 @@ int erroutfd; int messagesize; /* negotiated in 9P version setup */ int globalautoindent; int dodollarsigns; +char* mtpt; enum { diff --git a/src/cmd/acme/fns.h b/src/cmd/acme/fns.h index 34d561c5..c714175f 100644 --- a/src/cmd/acme/fns.h +++ b/src/cmd/acme/fns.h @@ -102,3 +102,5 @@ int abbrevenv(Rune**, uint*); #define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune)) #define runerealloc(a, b) (Rune*)erealloc((a), (b)*sizeof(Rune)) #define runemove(a, b, c) memmove((a), (b), (c)*sizeof(Rune)) + +int ismtpt(char*); diff --git a/src/cmd/acme/fsys.c b/src/cmd/acme/fsys.c index 9a7dbd10..b5ed8d6c 100644 --- a/src/cmd/acme/fsys.c +++ b/src/cmd/acme/fsys.c @@ -121,7 +121,7 @@ fsysinit(void) initfcall(); if(pipe(p) < 0) error("can't create pipe"); - if(post9pservice(p[0], "acme") < 0) + if(post9pservice(p[0], "acme", mtpt) < 0) error("can't post service"); sfd = p[1]; fmtinstall('F', fcallfmt); diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c index 66c6c664..2ca2061d 100644 --- a/src/cmd/acme/look.c +++ b/src/cmd/acme/look.c @@ -620,7 +620,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e) if(w != nil) goto Isfile; /* 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); e->bname = nil; goto Isntfile; diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c index ddb3527a..f972b6ab 100644 --- a/src/cmd/acme/text.c +++ b/src/cmd/acme/text.c @@ -200,6 +200,10 @@ textload(Text *t, uint q0, char *file, int setqid) warning(nil, "empty directory name"); return 0; } + if(ismtpt(file)){ + warning(nil, "will not open self mount point %s\n", file); + return 0; + } fd = open(file, OREAD); if(fd < 0){ warning(nil, "can't open %s: %r\n", file); -- cgit v1.2.3