Skip to content
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

run_program() fixes #2748

Merged
merged 4 commits into from
Mar 17, 2019
Merged

run_program() fixes #2748

merged 4 commits into from
Mar 17, 2019

Conversation

JuhaSointusalo
Copy link
Contributor

lib: change run_program() to use file parameter as program name on Windows
mgr,scr: fix argvs in calls to run_program()
client: remove quoting client path in launching GPU detection

See commit messages for details.

Fixes launching graphics apps with Manager and screensaver as reported on boinc_alpha.

argv is supposed to be Unix-style and in Unix-style argv[0] is program
name. Let's try to have it that way.
argv is supposed to be Unix-style and in Unix-style argv[0] is program
name. Let's try to have it that way.

Also clean up a comment that is not relevant to Windows code path.
On Windows, run_program() uses argv[0] as program name. argv is
Unix-style and POSIX says argv[0] should be just filename without path.
If someone sets argv[0] to only filename instead of full path then
run_program() may fail to launch the program.

Since the file parameter should have full path to the program use that
as program name when constructing the command line. The launched program
may see different argv[0] than programmer wanted but this way
run_program() can search %PATH% for the program should that be
necessary.
Client path was quoted because on Windows run_program() concatenates
arguments to a single string. Without quoting any path with a space
would cause problems interpreting the command line.

What run_program() does with its parameters is really an implementation
detail of it and users of run_program() shouldn't need to know or care
about it.

Moving quoting into run_program() also removes the need to duplicate
quoting everywhere run_program() is used.

The program name or path to it needs to be valid filesystem name and
it's always the first in argv so quoting it in run_program() is trivial.
run_program() doesn't know which other arguments may contain paths and
quoting arbitrary arguments is harder so keep quoted_data_dir for now.
@AenBleidd
Copy link
Member

This PR fixes #2657
@JuhaSointusalo, correct me if I wrong

@RichardHaselgrove
Copy link
Contributor

@AenBleidd

This PR fixes #2657

I think that's a little premature. @JuhaSointusalo specifically referenced a quite separate conversation on boinc_alpha about screensavers and graphics apps. Let's leave #2657 open again (good idea to re-open it) until we're all sure we're all on the same page.

@JuhaSointusalo
Copy link
Contributor Author

This PR fixes #2657

More like #2713.

@AenBleidd
Copy link
Member

@JuhaSointusalo, Is this ready for review?
If yes - @davidpanderson, @TheAspens, could you please assist?

@JuhaSointusalo
Copy link
Contributor Author

JuhaSointusalo commented Nov 9, 2018 via email

@AenBleidd
Copy link
Member

@davidpanderson, @TheAspens, could you please review this?

@AenBleidd
Copy link
Member

Just a kind reminder, @davidpanderson, @TheAspens

@CharlieFenton
Copy link
Contributor

If I am remembering correctly, this PR should not be merged but should just be closed. I believe this issue was fixed of by PR #2713 which was merged on Sep 26, 2018. Likewise, I believe PR #2657 should be closed without merging.

@AenBleidd
Copy link
Member

@CharlieFenton, could you please double check? I believe this particular PR fixes the issue presented in #2713 and have better implementation than #2657. Thanks

@TheAspens TheAspens removed their request for review March 14, 2019 16:38
@TheAspens
Copy link
Member

I have removed myself as a reviewer as this is an area that I do have expertise in. However, should we have a meeting to discuss the differences between this pull request and #2742 ?

@TheAspens
Copy link
Member

If we should have a meeting on this, and all the related pull requests, who all needs to be there? @davidpanderson , @JuhaSointusalo as the key developers - who else?

@RichardHaselgrove
Copy link
Contributor

I have been involved with this issue since it first appeared here as #2029. I did record in #2713 that I had tested a Windows build from that code, and that it successfully addressed all the issues I was aware of.

I'm happy to perform similar tests on the alternative formulation, or to join a meeting, if required, but for the time being I think we're OK

@CharlieFenton
Copy link
Contributor

CharlieFenton commented Mar 15, 2019

@AenBleidd Sorry, I now did a quick review of the commits in #2713 and see that they are independent of the changes in this PR. So I withdraw my objection. However, I have neither the time nor the inclination to wend my way through this long convoluted string of PRs. I believe that we agree that PR #2657 should be closed without merging; as far as I can see there were no commits in that PR.

I defer to @JuhaSointusalo and others to decide what should be done.

@davidpanderson
Copy link
Contributor

What problem does this PR fix, and how?

@JuhaSointusalo
Copy link
Contributor Author

Quick recap. There was a problem with GPU detection when client was started without using path to it but searched from %PATH% (plus some other conditions that don't matter to this discussion). For GPU detection another copy of client is started with run_program(). Here's what the function signature was originally:

int run_program(const char* dir, const char* file, int argc, char *const argv[], double nsecs, HANDLE& id)

argv[] is Unix exec*()style list of arguments where argv[0] is program name. As an implementation detail, the function didn't actually require argv[0] to be anything useful and instead used file for launching the program.

In #2713 I changed the function to use argv[0] as program name and ignore file on Windows. This was done so that the function could search %PATH% for the program. I carefully tested the code and found that it works correctly for GPU detection. What I neglected to was test the entire BOINC codebase.

Turns out the code that launches graphics apps and screensavers exploited the previously mentioned implementation detail and passed in rubbish argv[0]. That with my changes broke launching graphics apps and screensavers. My bad for not checking the other users of run_program().

That's the history part. On to this PR.

Passing in rubbish parameters just because you can get away with it today is plain and simply bad programming so this PR fixes the other users of run_program(). This PR also changes run_program() to use file instead of argv[0] as program name on Windows. POSIX says argv[0] should be the program name only without path so any code that actually does things according to POSIX wouldn't have worked with the changes I originally did. The last change is to not quote path in the code that launches GPU detection. How run_program() needs to quote paths is again an implementation detail that the function's callers should not need to know or care about.

Since there was a request to compare this PR and #2742. #2742 was opened because David didn't understand the changes I did, didn't read the commit messages, didn't bother ask me to explain the changes and instead though it would be a good idea to revert the changes I had intentionally done. This PR lets run_program() search %PATH%, #2742 doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants