blob: 4a576aa7d6023020510f059d287202c35262cb8b [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001From 786883cfa13e21f060ee6da6cabb94845f4349a0 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 14 Dec 2015 05:18:20 +0000
4Subject: [PATCH 14/36] Make root's home directory configurable
5
6OpenEmbedded has a configurable home directory for root. Allow
7systemd to be built using its idea of what root's home directory
8should be.
9
10Upstream-Status: Denied
11Upstream wants to have a unified hierarchy where everyone is
12using the same root folder.
13https://github.com/systemd/systemd/issues/541
14
15Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17---
18 Makefile.am | 2 ++
19 configure.ac | 7 +++++++
20 src/basic/user-util.c | 4 ++--
21 src/core/namespace.c | 2 +-
22 src/nspawn/nspawn.c | 4 ++--
23 units/console-shell.service.m4.in | 4 ++--
24 units/emergency.service.in | 4 ++--
25 units/rescue.service.in | 4 ++--
26 8 files changed, 20 insertions(+), 11 deletions(-)
27
28diff --git a/Makefile.am b/Makefile.am
29index b3f3343..a99e8eb 100644
30--- a/Makefile.am
31+++ b/Makefile.am
32@@ -202,6 +202,7 @@ AM_CPPFLAGS = \
33 -DLIBDIR=\"$(libdir)\" \
34 -DROOTLIBDIR=\"$(rootlibdir)\" \
35 -DROOTLIBEXECDIR=\"$(rootlibexecdir)\" \
36+ -DROOTHOMEDIR=\"$(roothomedir)\" \
37 -DTEST_DIR=\"$(abs_top_srcdir)/test\" \
38 -I $(top_srcdir)/src \
39 -I $(top_builddir)/src/basic \
40@@ -5713,6 +5714,7 @@ EXTRA_DIST += \
41 substitutions = \
42 '|rootlibexecdir=$(rootlibexecdir)|' \
43 '|rootbindir=$(rootbindir)|' \
44+ '|roothomedir=$(roothomedir)|' \
45 '|bindir=$(bindir)|' \
46 '|SYSTEMCTL=$(rootbindir)/systemctl|' \
47 '|SYSTEMD_NOTIFY=$(rootbindir)/systemd-notify|' \
48diff --git a/configure.ac b/configure.ac
49index c5ab9d0..16c83bb 100644
50--- a/configure.ac
51+++ b/configure.ac
52@@ -1470,6 +1470,11 @@ AC_ARG_WITH([rootlibdir],
53 [with_rootlibdir=${libdir}])
54 AX_NORMALIZE_PATH([with_rootlibdir])
55
56+AC_ARG_WITH([roothomedir],
57+ AS_HELP_STRING([--with-roothomedir=DIR], [Home directory for the root user]),
58+ [],
59+ [with_roothomedir=/root])
60+
61 AC_ARG_WITH([pamlibdir],
62 AS_HELP_STRING([--with-pamlibdir=DIR], [Directory for PAM modules]),
63 [],
64@@ -1553,6 +1558,7 @@ AC_SUBST([pamlibdir], [$with_pamlibdir])
65 AC_SUBST([pamconfdir], [$with_pamconfdir])
66 AC_SUBST([rootprefix], [$with_rootprefix])
67 AC_SUBST([rootlibdir], [$with_rootlibdir])
68+AC_SUBST([roothomedir], [$with_roothomedir])
69
70 AC_CONFIG_FILES([
71 Makefile
72@@ -1643,6 +1649,7 @@ AC_MSG_RESULT([
73 includedir: ${includedir}
74 lib dir: ${libdir}
75 rootlib dir: ${with_rootlibdir}
76+ root home dir: ${with_roothomedir}
77 SysV init scripts: ${SYSTEM_SYSVINIT_PATH}
78 SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH}
79 Build Python: ${PYTHON}
80diff --git a/src/basic/user-util.c b/src/basic/user-util.c
81index 19155bc..55672b3 100644
82--- a/src/basic/user-util.c
83+++ b/src/basic/user-util.c
84@@ -122,7 +122,7 @@ int get_user_creds(
85 *gid = 0;
86
87 if (home)
88- *home = "/root";
89+ *home = ROOTHOMEDIR;
90
91 if (shell)
92 *shell = "/bin/sh";
93@@ -353,7 +353,7 @@ int get_home_dir(char **_h) {
94 /* Hardcode home directory for root to avoid NSS */
95 u = getuid();
96 if (u == 0) {
97- h = strdup("/root");
98+ h = strdup(ROOTHOMEDIR);
99 if (!h)
100 return -ENOMEM;
101
102diff --git a/src/core/namespace.c b/src/core/namespace.c
103index b573f00..0f70b14 100644
104--- a/src/core/namespace.c
105+++ b/src/core/namespace.c
106@@ -409,7 +409,7 @@ int setup_namespace(
107 home_dir = strjoina("-", home_dir);
108 run_user_dir = prefix_roota(root_directory, "/run/user");
109 run_user_dir = strjoina("-", run_user_dir);
110- root_dir = prefix_roota(root_directory, "/root");
111+ root_dir = prefix_roota(root_directory, ROOTHOMEDIR);
112 root_dir = strjoina("-", root_dir);
113
114 r = append_mounts(&m, STRV_MAKE(home_dir, run_user_dir, root_dir),
115diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
116index 65e65ec..12f0ee8 100644
117--- a/src/nspawn/nspawn.c
118+++ b/src/nspawn/nspawn.c
119@@ -2564,7 +2564,7 @@ static int inner_child(
120 if (envp[n_env])
121 n_env ++;
122
123- if ((asprintf((char**)(envp + n_env++), "HOME=%s", home ? home: "/root") < 0) ||
124+ if ((asprintf((char**)(envp + n_env++), "HOME=%s", home ? home: ROOTHOMEDIR) < 0) ||
125 (asprintf((char**)(envp + n_env++), "USER=%s", arg_user ? arg_user : "root") < 0) ||
126 (asprintf((char**)(envp + n_env++), "LOGNAME=%s", arg_user ? arg_user : "root") < 0))
127 return log_oom();
128@@ -2647,7 +2647,7 @@ static int inner_child(
129 #endif /* HAVE_EXECVPE */
130 else {
131 if (!arg_chdir)
132- chdir(home ?: "/root");
133+ chdir(home ?: ROOTHOMEDIR);
134
135 execle("/bin/bash", "-bash", NULL, env_use);
136 execle("/bin/sh", "-sh", NULL, env_use);
137diff --git a/units/console-shell.service.m4.in b/units/console-shell.service.m4.in
138index a345ec2..3caae7d 100644
139--- a/units/console-shell.service.m4.in
140+++ b/units/console-shell.service.m4.in
141@@ -15,8 +15,8 @@ After=rc-local.service
142 Before=getty.target
143
144 [Service]
145-Environment=HOME=/root
146-WorkingDirectory=-/root
147+Environment=HOME=@roothomedir@
148+WorkingDirectory=-@roothomedir@
149 ExecStart=-@SULOGIN@
150 ExecStopPost=-@SYSTEMCTL@ poweroff
151 Type=idle
152diff --git a/units/emergency.service.in b/units/emergency.service.in
153index fb390ea..5623a57 100644
154--- a/units/emergency.service.in
155+++ b/units/emergency.service.in
156@@ -14,8 +14,8 @@ Conflicts=rescue.service
157 Before=shutdown.target
158
159 [Service]
160-Environment=HOME=/root
161-WorkingDirectory=-/root
162+Environment=HOME=@roothomedir@
163+WorkingDirectory=-@roothomedir@
164 ExecStartPre=-/bin/plymouth --wait quit
165 ExecStartPre=-/bin/echo -e 'Welcome to emergency mode! After logging in, type "journalctl -xb" to view\\nsystem logs, "systemctl reboot" to reboot, "systemctl default" or ^D to\\ntry again to boot into default mode.'
166 ExecStart=-/bin/sh -c "@SULOGIN@; @SYSTEMCTL@ --job-mode=fail --no-block default"
167diff --git a/units/rescue.service.in b/units/rescue.service.in
168index 92553f6..590ae17 100644
169--- a/units/rescue.service.in
170+++ b/units/rescue.service.in
171@@ -14,8 +14,8 @@ After=sysinit.target plymouth-start.service
172 Before=shutdown.target
173
174 [Service]
175-Environment=HOME=/root
176-WorkingDirectory=-/root
177+Environment=HOME=@roothomedir@
178+WorkingDirectory=-@roothomedir@
179 ExecStartPre=-/bin/plymouth quit
180 ExecStartPre=-/bin/echo -e 'Welcome to rescue mode! After logging in, type "journalctl -xb" to view\\nsystem logs, "systemctl reboot" to reboot, "systemctl default" or ^D to\\nboot into default mode.'
181 ExecStart=-/bin/sh -c "@SULOGIN@; @SYSTEMCTL@ --job-mode=fail --no-block default"
182--
1831.8.3.1
184