From b8eb07c22fc5f3dea04d9843e8fd6d2eac6e61fa Mon Sep 17 00:00:00 2001 From: Etienne CHAMPETIER Date: Wed, 1 Jun 2016 20:54:06 +0000 Subject: [PATCH] jail: don't always CLONE_NEWUTS no -h => no CLONE_NEWUTS -h "" => CLONE_NEWUTS -h "newjailhostname" => CLONE_NEWUTS + sethostname Signed-off-by: Etienne CHAMPETIER --- jail/jail.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jail/jail.c b/jail/jail.c index e425254..c442847 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -244,7 +244,7 @@ static int exec_jail(void *_notused) exit(EXIT_FAILURE); } - if (opts.namespace && opts.hostname + if (opts.namespace && opts.hostname && strlen(opts.hostname) > 0 && sethostname(opts.hostname, strlen(opts.hostname))) { ERROR("sethostname(%s) failed: %s\n", opts.hostname, strerror(errno)); exit(EXIT_FAILURE); @@ -386,9 +386,10 @@ int main(int argc, char **argv) uloop_init(); if (opts.namespace) { - jail_process.pid = clone(exec_jail, - child_stack + STACK_SIZE, - CLONE_NEWUTS | CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | SIGCHLD, NULL); + int flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | SIGCHLD; + if (opts.hostname) + flags |= CLONE_NEWUTS; + jail_process.pid = clone(exec_jail, child_stack + STACK_SIZE, flags, NULL); } else { jail_process.pid = fork(); } -- 2.11.0