Merge "init: fixed issues related to forking services"
This commit is contained in:
commit
03d67dd99e
1 changed files with 16 additions and 2 deletions
|
|
@ -101,8 +101,22 @@ static void SetUpPidNamespace(const std::string& service_name) {
|
||||||
|
|
||||||
// It's OK to LOG(FATAL) in this function since it's running in the first
|
// It's OK to LOG(FATAL) in this function since it's running in the first
|
||||||
// child process.
|
// child process.
|
||||||
if (mount("", "/proc", "proc", kSafeFlags | MS_REMOUNT, "") == -1) {
|
|
||||||
PLOG(FATAL) << "couldn't remount(/proc) for " << service_name;
|
// Recursively remount / as slave like zygote does so unmounting and mounting /proc
|
||||||
|
// doesn't interfere with the parent namespace's /proc mount. This will also
|
||||||
|
// prevent any other mounts/unmounts initiated by the service from interfering
|
||||||
|
// with the parent namespace but will still allow mount events from the parent
|
||||||
|
// namespace to propagate to the child.
|
||||||
|
if (mount("rootfs", "/", nullptr, (MS_SLAVE | MS_REC), nullptr) == -1) {
|
||||||
|
PLOG(FATAL) << "couldn't remount(/) recursively as slave for " << service_name;
|
||||||
|
}
|
||||||
|
// umount() then mount() /proc.
|
||||||
|
// Note that it is not sufficient to mount with MS_REMOUNT.
|
||||||
|
if (umount("/proc") == -1) {
|
||||||
|
PLOG(FATAL) << "couldn't umount(/proc) for " << service_name;
|
||||||
|
}
|
||||||
|
if (mount("", "/proc", "proc", kSafeFlags, "") == -1) {
|
||||||
|
PLOG(FATAL) << "couldn't mount(/proc) for " << service_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prctl(PR_SET_NAME, service_name.c_str()) == -1) {
|
if (prctl(PR_SET_NAME, service_name.c_str()) == -1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue