Merge pull request #300 from dqminh/subreaper

define PR_SET_CHILD_SUBREAPER if not set
This commit is contained in:
Mrunal Patel 2014-12-19 10:44:23 -08:00
commit 08fdb50b03
1 changed files with 11 additions and 6 deletions

View File

@ -15,6 +15,10 @@
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#ifndef PR_SET_CHILD_SUBREAPER
#define PR_SET_CHILD_SUBREAPER 36
#endif
static const kBufSize = 256; static const kBufSize = 256;
static const char *kNsEnter = "nsenter"; static const char *kNsEnter = "nsenter";
@ -32,8 +36,8 @@ void get_args(int *argc, char ***argv)
contents_size += kBufSize; contents_size += kBufSize;
contents = (char *)realloc(contents, contents_size); contents = (char *)realloc(contents, contents_size);
bytes_read = bytes_read =
read(fd, contents + contents_offset, read(fd, contents + contents_offset,
contents_size - contents_offset); contents_size - contents_offset);
contents_offset += bytes_read; contents_offset += bytes_read;
} }
while (bytes_read > 0); while (bytes_read > 0);
@ -90,16 +94,17 @@ void nsenter()
} }
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) { if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) {
fprintf(stderr, "nsenter: failed to set child subreaper: %s", strerror(errno)); fprintf(stderr, "nsenter: failed to set child subreaper: %s",
exit(1); strerror(errno));
} exit(1);
}
static const struct option longopts[] = { static const struct option longopts[] = {
{"nspid", required_argument, NULL, 'n'}, {"nspid", required_argument, NULL, 'n'},
{"console", required_argument, NULL, 't'}, {"console", required_argument, NULL, 't'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
pid_t init_pid = -1; pid_t init_pid = -1;
char *init_pid_str = NULL; char *init_pid_str = NULL;
char *console = NULL; char *console = NULL;