cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #04987
Re: [Merge] ~smoser/cloud-init:fix/1775371-non-utf8-in-proc-env into cloud-init:master
Diff comments:
> diff --git a/cloudinit/util.py b/cloudinit/util.py
> index d9b61cf..441d5f7 100644
> --- a/cloudinit/util.py
> +++ b/cloudinit/util.py
> @@ -2080,24 +2080,33 @@ def is_container():
> return False
>
>
> -def get_proc_env(pid):
> +def get_proc_env(pid, encoding='utf-8', errors='replace'):
> """
> Return the environment in a dict that a given process id was started with.
> - """
>
> - env = {}
> - fn = os.path.join("/proc/", str(pid), "environ")
> + @param encoding: if true, then decoding will be done with
> + .decode(encoding, errors) and text will be returned.
> + if false then binary will be returned.
> + @param errors: only used if encoding is true."""
> + fn = os.path.join("/proc", str(pid), "environ")
> +
> try:
> - contents = load_file(fn)
> - toks = contents.split("\x00")
> - for tok in toks:
> - if tok == "":
> - continue
> - (name, val) = tok.split("=", 1)
> - if name:
> - env[name] = val
> + contents = load_file(fn, decode=False)
> except (IOError, OSError):
This is handling file not found? Do we care to report this or is swallowing OK ?
> - pass
> + return {}
> +
> + env = {}
> + null, equal = (b"\x00", b"=")
> + if encoding:
> + null, equal = ("\x00", "=")
> + contents = contents.decode(encoding, errors)
> +
> + for tok in contents.split(null):
> + if not tok:
> + continue
> + (name, val) = tok.split(equal, 1)
> + if name:
> + env[name] = val
> return env
>
>
--
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/347698
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:fix/1775371-non-utf8-in-proc-env into cloud-init:master.
References