core: add default descriptions for slices
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Jun 2021 07:10:42 +0000 (09:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Jul 2021 16:15:33 +0000 (18:15 +0200)
[  OK  ] Created slice system-getty.slice (Slice /system/getty).
[  OK  ] Created slice system-modprobe.slice (Slice /system/modprobe).
[  OK  ] Created slice system-sshd\x2dkeygen.slice (Slice /system/sshd-keygen).
[  OK  ] Created slice user.slice (User and Session Slice).

Before, the first three slices were shown without any description which didn't
look nice.

(cherry picked from commit 4dd21726f852010aef17e9b952b4bb1646fdf496)
(cherry picked from commit 0b0d80d96009e10ce36d683b7991829a2cfca67c)
(cherry picked from commit 3fa82957117677ec9d858bf86c203be6a39f812c)

src/core/slice.c

index c6884d8c3b1d93c23dcbf25ab1e49e601252f3d6..e16c63193bd339834aae3f4256905e0ac9d206dd 100644 (file)
@@ -189,6 +189,14 @@ static int slice_load(Unit *u) {
         if (r < 0)
                 return r;
 
+        if (!u->description) {
+                _cleanup_free_ char *tmp = NULL;
+
+                r = unit_name_to_path(u->id, &tmp);
+                if (r >= 0)  /* Failure is ignored… */
+                        u->description = strjoin("Slice ", tmp);
+        }
+
         return slice_verify(s);
 }