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

Commit 176afbbe authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Do not block SIGTERM in init's child processes"

parents 4819edf4 4a4ec14e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <paths.h>
#include <pthread.h>
#include <seccomp_policy.h>
#include <signal.h>
#include <stdlib.h>
@@ -491,6 +492,16 @@ static void HandleSigtermSignal() {
    HandlePowerctlMessage("shutdown,container");
}

static void UnblockSigterm() {
    sigset_t mask;
    sigemptyset(&mask);
    sigaddset(&mask, SIGTERM);

    if (sigprocmask(SIG_UNBLOCK, &mask, nullptr) == -1) {
        PLOG(FATAL) << "failed to unblock SIGTERM for PID " << getpid();
    }
}

static void InstallSigtermHandler() {
    sigset_t mask;
    sigemptyset(&mask);
@@ -500,6 +511,12 @@ static void InstallSigtermHandler() {
        PLOG(FATAL) << "failed to block SIGTERM";
    }

    // Register a handler to unblock SIGTERM in the child processes.
    const int result = pthread_atfork(nullptr, nullptr, &UnblockSigterm);
    if (result != 0) {
        LOG(FATAL) << "Failed to register a fork handler: " << strerror(result);
    }

    sigterm_signal_fd = signalfd(-1, &mask, SFD_CLOEXEC);
    if (sigterm_signal_fd == -1) {
        PLOG(FATAL) << "failed to create signalfd for SIGTERM";