Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03d67dd9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "init: fixed issues related to forking services"

parents 5b2d0987 4bfdcb39
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -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
    // 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) {