Ruby: internal/process.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

process.h
Go to the documentation of this file.
1#ifndef INTERNAL_PROCESS_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_PROCESS_H
12#include "ruby/internal/config.h" /* for rb_pid_t */
13#include <stddef.h> /* for size_t */
14
15#ifdef HAVE_SYS_TYPES_H
16# include <sys/types.h> /* for mode_t */
17#endif
18
19#ifdef _WIN32
20# include "ruby/win32.h" /* for mode_t */
21#endif
22
23#include "ruby/ruby.h" /* for VALUE */
24#include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */
25#include "internal/warnings.h" /* for COMPILER_WARNING_PUSH */
26
27#define RB_MAX_GROUPS (65536)
28
29struct waitpid_state;
30 struct rb_execarg {
31 union {
32 struct {
33 VALUE shell_script;
34 } sh;
35 struct {
36 VALUE command_name;
37 VALUE command_abspath; /* full path string or nil */
38 VALUE argv_str;
39 VALUE argv_buf;
40 } cmd;
41 } invoke;
42 VALUE redirect_fds;
43 VALUE envp_str;
44 VALUE envp_buf;
45 VALUE dup2_tmpbuf;
46 unsigned use_shell : 1;
47 unsigned pgroup_given : 1;
48 unsigned umask_given : 1;
49 unsigned unsetenv_others_given : 1;
50 unsigned unsetenv_others_do : 1;
51 unsigned close_others_given : 1;
52 unsigned close_others_do : 1;
53 unsigned chdir_given : 1;
54 unsigned new_pgroup_given : 1;
55 unsigned new_pgroup_flag : 1;
56 unsigned uid_given : 1;
57 unsigned gid_given : 1;
58 unsigned exception : 1;
59 unsigned exception_given : 1;
60 struct waitpid_state *waitpid_state; /* for async process management */
61 rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
62 VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
63 mode_t umask_mask;
64 rb_uid_t uid;
65 rb_gid_t gid;
66 int close_others_maxhint;
67 VALUE fd_dup2;
68 VALUE fd_close;
69 VALUE fd_open;
70 VALUE fd_dup2_child;
71 VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
72 VALUE path_env;
73 VALUE chdir_dir;
74};
75
76/* process.c */
77rb_pid_t rb_fork_ruby(int *status);
78void rb_last_status_clear(void);
79static inline char **ARGVSTR2ARGV(VALUE argv_str);
80static inline size_t ARGVSTR2ARGC(VALUE argv_str);
81
82#ifdef HAVE_PWD_H
83 VALUE rb_getlogin(void);
84 VALUE rb_getpwdirnam_for_login(VALUE login); /* read as: "get pwd db home dir by username for login" */
85 VALUE rb_getpwdiruid(void); /* read as: "get pwd db home dir for getuid()" */
86#endif
87
88RUBY_SYMBOL_EXPORT_BEGIN
89/* process.c (export) */
90int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
91rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen);
92 VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt);
93struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
94int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
95void rb_execarg_parent_start(VALUE execarg_obj);
96void rb_execarg_parent_end(VALUE execarg_obj);
97int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
98 VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
99void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
100RUBY_SYMBOL_EXPORT_END
101
102/* argv_str contains extra two elements.
103 * The beginning one is for /bin/sh used by exec_with_sh.
104 * The last one for terminating NULL used by execve.
105 * See rb_exec_fillarg() in process.c. */
106static inline char **
107ARGVSTR2ARGV(VALUE argv_str)
108{
109 char **buf = RB_IMEMO_TMPBUF_PTR(argv_str);
110 return &buf[1];
111}
112
113static inline size_t
114ARGVSTR2ARGC(VALUE argv_str)
115{
116 size_t i = 0;
117 char *const *p = ARGVSTR2ARGV(argv_str);
118 while (p[i++])
119 ;
120 return i - 1;
121}
122
123#ifdef HAVE_WORKING_FORK
124 COMPILER_WARNING_PUSH
125#if __has_warning("-Wdeprecated-declarations") || RBIMPL_COMPILER_IS(GCC)
126 COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
127#endif
128static inline rb_pid_t
129rb_fork(void)
130{
131 return fork();
132}
133 COMPILER_WARNING_POP
134#endif
135
136#endif /* INTERNAL_PROCESS_H */
imemo.h
IMEMO: Internal memo object.
config.h
Thin wrapper to ruby/config.h.
rb_execarg_get
struct rb_execarg * rb_execarg_get(VALUE execarg_obj)
Definition: process.c:2837
rb_execarg_parent_end
void rb_execarg_parent_end(VALUE execarg_obj)
Definition: process.c:3082
rb_fork_ruby
rb_pid_t rb_fork_ruby(int *status)
rb_last_status_clear
void rb_last_status_clear(void)
Definition: process.c:666
rb_execarg_setenv
void rb_execarg_setenv(VALUE execarg_obj, VALUE env)
Definition: process.c:2875
rb_execarg_extract_options
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
Definition: process.c:2506
rb_exec_async_signal_safe
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen)
Definition: process.c:3751
rb_execarg_new
VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt)
Definition: process.c:2862
rb_execarg_parent_start
void rb_execarg_parent_start(VALUE execarg_obj)
Definition: process.c:3043
rb_execarg_addopt
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
Definition: process.c:2240
rb_execarg_run_options
int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char *errmsg, size_t errmsg_buflen)
Definition: process.c:3622
rb_fork_async_signal_safe
rb_pid_t rb_fork_async_signal_safe(int *status, int(*chfunc)(void *, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen)
buf
voidpf void * buf
Definition: ioapi.h:138
key
key
Definition: openssl_missing.h:185
ruby.h
argc
int argc
Definition: ruby.c:240
argv
char ** argv
Definition: ruby.c:241
rb_execarg
Definition: process.h:30
rb_execarg::close_others_do
unsigned close_others_do
Definition: process.h:52
rb_execarg::sh
struct rb_execarg::@113::@114 sh
rb_execarg::umask_mask
mode_t umask_mask
Definition: process.h:63
rb_execarg::pgroup_given
unsigned pgroup_given
Definition: process.h:47
rb_execarg::gid
rb_gid_t gid
Definition: process.h:65
rb_execarg::envp_buf
VALUE envp_buf
Definition: process.h:44
rb_execarg::dup2_tmpbuf
VALUE dup2_tmpbuf
Definition: process.h:45
rb_execarg::command_abspath
VALUE command_abspath
Definition: process.h:37
rb_execarg::redirect_fds
VALUE redirect_fds
Definition: process.h:42
rb_execarg::uid
rb_uid_t uid
Definition: process.h:64
rb_execarg::argv_buf
VALUE argv_buf
Definition: process.h:39
rb_execarg::unsetenv_others_given
unsigned unsetenv_others_given
Definition: process.h:49
rb_execarg::command_name
VALUE command_name
Definition: process.h:36
rb_execarg::use_shell
unsigned use_shell
Definition: process.h:46
rb_execarg::new_pgroup_given
unsigned new_pgroup_given
Definition: process.h:54
rb_execarg::chdir_given
unsigned chdir_given
Definition: process.h:53
rb_execarg::fd_open
VALUE fd_open
Definition: process.h:69
rb_execarg::rlimit_limits
VALUE rlimit_limits
Definition: process.h:62
rb_execarg::close_others_maxhint
int close_others_maxhint
Definition: process.h:66
rb_execarg::waitpid_state
struct waitpid_state * waitpid_state
Definition: process.h:60
rb_execarg::fd_close
VALUE fd_close
Definition: process.h:68
rb_execarg::fd_dup2
VALUE fd_dup2
Definition: process.h:67
rb_execarg::envp_str
VALUE envp_str
Definition: process.h:43
rb_execarg::new_pgroup_flag
unsigned new_pgroup_flag
Definition: process.h:55
rb_execarg::gid_given
unsigned gid_given
Definition: process.h:57
rb_execarg::shell_script
VALUE shell_script
Definition: process.h:33
rb_execarg::cmd
struct rb_execarg::@113::@115 cmd
rb_execarg::uid_given
unsigned uid_given
Definition: process.h:56
rb_execarg::env_modification
VALUE env_modification
Definition: process.h:71
rb_execarg::umask_given
unsigned umask_given
Definition: process.h:48
rb_execarg::argv_str
VALUE argv_str
Definition: process.h:38
rb_execarg::path_env
VALUE path_env
Definition: process.h:72
rb_execarg::fd_dup2_child
VALUE fd_dup2_child
Definition: process.h:70
rb_execarg::chdir_dir
VALUE chdir_dir
Definition: process.h:73
rb_execarg::exception_given
unsigned exception_given
Definition: process.h:58
rb_execarg::unsetenv_others_do
unsigned unsetenv_others_do
Definition: process.h:50
rb_execarg::close_others_given
unsigned close_others_given
Definition: process.h:51
rb_execarg::invoke
union rb_execarg::@113 invoke
rb_execarg::pgroup_pgid
rb_pid_t pgroup_pgid
Definition: process.h:61
waitpid_state
Definition: process.c:1070
waitpid_state::status
int status
Definition: process.c:1076
VALUE
unsigned long VALUE
Definition: value.h:38
warnings.h
Internal header to suppres / mandate warnings.
COMPILER_WARNING_PUSH
#define COMPILER_WARNING_PUSH
Definition: warnings.h:13
COMPILER_WARNING_POP
#define COMPILER_WARNING_POP
Definition: warnings.h:14
COMPILER_WARNING_IGNORED
#define COMPILER_WARNING_IGNORED(flag)
Definition: warnings.h:16
env
#define env
win32.h
mode_t
#define mode_t
Definition: win32.h:119