From c17e9668d62a4655d285de0c280f2a0b921c87e1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 12 Feb 2015 12:21:16 +0100 Subject: [PATCH] core: don't fail to run services in --user instances if $HOME is missing Otherwise we cannot even invoke systemd-exit.service anymore, thus not even exit. https://bugs.freedesktop.org/show_bug.cgi?id=83100 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=759320 (cherry picked from commit 4c08c8242a687e00b289e948ccd07b96f0bc4866) Conflicts: src/core/execute.c --- src/core/execute.c | 3 ++- src/core/execute.h | 1 + src/core/unit.c | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/execute.c b/src/core/execute.c index ed75035bf..2c17bd234 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1600,7 +1600,8 @@ static int exec_child(ExecCommand *command, return -errno; } - if (chdir(context->working_directory ? context->working_directory : "/") < 0) { + if (chdir(context->working_directory ?: "/") < 0 && + !context->working_directory_missing_ok) { *error = EXIT_CHDIR; return -errno; } diff --git a/src/core/execute.h b/src/core/execute.h index c45dde53a..a9ad0d7ac 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -99,6 +99,7 @@ struct ExecContext { struct rlimit *rlimit[_RLIMIT_MAX]; char *working_directory, *root_directory; + bool working_directory_missing_ok; mode_t umask; int oom_score_adjust; diff --git a/src/core/unit.c b/src/core/unit.c index 891df3cb0..7d52c41bd 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3052,6 +3052,10 @@ int unit_patch_contexts(Unit *u) { r = get_home_dir(&ec->working_directory); if (r < 0) return r; + + /* Allow user services to run, even if the + * home directory is missing */ + ec->working_directory_missing_ok = true; } if (u->manager->running_as == SYSTEMD_USER &&