fix(init): wait for elevated init child on Windows#259
Merged
Conversation
Replace fire-and-forget ShellExecute("runas") with ShellExecuteEx
(SEE_MASK_NOCLOSEPROCESS), wait on the returned process handle, and
propagate the child's result to the parent. Also forward the original
command-line args (e.g. --user, --yes) to the elevated child instead of
hardcoding "init", and re-verify System PATH state after the wait so a
silent child failure can't be reported as success.
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.
Summary
Fix the Windows auto-elevation flow in
dtvem initso it doesn't falselyreport success when the elevated child didn't actually apply the PATH change.
ShellExecute("runas", ...)(fire-and-forget) withShellExecuteExusingSEE_MASK_NOCLOSEPROCESS, thenWaitForSingleObject+GetExitCodeProcessso the parent can propagatethe elevated child's result.
os.Args[1:](e.g.--user,-y,--verbose)to the elevated child instead of hardcoding
init. Env vars likeDTVEM_VERBOSEare inherited automatically byShellExecuteEx.ERROR_CANCELLED/ 1223) and surface a clear error.child-side failure (the
initcommand currentlyreturns on errorwithout
os.Exit(1)) still produces a parent-side error.Resolves #252
Test plan
dtvem initfrom a non-admin PowerShell; accept theUAC prompt; verify the original session reports success and that
~/.dtvem/shimsactually lands at the front of the System PATH.dtvem initfrom a non-admin PowerShell and deny the UACprompt; verify the parent surfaces a "UAC prompt canceled" error
rather than printing "dtvem initialized successfully!".
dtvem init --userfrom a non-admin PowerShell; verify theelevation path is not taken (User PATH branch) and behavior is
unchanged.
dtvem initfrom an already-elevated PowerShell; verify itstill modifies System PATH directly without re-launching itself.
./rnr check(format, lint, all tests) passes locally.