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

agent: sandbox_pause should not take arguments #585

Merged
merged 1 commit into from
Aug 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use braces

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary right? C code doesn't need to follow go coding style here.

return;

for (;;) pause();

Expand Down