chiark / gitweb /
unit: introduce %s specifier for the user shell
[elogind.git] / src / core / unit.c
index ed519b3bd561f265ec7fe4f6d1af6034b692380c..673af13c3eb3bf5a5e3bb3764d08908be8a82aac 100644 (file)
@@ -2232,7 +2232,7 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
 
         /* fish username from passwd */
         username = s->exec_context.user;
 
         /* fish username from passwd */
         username = s->exec_context.user;
-        r = get_user_creds(&username, NULL, NULL, NULL);
+        r = get_user_creds(&username, NULL, NULL, NULL, NULL);
         if (r < 0)
                 return NULL;
 
         if (r < 0)
                 return NULL;
 
@@ -2256,13 +2256,37 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
         }
 
         username = s->exec_context.user;
         }
 
         username = s->exec_context.user;
-        r = get_user_creds(&username, NULL, NULL, &home);
+        r = get_user_creds(&username, NULL, NULL, &home, NULL);
         if (r < 0)
                return NULL;
 
         return strdup(home);
 }
 
         if (r < 0)
                return NULL;
 
         return strdup(home);
 }
 
+static char *specifier_user_shell(char specifier, void *data, void *userdata) {
+        Service *s = userdata;
+        int r;
+        const char *username, *shell;
+
+        /* return HOME if set, otherwise from passwd */
+        if (!s->exec_context.user) {
+                char *sh;
+
+                r = get_shell(&sh);
+                if (r < 0)
+                        return strdup("/bin/sh");
+
+                return sh;
+        }
+
+        username = s->exec_context.user;
+        r = get_user_creds(&username, NULL, NULL, NULL, &shell);
+        if (r < 0)
+                return strdup("/bin/sh");
+
+        return strdup(shell);
+}
+
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
@@ -2316,6 +2340,7 @@ char *unit_full_printf(Unit *u, const char *format) {
                 { 't', specifier_runtime,             NULL },
                 { 'u', specifier_user_name,           NULL },
                 { 'h', specifier_user_home,           NULL },
                 { 't', specifier_runtime,             NULL },
                 { 'u', specifier_user_name,           NULL },
                 { 'h', specifier_user_home,           NULL },
+                { 's', specifier_user_shell,          NULL },
                 { 0, NULL, NULL }
         };
 
                 { 0, NULL, NULL }
         };