summaryrefslogtreecommitdiffstats
path: root/src/core/kill.c
blob: 6fe96cfc07c0f2018989b07e742eb02d0d6cf954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* SPDX-License-Identifier: LGPL-2.1+ */

#include "kill.h"
#include "signal-util.h"
#include "string-table.h"
#include "util.h"

void kill_context_init(KillContext *c) {
        assert(c);

        c->kill_signal = SIGTERM;
        c->final_kill_signal = SIGKILL;
        c->send_sigkill = true;
        c->send_sighup = false;
        c->watchdog_signal = SIGABRT;
}

void kill_context_dump(KillContext *c, FILE *f, const char *prefix) {
        assert(c);

        prefix = strempty(prefix);

        fprintf(f,
                "%sKillMode: %s\n"
                "%sKillSignal: SIG%s\n"
                "%sFinalKillSignal: SIG%s\n"
                "%sSendSIGKILL: %s\n"
                "%sSendSIGHUP:  %s\n",
                prefix, kill_mode_to_string(c->kill_mode),
                prefix, signal_to_string(c->kill_signal),
                prefix, signal_to_string(c->final_kill_signal),
                prefix, yes_no(c->send_sigkill),
                prefix, yes_no(c->send_sighup));
}

static const char* const kill_mode_table[_KILL_MODE_MAX] = {
        [KILL_CONTROL_GROUP] = "control-group",
        [KILL_PROCESS] = "process",
        [KILL_MIXED] = "mixed",
        [KILL_NONE] = "none"
};

DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);

static const char* const kill_who_table[_KILL_WHO_MAX] = {
        [KILL_MAIN] = "main",
        [KILL_CONTROL] = "control",
        [KILL_ALL] = "all",
        [KILL_MAIN_FAIL] = "main-fail",
        [KILL_CONTROL_FAIL] = "control-fail",
        [KILL_ALL_FAIL] = "all-fail"
};

DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);