Skip to content

Commit

Permalink
revert: agent: sandbox_pause should get arguments from proc
Browse files Browse the repository at this point in the history
When agent runs as init, it is not able to read `/proc/self/cmdline` because
of `/proc` has not been mounted when the C constructor is called.

This reverts commit cfbd8c9.

fixes kata-containers#620

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Aug 1, 2019
1 parent d6d8514 commit 72a50ef
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,18 @@ 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(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)
void __attribute__((constructor)) sandbox_pause(int argc, const char **argv) {
if (argc != 2 || strcmp(argv[1], PAUSE_BIN)) {
return;
}
for (;;) pause();
Expand Down

0 comments on commit 72a50ef

Please sign in to comment.