From 8d697f662cf2e59930f6b79726502cc016cec325 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Thu, 15 Jun 2023 16:14:00 -0300 Subject: openrc-run.sh: save and load variables on default start temporary system for testing, it's gonna store any environment variables defined in export_vars="", and subsequent services will load them. ideally we only want to load the variables saved by services we depend on, so that would change later. Signed-off-by: Anna (navi) Figueiredo Gomes --- sh/openrc-run.sh.in | 5 +++++ sh/rc-functions.sh | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in index ed565a46..12a4c6eb 100644 --- a/sh/openrc-run.sh.in +++ b/sh/openrc-run.sh.in @@ -149,6 +149,11 @@ _status() # supervisor modules default_start() { + if yesno "${RC_USER_SERVICES}"; then + load_variables + save_variables + fi + local func=ssd_start case "$supervisor" in runit) func=runit_start ;; diff --git a/sh/rc-functions.sh b/sh/rc-functions.sh index 81d065b8..922bb870 100644 --- a/sh/rc-functions.sh +++ b/sh/rc-functions.sh @@ -134,6 +134,23 @@ _depend() { done } +save_variables() { + mkdir -p "${RC_SVCDIR}"/env/ + + local _envname + + if [ -n "${export_vars}" ]; then + rm "${RC_SVCDIR}/env/${RC_SVCNAME}" + for _envname in ${export_vars}; do + eval echo "${_envname}=\$${_envname}" >> "${RC_SVCDIR}/env/${RC_SVCNAME}" + done + fi +} + +load_variables() { + sourcex -e "${RC_SVCDIR}/env/*" +} + # Add our sbin to $PATH case "$PATH" in "$RC_LIBEXECDIR"/sbin|"$RC_LIBEXECDIR"/sbin:*);; -- cgit v1.2.3