-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
std.child_process: enable using non-standard pipes #11701
Conversation
fa27d15
to
79a7afb
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Andrew: "Libc is to be entirely avoided on Windows" Thus: Use Reminder for me to implement eventually |
This comment was marked as resolved.
This comment was marked as resolved.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful.
reason: works differently on windows and Linux
I would like to have some feedback from @marler8997 or another person that did more stuff with IPC on better benchmarks or to have some insight in use cases for So far I have this https://gist.github.com/matu3ba/c643b26b5e18a2aff20ef75468aa088d with a minimal printing hello world as child process and no user-defined function what to do in the parent right before On Arch Linux I get round about these values, if repeated sufficiently often
With the changes applies (null inserted into spawn function):
|
@@ -127,25 +163,33 @@ pub const ChildProcess = struct { | |||
self.gid = user_info.gid; | |||
} | |||
|
|||
const ExPipeInfoProto = switch (builtin.zig_backend) { |
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.
I don't think this is a great type name
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.
What about ExtraPipeProto
? How would you call writing the pipe information to the child process?
self.stderr = File{ .handle = stderr_pipe[0] }; | ||
} else { | ||
self.stderr = null; | ||
// user must communicate extra pipes to child process either via |
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.
Or just convention. e.g. SD_LISTEN_FDS_START
is compile-time known to be 3
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.
I may understand it wrong, what you are suggesting. As I understand it, you want to hardcode the file descriptor numbers.
Doing this for file descriptors other than 0,1,2 is error prone, even if we can assume that 3
is the next free one for the current process.
Take as example that the user has as additional requirement to open a file before using 3
or does other stuff, which uses file descriptors. Now 3
might be taken and the user introduced an error.
Another example, which is more of the worst case to debug: Another process uses file descriptor 3 already to do IPC with the one that now wants to spawn a child process and uses file descriptor 3 to do IPC.
I have attempted to rebase this against master branch on your behalf in order to re-run the failing CI checks. However there are conflicts. If you would like to continue working on this, please open a new PR against master branch. |
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
The user provides an array of struct with info for direction for the pipe.
Each struct also contains the space for the input and output end of pipe,
which simplifies handling.
Typically a low number of non-standard pipes are used, so no premature optimization
and complicating the usage.
Also, it is expected that the upper bound of used pipes per process is comptime-known,
so slicing a continuous chunk would be most efficient.
on Linux and file handles on Windows in the child process
work in all cases.
subsequently created children
Note: Standard streams are expected to be inheritable by child processes, so those
streams are "intentionally leaked to the child".
Benchmarking with realistic workloads is needed to decide the final design.
Especially, since storing space for one additionally unused pipe end can be wasteful.