diff mbox series

[4/5] systemd: support persistent tmp

Message ID 20231211005815.1119314-5-changqing.li@windriver.com
State New
Headers show
Series Fix persistent tmp | expand

Commit Message

Changqing Li Dec. 11, 2023, 12:58 a.m. UTC
From: Changqing Li <changqing.li@windriver.com>

* update 00-create-volatile.conf, for volatile tmp, make /tmp ->
/var/tmp, /var/tmp -> /var/volatile/tmp and set age of /var/volatile/tmp
to 10d

* if VOLATILE_TMP_DIR/VOLATILE_LOG_DIR set to no, remove volatile
related configs from 00-create-volatile.conf

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 .../systemd/systemd/00-create-volatile.conf   |  3 ++-
 meta/recipes-core/systemd/systemd_254.4.bb    | 22 +++++++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd/00-create-volatile.conf b/meta/recipes-core/systemd/systemd/00-create-volatile.conf
index c4277221a2..860f2783ef 100644
--- a/meta/recipes-core/systemd/systemd/00-create-volatile.conf
+++ b/meta/recipes-core/systemd/systemd/00-create-volatile.conf
@@ -5,4 +5,5 @@ 
 
 d		/run/lock		1777	-	-	-
 d		/var/volatile/log		-	-	-	-
-d		/var/volatile/tmp		1777	-	-
+d		/var/volatile/tmp		1777	-	-   10d
+L+      /tmp                   1777    root   root   -     /var/tmp
diff --git a/meta/recipes-core/systemd/systemd_254.4.bb b/meta/recipes-core/systemd/systemd_254.4.bb
index 0c12926bef..01ef5cfd7b 100644
--- a/meta/recipes-core/systemd/systemd_254.4.bb
+++ b/meta/recipes-core/systemd/systemd_254.4.bb
@@ -289,6 +289,21 @@  do_install() {
 	done
 
 	install -m 0644 ${WORKDIR}/00-create-volatile.conf ${D}${nonarch_libdir}/tmpfiles.d/
+	if [ ${@ oe.types.boolean('${VOLATILE_LOG_DIR}') } = False ]; then
+		sed -i -e "/^d.*\/var\/volatile\/log/d" ${D}${nonarch_libdir}/tmpfiles.d/00-create-volatile.conf
+	fi
+
+	if [ ${@ oe.types.boolean('${VOLATILE_TMP_DIR}') } = False ]; then
+		sed -i -e "/^d.*\/var\/volatile\/tmp/d" ${D}${nonarch_libdir}/tmpfiles.d/00-create-volatile.conf
+		sed -i -e "/^L+.*\/tmp/d" ${D}${nonarch_libdir}/tmpfiles.d/00-create-volatile.conf
+	else
+		# For volatile tmp, /tmp link to /var/tmp, /var/tmp links to /var/volatile/tmp, so don't need
+		# mount /tmp again
+		rm -f ${D}${systemd_unitdir}/system/tmp.mount
+		rm -f ${D}${systemd_unitdir}/system/local-fs.target.wants/tmp.mount
+		# The age are set in 00-create-volatile.conf
+		rm -rf ${D}${nonarch_libdir}/tmpfiles.d/tmp.conf
+	fi
 
 	if ${@bb.utils.contains('DISTRO_FEATURES','sysvinit','true','false',d)}; then
 		install -d ${D}${sysconfdir}/init.d
@@ -308,13 +323,6 @@  do_install() {
 		rm -rf ${D}${localstatedir}/log/journal/remote
 	fi
 
-	# if the user requests /tmp be on persistent storage (i.e. not volatile)
-	# then don't use a tmpfs for /tmp
-	if [ "${VOLATILE_TMP_DIR}" != "yes" ]; then
-		rm -f ${D}${rootlibdir}/systemd/system/tmp.mount
-		rm -f ${D}${rootlibdir}/systemd/system/local-fs.target.wants/tmp.mount
-	fi
-
 	install -d ${D}${systemd_system_unitdir}/graphical.target.wants
 	install -d ${D}${systemd_system_unitdir}/multi-user.target.wants
 	install -d ${D}${systemd_system_unitdir}/poweroff.target.wants