]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl,loginctl,machinectl: add --signal=list
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Feb 2021 15:03:03 +0000 (16:03 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2021 07:50:40 +0000 (08:50 +0100)
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.

man/loginctl.xml
man/standard-options.xml
src/shared/parse-argument.c

index d3745ce52d64eaccf22a7719b43ed38881a689e1..33683144fa3fcc4beb88f695745f649f98794eb4 100644 (file)
         <term><option>-s</option></term>
         <term><option>--signal=</option></term>
 
-        <listitem><para>When used with <command>kill-session</command>
-        or <command>kill-user</command>, choose which signal to send
-        to selected processes. Must be one of the well known signal
-        specifiers, such as <constant>SIGTERM</constant>,
-        <constant>SIGINT</constant> or <constant>SIGSTOP</constant>.
-        If omitted, defaults to
-        <constant>SIGTERM</constant>.</para></listitem>
+        <listitem><para>When used with <command>kill-session</command> or <command>kill-user</command>,
+        choose which signal to send to selected processes. Must be one of the well known signal specifiers,
+        such as <constant>SIGTERM</constant>, <constant>SIGINT</constant> or <constant>SIGSTOP</constant>.
+        If omitted, defaults to <constant>SIGTERM</constant>.</para>
+
+        <para>The special value <literal>help</literal> will list the known values and the program will exit
+        immediately, and the special value <literal>list</literal> will list known values along with the
+        numerical signal numbers and the program will exit immediately.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 848439119e9c8f1ae909183fdfa0324bc3546bef..4565a43b2449966b413eb585a8829a710273b054 100644 (file)
@@ -73,7 +73,8 @@
       <option>SIGTERM</option>.</para>
 
       <para>The special value <literal>help</literal> will list the known values and the program will exit
-      immediately.</para>
+      immediately, and the special value <literal>list</literal> will list known values along with the
+      numerical signal numbers and the program will exit immediately.</para>
     </listitem>
   </varlistentry>
 </variablelist>
index a30d3adc13f0a66b18c808291f2a1c6bb3073ecc..ca10d51793b1c32a5f878b9b9438fbe0ac0a9eec 100644 (file)
@@ -1,7 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "format-table.h"
 #include "parse-argument.h"
 #include "signal-util.h"
+#include "stdio-util.h"
 #include "string-table.h"
 #include "string-util.h"
 
@@ -16,6 +18,29 @@ int parse_signal_argument(const char *s, int *ret) {
                 return 0;
         }
 
+        if (streq(s, "list")) {
+                _cleanup_(table_unrefp) Table *table = NULL;
+
+                table = table_new("signal", "name");
+                if (!table)
+                        return log_oom();
+
+                for (int i = 1; i < _NSIG; i++) {
+                        r = table_add_many(
+                                        table,
+                                        TABLE_INT, i,
+                                        TABLE_SIGNAL, i);
+                        if (r < 0)
+                                return table_log_add_error(r);
+                }
+
+                r = table_print(table, NULL);
+                if (r < 0)
+                        return table_log_print_error(r);
+
+                return 0;
+        }
+
         r = signal_from_string(s);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse signal string \"%s\".", s);