diff --git a/pause.go b/pause.go index 5d22c92a2a..3efcdeeaee 100644 --- a/pause.go +++ b/pause.go @@ -9,18 +9,36 @@ package main /* #cgo CFLAGS: -Wall #define _GNU_SOURCE -#include #include #include #include #include +#include #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();