From 4e30080c64507c9a83bbedb4178bc9a892065dea Mon Sep 17 00:00:00 2001 From: Alexey Guskov Date: Wed, 29 Jul 2015 21:25:56 +0300 Subject: [PATCH] make docker compile on freebsd Signed-off-by: Alexey Guskov --- .../{directory_linux.go => directory_unix.go} | 2 +- .../operatingsystem_freebsd.go | 18 +++++++++++++ reexec/command_freebsd.go | 23 ++++++++++++++++ reexec/command_unsupported.go | 2 +- sockets/unix_socket.go | 2 +- sysinfo/sysinfo_freebsd.go | 7 +++++ system/stat_freebsd.go | 27 +++++++++++++++++++ system/stat_unsupported.go | 2 +- 8 files changed, 79 insertions(+), 4 deletions(-) rename directory/{directory_linux.go => directory_unix.go} (97%) create mode 100644 parsers/operatingsystem/operatingsystem_freebsd.go create mode 100644 reexec/command_freebsd.go create mode 100644 sysinfo/sysinfo_freebsd.go create mode 100644 system/stat_freebsd.go diff --git a/directory/directory_linux.go b/directory/directory_unix.go similarity index 97% rename from directory/directory_linux.go rename to directory/directory_unix.go index 80fb9a8..dbebdd3 100644 --- a/directory/directory_linux.go +++ b/directory/directory_unix.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux freebsd package directory diff --git a/parsers/operatingsystem/operatingsystem_freebsd.go b/parsers/operatingsystem/operatingsystem_freebsd.go new file mode 100644 index 0000000..0589cf2 --- /dev/null +++ b/parsers/operatingsystem/operatingsystem_freebsd.go @@ -0,0 +1,18 @@ +package operatingsystem + +import ( + "errors" +) + +// GetOperatingSystem gets the name of the current operating system. +func GetOperatingSystem() (string, error) { + // TODO: Implement OS detection + return "", errors.New("Cannot detect OS version") +} + +// IsContainerized returns true if we are running inside a container. +// No-op on FreeBSD, always returns false. +func IsContainerized() (bool, error) { + // TODO: Implement jail detection + return false, errors.New("Cannot detect if we are in container") +} diff --git a/reexec/command_freebsd.go b/reexec/command_freebsd.go new file mode 100644 index 0000000..c7f797a --- /dev/null +++ b/reexec/command_freebsd.go @@ -0,0 +1,23 @@ +// +build freebsd + +package reexec + +import ( + "os/exec" +) + +// Self returns the path to the current process's binary. +// Uses os.Args[0]. +func Self() string { + return naiveSelf() +} + +// Command returns *exec.Cmd which have Path as current binary. +// For example if current binary is "docker" at "/usr/bin/", then cmd.Path will +// be set to "/usr/bin/docker". +func Command(args ...string) *exec.Cmd { + return &exec.Cmd{ + Path: Self(), + Args: args, + } +} diff --git a/reexec/command_unsupported.go b/reexec/command_unsupported.go index 630eecb..ad4ea38 100644 --- a/reexec/command_unsupported.go +++ b/reexec/command_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux,!windows +// +build !linux,!windows,!freebsd package reexec diff --git a/sockets/unix_socket.go b/sockets/unix_socket.go index 42e558e..a69c28b 100644 --- a/sockets/unix_socket.go +++ b/sockets/unix_socket.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux freebsd package sockets diff --git a/sysinfo/sysinfo_freebsd.go b/sysinfo/sysinfo_freebsd.go new file mode 100644 index 0000000..25896f9 --- /dev/null +++ b/sysinfo/sysinfo_freebsd.go @@ -0,0 +1,7 @@ +package sysinfo + +// TODO FreeBSD +func New(quiet bool) *SysInfo { + sysInfo := &SysInfo{} + return sysInfo +} diff --git a/system/stat_freebsd.go b/system/stat_freebsd.go new file mode 100644 index 0000000..4b2198b --- /dev/null +++ b/system/stat_freebsd.go @@ -0,0 +1,27 @@ +package system + +import ( + "syscall" +) + +// fromStatT converts a syscall.Stat_t type to a system.Stat_t type +func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { + return &Stat_t{size: s.Size, + mode: uint32(s.Mode), + uid: s.Uid, + gid: s.Gid, + rdev: uint64(s.Rdev), + mtim: s.Mtimespec}, nil +} + +// Stat takes a path to a file and returns +// a system.Stat_t type pertaining to that file. +// +// Throws an error if the file does not exist +func Stat(path string) (*Stat_t, error) { + s := &syscall.Stat_t{} + if err := syscall.Stat(path, s); err != nil { + return nil, err + } + return fromStatT(s) +} diff --git a/system/stat_unsupported.go b/system/stat_unsupported.go index 7e0d034..5251ae2 100644 --- a/system/stat_unsupported.go +++ b/system/stat_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux,!windows +// +build !linux,!windows,!freebsd package system