summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-16 12:34:54 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-16 12:34:54 +0200
commitd05c5031ad4c528fe6bbfed289519edb9f13180a (patch)
tree6b71a2bab0120c86da640693474beb4931043b0c /src/core
parentb2896c905bef7be7ed9a760d9d61aa6ad0f614a3 (diff)
unit: introduce %s specifier for the user shell
Diffstat (limited to 'src/core')
-rw-r--r--src/core/execute.c2
-rw-r--r--src/core/unit.c29
2 files changed, 28 insertions, 3 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index c0e8f9e013..daba1a3846 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1182,7 +1182,7 @@ int exec_spawn(ExecCommand *command,
if (context->user) {
username = context->user;
- err = get_user_creds(&username, &uid, &gid, &home);
+ err = get_user_creds(&username, &uid, &gid, &home, NULL);
if (err < 0) {
r = EXIT_USER;
goto fail_child;
diff --git a/src/core/unit.c b/src/core/unit.c
index ed519b3bd5..673af13c3e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2232,7 +2232,7 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
/* 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;
@@ -2256,13 +2256,37 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
}
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);
}
+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) {
/*
@@ -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 },
+ { 's', specifier_user_shell, NULL },
{ 0, NULL, NULL }
};