chiark / gitweb /
core: move ManagerRunningAs to shared
[elogind.git] / src / core / unit-printf.c
index cd492061bb8a837ebb10144c1aa231e3fc984755..cbae45d9f75c2f2db756982acac52f7154ef4772 100644 (file)
@@ -107,7 +107,7 @@ static char *specifier_runtime(char specifier, void *data, void *userdata) {
         Unit *u = userdata;
         assert(u);
 
         Unit *u = userdata;
         assert(u);
 
-        if (u->manager->running_as == MANAGER_USER) {
+        if (u->manager->running_as == SYSTEMD_USER) {
                 const char *e;
 
                 e = getenv("XDG_RUNTIME_DIR");
                 const char *e;
 
                 e = getenv("XDG_RUNTIME_DIR");
@@ -119,16 +119,23 @@ static char *specifier_runtime(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_name(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_name(char specifier, void *data, void *userdata) {
-        Service *s = userdata;
+        Unit *u = userdata;
+        ExecContext *c;
         int r;
         const char *username;
 
         int r;
         const char *username;
 
+        assert(u);
+
+        c = unit_get_exec_context(u);
+        if (!c)
+                return NULL;
+
         /* get USER env from our own env if set */
         /* get USER env from our own env if set */
-        if (!s->exec_context.user)
+        if (!c->user)
                 return getusername_malloc();
 
         /* fish username from passwd */
                 return getusername_malloc();
 
         /* fish username from passwd */
-        username = s->exec_context.user;
+        username = c->user;
         r = get_user_creds(&username, NULL, NULL, NULL, NULL);
         if (r < 0)
                 return NULL;
         r = get_user_creds(&username, NULL, NULL, NULL, NULL);
         if (r < 0)
                 return NULL;
@@ -137,12 +144,19 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_home(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_home(char specifier, void *data, void *userdata) {
-        Service *s = userdata;
+        Unit *u = userdata;
+        ExecContext *c;
         int r;
         const char *username, *home;
 
         int r;
         const char *username, *home;
 
+        assert(u);
+
+        c = unit_get_exec_context(u);
+        if (!c)
+                return NULL;
+
         /* return HOME if set, otherwise from passwd */
         /* return HOME if set, otherwise from passwd */
-        if (!s->exec_context.user) {
+        if (!c->user) {
                 char *h;
 
                 r = get_home_dir(&h);
                 char *h;
 
                 r = get_home_dir(&h);
@@ -152,7 +166,7 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
                 return h;
         }
 
                 return h;
         }
 
-        username = s->exec_context.user;
+        username = c->user;
         r = get_user_creds(&username, NULL, NULL, &home, NULL);
         if (r < 0)
                return NULL;
         r = get_user_creds(&username, NULL, NULL, &home, NULL);
         if (r < 0)
                return NULL;
@@ -161,12 +175,19 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_shell(char specifier, void *data, void *userdata) {
 }
 
 static char *specifier_user_shell(char specifier, void *data, void *userdata) {
-        Service *s = userdata;
+        Unit *u = userdata;
+        ExecContext *c;
         int r;
         const char *username, *shell;
 
         int r;
         const char *username, *shell;
 
+        assert(u);
+
+        c = unit_get_exec_context(u);
+        if (!c)
+                return NULL;
+
         /* return HOME if set, otherwise from passwd */
         /* return HOME if set, otherwise from passwd */
-        if (!s->exec_context.user) {
+        if (!c->user) {
                 char *sh;
 
                 r = get_shell(&sh);
                 char *sh;
 
                 r = get_shell(&sh);
@@ -176,7 +197,7 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) {
                 return sh;
         }
 
                 return sh;
         }
 
-        username = s->exec_context.user;
+        username = c->user;
         r = get_user_creds(&username, NULL, NULL, NULL, &shell);
         if (r < 0)
                 return strdup("/bin/sh");
         r = get_user_creds(&username, NULL, NULL, NULL, &shell);
         if (r < 0)
                 return strdup("/bin/sh");
@@ -184,6 +205,42 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) {
         return strdup(shell);
 }
 
         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) {
 
         /*
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
@@ -223,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
          * %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[] = {
          */
 
         const Specifier table[] = {
@@ -241,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 },
                 { '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 }
         };
 
                 { 0, NULL, NULL }
         };