-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add some checks to restoreOrgVars
on startGame
#1161
Add some checks to restoreOrgVars
on startGame
#1161
Conversation
Sorry it took me so long to get around to taking a look at this! I think I see the solution here, essentially check for some known variables that Steam will override, and if they're defined in either the Global or Per-Game Custom Environment Variables config file, don't overwrite them. The issue in #1158 was then, based on the comment in that issue, not actually caused by Steam but by some funky SteamTinkerLaunch behaviour, which this prevents. I think calling your solution "ugly" is a stretch 😅 It makes sense, although I think we can improve it a little bit. We could make an array with these variables and loop through them, something like Then we can loop through with something like this, where we can dynamically build the variable name to assign to using Basically using if [ "$1" != "startGame" ]; then
# Return early if not startGame, I think this is safe to do as nothing else in the function should run if $1 != startGame
# This should also simplify the condition in the loop
return
fi
# STLRESTOREVARS could be a potential name, but open to better suggestions
STLRESTOREVARS=( "LD_PRELOAD" "LD_LIBRARY_PATH" "LC_ALL" "PATH" )
for RESTOREVAR in "${STLRESTOREVARS[@]}"; do
# e.g. 'ORG_LD_PRELOAD' for 'LD_PRELOAD' on first iteration of the loop
BUILTORGVARNAME="\$ORG_${RESTOREVAR}"
# I think we can use grep like this? I think sed is fussy about using variables, not sure about grep!
if grep -q "^${RESTOREVAR}" "$GLOBCUSTVARS" || grep -q "^${RESTOREVAR}" "$GAMECUSTVARS"; then
# Since `eval` extracts the value and runs the command, the part inside the quotes comes out to e.g. 'LC_ALL="$ORG_LC_ALL"'
# The dollarsign comes from the '\$' earlier, it's also possible to add it here but I would prefer to build it all in BUILTORGVARNAME
#
# Since this runs as a command, this is equivalent to typing in a Bash prompt 'LC_ALL=$ORG_LC_ALL'
# Everything in the quotes is a string that gets built as a command to run, and 'eval' then runs it
#
# It's all a bit weird, I hope that makes sense. I also only tested this with some test code in a Bash prompt, so it may need some more refining
eval "${RESTOREVAR}=\"${BUILTORGVARNAME}\""
fi
done Something like the above should be a bit more concise and allow us to more easily extend this if there are other variables to include, or if we ever want to make this list user-facing. As well as this, in the loop we should make the log a big more explicit that these are not being overridden and that, in some cases, this could be problematic. Any user overriding these should ideally know what they are doing and should be doing it for good reason (locale could be overwritten for testing purposes, for example). Apart from the above potential improvement, I think this approach is fine, provided it doesn't cause any regressions for cases where the user doesn't override these. In other words, things should continue as normal if this is not defined in any of the custom environment variable files, but if they are defined, your issue in #1158 should be resolved :-) If you can give some explicit testing steps I would also be happy to test this out, just to make sure we're on the same page. Thanks a lot for your work and patience here to figure this out! |
Don't apologise for taking some time to review things. It's a hobby project, you likely have better things to do and stressing over replying here will probably lead to burn out :) My fix was ugly it was just a throw-my-hands-up-and-get-something-that-works-and-go-cry fix. What's funny is I asked my g/f how she'd fix it (she's a better coder than me) and she said she'd build an array and check against it 😅 Probably not quite the same as what you came up with, but still. Just to address something: I specifically put in a check for However,
So instead of Alternatively we don't have an I may lean towards no As for a way to test you can simply try |
Heh, I like that expression. 😄 And well, it is still an array, we just dynamically assign them. In other languages you could probably use a hash/dictionary or something similar, but in Bash we can make do with this :-) You raise some good points here about when we should and should not use this logic. I think in most cases a user is going to expect what they define in their custom environment variables file to carry over, the benefit of this PR is to allow those variables to survive and to not have SteamTinkerLaunch override them.
First, I guess the 8 calls are for different code paths? Or is this called 8 times consectutively when starting a custom program? If so, it's not something for this PR but yikes... I'll need to investigate that! Apart from that, I would agree that custom environment variables should be passed to custom commands and that this logic should apply for them as well. If a user runs into problems here, there is a warning log that the values aren't being restored because they're already defined in the custom environments variable file.
I agree with you here as well.
This is a tricky one for sure. And there have historically been cases where Winetricks has benefitted from overriding, for example, locale. On the other hand this could cause unexpected behaviour with Winetricks that is actually needed for a game. I think for now we should keep still allow the current behaviour of this PR to apply to Winetricks, where variables won't get restored if they're defined in the custom environment variables file. This means a user can apply those overrides if they need to.
I am leaning towards this as well, based on the above. I think updating the wiki to document this will help too. Honestly, I don't think many people read the wiki (a couple people complained before when I mentioned the wiki) but still, I think making a note of this is useful. I also refer to the wiki as well if I'm ever looking at code and wondering the use-case. I think having no conditional check for what is calling I am with you on users that do this must have a good reason. This is something users probably aren't going to do lightly, and I think it is valuable to override these. The more I consider it the more I agree that SteamTinkerLaunch not doing this is already a bug, as I would have also expected the override to work. Although SteamTinkerLauch probably didn't do it before because we want to restore those original variables since we might modify them (in particular, PATH on SteamOS we probably modify (not on disk, just the environment variable)).
I will give it a try ASAP, does it work on your end out of interest? The code looks good to me, if testing goes well I don't have any comments on the code itself. I'm glad you were able to implement it from my horrid explanation heh. ShellCheck is grumpy because now it thinks the If you could also add a comment in Thanks again for your work on this! Provided it works in my own testing (which from looking at the code I expect it should), I have no trouble merging this. Resolving the ShellCheck complaints would be great but it won't block merging. |
Tested this PR, works as expected with Once the ShellCheck warnings are addressed, and a |
Needs a rebase because of the version bumps in the commits made since this PR was opened. I can do the rebasing if you want, or feel free to do it when adding the ShellCheck directives. 🙂 |
Tweak the WARN message in `restoreOrgVars` Remove unnecessary comment from `gameStart` Kate also decided to clean up some whitespace
c08cdd3
to
22a1f46
Compare
Basically from https://github.com/sonic2kk/steamtinkerlaunch/blob/master/steamtinkerlaunch#L7247 onwards there are a load of if blocks that all Changes done. Hopefully right 🤞 |
The new changes address the comments above, thanks for bumping the version as well! This can be merged. |
Thanks again for the work on your recent PRs! It's still a part of being a "maintainer" that I'm getting used to, I really appreciate you working with me :-) |
My tentative and ugly attempt at fixing #1158
Simply when we're in
startGame
check the relevant custom-vars to see if any of the envvars that would normally be reset to original values are defined, and just don't reset them.Probably needs more testing to be safe, but so far so good.
I wasted so much time on this 😿