Skip to content

Commit

Permalink
tools: fix compiler warnings
Browse files Browse the repository at this point in the history
Change-Id: I1a650db4772d19dd0f7ae2e3f93ee653c4f3b208
Signed-off-by: Shreenidhi Shedi <[email protected]>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/11810
Tested-by: gerrit-photon <[email protected]>
Reviewed-by: Tapas Kundu <[email protected]>
  • Loading branch information
sshedi committed Dec 10, 2020
1 parent 25bb790 commit bb79673
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 13 additions & 3 deletions tools/src/contain/contain.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int main(int argc, char **argv) {
switch (child = fork()) {
case -1:
error(1, errno, "fork");
break;
case 0:
raise(SIGSTOP);
if (geteuid() != 0)
Expand Down Expand Up @@ -101,9 +102,17 @@ int main(int argc, char **argv) {
kill(child, SIGCONT);
waitforexit(child);

setgid(0);
setgroups(0, NULL);
setuid(0);
if (setgid(0)) {
error(1, errno, "setgid");
}

if (setgroups(0, NULL)) {
error(1, errno, "setgroups");
}

if (setuid(0)) {
error(1, errno, "setuid");
}

master = stdio ? -1 : getconsole();
createroot(argv[optind], master, inside, bind);
Expand All @@ -112,6 +121,7 @@ int main(int argc, char **argv) {
switch (child = fork()) {
case -1:
error(1, errno, "fork");
break;
case 0:
mountproc();
if (!hostnet)
Expand Down
12 changes: 10 additions & 2 deletions tools/src/contain/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ void createroot(char *src, int console, char *helper, char *bind) {
bindnode("/dev/tty", "dev/tty");
bindnode("/dev/urandom", "dev/urandom");
bindnode("/dev/zero", "dev/zero");
symlink("pts/ptmx", "dev/ptmx");

if (symlink("pts/ptmx", "dev/ptmx")) {
error(1, errno, "symlink-pts/ptmx");
}

mkdir("run/shm" , 0777);
if (mount("tmpfs", "run/shm", "tmpfs", 0, "mode=0777") < 0)
error(1, 0, "Failed to mount /run/shm tmpfs in new root filesystem");
symlink("/run/shm", "dev/shm");

if (symlink("/run/shm", "dev/shm")) {
error(1, errno, "symlink-/run/shm");
}


while ((bind = binditem(bind, &bindsrc, &binddst)))
Expand All @@ -100,9 +106,11 @@ void createroot(char *src, int console, char *helper, char *bind) {
switch (child = fork()) {
case -1:
error(1, errno, "fork");
break;
case 0:
execlp(SHELL, SHELL, "-c", helper, NULL);
error(1, errno, "exec %s", helper);
break;
default:
waitforexit(child);
}
Expand Down

0 comments on commit bb79673

Please sign in to comment.