/src/ruby/internal/process.h
Line | Count | Source |
1 | | #ifndef INTERNAL_PROCESS_H /*-*-C-*-vi:se ft=c:*/ |
2 | | #define INTERNAL_PROCESS_H |
3 | | /** |
4 | | * @author Ruby developers <ruby-core@ruby-lang.org> |
5 | | * @copyright This file is a part of the programming language Ruby. |
6 | | * Permission is hereby granted, to either redistribute and/or |
7 | | * modify this file, provided that the conditions mentioned in the |
8 | | * file COPYING are met. Consult the file for details. |
9 | | * @brief Internal header for Process. |
10 | | */ |
11 | | #include "ruby/internal/config.h" /* for rb_pid_t */ |
12 | | #include <stddef.h> /* for size_t */ |
13 | | |
14 | | #ifdef HAVE_SYS_TYPES_H |
15 | | # include <sys/types.h> /* for mode_t */ |
16 | | #endif |
17 | | |
18 | | #ifdef _WIN32 |
19 | | # include "ruby/win32.h" /* for mode_t */ |
20 | | #endif |
21 | | |
22 | | #include "ruby/ruby.h" /* for VALUE */ |
23 | | #include "internal/compilers.h" /* for __has_warning */ |
24 | | #include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */ |
25 | | |
26 | 0 | #define RB_MAX_GROUPS (65536) |
27 | | |
28 | | struct waitpid_state; |
29 | | struct rb_process_status; |
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 rb_process_status *status; |
61 | | struct waitpid_state *waitpid_state; /* for async process management */ |
62 | | rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */ |
63 | | VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */ |
64 | | mode_t umask_mask; |
65 | | rb_uid_t uid; |
66 | | rb_gid_t gid; |
67 | | int close_others_maxhint; |
68 | | VALUE fd_dup2; |
69 | | VALUE fd_close; |
70 | | VALUE fd_open; |
71 | | VALUE fd_dup2_child; |
72 | | VALUE env_modification; /* Qfalse or [[k1,v1], ...] */ |
73 | | VALUE path_env; |
74 | | VALUE chdir_dir; |
75 | | }; |
76 | | |
77 | | /* process.c */ |
78 | | rb_pid_t rb_call_proc__fork(void); |
79 | | void rb_last_status_clear(void); |
80 | | static inline char **ARGVSTR2ARGV(VALUE argv_str); |
81 | | static inline size_t ARGVSTR2ARGC(VALUE argv_str); |
82 | | |
83 | | #ifdef HAVE_PWD_H |
84 | | VALUE rb_getlogin(void); |
85 | | VALUE rb_getpwdirnam_for_login(VALUE login); /* read as: "get pwd db home dir by username for login" */ |
86 | | VALUE rb_getpwdiruid(void); /* read as: "get pwd db home dir for getuid()" */ |
87 | | #endif |
88 | | |
89 | | RUBY_SYMBOL_EXPORT_BEGIN |
90 | | /* process.c (export) */ |
91 | | int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen); |
92 | | 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); |
93 | | VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt); |
94 | | struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */ |
95 | | int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val); |
96 | | void rb_execarg_parent_start(VALUE execarg_obj); |
97 | | void rb_execarg_parent_end(VALUE execarg_obj); |
98 | | int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen); |
99 | | VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash); |
100 | | void rb_execarg_setenv(VALUE execarg_obj, VALUE env); |
101 | | RUBY_SYMBOL_EXPORT_END |
102 | | |
103 | | /* argv_str contains extra two elements. |
104 | | * The beginning one is for /bin/sh used by exec_with_sh. |
105 | | * The last one for terminating NULL used by execve. |
106 | | * See rb_exec_fillarg() in process.c. */ |
107 | | static inline char ** |
108 | | ARGVSTR2ARGV(VALUE argv_str) |
109 | 0 | { |
110 | 0 | char **buf = RB_IMEMO_TMPBUF_PTR(argv_str); |
111 | 0 | return &buf[1]; |
112 | 0 | } Unexecuted instantiation: error.c:ARGVSTR2ARGV Unexecuted instantiation: file.c:ARGVSTR2ARGV Unexecuted instantiation: io.c:ARGVSTR2ARGV Unexecuted instantiation: process.c:ARGVSTR2ARGV |
113 | | |
114 | | static inline size_t |
115 | | ARGVSTR2ARGC(VALUE argv_str) |
116 | 0 | { |
117 | 0 | size_t i = 0; |
118 | 0 | char *const *p = ARGVSTR2ARGV(argv_str); |
119 | 0 | while (p[i++]) |
120 | 0 | ; |
121 | 0 | return i - 1; |
122 | 0 | } Unexecuted instantiation: error.c:ARGVSTR2ARGC Unexecuted instantiation: file.c:ARGVSTR2ARGC Unexecuted instantiation: io.c:ARGVSTR2ARGC Unexecuted instantiation: process.c:ARGVSTR2ARGC |
123 | | |
124 | | #endif /* INTERNAL_PROCESS_H */ |