From a4f73739985ee7d2919fe030a13b1f5e11ebe742 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Wed, 23 Oct 2019 00:59:26 -0700 Subject: [PATCH] agent: fix pause bin on musl 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: #584 Signed-off-by: Peng Tao --- agent.go | 2 +- pause.go | 12 ++++++++---- pause_test.go | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/agent.go b/agent.go index 66d0da7075..96f9e75ea4 100644 --- a/agent.go +++ b/agent.go @@ -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{ diff --git a/pause.go b/pause.go index 5d22c92a2a..0e82fe8ca0 100644 --- a/pause.go +++ b/pause.go @@ -15,10 +15,13 @@ package main #include #include -#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; } @@ -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) ) diff --git a/pause_test.go b/pause_test.go index 14c24ee3d7..f64ca62aea 100644 --- a/pause_test.go +++ b/pause_test.go @@ -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{