ryantimwilson / rpms / systemd

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