Merge pull request #188 from laijs/check-result

check the return value of the functions declared with warn_unused_result
This commit is contained in:
Lai Jiangshan
2016-09-26 15:19:53 +08:00
committed by GitHub
3 changed files with 47 additions and 18 deletions
+25 -9
View File
@@ -313,15 +313,22 @@ static int container_setup_mount(struct hyper_container *container)
return -1;
}
if (unlink("./dev/ptmx") < 0)
if (unlink("./dev/ptmx") < 0) {
perror("remove /dev/ptmx failed");
if (symlink("/dev/pts/ptmx", "./dev/ptmx") < 0)
return -1;
}
if (symlink("/dev/pts/ptmx", "./dev/ptmx") < 0) {
perror("link /dev/pts/ptmx to /dev/ptmx failed");
return -1;
}
symlink("/proc/self/fd", "./dev/fd");
symlink("/proc/self/fd/0", "./dev/stdin");
symlink("/proc/self/fd/1", "./dev/stdout");
symlink("/proc/self/fd/2", "./dev/stderr");
if (symlink("/proc/self/fd", "./dev/fd") < 0 ||
symlink("/proc/self/fd/0", "./dev/stdin") < 0 ||
symlink("/proc/self/fd/1", "./dev/stdout") < 0 ||
symlink("/proc/self/fd/2", "./dev/stderr") < 0) {
perror("failed to symlink for /dev/fd, /dev/stdin, /dev/stdout or /dev/stderr");
return -1;
}
return 0;
}
@@ -584,7 +591,10 @@ static int hyper_setup_container_rootfs(void *data)
perror("failed to bind rootfs");
goto fail;
}
chdir(rootfs);
if (chdir(rootfs) < 0) {
perror("failed to change the root to path of the container root(before manipulating)");
goto fail;
}
/*
* Recreate dns resolver iif configured by pod spec. Other cases
@@ -621,9 +631,15 @@ static int hyper_setup_container_rootfs(void *data)
}
/* pivot_root won't work, see
* Documention/filesystem/ramfs-rootfs-initramfs.txt */
chroot(".");
if (chroot(".") < 0) {
perror("failed to setup the root for the mount namepsace");
goto fail;
}
chdir("/");
if (chdir("/") < 0) {
perror("failed chdir to the new root");
goto fail;
}
if (container_setup_sysctl(container) < 0) {
fprintf(stderr, "container sets up sysctl failed\n");
+8 -2
View File
@@ -271,7 +271,10 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
if (exec->tty) {
char ptmx[512];
sprintf(ptmx, "/dev/pts/%d", exec->ptyno);
chown(ptmx, uid, gid);
if (chown(ptmx, uid, gid) < 0) {
perror("failed to change the owner for the slave pty file");
goto fail;
}
}
// apply
@@ -490,7 +493,10 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, struct hyper_pod *pod, int
perror("fail to enter container ns");
goto out;
}
chdir("/");
if (chdir("/") < 0) {
perror("fail to change to the root of the rootfs");
goto out;
}
/* TODO: merge container env to exec env in hyperd */
if (hyper_setup_env(c->exec.envs, c->exec.envs_num) < 0) {
+14 -7
View File
@@ -1370,13 +1370,20 @@ int main(int argc, char *argv[])
return -1;
}
symlink("/busybox", "/sh");
symlink("/busybox", "/tar");
symlink("/busybox", "/sbin/modprobe");
symlink("/busybox", "/sbin/depmod");
symlink("/iptables", "/sbin/iptables");
symlink("/iptables", "/sbin/iptables-restore");
symlink("/iptables", "/sbin/iptables-save");
if (symlink("/busybox", "/sh") < 0 ||
symlink("/busybox", "/tar") < 0 ||
symlink("/busybox", "/sbin/modprobe") < 0 ||
symlink("/busybox", "/sbin/depmod") < 0) {
perror("failed to symlink tools to /busybox");
return -1;
}
if (symlink("/iptables", "/sbin/iptables") < 0 ||
symlink("/iptables", "/sbin/iptables-restore") < 0 ||
symlink("/iptables", "/sbin/iptables-save") < 0) {
perror("failed to symlink tools to /iptables");
/* TODO disable portmapping */
}
cmdline = read_cmdline();