summaryrefslogtreecommitdiffstats
path: root/jail
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2015-03-28 15:41:58 +0100
committerJohn Crispin <blogic@openwrt.org>2015-03-28 18:35:21 +0100
commit91da63d3d3fd680c805dd1a1b78df5b8731a8173 (patch)
treeec9a568a398ae536ccf7ac89a23942a60ef25c98 /jail
parent74d835463e05e5761f6f5271e487f299f29d3f07 (diff)
downloadunitd-91da63d3d3fd680c805dd1a1b78df5b8731a8173.tar
unitd-91da63d3d3fd680c805dd1a1b78df5b8731a8173.zip
properly handle return codes
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'jail')
-rw-r--r--jail/jail.c16
1 files changed, 12 insertions, 4 deletions
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();