From d909440c48b7b64b016478de1e6ee78e2faa9e13 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 11 Feb 2015 17:12:03 -0800 Subject: [PATCH] Unexport certain internal funcs and types Signed-off-by: Michael Crosby --- console.go | 2 +- container.go | 7 ++++--- generic_error.go | 12 ++++++------ linux_console.go | 2 ++ linux_container.go | 2 +- linux_network.go | 14 ++++---------- notify_linux.go => linux_notify.go | 4 ++-- notify_linux_test.go => linux_notify_test.go | 2 +- stats.go | 12 ++++++------ 9 files changed, 27 insertions(+), 30 deletions(-) rename notify_linux.go => linux_notify.go (91%) rename notify_linux_test.go => linux_notify_test.go (98%) diff --git a/console.go b/console.go index d3392ee3..1998086f 100644 --- a/console.go +++ b/console.go @@ -2,7 +2,7 @@ package libcontainer import "io" -// Console is a psuedo TTY. +// Console represents a psuedo TTY. type Console interface { io.ReadWriter io.Closer diff --git a/container.go b/container.go index 1954a994..2d4cbcad 100644 --- a/container.go +++ b/container.go @@ -1,6 +1,7 @@ -/* -NOTE: The API is in flux and mainly not implemented. Proceed with caution until further notice. -*/ +// Libcontainer provides a native Go implementation for creating containers +// with namespaces, cgroups, capabilities, and filesystem access controls. +// It allows you to manage the lifecycle of the container performing additional operations +// after the container is created. package libcontainer import ( diff --git a/generic_error.go b/generic_error.go index 5207822a..85010007 100644 --- a/generic_error.go +++ b/generic_error.go @@ -23,7 +23,7 @@ func newGenericError(err error, c ErrorCode) Error { if le, ok := err.(Error); ok { return le } - return &GenericError{ + return &genericError{ Timestamp: time.Now(), Err: err, ECode: c, @@ -35,7 +35,7 @@ func newSystemError(err error) Error { if le, ok := err.(Error); ok { return le } - return &GenericError{ + return &genericError{ Timestamp: time.Now(), Err: err, ECode: SystemError, @@ -43,21 +43,21 @@ func newSystemError(err error) Error { } } -type GenericError struct { +type genericError struct { Timestamp time.Time ECode ErrorCode Err error Stack stacktrace.Stacktrace } -func (e *GenericError) Error() string { +func (e *genericError) Error() string { return fmt.Sprintf("[%d] %s: %s", e.ECode, e.ECode, e.Err) } -func (e *GenericError) Code() ErrorCode { +func (e *genericError) Code() ErrorCode { return e.ECode } -func (e *GenericError) Detail(w io.Writer) error { +func (e *genericError) Detail(w io.Writer) error { return errorTemplate.Execute(w, e) } diff --git a/linux_console.go b/linux_console.go index f1eeaedf..5cb5f713 100644 --- a/linux_console.go +++ b/linux_console.go @@ -12,6 +12,8 @@ import ( "github.com/docker/libcontainer/label" ) +// NewConsole returns an initalized console that can be used within a container by copying bytes +// from the master side to the slave that is attached as the tty for the container's init process. func NewConsole() (Console, error) { master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0) if err != nil { diff --git a/linux_container.go b/linux_container.go index 668cf06c..efe9375b 100644 --- a/linux_container.go +++ b/linux_container.go @@ -289,7 +289,7 @@ func (c *linuxContainer) Signal(signal os.Signal) error { } func (c *linuxContainer) NotifyOOM() (<-chan struct{}, error) { - return NotifyOnOOM(c.cgroupManager.GetPaths()) + return notifyOnOOM(c.cgroupManager.GetPaths()) } func (c *linuxContainer) updateState(process parentProcess) error { diff --git a/linux_network.go b/linux_network.go index 0b5d3394..e720dade 100644 --- a/linux_network.go +++ b/linux_network.go @@ -3,7 +3,6 @@ package libcontainer import ( - "errors" "fmt" "io/ioutil" "net" @@ -15,10 +14,6 @@ import ( "github.com/docker/libcontainer/utils" ) -var ( - ErrNotValidStrategyType = errors.New("not a valid network strategy type") -) - var strategies = map[string]networkStrategy{ "veth": &veth{}, "loopback": &loopback{}, @@ -32,19 +27,18 @@ type networkStrategy interface { } // getStrategy returns the specific network strategy for the -// provided type. If no strategy is registered for the type an -// ErrNotValidStrategyType is returned. +// provided type. func getStrategy(tpe string) (networkStrategy, error) { s, exists := strategies[tpe] if !exists { - return nil, ErrNotValidStrategyType + return nil, fmt.Errorf("unknown strategy type %q", tpe) } return s, nil } // Returns the network statistics for the network interfaces represented by the NetworkRuntimeInfo. -func getNetworkInterfaceStats(interfaceName string) (*NetworkInterface, error) { - out := &NetworkInterface{Name: interfaceName} +func getNetworkInterfaceStats(interfaceName string) (*networkInterface, error) { + out := &networkInterface{Name: interfaceName} // This can happen if the network runtime information is missing - possible if the // container was created by an old version of libcontainer. if interfaceName == "" { diff --git a/notify_linux.go b/linux_notify.go similarity index 91% rename from notify_linux.go rename to linux_notify.go index 062fa11a..db51d57d 100644 --- a/notify_linux.go +++ b/linux_notify.go @@ -12,10 +12,10 @@ import ( const oomCgroupName = "memory" -// NotifyOnOOM returns channel on which you can expect event about OOM, +// notifyOnOOM returns channel on which you can expect event about OOM, // if process died without OOM this channel will be closed. // s is current *libcontainer.State for container. -func NotifyOnOOM(paths map[string]string) (<-chan struct{}, error) { +func notifyOnOOM(paths map[string]string) (<-chan struct{}, error) { dir := paths[oomCgroupName] if dir == "" { return nil, fmt.Errorf("There is no path for %q in state", oomCgroupName) diff --git a/notify_linux_test.go b/linux_notify_test.go similarity index 98% rename from notify_linux_test.go rename to linux_notify_test.go index 65189d36..09bdf644 100644 --- a/notify_linux_test.go +++ b/linux_notify_test.go @@ -30,7 +30,7 @@ func TestNotifyOnOOM(t *testing.T) { paths := map[string]string{ "memory": memoryPath, } - ooms, err := NotifyOnOOM(paths) + ooms, err := notifyOnOOM(paths) if err != nil { t.Fatal("expected no error, got:", err) } diff --git a/stats.go b/stats.go index 198a8bf5..926d4d6b 100644 --- a/stats.go +++ b/stats.go @@ -2,7 +2,12 @@ package libcontainer import "github.com/docker/libcontainer/cgroups" -type NetworkInterface struct { +type Stats struct { + Interfaces []*networkInterface + CgroupStats *cgroups.Stats +} + +type networkInterface struct { // Name is the name of the network interface. Name string @@ -15,8 +20,3 @@ type NetworkInterface struct { TxErrors uint64 TxDropped uint64 } - -type Stats struct { - Interfaces []*NetworkInterface - CgroupStats *cgroups.Stats -}