1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "kill.h"
4 #include "signal-util.h"
5 #include "string-table.h"
6 #include "util.h"
7 
kill_context_init(KillContext * c)8 void kill_context_init(KillContext *c) {
9         assert(c);
10 
11         c->kill_signal = SIGTERM;
12         /* restart_kill_signal is unset by default and we fall back to kill_signal */
13         c->final_kill_signal = SIGKILL;
14         c->send_sigkill = true;
15         c->send_sighup = false;
16         c->watchdog_signal = SIGABRT;
17 }
18 
kill_context_dump(KillContext * c,FILE * f,const char * prefix)19 void kill_context_dump(KillContext *c, FILE *f, const char *prefix) {
20         assert(c);
21 
22         prefix = strempty(prefix);
23 
24         fprintf(f,
25                 "%sKillMode: %s\n"
26                 "%sKillSignal: SIG%s\n"
27                 "%sRestartKillSignal: SIG%s\n"
28                 "%sFinalKillSignal: SIG%s\n"
29                 "%sSendSIGKILL: %s\n"
30                 "%sSendSIGHUP: %s\n",
31                 prefix, kill_mode_to_string(c->kill_mode),
32                 prefix, signal_to_string(c->kill_signal),
33                 prefix, signal_to_string(restart_kill_signal(c)),
34                 prefix, signal_to_string(c->final_kill_signal),
35                 prefix, yes_no(c->send_sigkill),
36                 prefix, yes_no(c->send_sighup));
37 }
38 
39 static const char* const kill_mode_table[_KILL_MODE_MAX] = {
40         [KILL_CONTROL_GROUP] = "control-group",
41         [KILL_PROCESS]       = "process",
42         [KILL_MIXED]         = "mixed",
43         [KILL_NONE]          = "none",
44 };
45 
46 DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);
47 
48 static const char* const kill_who_table[_KILL_WHO_MAX] = {
49         [KILL_MAIN]         = "main",
50         [KILL_CONTROL]      = "control",
51         [KILL_ALL]          = "all",
52         [KILL_MAIN_FAIL]    = "main-fail",
53         [KILL_CONTROL_FAIL] = "control-fail",
54         [KILL_ALL_FAIL]     = "all-fail",
55 };
56 
57 DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);
58