This repository was archived by the owner on Oct 11, 2023. It is now read-only.
cmd/power: Set correct container name and ensure full command executed #2138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a few issues that are preventing
shutdownand friends frombehaving correctly:
The command name, which is being used to determine via what command it
was being called (ie:
shutdown,reboot, orhalt) was not being parsedfor absolute paths. This was preventing certain logic from being handled
(example: enforcing a static time value of
nowfor shutdown), but moreproblematically was the fact that it was being used as the container
name being passed to
runDocker, the function that launches theindependent shutdown container. This was causing the shutdown container
to fail as something like
/sbin/shutdownis not a valid name for acontainer. The logic to parse out the base command being run is actually
present in
runDocker, but does not run if a name is supplied to thefunction.
Further, the command line was not being parsed in the shutdown
container if the name supplied to
runDockerwas non-empty. Rather, thefull command to run just became the name of the container. Hence,
something like
/sbin/shutdown -h nowbecame justshutdown, executingthe default power off behaviour for all actions (including reboots).
Further to this,
open-vm-toolsexpects/sbin/shutdown -h nowto be avalid command to halt the system, which was not being recognized as the
only recognized short-form halt flag in shutdown was its capital version
(
-H).This fixes these three issues by parsing out the base of the called
command before sending it to reboot, using all of
os.Argvas the commandline to run regardless of if a name was set for the container or not,
and finally adding the lowercase
-hswitch to the "shutdown" form ofthis command ("halt" is still uppercase only).
Fixes #2121.
Fixes #2074.