Skip to content

Commit

Permalink
Entered working directory before switch user.
Browse files Browse the repository at this point in the history
If `chdir` into the working directory after switch user, the user may
fail because of permissions problem.

Review: https://reviews.apache.org/r/51782/
  • Loading branch information
haosdent authored and jieyu committed Sep 13, 2016
1 parent dcf48fe commit d25cafa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/slave/containerizer/mesos/launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ int MesosContainerizerLaunch::execute()
}
}

if (flags.working_directory.isSome()) {
Try<Nothing> chdir = os::chdir(flags.working_directory.get());
if (chdir.isError()) {
cerr << "Failed to chdir into current working directory "
<< "'" << flags.working_directory.get() << "': "
<< chdir.error() << endl;
return EXIT_FAILURE;
}
}

// Change user if provided. Note that we do that after executing the
// preparation commands so that those commands will be run with the
// same privilege as the mesos-agent.
Expand Down Expand Up @@ -451,16 +461,6 @@ int MesosContainerizerLaunch::execute()
}
#endif // __linux__

if (flags.working_directory.isSome()) {
Try<Nothing> chdir = os::chdir(flags.working_directory.get());
if (chdir.isError()) {
cerr << "Failed to chdir into current working directory "
<< "'" << flags.working_directory.get() << "': "
<< chdir.error() << endl;
return EXIT_FAILURE;
}
}

// Relay the environment variables.
// TODO(jieyu): Consider using a clean environment.

Expand Down

0 comments on commit d25cafa

Please sign in to comment.