]> Cypherpunks repositories - gostls13.git/commitdiff
- make godoc restart feature work properly
authorRobert Griesemer <gri@golang.org>
Mon, 18 May 2009 23:26:34 +0000 (16:26 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 18 May 2009 23:26:34 +0000 (16:26 -0700)
R=rsc
DELTA=11  (10 added, 0 deleted, 1 changed)
OCL=29007
CL=29009

usr/gri/pretty/godoc.go

index dcf3aa10281bd1e3bec3a8d1fcad275a5cc0d0b3..9590d6a42d6c833027a706bc1c9d0a9d934185a3 100644 (file)
@@ -58,6 +58,7 @@ var (
        verbose = flag.Bool("v", false, "verbose mode");
 
        // file system roots
+       launchdir string;       // directory from which godoc was launched
        goroot string;
        pkgroot = flag.String("pkgroot", "src/lib", "root package source directory (if unrooted, relative to goroot)");
        tmplroot = flag.String("tmplroot", "usr/gri/pretty", "root template directory (if unrooted, relative to goroot)");
@@ -585,7 +586,10 @@ func loggingHandler(h http.Handler) http.Handler {
 
 
 func restartGodoc(c *http.Conn, r *http.Request) {
-       binary := os.Args[0];  // TODO currently requires absolute paths because of chdir in the beginning
+       binary := os.Args[0];
+       if len(binary) > 0 || binary[0] != '/' {
+               binary = pathutil.Join(launchdir, binary);
+       }
        pid, err := os.ForkExec(binary, os.Args, os.Environ(), "", []*os.File{os.Stdin, os.Stdout, os.Stderr});
        if err != nil {
                log.Stderrf("os.ForkExec(%s): %v", binary, err);
@@ -621,6 +625,12 @@ func main() {
                }
        }
 
+       var err os.Error;
+       if launchdir, err = os.Getwd(); err != nil {
+               log.Stderrf("unable to determine current working directory - restart may fail");
+               launchdir = "";
+       }
+
        if err := os.Chdir(goroot); err != nil {
                log.Exitf("chdir %s: %v", goroot, err);
        }