- Notifications
You must be signed in to change notification settings - Fork5.2k
Add Environment.ProcessPath#42768
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Dotnet-GitSync-Bot commentedSep 26, 2020
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost commentedSep 26, 2020
Tagging subscribers to this area:@eiriktsarpalis,@jeffhandley |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
stephentoub left a comment
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.
Is this usable most placesProcess.GetCurrentProcess().MainModule.FileName; is currently used? If yes, can we add an analyzer for that? Looking at source.dot.net, that pattern is quite common.
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessPath.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
jkotas commentedSep 26, 2020
Yes, it should be.
Sounds good to me. Is the best way to do it to copy&paste UseEnvironmentProcessId analyzer and fix up the few places in it? It feels like a lot of code duplication to me, but it seems to be the common pattern in the analyzer repo. |
stephentoub commentedSep 26, 2020
It's ok for a single analyzer/fixer to support multiple diagnostic IDs. Given that both of these are detecting patterns on Process usage and recommending Environment usage instead, I think it would make sense for the same code to handle both (assuming there is indeed a lot of overlap), albeit triggering different diagnostic IDs.@mavasani can provide alternative guidance if he thinks another approach is better. |
mavasani commentedSep 26, 2020
|
jkotas commentedSep 27, 2020
@CoffeeFlux Do you have any thoughts on the invariants that this API should maintain and how to implement it? |
src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
CoffeeFlux commentedSep 28, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Various thoughts on issues raised above: We should definitely be calling Returning null for wasm also seems straightforward, though of some note here is that this only holds true for browser and not necessarily standalone wasm runtimes, should we ever want to support those.
This one seems like a no-brainer to me. The returned value should not change over the course of program execution, so it should return the original executable path. I don't see any value in keeping it up to date with filesystem or cwd changes. The easiest way to implement this is to cache the value after the first call, and we should do that. The other questions are more interesting.
I personally think it should return something that isn't cwd-sensitive if at all possible, to the point that I'd consider checking args[0] before using cwd-sensitive detection. It might be hard to 100% guarantee this though, so I would consider it best-effort.
Once again, returning the original executable seems desirable if possible, and I think this is also the simplest implementation for Windows, OSX, and Linux? I once again lean towards saying this is best-effort rather than a 100% guarantee. If we decide we want to make that a hard guarantee, I don't see any good alternative to putting it in the runtime and fetching it once during startup. Again, I personally don't think we have to absolutely guarantee that, but if we want to this is the only real option. Another complication is Android, which does not have an 'executable' in the traditional sense when launching apps normally; everything forks from Zygote and loads the relevant APK. This means Another consideration for This isn't an issue when trying to open it, because |
jkotas commentedSep 28, 2020
Do you mean
Agree. I should have said browser, the implementation file is
Agree. This API is intentionally policy free and returns the executable name from the OS point of view. There is a second API proposal (#41341) to return the "directory that user wanted" that is computed via some to be determined policy.
So what I am hearing:
Sounds reasonable? I can behind this. |
CoffeeFlux commentedSep 28, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry, what I meant with the glib and musl comment is whether either of them is aware this can happen and handles it inside |
am11 commentedSep 28, 2020
Agreed, it could work with cache as well. So if we do not get the perfect (real and absolute) path on some platform in some edge-case scenario against the first call, we could still cache the value and use it for the lifetime of application (best effort was made just once in lifetime of app). |
src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
jkotas commentedSep 29, 2020
@am11 This should be ready for review if you would like to take a look. |
CoffeeFlux commentedSep 30, 2020
Will go through it tomorrow. |
am11 left a comment
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.
Thanks@jkotas for this API. I have tested the changes on illumos. I think it is quite fair to return null for non-absolute or other forms of unresolved cases as done here, instead of prepending cwd in fallback path (which is not clear how to even reproduce with .NET hosting). 👍
jkotas commentedSep 30, 2020
|
stephentoub left a comment
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.
Thanks
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessPath.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…tProcessPath.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
CoffeeFlux left a comment
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.
Mostly just some random nits. LGTM, thanks!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| #else | ||
| #ifdef__linux__ | ||
| #definesymlinkEntrypointExecutable "/proc/self/exe" |
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.
Nit: I think a normal variable is more appropriate here than a mid-function define, unless there's a good reason for this to be using the preprocessor that I'm missing. Codegen should be identical.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
jkotas commentedOct 1, 2020
Opened#42948 on the analyzer. Thank you all for the discussion about the design and codereview feedback. |
Fixes#40862