From 91da63d3d3fd680c805dd1a1b78df5b8731a8173 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sat, 28 Mar 2015 15:41:58 +0100 Subject: properly handle return codes Signed-off-by: John Crispin --- jail/jail.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'jail') diff --git a/jail/jail.c b/jail/jail.c index 3b5587a..a6de133 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -313,12 +313,16 @@ static int spawn_child(void *arg) sysfs = 1; break; case 'n': - sethostname(optarg, strlen(optarg)); + if (sethostname(optarg, strlen(optarg))) + ERROR("failed to sethostname: %s\n", strerror(errno)); break; } } - asprintf(&mpoint, "%s/old", path); + if (asprintf(&mpoint, "%s/old", path) < 0) { + ERROR("failed to alloc pivot path: %s\n", strerror(errno)); + return -1; + } mkdir_p(mpoint, 0755); if (pivot_root(path, mpoint) == -1) { ERROR("pivot_root failed:%s\n", strerror(errno)); @@ -370,13 +374,17 @@ static void spawn_namespace(const char *path, int argc, char **argv) char *dir = get_current_dir_name(); uloop_init(); - chdir(path); + if (chdir(path)) { + ERROR("failed to chdir() into the jail\n"); + return; + } namespace_process.pid = clone(spawn_child, child_stack + STACK_SIZE, CLONE_NEWUTS | CLONE_NEWPID | CLONE_NEWNS | SIGCHLD, argv); if (namespace_process.pid != -1) { - chdir(dir); + if (chdir(dir)) + ERROR("failed to chdir() out of the jail\n"); free(dir); uloop_process_add(&namespace_process); uloop_run(); -- cgit v1.2.3