Merge "pkg/webserver: remove usage of the obsolete runsit package"

This commit is contained in:
Brad Fitzpatrick 2017-12-27 01:13:33 +00:00 committed by Gerrit Code Review
commit 36f351ff50
3 changed files with 27 additions and 37 deletions

4
TODO
View File

@ -214,10 +214,6 @@ Offline list:
-- get webdav server working again, for mounting on Windows. This worked before Go 1
but bitrot when we moved pkg/fs to use the rsc/fuse.
-- work on runsit more, so I can start using this more often. runsit should
be able to reload itself, and also watch for binaries changing and restart
when binaries change. (or symlinks to binaries)
-- BUG: osutil paths.go on OS X: should use Library everywhere instead of mix of
Library and ~/.camlistore?

View File

@ -1,4 +1,20 @@
package listen
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package listen // import "camlistore.org/pkg/webserver/listen"
import (
"errors"
@ -19,9 +35,8 @@ func NewFlag(flagName, defaultValue string, serverType string) *Addr {
return addr
}
// Listen is a replacement for net.Listen that also respects runsit
// listeners: port, :port, ip:port, FD:<fd_num>, ADDR:<name> or <name>
// named ports.
// Listen is a replacement for net.Listen and supports
// port, :port, ip:port, FD:<fd_num>, ADDR:<name>
// Listeners are always TCP.
func Listen(addr string) (net.Listener, error) {
a := &Addr{s: addr}
@ -37,15 +52,15 @@ func Usage(name string) string {
if !strings.HasSuffix(name, " address") {
name += " address"
}
return name + "; may be port, :port, ip:port, FD:<fd_num>, or ADDR:<name> to use named runsit ports"
return name + "; may be port, :port, ip:port, FD:<fd_num>, or ADDR:<name> to use named ports"
}
// Addr is a flag variable. Use like:
//
// var webPort listen.Addr
// flag.Var(&webPort, "web_addr", listen.Usage("Web server address"))
// flag.Parse()
// webListener, err := webPort.Listen()
// var webPort listen.Addr
// flag.Var(&webPort, "web_addr", listen.Usage("Web server address"))
// flag.Parse()
// webListener, err := webPort.Listen()
type Addr struct {
s string
ln net.Listener
@ -60,15 +75,6 @@ func (a *Addr) String() string {
func (a *Addr) Set(v string) error {
a.s = v
// Try the requested port by runsit port name first.
fd, ok, err := namedPort(v)
if err != nil {
return err
}
if ok {
return a.listenOnFD(fd)
}
if strings.HasPrefix(v, "FD:") {
fdStr := v[len("FD:"):]
fd, err := strconv.ParseUint(fdStr, 10, 32)
@ -83,7 +89,7 @@ func (a *Addr) Set(v string) error {
ipPort = ":" + v
}
_, _, err = net.SplitHostPort(ipPort)
_, _, err := net.SplitHostPort(ipPort)
if err != nil {
return fmt.Errorf("invalid PORT or IP:PORT %q: %v", v, err)
}
@ -97,23 +103,11 @@ func isPort(s string) bool {
}
func (a *Addr) listenOnFD(fd uintptr) (err error) {
f := os.NewFile(fd, fmt.Sprintf("fd #%d from runsit parent", fd))
f := os.NewFile(fd, fmt.Sprintf("fd #%d from process parent", fd))
a.ln, err = net.FileListener(f)
return
}
func namedPort(name string) (fd uintptr, ok bool, err error) {
s := os.Getenv("RUNSIT_PORTFD_" + name)
if s == "" {
return
}
u64, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return
}
return uintptr(u64), true, nil
}
var _ flag.Value = (*Addr)(nil)
// Listen returns the address's TCP listener.

View File

@ -36,7 +36,7 @@ import (
"sync"
"time"
"github.com/bradfitz/runsit/listen"
"camlistore.org/pkg/webserver/listen"
"go4.org/net/throttle"
"go4.org/wkfs"