-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `JobContainer` and `JobProcess` types as the two types to represent a job container and a process in a job container. * Add logic to find the executable being asked to run for a job container. * Logic to launch the container as specific user. * Logic to mount the containers scratch space on the host to a directory. * Small subset of tests added to jobobject package Signed-off-by: Daniel Canter <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,811 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jobcontainers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func assertEqual(t *testing.T, a uint32, b uint32) { | ||
if a != b { | ||
t.Fatalf("%d != %d", a, b) | ||
} | ||
} | ||
|
||
func TestJobCPURate(t *testing.T) { | ||
rate := calculateJobCPURate(10, 1) | ||
assertEqual(t, rate, 1000) | ||
|
||
rate = calculateJobCPURate(10, 5) | ||
assertEqual(t, rate, 5000) | ||
|
||
rate = calculateJobCPURate(20, 5) | ||
assertEqual(t, rate, 2500) | ||
|
||
rate = calculateJobCPURate(1, 1) | ||
assertEqual(t, rate, 10000) | ||
|
||
rate = calculateJobCPURate(1, 0) | ||
assertEqual(t, rate, 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,46 @@ | ||
package jobcontainers | ||
|
||
import ( | ||
"unicode/utf16" | ||
"unsafe" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// defaultEnvBlock will return a new environment block in the context of the user token | ||
// `token`. | ||
// | ||
// This is almost a direct copy of the go stdlib implementation with some slight changes | ||
// to force a valid token to be passed. | ||
// https://github.com/golang/go/blob/f21be2fdc6f1becdbed1592ea0b245cdeedc5ac8/src/internal/syscall/execenv/execenv_windows.go#L24 | ||
func defaultEnvBlock(token windows.Token) (env []string, err error) { | ||
if token == 0 { | ||
return nil, errors.New("invalid token for creating environment block") | ||
} | ||
|
||
var block *uint16 | ||
if err := windows.CreateEnvironmentBlock(&block, token, false); err != nil { | ||
return nil, err | ||
} | ||
defer windows.DestroyEnvironmentBlock(block) | ||
|
||
blockp := uintptr(unsafe.Pointer(block)) | ||
for { | ||
// find NUL terminator | ||
end := unsafe.Pointer(blockp) | ||
for *(*uint16)(end) != 0 { | ||
end = unsafe.Pointer(uintptr(end) + 2) | ||
} | ||
|
||
n := (uintptr(end) - uintptr(unsafe.Pointer(blockp))) / 2 | ||
if n == 0 { | ||
// environment block ends with empty string | ||
break | ||
} | ||
entry := (*[(1 << 30) - 1]uint16)(unsafe.Pointer(blockp))[:n:n] | ||
env = append(env, string(utf16.Decode(entry))) | ||
blockp += 2 * (uintptr(len(entry)) + 1) | ||
} | ||
return | ||
} |
Oops, something went wrong.