commit 2db3ce1d0a6f579625fe7440af871902ef5dfd85
parent 173da842b5b93bf2ca4f877b7eadc2585aee1005
Author: Russ Cox <rsc@swtch.com>
Date: Tue, 1 Jul 2008 17:05:09 -0400
9vx: better handling of -r (thanks to Anthony Martin)
Diffstat:
3 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/src/9vx/devfs-posix.c b/src/9vx/devfs-posix.c
@@ -106,6 +106,9 @@ fsattach(char *spec)
}
}
+ if(localroot == nil)
+ error("no #Zplan9 root without -r");
+
if(stat(localroot, &st) < 0)
oserror();
@@ -161,13 +164,20 @@ fspath(Chan *c, char *suffix)
ufd = c->aux;
s = ufd->path->s;
- len = strlen(localroot)+strlen(s)+1;
- if(suffix)
- len += 1+strlen(suffix);
- t = smalloc(len);
- if(ufd->plan9)
+ if(ufd->plan9){
+ len = strlen(localroot)+strlen(s)+1;
+ if(suffix)
+ len += 1+strlen(suffix);
+ t = smalloc(len);
strcpy(t, localroot);
- strcat(t, s);
+ strcat(t, s);
+ }else{
+ len = strlen(s)+1;
+ if(suffix)
+ len += 1+strlen(suffix);
+ t = smalloc(len);
+ strcpy(t, s);
+ }
if(suffix){
if(s[strlen(s)-1] != '/')
strcat(t, "/");
diff --git a/src/9vx/main.c b/src/9vx/main.c
@@ -75,6 +75,7 @@ main(int argc, char **argv)
int usetty;
int nogui;
int nofork;
+ char buf[1024];
/* Minimal set up to make print work. */
setmach(&mach0);
@@ -139,8 +140,13 @@ main(int argc, char **argv)
if(argc != 0)
usage();
- if(localroot == nil && (localroot = findroot()) == nil)
- panic("cannot find plan 9 root; use -r");
+ if(!bootboot){
+ if(localroot == nil && (localroot = findroot()) == nil)
+ panic("cannot find plan 9 root; use -r");
+ snprint(buf, sizeof buf, "%s/386/bin/rc", localroot);
+ if(access(buf, 0) < 0)
+ panic("%s does not exist", buf);
+ }
if(username == nil && (username = getuser()) == nil)
username = "tor";
@@ -209,22 +215,25 @@ main(int argc, char **argv)
static char*
findroot(void)
{
- static char buf[1024];
-
- if(access("386/bin/rc", 0) >= 0){
- if(getcwd(buf, sizeof buf) == nil){
- oserrstr();
- panic("getcwd: %r");
- }
- return buf;
- }
+ static char cwd[1024];
+ int i;
+ char buf[1024];
+ char *dir[] = {
+ cwd,
+ "/Users/rsc/9vx",
+ "/home/rsc/plan9/4e"
+ };
- /* Sorry, but great for debugging. */
- if(access("/Users/rsc/9vx", 0) >= 0)
- return "/Users/rsc/9vx";
- if(access("/home/rsc/plan9/4e/386/bin/rc", 0) >= 0)
- return "/home/rsc/plan9/4e";
+ if(getcwd(cwd, sizeof cwd) == nil){
+ oserrstr();
+ panic("getcwd: %r");
+ }
+ for(i=0; i<nelem(dir); i++){
+ snprint(buf, sizeof buf, "%s/386/bin/rc", dir[i]);
+ if(access(buf, 0) >= 0)
+ return dir[i];
+ }
return nil;
}
diff --git a/src/BUGS b/src/BUGS
@@ -12,8 +12,3 @@ gs spins on startup, cause unknown. (run "gs", no arguments)
blank line inserted when kernel terminal scrolls
can cause sigsegv panic resizing the window, rarely
-
-if you use -r xxx where xxx is an empty directory,
-9vx just sits there after printing the 256MB memory line,
-with no indication what you did wrong.
-