62b301
From 9ba5d8811630a3d2af90fdc52f4fd6b03ee9e692 Mon Sep 17 00:00:00 2001
62b301
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
62b301
Date: Tue, 21 May 2019 19:26:12 +0200
62b301
Subject: [PATCH] core: unset HOME=/ that the kernel gives us
62b301
62b301
Partially fixes #12389.
62b301
62b301
%h would return "/" in a machine, but "/root" in a container. Let's fix
62b301
this by resetting $HOME to the expected value.
62b301
62b301
(cherry picked from commit 9d48671c62de133a2b9fe7c31e70c0ff8e68f2db)
62b301
62b301
Resolves: #2056527
62b301
---
62b301
 src/core/main.c | 5 +++++
62b301
 1 file changed, 5 insertions(+)
62b301
62b301
diff --git a/src/core/main.c b/src/core/main.c
62b301
index d897155644..08a4df3c97 100644
62b301
--- a/src/core/main.c
62b301
+++ b/src/core/main.c
62b301
@@ -1307,6 +1307,11 @@ static int fixup_environment(void) {
62b301
         if (setenv("TERM", t, 1) < 0)
62b301
                 return -errno;
62b301
 
62b301
+        /* The kernels sets HOME=/ for init. Let's undo this. */
62b301
+        if (path_equal_ptr(getenv("HOME"), "/") &&
62b301
+            unsetenv("HOME") < 0)
62b301
+                log_warning_errno(errno, "Failed to unset $HOME: %m");
62b301
+
62b301
         return 0;
62b301
 }
62b301