bump(github.com/docker/libcompose) v0.3.0

This commit is contained in:
Tomas Kral
2016-08-22 10:51:22 +02:00
parent 223b4f37fa
commit e341adce0e
57 changed files with 944 additions and 12907 deletions
+14 -77
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"strings"
)
@@ -23,13 +24,9 @@ func (p Procs) Len() int { return len(p) }
func (p Procs) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p Procs) Less(i, j int) bool { return p[i].PID < p[j].PID }
// Self returns a process for the current process read via /proc/self.
// Self returns a process for the current process.
func Self() (Proc, error) {
fs, err := NewFS(DefaultMountPoint)
if err != nil {
return Proc{}, err
}
return fs.Self()
return NewProc(os.Getpid())
}
// NewProc returns a process for the given pid under /proc.
@@ -38,42 +35,32 @@ func NewProc(pid int) (Proc, error) {
if err != nil {
return Proc{}, err
}
return fs.NewProc(pid)
}
// AllProcs returns a list of all currently available processes under /proc.
// AllProcs returns a list of all currently avaible processes under /proc.
func AllProcs() (Procs, error) {
fs, err := NewFS(DefaultMountPoint)
if err != nil {
return Procs{}, err
}
return fs.AllProcs()
}
// Self returns a process for the current process.
func (fs FS) Self() (Proc, error) {
p, err := os.Readlink(fs.Path("self"))
if err != nil {
return Proc{}, err
}
pid, err := strconv.Atoi(strings.Replace(p, string(fs), "", -1))
if err != nil {
return Proc{}, err
}
return fs.NewProc(pid)
return fs.AllProcs()
}
// NewProc returns a process for the given pid.
func (fs FS) NewProc(pid int) (Proc, error) {
if _, err := os.Stat(fs.Path(strconv.Itoa(pid))); err != nil {
if _, err := fs.stat(strconv.Itoa(pid)); err != nil {
return Proc{}, err
}
return Proc{PID: pid, fs: fs}, nil
}
// AllProcs returns a list of all currently available processes.
// AllProcs returns a list of all currently avaible processes.
func (fs FS) AllProcs() (Procs, error) {
d, err := os.Open(fs.Path())
d, err := fs.open("")
if err != nil {
return Procs{}, err
}
@@ -98,7 +85,7 @@ func (fs FS) AllProcs() (Procs, error) {
// CmdLine returns the command line of a process.
func (p Proc) CmdLine() ([]string, error) {
f, err := os.Open(p.path("cmdline"))
f, err := p.open("cmdline")
if err != nil {
return nil, err
}
@@ -109,39 +96,9 @@ func (p Proc) CmdLine() ([]string, error) {
return nil, err
}
if len(data) < 1 {
return []string{}, nil
}
return strings.Split(string(data[:len(data)-1]), string(byte(0))), nil
}
// Comm returns the command name of a process.
func (p Proc) Comm() (string, error) {
f, err := os.Open(p.path("comm"))
if err != nil {
return "", err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
return strings.TrimSpace(string(data)), nil
}
// Executable returns the absolute path of the executable command of a process.
func (p Proc) Executable() (string, error) {
exe, err := os.Readlink(p.path("exe"))
if os.IsNotExist(err) {
return "", nil
}
return exe, err
}
// FileDescriptors returns the currently open file descriptors of a process.
func (p Proc) FileDescriptors() ([]uintptr, error) {
names, err := p.fileDescriptors()
@@ -161,26 +118,6 @@ func (p Proc) FileDescriptors() ([]uintptr, error) {
return fds, nil
}
// FileDescriptorTargets returns the targets of all file descriptors of a process.
// If a file descriptor is not a symlink to a file (like a socket), that value will be the empty string.
func (p Proc) FileDescriptorTargets() ([]string, error) {
names, err := p.fileDescriptors()
if err != nil {
return nil, err
}
targets := make([]string, len(names))
for i, name := range names {
target, err := os.Readlink(p.path("fd", name))
if err == nil {
targets[i] = target
}
}
return targets, nil
}
// FileDescriptorsLen returns the number of currently open file descriptors of
// a process.
func (p Proc) FileDescriptorsLen() (int, error) {
@@ -193,7 +130,7 @@ func (p Proc) FileDescriptorsLen() (int, error) {
}
func (p Proc) fileDescriptors() ([]string, error) {
d, err := os.Open(p.path("fd"))
d, err := p.open("fd")
if err != nil {
return nil, err
}
@@ -207,6 +144,6 @@ func (p Proc) fileDescriptors() ([]string, error) {
return names, nil
}
func (p Proc) path(pa ...string) string {
return p.fs.Path(append([]string{strconv.Itoa(p.PID)}, pa...)...)
func (p Proc) open(pa string) (*os.File, error) {
return p.fs.open(path.Join(strconv.Itoa(p.PID), pa))
}