chiark / gitweb /
unit-printf: add specifiers for the host name, machine id, boot id
authorLennart Poettering <lennart@poettering.net>
Tue, 18 Sep 2012 09:53:47 +0000 (11:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Sep 2012 09:53:47 +0000 (11:53 +0200)
TODO
man/systemd.unit.xml
src/core/unit-printf.c

diff --git a/TODO b/TODO
index 2a3cc77bec117d5acc7ef5f028b3e3808071de76..f7da51c6ed8495a9825d160b9d764b354a37e2e2 100644 (file)
--- a/TODO
+++ b/TODO
@@ -62,8 +62,6 @@ Features:
 
 * journald: add kernel cmdline option to disable ratelimiting for debug purposes
 
-* Add a way to reference the machine/boot ID from ExecStart= and similar command lines
-
 * move PID 1 segfaults to /var/lib/systemd/coredump?
 
 * Document word splitting syntax for ExecStart= and friends
index e0aadf4cd30313236727136c09b7446a1ea70219..55569681cf43164801073c55ed186b7cceccb3a5 100644 (file)
                         <entry>User shell</entry>
                         <entry>This is the shell of the configured user of the unit, or (if none is set) the user running the systemd instance.</entry>
                       </row>
+                      <row>
+                        <entry><literal>%m</literal></entry>
+                        <entry>Machine ID</entry>
+                        <entry>The machine ID of the running system, formatted as string. See <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information.</entry>
+                      </row>
+                      <row>
+                        <entry><literal>%b</literal></entry>
+                        <entry>Boot ID</entry>
+                        <entry>The boot ID of the running system, formatted as string. See <citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more information.</entry>
+                      </row>
+                      <row>
+                        <entry><literal>%H</literal></entry>
+                        <entry>Host name</entry>
+                        <entry>The host name of the running system.</entry>
+                      </row>
                     </tbody>
                   </tgroup>
                 </table>
index 35da29abdf1779776bfff0c477c5adfb02915909..308bbd6351eeb34a5d172ddeec3d7ddd3352c3f1 100644 (file)
@@ -124,6 +124,8 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
         int r;
         const char *username;
 
+        assert(u);
+
         c = unit_get_exec_context(u);
         if (!c)
                 return NULL;
@@ -147,6 +149,8 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
         int r;
         const char *username, *home;
 
+        assert(u);
+
         c = unit_get_exec_context(u);
         if (!c)
                 return NULL;
@@ -176,6 +180,8 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) {
         int r;
         const char *username, *shell;
 
+        assert(u);
+
         c = unit_get_exec_context(u);
         if (!c)
                 return NULL;
@@ -199,6 +205,42 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) {
         return strdup(shell);
 }
 
+static char *specifier_machine_id(char specifier, void *data, void *userdata) {
+        sd_id128_t id;
+        char *buf;
+        int r;
+
+        r = sd_id128_get_machine(&id);
+        if (r < 0)
+                return NULL;
+
+        buf = new(char, 33);
+        if (!buf)
+                return NULL;
+
+        return sd_id128_to_string(id, buf);
+}
+
+static char *specifier_boot_id(char specifier, void *data, void *userdata) {
+        sd_id128_t id;
+        char *buf;
+        int r;
+
+        r = sd_id128_get_boot(&id);
+        if (r < 0)
+                return NULL;
+
+        buf = new(char, 33);
+        if (!buf)
+                return NULL;
+
+        return sd_id128_to_string(id, buf);
+}
+
+static char *specifier_host_name(char specifier, void *data, void *userdata) {
+        return gethostname_malloc();
+}
+
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
@@ -238,6 +280,9 @@ char *unit_full_printf(Unit *u, const char *format) {
          * %u the username of the configured user or running user
          * %h the homedir of the configured user or running user
          * %s the shell of the configured user or running user
+         * %m the machine ID of the running system
+         * %b the boot ID of the running system
+         * %H the host name of the running system
          */
 
         const Specifier table[] = {
@@ -256,6 +301,10 @@ char *unit_full_printf(Unit *u, const char *format) {
                 { 'u', specifier_user_name,           NULL },
                 { 'h', specifier_user_home,           NULL },
                 { 's', specifier_user_shell,          NULL },
+
+                { 'm', specifier_machine_id,          NULL },
+                { 'H', specifier_host_name,           NULL },
+                { 'b', specifier_boot_id,             NULL },
                 { 0, NULL, NULL }
         };