Follow symlinks in chroot directory

Summary:
On Mac OS X, the chroot directory we typically use ("/tmp") is actually
a symlink for "/private/tmp". Since we dereference symlinks in user-defined
paths, we must also dereference symlinks in chroot_dir_ such that we can perform
string comparisons on those paths.

Test Plan: ran env_test on Mac OS X and devserver

Reviewers: sdong, IslamAbdelRahman

Reviewed By: IslamAbdelRahman

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D57957
main
Andrew Kryczka 9 years ago
parent d86f9b9c3f
commit f548da33e8
  1. 10
      util/env_chroot.cc

@ -22,7 +22,13 @@ namespace rocksdb {
class ChrootEnv : public EnvWrapper {
public:
ChrootEnv(Env* base_env, const std::string& chroot_dir)
: EnvWrapper(base_env), chroot_dir_(chroot_dir) {}
: EnvWrapper(base_env) {
char* real_chroot_dir = realpath(chroot_dir.c_str(), nullptr);
// chroot_dir must exist so realpath() returns non-nullptr.
assert(real_chroot_dir != nullptr);
chroot_dir_ = real_chroot_dir;
free(real_chroot_dir);
}
virtual Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
@ -277,7 +283,7 @@ class ChrootEnv : public EnvWrapper {
return status_and_enc_path;
}
const std::string chroot_dir_;
std::string chroot_dir_;
};
Env* NewChrootEnv(Env* base_env, const std::string& chroot_dir) {

Loading…
Cancel
Save