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

Add the ERL_SYS_SHELL env variable to point to system shell for os:cmd() #8972

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

yarisx
Copy link
Contributor

@yarisx yarisx commented Oct 22, 2024

A fix for #8944

Copy link
Contributor

github-actions bot commented Oct 22, 2024

CT Test Results

    2 files     70 suites   1h 5m 58s ⏱️
1 554 tests 1 312 ✅ 242 💤 0 ❌
1 771 runs  1 496 ✅ 275 💤 0 ❌

Results for commit bb27085.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@garazdawi
Copy link
Contributor

Hello! Thanks for the PR!

The variable should be a kernel configuration parameter that is set to the correct value when kernel is started. It also needs to be documented here and a testcase needs to be added to os_SUITE.

@garazdawi garazdawi self-assigned this Oct 22, 2024
@yarisx yarisx force-pushed the ymaslenn/8944_set_sys_shell branch from f3e7b34 to 94dde80 Compare October 23, 2024 08:37
@garazdawi
Copy link
Contributor

Thanks for the update! I've pushed a commit that renames the variable to os_cmd_shell which I think better describes what it does and also moved the shell detection logic to happen when we start instead of everytime we do os:cmd.

Would you mind updating the docs of os:cmd/2 to point to the docs for the configuration parameter so that users know where to find it?

Feel free to squash my commit into yours if you agree with my changes.

@yarisx yarisx force-pushed the ymaslenn/8944_set_sys_shell branch from f71fc7a to 7af29a1 Compare October 24, 2024 10:26
@yarisx
Copy link
Contributor Author

yarisx commented Oct 24, 2024

I'm a bit confused by the test results. As I see one subtest in shell_history_custom_error/1 test failed with the timeout, but a similar subtest passed just fine. Moreover I don't see how this part of the functionality can be affected by my changes, and locally the test passed just fine. Could you give me a hint on what might cause the test to fail?

Copy link
Contributor

@garazdawi garazdawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a race in that testcase that you've had the misfortune of hitting, so you can ignore that.

However, the os:internal_init_os_cmd/1 should not need to be called in all those test suites. The testcase needs to make sure that it resets the state (as you have done). Why did you add them?

Also could you please add a test that uses ?CT_PEER to start a new code where the config parameter is set at startup to see that that works. I don't think os:cmd is used anywhere when booting Erlang so we should be safe.

lib/kernel/src/os.erl Show resolved Hide resolved
lib/kernel/test/os_SUITE.erl Outdated Show resolved Hide resolved
lib/kernel/test/os_SUITE.erl Outdated Show resolved Hide resolved
@yarisx
Copy link
Contributor Author

yarisx commented Oct 25, 2024

I added os:internal_init_os_cmd/1 because locally the tests that contain os:cmd/2 (at least some of them) crashed with badmatch at {ok, Shell} = application:get_env() in os:mk_cmd/2.
I will add the test with ?CT_PEER

@garazdawi
Copy link
Contributor

I added os:internal_init_os_cmd/1 because locally the tests that contain os:cmd/2 (at least some of them) crashed with badmatch at {ok, Shell} = application:get_env() in os:mk_cmd/2.

How odd, can you remove them and see if that happens in github ci as well?

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Oct 28, 2024
@yarisx yarisx force-pushed the ymaslenn/8944_set_sys_shell branch from 9ac158d to 5280771 Compare November 4, 2024 13:01
Copy link
Contributor

@garazdawi garazdawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like all tests are passing. Just two leftover os:internal... that should be removed. Once done I'll put into testing and check that it works on all OSs we test on.

lib/kernel/test/application_SUITE.erl Outdated Show resolved Hide resolved
lib/kernel/test/application_SUITE.erl Outdated Show resolved Hide resolved
@garazdawi garazdawi added the testing currently being tested, tag is used by OTP internal CI label Nov 4, 2024
@yarisx
Copy link
Contributor Author

yarisx commented Nov 4, 2024

Now when I run local tests on the latest commit I again get {badmatch, undefined} for os:mk_cmd(), but not in all testsuites that use os:cmd/2. More so, I get errors in tests that passed here on 5280771 commit, and were not touched since. Looks weird...

@garazdawi garazdawi removed the testing currently being tested, tag is used by OTP internal CI label Nov 4, 2024
@garazdawi
Copy link
Contributor

Yes, I can see the problem in github actions tests as well. I would guess that some testcase in application_SUITE clears the env of kernel for some reason...

@garazdawi
Copy link
Contributor

I found the problem, it was that we did not re-init the variable when kernel:config_change/3 was called.

I pushed a fix for that. I also scratched an itch that was semi-related to this and that was that I don't think we should allow this value to be changeable at run-time. So I moved the value to persistent term so that updating the application parameter in run-time has no effect.

@yarisx
Copy link
Contributor Author

yarisx commented Nov 5, 2024

Now as I see all the tests are passing. Is anything expected from my side? One of our customers is eager for getting the patch in their upcoming release, so if the code change is OK I will apply it to our OTP version while waiting for the formal release.

@garazdawi garazdawi added the testing currently being tested, tag is used by OTP internal CI label Nov 5, 2024
@garazdawi
Copy link
Contributor

I've put it into testing so that we get some more platform coverage (windows, *bsd, solaris etc). If all tests pass I will merge this PR for release in 27.2. So nothing is expected from you unless something fails somewhere where I think you can help out.

yarisx and others added 3 commits November 7, 2024 15:08
… for os:cmd/2

Initialize the parameter at startup

Fix the test - restore the old shell after the test
Add initialization to other tests that use os:cmd/2
Update os:cmd/2 description
This has two purposes:

1. Make it impossible to change the value through the application:set_env API.
2. Make the lookup slightly faster.
@garazdawi garazdawi force-pushed the ymaslenn/8944_set_sys_shell branch from bb27085 to fc4e1de Compare November 7, 2024 14:09
@garazdawi garazdawi merged commit adb8bb0 into erlang:maint Nov 7, 2024
7 checks passed
@garazdawi garazdawi added this to the OTP-27.2 milestone Nov 7, 2024
@garazdawi
Copy link
Contributor

Merged for release in 27.2. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants