Skip to content

Commit

Permalink
Incredibly rough POC of a Process.spawn_private method
Browse files Browse the repository at this point in the history
Essentially, we introduce the concept of a waitpid_private_handle, and a
VM-wide table of child PIDs -> such handles.

When spawning a process, it can optionally be bound to such a handle, in
which case that handle/pid combo is inserted into a global table.

Whenever Ruby waits on a child process, if there is an active handle for
that pid, we "steal" the status and stash it against the handle. We
pretend to the caller that there was no child process.

If the handle is used to perform the wait, however, we return the
(possibly previously-saved) status.

Essentially, if you don't have the handle, you can't waitpid the child.
  • Loading branch information
KJTsanaktsidis committed Jan 11, 2023
1 parent 5bf7218 commit 6009c56
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 47 deletions.
3 changes: 3 additions & 0 deletions internal/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ruby/ruby.h" /* for VALUE */
#include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */
#include "internal/warnings.h" /* for COMPILER_WARNING_PUSH */
#include "vm_core.h"

#define RB_MAX_GROUPS (65536)

Expand Down Expand Up @@ -59,6 +60,7 @@ struct rb_execarg {
unsigned exception_given : 1;
struct rb_process_status *status;
struct waitpid_state *waitpid_state; /* for async process management */
struct waitpid_private_handle *waitpid_private_handle;
rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
mode_t umask_mask;
Expand All @@ -76,6 +78,7 @@ struct rb_execarg {

/* process.c */
rb_pid_t rb_call_proc__fork(void);
void waitpid_private_handle_clear_table(rb_vm_t *vm);
void rb_last_status_clear(void);
static inline char **ARGVSTR2ARGV(VALUE argv_str);
static inline size_t ARGVSTR2ARGC(VALUE argv_str);
Expand Down
Loading

0 comments on commit 6009c56

Please sign in to comment.