-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cmd.run on MacOS (rebased) #54136
Merged
dwoz
merged 4 commits into
saltstack:2019.2.1
from
ScoreUnder:2019.2.1-patch-macos-cmd.run
Aug 8, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ab8b39c
Fix environment in cmd.run runas on MacOS
ScoreUnder da38993
Add integration tests for cwd/runas changes on MacOS
ScoreUnder 733d2e7
Fixes to ITs
ScoreUnder 1182eb9
Add integration test justifying strange use of braces after cd in cmd…
ScoreUnder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take into account that the user default shell can be different than
/bin/bash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be worked around by looking at
__salt__['user.info'](runas)['shell']
,though we may then run into a problem if we are trying to run a command as a user with(actually I think this has always been a problem for this module on macos)/usr/bin/false
or/sbin/nologin
as their shell, or if they have a shell likefish
which accepts a different syntax.For the record, my main goal in using
bash -l
is to get the environment into a better state than the onesu -l
leaves it in (which doesn't have /usr/local/bin in the path, for example), so I still consider this a fair improvement over the previous behaviour.Would it be best to launch the command under bash/zsh depending on macos version, or under the user's default shell when it is not /bin/sh, or maybe is there a third option I haven't thought of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps that mystery third option is to use zsh when the shell is zsh, and bash otherwise...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like
zsh
is working well just withsu -l
as you can see in my example above where thePATH
is properly set and all my environment variables from.zshenv
are available.So maybe it is only necessary to check wether the user's default shell is
bash
and only if it isbash
then add that line.Also, an improvement for that line is to call the right bash executable since it could be
/usr/local/bin/bash