Skip to content

Commit

Permalink
agent: fix pause bin on musl
Browse files Browse the repository at this point in the history
gcc __attribute__ constructors cannot take arguments and cannot
access main function arguments on musl. Such functionality is glibc
specific and only works on x86 and x86_64. As a result, the pause
binary always quits on musl causing sandbox share pidns to malfunction.

Let's use env to indicate pause instead.

Fixes: kata-containers#584
Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Oct 23, 2019
1 parent cc6866a commit a4f7373
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func (s *sandbox) setupSharedPidNs() error {

cmd := &exec.Cmd{
Path: selfBinPath,
Args: []string{os.Args[0], pauseBinArg},
Env: []string{fmt.Sprintf("%s=%s", pauseBinKey, pauseBinValue)},
}

cmd.SysProcAttr = &syscall.SysProcAttr{
Expand Down
12 changes: 8 additions & 4 deletions pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ package main
#include <string.h>
#include <unistd.h>
#define PAUSE_BIN "pause-bin"
#define PAUSE_BIN_KEY "pause-bin-key"
#define PAUSE_BIN_VALUE "pause-bin-value"
void __attribute__((constructor)) sandbox_pause(int argc, const char **argv) {
if (argc != 2 || strcmp(argv[1], PAUSE_BIN)) {
void __attribute__((constructor)) sandbox_pause() {
char *value = getenv(PAUSE_BIN_KEY);
if (value == NULL || strcmp(value, PAUSE_BIN_VALUE)) {
return;
}
Expand All @@ -31,5 +34,6 @@ void __attribute__((constructor)) sandbox_pause(int argc, const char **argv) {
import "C"

const (
pauseBinArg = string(C.PAUSE_BIN)
pauseBinKey = string(C.PAUSE_BIN_KEY)
pauseBinValue = string(C.PAUSE_BIN_VALUE)
)
2 changes: 1 addition & 1 deletion pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestForkPauseBin(t *testing.T) {

cmd := &exec.Cmd{
Path: selfBinPath,
Args: []string{os.Args[0], pauseBinArg},
Env: []string{fmt.Sprintf("%s=%s", pauseBinKey, pauseBinValue)},
}

cmd.SysProcAttr = &syscall.SysProcAttr{
Expand Down

0 comments on commit a4f7373

Please sign in to comment.