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

ADDED: extra_streams() option to process_create/3 #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dmchurch
Copy link
Contributor

@dmchurch dmchurch commented Aug 6, 2021

This enables the Unix-style pattern of passing additional file
descriptors to child processes beyond stdin, stdout, and stderr, so that
parent and child can communicate on multiple streams. For example, a
Prolog program could launch a fully-interactive child process, passing
stdin/stdout/stderr connected to the TTY, while reserving a separate
pair of descriptors for programmatic communication with the child.

It also fixes a couple Cmake tooling errors, which prevented Prolog from
ever recognizing the availability of posix_spawn() and pipe2().

dmchurch and others added 3 commits August 6, 2021 18:42
This enables the Unix-style pattern of passing additional file
descriptors to child processes beyond stdin, stdout, and stderr, so that
parent and child can communicate on multiple streams. For example, a
Prolog program could launch a fully-interactive child process, passing
stdin/stdout/stderr connected to the TTY, while reserving a separate
pair of descriptors for programmatic communication with the child.
@JanWielemaker
Copy link
Member

Thanks. Looks useful. I'm not too happy about adding features we cannot support cross-platform (Windows). There are surely some nice use cases for this. Somehow the changes blocked passing the environment though. Try e.g. ?- help(process_create). or process_create(path(printenv), [], [])..

Pushed an additional patch for the PlDoc comments. Code should use `text` if it is Prolog text and using double backquotes for non-Prolog text. Expressions as functor(...) do not need quotes: if they are valid Prolog text they are considered code. The old stuff is still supported. Currently PlDoc accepts mostly current markdown syntax and eventually I'd like to get rid of all the old stuff.

@dmchurch
Copy link
Contributor Author

dmchurch commented Aug 7, 2021

I'm not too happy about adding features we cannot support cross-platform (Windows)

I'm not thrilled about it either. Weirdly, though, it's not a technical limitation but a procedural one. You can absolutely open a stream handle and let the child process inherit it, but there's no way to assign numeric values or ordering to them, which defeats the purpose of passing the descriptors in the first place. If you know of or come up with a good way to meaningfully pass handles from parent to child, I'd be delighted to implement it!

@dmchurch
Copy link
Contributor Author

dmchurch commented Aug 7, 2021

Somehow the changes blocked passing the environment though.

This looks to be an existing issue with the spawn method, which wasn't getting used before because of the configuration bug. I'll look into fixing it; until then work around with process_set_method(fork) or process_set_method(vfork).

Fixes the issue of process_create/3 not passing environment to child
when no environment variables are specified and create mode is spawn,
exposed by fixing the spawn method. Also fixes some fd collision bugs
in the extra_streams() functionality, and introduces unit testing
for all three process creation methods (which found the above).
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