1 #ifndef INTERNAL_PROCESS_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_PROCESS_H
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.
11 #include "ruby/internal/config.h" /* for rb_pid_t */
12 #include <stddef.h> /* for size_t */
14 #ifdef HAVE_SYS_TYPES_H
15 # include <sys/types.h> /* for mode_t */
19 # include "ruby/win32.h" /* for mode_t */
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 */
26 #define RB_MAX_GROUPS (65536)
29 struct rb_process_status
;
37 VALUE command_abspath
; /* full path string or nil */
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], ...] */
67 int close_others_maxhint
;
72 VALUE env_modification
; /* Qfalse or [[k1,v1], ...] */
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
);
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()" */
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
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
)
110 char **buf
= RB_IMEMO_TMPBUF_PTR(argv_str
);
115 ARGVSTR2ARGC(VALUE argv_str
)
118 char *const *p
= ARGVSTR2ARGV(argv_str
);
124 #endif /* INTERNAL_PROCESS_H */