1
0
mirror of /repos/baseimage-docker.git synced 2025-12-31 08:11:29 +01:00

Trim trailing newlines from file-based envs

Many editors add a trailing newline to files. This can result in
slightly unexpected values for environment variables read from
/etc/container_environment.
This commit is contained in:
Stuart Campbell 2014-04-01 17:57:03 +11:00
parent 8f9eefa1f6
commit 5e2ee3838d

View File

@ -59,7 +59,10 @@ def import_envvars(clear_existing_environment = True):
for envfile in listdir("/etc/container_environment"): for envfile in listdir("/etc/container_environment"):
name = os.path.basename(envfile) name = os.path.basename(envfile)
with open("/etc/container_environment/" + envfile, "r") as f: with open("/etc/container_environment/" + envfile, "r") as f:
value = f.read() # Text files often end with a trailing newline, which we
# don't want to include in the env variable value. See
# https://github.com/phusion/baseimage-docker/pull/49
value = re.sub('\n\Z', '', f.read())
new_env[name] = value new_env[name] = value
if clear_existing_environment: if clear_existing_environment:
os.environ.clear() os.environ.clear()