Skip to content

Commit 97ab9df

Browse files
committed
systemctl,loginctl,machinectl: add --signal=list
This lists numerical signal values: $ systemctl --signal list SIGNAL NAME 1 SIGHUP 2 SIGINT 3 SIGQUIT ... 62 SIGRTMIN+28 63 SIGRTMIN+29 64 SIGRTMIN+30 This is useful when trying to kill e.g. systemd with a specific signal number using kill. kill doesn't accept our fancy signal names like RTMIN+4, so one would have to calculate that value somehow. Doing systemctl --signal list | grep -F RTMIN+4 is a nice way of doing that.
1 parent 86beb21 commit 97ab9df

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

man/loginctl.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,14 @@
334334
<term><option>-s</option></term>
335335
<term><option>--signal=</option></term>
336336

337-
<listitem><para>When used with <command>kill-session</command>
338-
or <command>kill-user</command>, choose which signal to send
339-
to selected processes. Must be one of the well known signal
340-
specifiers, such as <constant>SIGTERM</constant>,
341-
<constant>SIGINT</constant> or <constant>SIGSTOP</constant>.
342-
If omitted, defaults to
343-
<constant>SIGTERM</constant>.</para></listitem>
337+
<listitem><para>When used with <command>kill-session</command> or <command>kill-user</command>,
338+
choose which signal to send to selected processes. Must be one of the well known signal specifiers,
339+
such as <constant>SIGTERM</constant>, <constant>SIGINT</constant> or <constant>SIGSTOP</constant>.
340+
If omitted, defaults to <constant>SIGTERM</constant>.</para>
341+
342+
<para>The special value <literal>help</literal> will list the known values and the program will exit
343+
immediately, and the special value <literal>list</literal> will list known values along with the
344+
numerical signal numbers and the program will exit immediately.</para></listitem>
344345
</varlistentry>
345346

346347
<varlistentry>

man/standard-options.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
<option>SIGTERM</option>.</para>
7474

7575
<para>The special value <literal>help</literal> will list the known values and the program will exit
76-
immediately.</para>
76+
immediately, and the special value <literal>list</literal> will list known values along with the
77+
numerical signal numbers and the program will exit immediately.</para>
7778
</listitem>
7879
</varlistentry>
7980
</variablelist>

src/shared/parse-argument.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3+
#include "format-table.h"
34
#include "parse-argument.h"
45
#include "signal-util.h"
6+
#include "stdio-util.h"
57
#include "string-table.h"
68
#include "string-util.h"
79

@@ -16,6 +18,29 @@ int parse_signal_argument(const char *s, int *ret) {
1618
return 0;
1719
}
1820

21+
if (streq(s, "list")) {
22+
_cleanup_(table_unrefp) Table *table = NULL;
23+
24+
table = table_new("signal", "name");
25+
if (!table)
26+
return log_oom();
27+
28+
for (int i = 1; i < _NSIG; i++) {
29+
r = table_add_many(
30+
table,
31+
TABLE_INT, i,
32+
TABLE_SIGNAL, i);
33+
if (r < 0)
34+
return table_log_add_error(r);
35+
}
36+
37+
r = table_print(table, NULL);
38+
if (r < 0)
39+
return table_log_print_error(r);
40+
41+
return 0;
42+
}
43+
1944
r = signal_from_string(s);
2045
if (r < 0)
2146
return log_error_errno(r, "Failed to parse signal string \"%s\".", s);

0 commit comments

Comments
 (0)