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

Commit a75f2103 authored by Bart Van Assche's avatar Bart Van Assche
Browse files

init: Make WaitToBeReaped() wait less long



Reduce the time spent in WaitToBeReaped() by waiting for SIGCHLD instead
of waiting for 50 ms.

Bug: 308687042
Change-Id: I5e259fdd22dec68e45d27205def2fc6463c06ca3
Signed-off-by: default avatarBart Van Assche <bvanassche@google.com>
parent 43323a7e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ namespace init {

static int property_triggers_enabled = 0;

static int sigchld_fd = -1;
int sigchld_fd = -1;
static int sigterm_fd = -1;
static int property_fd = -1;

@@ -800,6 +800,7 @@ static void InstallSignalFdHandler(Epoll* epoll) {
        PLOG(FATAL) << cs_result.error();
    }
    sigchld_fd = cs_result.value();
    Service::SetSigchldFd(sigchld_fd);

    if (sigismember(&mask, SIGTERM)) {
        Result<int> cs_result = CreateAndRegisterSignalFd(epoll, SIGTERM);
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
namespace android {
namespace init {

extern int sigchld_fd;

Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& service_list);

+1 −1
Original line number Diff line number Diff line
@@ -563,7 +563,7 @@ static void StopServices(const std::set<std::string>& services, std::chrono::mil
        }
    }
    if (timeout > 0ms) {
        WaitToBeReaped(pids, timeout);
        WaitToBeReaped(sigchld_fd, pids, timeout);
    } else {
        // Even if we don't to wait for services to stop, we still optimistically reap zombies.
        ReapAnyOutstandingChildren();
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ static bool ExpandArgsAndExecv(const std::vector<std::string>& args, bool sigsto

unsigned long Service::next_start_order_ = 1;
bool Service::is_exec_service_running_ = false;
int Service::sigchld_fd_ = -1;

Service::Service(const std::string& name, Subcontext* subcontext_for_restart_commands,
                 const std::string& filename, const std::vector<std::string>& args)
+3 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ class Service {
    const Subcontext* subcontext() const { return subcontext_; }
    const std::string& filename() const { return filename_; }
    void set_filename(const std::string& name) { filename_ = name; }
    static void SetSigchldFd(int sigchld_fd) { sigchld_fd_ = sigchld_fd; }

  private:
    void NotifyStateChange(const std::string& new_state) const;
@@ -168,8 +169,10 @@ class Service {
    void RunService(const std::vector<Descriptor>& descriptors, InterprocessFifo cgroups_activated,
                    InterprocessFifo setsid_finished);
    void SetMountNamespace();

    static unsigned long next_start_order_;
    static bool is_exec_service_running_;
    static int sigchld_fd_;

    const std::string name_;
    std::set<std::string> classnames_;
Loading