X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=jail%2Fjail.c;h=a6de1338a1e4e09fe7765b9e8db33fe9847163d5;hp=3b5587a9ddf77f88f5683a68e1f6196b9eeb2977;hb=91da63d3d3fd680c805dd1a1b78df5b8731a8173;hpb=74d835463e05e5761f6f5271e487f299f29d3f07 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();