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

Made it work on OS X. #16

Merged
merged 9 commits into from
Jun 27, 2024
Merged

Made it work on OS X. #16

merged 9 commits into from
Jun 27, 2024

Conversation

dimacurrentai
Copy link
Contributor

Thanks @yarmaksergey, and ref. C5T/Current#1004.

}
return *p;
}
#ifndef C5T_DLIB
C5T_ACTOR_MODEL_Interface& GetSingleton();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enabled by now-merged C5T/Current#1004, before this was silently OK on Linux, but failing on OS X.

@@ -55,8 +55,10 @@ struct C5T_LOGGER_SINGLETON_Interface {
virtual C5T_LOGGER_Interface& operator[](std::string const& log_file_name) = 0;
};

#ifndef C5T_DLIB
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enabled by now-merged C5T/Current#1004, before this was silently OK on Linux, but failing on OS X.

@@ -141,9 +141,9 @@ void C5T_POPEN2(std::vector<std::string> const& cmdline,
return std::thread(
[](std::function<void(const std::string)> cb_line, int read_fd, int terminate_fd) {
struct pollfd fds[2];
fds[0].fd = read_fd;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the tweak works since I now check the termination signal first.

(Strictly speaking, there was no need to flip them in the args to ::poll(), just swapping the if-s would do.)

My best guess is that the true reason this code did not work before on OS X is that once the child process is terminated, ::poll() notifies about its stdout as well.

I did not explore much further, just made sure to give priority to the check that the ::waitpid() has already succeeded.

Tested afresh with https://github.com/dimacurrentai/exec_on_macos/.

@@ -10,34 +10,34 @@

TEST(Popen2Test, Smoke) {
std::string result;
C5T_POPEN2({"/usr/bin/bash", "-c", "echo PASS"}, [&result](std::string const& line) { result = line; });
C5T_POPEN2({"bash", "-c", "echo PASS"}, [&result](std::string const& line) { result = line; });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And the last change was that /usr/bin/bash (which was incorrectly hardcoded) is not available on OS X. I've changed it into /bin/bash first, but then realized that just bash would do fine.

@dimacurrentai
Copy link
Contributor Author

Merging now.

@dkorolev dkorolev merged commit e084d05 into dkorolev:main Jun 27, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants