Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 May 2018 19:36:26 +0000 (UTC)
From:      Mark Felder <feld@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334221 - head/etc
Message-ID:  <201805251936.w4PJaQIf093393@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: feld (ports committer)
Date: Fri May 25 19:36:26 2018
New Revision: 334221
URL: https://svnweb.freebsd.org/changeset/base/334221

Log:
  rc.subr: Support loading environmental variables from a file
  
  The current support for setting environment via foo_env="" in rc.conf is
  not scalable and does not handle envs with spaces in the value. It seems
  a common pattern for some newer software is to skip configuration files
  altogether and rely on the env. This is well supported in systemd unit
  files and may be the inspiration for this trend.
  
  MFH:		1 week
  Differential Revision:	https://reviews.freebsd.org/D14453

Modified:
  head/etc/rc.subr

Modified: head/etc/rc.subr
==============================================================================
--- head/etc/rc.subr	Fri May 25 19:16:05 2018	(r334220)
+++ head/etc/rc.subr	Fri May 25 19:36:26 2018	(r334221)
@@ -754,6 +754,8 @@ check_startmsgs()
 #
 #	${name}_env	n	Environment variables to run ${command} with.
 #
+#	${name}_env_file n	File to source variables to run ${command} with.
+#
 #	${name}_fib	n	Routing table number to run ${command} with.
 #
 #	${name}_nice	n	Nice level to run ${command} at.
@@ -954,7 +956,14 @@ run_rc_command()
 	    _group=\$${name}_group	_groups=\$${name}_groups \
 	    _fib=\$${name}_fib		_env=\$${name}_env \
 	    _prepend=\$${name}_prepend	_login_class=\${${name}_login_class:-daemon} \
-	    _limits=\$${name}_limits    _oomprotect=\$${name}_oomprotect
+	    _limits=\$${name}_limits    _oomprotect=\$${name}_oomprotect \
+	    _env_file=\$${name}_env_file
+
+	if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then	# load env from file
+		set -a
+		. $_env_file
+		set +a
+	fi
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805251936.w4PJaQIf093393>