Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent: sandbox_pause should get arguments from proc
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.

Fix it by grabbing arguments from /proc/self/cmdline instead.

Fixes: #584
Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Jul 2, 2019
1 parent bad7d1b commit cfbd8c9
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,36 @@ package main
/*
#cgo CFLAGS: -Wall
#define _GNU_SOURCE
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#define PAUSE_BIN "pause-bin"
void __attribute__((constructor)) sandbox_pause(int argc, const char **argv) {
if (argc != 2 || strcmp(argv[1], PAUSE_BIN)) {
return;
void __attribute__((constructor)) sandbox_pause(void) {
FILE *f;
int len, do_pause = 0;
size_t n = 0;
char *p = NULL;
f = fopen("/proc/self/cmdline", "r");
if (f == NULL) {
perror("failed to open proc");
exit(-errno);
}
while ((len = getdelim(&p, &n, '\0', f)) != -1) {
if (len == sizeof(PAUSE_BIN) && !strncmp(p, PAUSE_BIN, sizeof(PAUSE_BIN)-1)) {
do_pause = 1;
break;
}
}
fclose(f);
free(p);
if (do_pause == 0)
return;
for (;;) pause();
Expand Down

0 comments on commit cfbd8c9

Please sign in to comment.