ryantimwilson / rpms / systemd

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