Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
8ee8fdea
Commit
8ee8fdea
authored
May 15, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restart functionality
R=rsc DELTA=21 (19 added, 0 deleted, 2 changed) OCL=28938 CL=28941
parent
c81d09d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
godoc.go
usr/gri/pretty/godoc.go
+21
-2
No files found.
usr/gri/pretty/godoc.go
View file @
8ee8fdea
...
...
@@ -601,7 +601,7 @@ func servePkg(c *http.Conn, r *http.Request) {
// ----------------------------------------------------------------------------
// Server
func
L
oggingHandler
(
h
http
.
Handler
)
http
.
Handler
{
func
l
oggingHandler
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
c
*
http
.
Conn
,
req
*
http
.
Request
)
{
log
.
Stderrf
(
"%s
\t
%s"
,
req
.
Host
,
req
.
Url
.
Path
);
h
.
ServeHTTP
(
c
,
req
);
...
...
@@ -609,6 +609,18 @@ 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
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
);
return
;
// do not terminate
}
log
.
Stderrf
(
"restarted %s, pid = %d
\n
"
,
binary
,
pid
);
os
.
Exit
(
0
);
}
func
usage
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: godoc package [name ...]
\n
"
...
...
@@ -648,12 +660,19 @@ func main() {
log
.
Stderrf
(
"goroot = %s
\n
"
,
goroot
);
log
.
Stderrf
(
"pkgroot = %s
\n
"
,
*
pkgroot
);
log
.
Stderrf
(
"tmplroot = %s
\n
"
,
*
tmplroot
);
handler
=
L
oggingHandler
(
handler
);
handler
=
l
oggingHandler
(
handler
);
}
http
.
Handle
(
Pkg
,
http
.
HandlerFunc
(
servePkg
));
http
.
Handle
(
"/debug/restart"
,
http
.
HandlerFunc
(
restartGodoc
));
http
.
Handle
(
"/"
,
http
.
HandlerFunc
(
serveFile
));
// The server may have been restarted; always wait 1sec to
// give the forking server a chance to shut down and release
// the http port. (This is necessary because under OS X Exec
// won't work if there are more than one thread running.)
time
.
Sleep
(
1e9
);
if
err
:=
http
.
ListenAndServe
(
*
httpaddr
,
handler
);
err
!=
nil
{
log
.
Exitf
(
"ListenAndServe %s: %v"
,
*
httpaddr
,
err
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment