forked from openshift/geard
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial system pkg to libcontainer
Port over console and ptmx code into console package Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
- Loading branch information
Michael Crosby
committed
Jul 14, 2014
1 parent
65c37a8
commit a2dc64c
Showing
7 changed files
with
164 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build linux | ||
|
||
package system | ||
|
||
import ( | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
func Execv(cmd string, args []string, env []string) error { | ||
name, err := exec.LookPath(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return syscall.Exec(name, args, env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package system | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// look in /proc to find the process start time so that we can verify | ||
// that this pid has started after ourself | ||
func GetProcessStartTime(pid int) (string, error) { | ||
data, err := ioutil.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat")) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
parts := strings.Split(string(data), " ") | ||
// the starttime is located at pos 22 | ||
// from the man page | ||
// | ||
// starttime %llu (was %lu before Linux 2.6) | ||
// (22) The time the process started after system boot. In kernels before Linux 2.6, this | ||
// value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks | ||
// (divide by sysconf(_SC_CLK_TCK)). | ||
return parts[22-1], nil // starts at 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package system | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"syscall" | ||
) | ||
|
||
// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092 | ||
// | ||
// We need different setns values for the different platforms and arch | ||
// We are declaring the macro here because the SETNS syscall does not exist in th stdlib | ||
var setNsMap = map[string]uintptr{ | ||
"linux/amd64": 308, | ||
} | ||
|
||
func Setns(fd uintptr, flags uintptr) error { | ||
ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)] | ||
if !exists { | ||
return fmt.Errorf("unsupported platform %s/%s", runtime.GOOS, runtime.GOARCH) | ||
} | ||
|
||
_, _, err := syscall.RawSyscall(ns, fd, flags, 0) | ||
if err != 0 { | ||
return err | ||
} | ||
|
||
return nil | ||
} |