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

Commit 9be63f63 authored by Luis Hector Chavez's avatar Luis Hector Chavez Committed by android-build-merger
Browse files

Merge "init: Cleanly exit subcontext processes upon init's death" am: f86e85cb

am: 7b34edae

Change-Id: I2c0c77273e16ebc6423e764b6f165aa6c2b173d6
parents b26ecd25 7b34edae
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,9 @@ constexpr size_t kBufferSize = 4096;
Result<std::string> ReadMessage(int socket) {
Result<std::string> ReadMessage(int socket) {
    char buffer[kBufferSize] = {};
    char buffer[kBufferSize] = {};
    auto result = TEMP_FAILURE_RETRY(recv(socket, buffer, sizeof(buffer), 0));
    auto result = TEMP_FAILURE_RETRY(recv(socket, buffer, sizeof(buffer), 0));
    if (result <= 0) {
    if (result == 0) {
        return Error();
    } else if (result < 0) {
        return ErrnoError();
        return ErrnoError();
    }
    }
    return std::string(buffer, result);
    return std::string(buffer, result);
@@ -175,6 +177,12 @@ void SubcontextProcess::MainLoop() {


        auto init_message = ReadMessage(init_fd_);
        auto init_message = ReadMessage(init_fd_);
        if (!init_message) {
        if (!init_message) {
            if (init_message.error_errno() == 0) {
                // If the init file descriptor was closed, let's exit quietly. If
                // this was accidental, init will restart us. If init died, this
                // avoids calling abort(3) unnecessarily.
                return;
            }
            LOG(FATAL) << "Could not read message from init: " << init_message.error();
            LOG(FATAL) << "Could not read message from init: " << init_message.error();
        }
        }