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

Commit 77f3fe5e authored by Bart Van Assche's avatar Bart Van Assche
Browse files

init: Fix the implementation of the task_profiles keyword



The documentation added by commit c9c0bbac ("init: Add task_profiles
init command") mentions that the task_profiles keyword sets process
attributes. Make the implementation of that keyword match the
documentation.

Change-Id: Ia080132f16bfc2488f8c25176d6aed37a2c42780
Signed-off-by: default avatarBart Van Assche <bvanassche@google.com>
parent 4029b05b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -368,8 +368,9 @@ runs the service.
  given console.

`task_profiles <profile> [ <profile>\* ]`
> Set task profiles for the process when it forks. This is designed to replace the use of
  writepid option for moving a process into a cgroup.
> Set task profiles. Before Android U, the profiles are applied to the main thread of the service.
  For Android U and later, the profiles are applied to the entire service process. This is designed
  to replace the use of writepid option for moving a process into a cgroup.

`timeout_period <seconds>`
> Provide a timeout after which point the service will be killed. The oneshot keyword is respected
+12 −2
Original line number Diff line number Diff line
@@ -546,9 +546,19 @@ void Service::RunService(const std::vector<Descriptor>& descriptors,
        _exit(EXIT_FAILURE);
    }

    if (task_profiles_.size() > 0 && !SetTaskProfiles(getpid(), task_profiles_)) {
    if (task_profiles_.size() > 0) {
        bool succeeded = SelinuxGetVendorAndroidVersion() < __ANDROID_API_U__
                                 ?
                                 // Compatibility mode: apply the task profiles to the current
                                 // thread.
                                 SetTaskProfiles(getpid(), task_profiles_)
                                 :
                                 // Apply the task profiles to the current process.
                                 SetProcessProfiles(getuid(), getpid(), task_profiles_);
        if (!succeeded) {
            LOG(ERROR) << "failed to set task profiles";
        }
    }

    // As requested, set our gid, supplemental gids, uid, context, and
    // priority. Aborts on failure.