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;
30struct rb_execarg {
31 union {
32 struct {
34 } sh;
35 struct {
37 VALUE command_abspath; /* full path string or nil */
40 } cmd;
46 unsigned use_shell : 1;
47 unsigned pgroup_given : 1;
48 unsigned umask_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], ...] */
64 rb_uid_t uid;
65 rb_gid_t gid;
71 VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
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
83VALUE rb_getlogin(void);
84VALUE rb_getpwdirnam_for_login(VALUE login); /* read as: "get pwd db home dir by username for login" */
85VALUE 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);
92VALUE 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);
98VALUE 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
125#if __has_warning("-Wdeprecated-declarations") || RBIMPL_COMPILER_IS(GCC)
126COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
127#endif
128static inline rb_pid_t
129rb_fork(void)
130{
131 return fork();
132}
134#endif
135
136#endif /* INTERNAL_PROCESS_H */
IMEMO: Internal memo object.
Thin wrapper to ruby/config.h.
struct rb_execarg * rb_execarg_get(VALUE execarg_obj)
Definition: process.c:2837
void rb_execarg_parent_end(VALUE execarg_obj)
Definition: process.c:3082
rb_pid_t rb_fork_ruby(int *status)
void rb_last_status_clear(void)
Definition: process.c:666
void rb_execarg_setenv(VALUE execarg_obj, VALUE env)
Definition: process.c:2875
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
Definition: process.c:2506
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen)
Definition: process.c:3751
VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt)
Definition: process.c:2862
void rb_execarg_parent_start(VALUE execarg_obj)
Definition: process.c:3043
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
Definition: process.c:2240
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_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)
voidpf void * buf
Definition: ioapi.h:138
int argc
Definition: ruby.c:240
char ** argv
Definition: ruby.c:241
unsigned close_others_do
Definition: process.h:52
struct rb_execarg::@113::@114 sh
mode_t umask_mask
Definition: process.h:63
unsigned pgroup_given
Definition: process.h:47
rb_gid_t gid
Definition: process.h:65
VALUE envp_buf
Definition: process.h:44
VALUE dup2_tmpbuf
Definition: process.h:45
VALUE command_abspath
Definition: process.h:37
VALUE redirect_fds
Definition: process.h:42
rb_uid_t uid
Definition: process.h:64
VALUE argv_buf
Definition: process.h:39
unsigned unsetenv_others_given
Definition: process.h:49
VALUE command_name
Definition: process.h:36
unsigned use_shell
Definition: process.h:46
unsigned new_pgroup_given
Definition: process.h:54
unsigned chdir_given
Definition: process.h:53
VALUE fd_open
Definition: process.h:69
VALUE rlimit_limits
Definition: process.h:62
int close_others_maxhint
Definition: process.h:66
struct waitpid_state * waitpid_state
Definition: process.h:60
VALUE fd_close
Definition: process.h:68
VALUE fd_dup2
Definition: process.h:67
VALUE envp_str
Definition: process.h:43
unsigned new_pgroup_flag
Definition: process.h:55
unsigned gid_given
Definition: process.h:57
VALUE shell_script
Definition: process.h:33
struct rb_execarg::@113::@115 cmd
unsigned uid_given
Definition: process.h:56
VALUE env_modification
Definition: process.h:71
unsigned umask_given
Definition: process.h:48
VALUE argv_str
Definition: process.h:38
VALUE path_env
Definition: process.h:72
VALUE fd_dup2_child
Definition: process.h:70
VALUE chdir_dir
Definition: process.h:73
unsigned exception_given
Definition: process.h:58
unsigned unsetenv_others_do
Definition: process.h:50
unsigned close_others_given
Definition: process.h:51
union rb_execarg::@113 invoke
rb_pid_t pgroup_pgid
Definition: process.h:61
unsigned long VALUE
Definition: value.h:38
Internal header to suppres / mandate warnings.
#define COMPILER_WARNING_PUSH
Definition: warnings.h:13
#define COMPILER_WARNING_POP
Definition: warnings.h:14
#define COMPILER_WARNING_IGNORED(flag)
Definition: warnings.h:16
#define env
#define mode_t
Definition: win32.h:119