Skip to content

Commit

Permalink
use env, a posix command
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Mar 29, 2024
1 parent 4ebd040 commit bc8af89
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions cloudinit/sources/DataSourceOpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,11 @@ def parse_shell_config(content, asuser=None):
)
)

def varprinter(vlist):
# output '\0'.join(['_start_', key=value NULL for vars in vlist]
return "\n".join(
(
'printf "%s\\0" _start_',
"for __v in %s; do" % " ".join(vlist),
' printf "%s=%s\\0" "$__v" "${!__v}";',
"done",
"",
)
)

# the rendered 'bcmd' is bash syntax that does
# setup: declare variables we use (so they show up in 'all')
# varprinter(allvars): print all variables known at beginning
# env: print all variables known at beginning
# content: execute the provided content
# varprinter(keylist): print all variables known after content
# env: print all variables known after content
#
# output is then a null terminated array of:
# literal '_start_'
Expand All @@ -347,10 +335,10 @@ def varprinter(vlist):
bcmd = (
"unset IFS\n"
+ setup
+ varprinter(allvars)
+ "env\n"
+ "{\n%s\n\n:\n} > /dev/null\n" % content
+ "unset IFS\n"
+ varprinter(keylist)
+ "env\n"
+ "\n"
)

Expand Down

0 comments on commit bc8af89

Please sign in to comment.