Set PATHEXT for job containers to handle binaries with no extension#1174
Merged
dcantah merged 1 commit intomicrosoft:masterfrom Sep 24, 2021
Merged
Conversation
This change sets the PATHEXT environment variable which Go checks during exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon separated list of extensions to check against if a path ended without one (e.g. /path/to/my/binary). This simply adds an empty string entry to the end so that binaries with no extension can be launched correctly. Although this isn't a common occurrence it's still a good thing to support. Windows Server containers are able to handle this fine, and CreateProcess is perfectly happy launching a valid executable without an extension. This is mainly to support the agnhost image which is a common k8s testing image whose entrypoint is a binary named agnhost with no extension. https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows Signed-off-by: Daniel Canter <dcanter@microsoft.com>
Comment on lines
+220
to
+223
| if err := os.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD; "); err != nil { | ||
| return nil, errors.Wrap(err, "failed to set PATHEXT") | ||
| } | ||
|
|
There was a problem hiding this comment.
Could we add this only to the environment that's passed to the cmd instead of setting it on the running environment?
Contributor
Author
There was a problem hiding this comment.
It's needed to find the process to launch in the first place so nope. Basically exec.Cmd calls exec.LookPath as one of the steps before launching the process and this is what fails as it doesn't treat a file with an extension not in its default set of extensions (and no extension falls in this category) as valid.
Contributor
Author
There was a problem hiding this comment.
So we're adding an empty string entry so it deems this as valid now.
katiewasnothere
approved these changes
Sep 24, 2021
anmaxvl
approved these changes
Sep 24, 2021
anmaxvl
pushed a commit
to anmaxvl/hcsshim
that referenced
this pull request
Nov 17, 2021
Related work items: microsoft#1062, microsoft#1087, microsoft#1089, microsoft#1095, microsoft#1104, microsoft#1112, microsoft#1117, microsoft#1118, microsoft#1125, microsoft#1137, microsoft#1139, microsoft#1140, microsoft#1141, microsoft#1142, microsoft#1143, microsoft#1145, microsoft#1146, microsoft#1150, microsoft#1151, microsoft#1153, microsoft#1154, microsoft#1155, microsoft#1156, microsoft#1157, microsoft#1158, microsoft#1159, microsoft#1161, microsoft#1162, microsoft#1163, microsoft#1164, microsoft#1165, microsoft#1166, microsoft#1167, microsoft#1168, microsoft#1169, microsoft#1171, microsoft#1172, microsoft#1173, microsoft#1174, microsoft#1178
princepereira
pushed a commit
to princepereira/hcsshim
that referenced
this pull request
Aug 29, 2024
…on-fix Set PATHEXT for job containers to handle binaries with no extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 change sets the PATHEXT environment variable which Go checks during
exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon
separated list of extensions to check against if a path ended without one
(e.g. /path/to/my/binary). This simply adds an empty string entry to the end
so that binaries with no extension can be launched correctly. Although this isn't
a common occurrence it's still a good thing to support. Windows Server containers
are able to handle this fine, and CreateProcess is perfectly happy launching
a valid executable without an extension.
This is mainly to support the agnhost image which is a common k8s testing image whose
entrypoint is a binary named agnhost with no extension.
https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows
Signed-off-by: Daniel Canter dcanter@microsoft.com