2020-04-10 01:11:40 -04:00
|
|
|
#ifndef INTERNAL_PROCESS_H /*-*-C-*-vi:se ft=c:*/
|
|
|
|
#define INTERNAL_PROCESS_H
|
|
|
|
/**
|
2020-04-08 00:28:13 -04:00
|
|
|
* @author Ruby developers <ruby-core@ruby-lang.org>
|
2019-11-29 01:18:34 -05:00
|
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
|
|
* modify this file, provided that the conditions mentioned in the
|
|
|
|
* file COPYING are met. Consult the file for details.
|
2020-04-08 00:28:13 -04:00
|
|
|
* @brief Internal header for Process.
|
2019-11-29 01:18:34 -05:00
|
|
|
*/
|
2020-05-08 05:31:09 -04:00
|
|
|
#include "ruby/internal/config.h" /* for rb_pid_t */
|
2019-12-03 22:30:06 -05:00
|
|
|
#include <stddef.h> /* for size_t */
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h> /* for mode_t */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include "ruby/win32.h" /* for mode_t */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ruby/ruby.h" /* for VALUE */
|
|
|
|
#include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */
|
2020-05-02 08:34:10 -04:00
|
|
|
#include "internal/warnings.h" /* for COMPILER_WARNING_PUSH */
|
2019-11-29 01:18:34 -05:00
|
|
|
|
|
|
|
#define RB_MAX_GROUPS (65536)
|
|
|
|
|
|
|
|
struct waitpid_state;
|
2020-12-05 07:05:40 -05:00
|
|
|
struct rb_process_status;
|
2019-11-29 01:18:34 -05:00
|
|
|
struct rb_execarg {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
VALUE shell_script;
|
|
|
|
} sh;
|
|
|
|
struct {
|
|
|
|
VALUE command_name;
|
|
|
|
VALUE command_abspath; /* full path string or nil */
|
|
|
|
VALUE argv_str;
|
|
|
|
VALUE argv_buf;
|
|
|
|
} cmd;
|
|
|
|
} invoke;
|
|
|
|
VALUE redirect_fds;
|
|
|
|
VALUE envp_str;
|
|
|
|
VALUE envp_buf;
|
|
|
|
VALUE dup2_tmpbuf;
|
|
|
|
unsigned use_shell : 1;
|
|
|
|
unsigned pgroup_given : 1;
|
|
|
|
unsigned umask_given : 1;
|
|
|
|
unsigned unsetenv_others_given : 1;
|
|
|
|
unsigned unsetenv_others_do : 1;
|
|
|
|
unsigned close_others_given : 1;
|
|
|
|
unsigned close_others_do : 1;
|
|
|
|
unsigned chdir_given : 1;
|
|
|
|
unsigned new_pgroup_given : 1;
|
|
|
|
unsigned new_pgroup_flag : 1;
|
|
|
|
unsigned uid_given : 1;
|
|
|
|
unsigned gid_given : 1;
|
|
|
|
unsigned exception : 1;
|
|
|
|
unsigned exception_given : 1;
|
2020-12-05 07:05:40 -05:00
|
|
|
struct rb_process_status *status;
|
2019-11-29 01:18:34 -05:00
|
|
|
struct waitpid_state *waitpid_state; /* for async process management */
|
|
|
|
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;
|
|
|
|
rb_uid_t uid;
|
|
|
|
rb_gid_t gid;
|
|
|
|
int close_others_maxhint;
|
|
|
|
VALUE fd_dup2;
|
|
|
|
VALUE fd_close;
|
|
|
|
VALUE fd_open;
|
|
|
|
VALUE fd_dup2_child;
|
|
|
|
VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
|
|
|
|
VALUE path_env;
|
|
|
|
VALUE chdir_dir;
|
|
|
|
};
|
|
|
|
|
2019-12-03 22:30:06 -05:00
|
|
|
/* process.c */
|
2019-11-29 01:18:34 -05:00
|
|
|
rb_pid_t rb_fork_ruby(int *status);
|
|
|
|
void rb_last_status_clear(void);
|
2019-12-03 22:30:06 -05:00
|
|
|
static inline char **ARGVSTR2ARGV(VALUE argv_str);
|
|
|
|
static inline size_t ARGVSTR2ARGC(VALUE argv_str);
|
2019-11-29 01:18:34 -05:00
|
|
|
|
2020-04-15 07:29:16 -04:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
VALUE rb_getlogin(void);
|
|
|
|
VALUE rb_getpwdirnam_for_login(VALUE login); /* read as: "get pwd db home dir by username for login" */
|
|
|
|
VALUE rb_getpwdiruid(void); /* read as: "get pwd db home dir for getuid()" */
|
|
|
|
#endif
|
|
|
|
|
2019-11-29 01:18:34 -05:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
/* process.c (export) */
|
|
|
|
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
|
|
|
|
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);
|
|
|
|
VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt);
|
|
|
|
struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
|
|
|
|
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
|
|
|
|
void rb_execarg_parent_start(VALUE execarg_obj);
|
|
|
|
void rb_execarg_parent_end(VALUE execarg_obj);
|
|
|
|
int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
|
|
|
|
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
|
|
|
|
void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
|
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2019-12-03 22:30:06 -05:00
|
|
|
|
|
|
|
/* argv_str contains extra two elements.
|
|
|
|
* The beginning one is for /bin/sh used by exec_with_sh.
|
|
|
|
* The last one for terminating NULL used by execve.
|
|
|
|
* See rb_exec_fillarg() in process.c. */
|
|
|
|
static inline char **
|
|
|
|
ARGVSTR2ARGV(VALUE argv_str)
|
|
|
|
{
|
|
|
|
char **buf = RB_IMEMO_TMPBUF_PTR(argv_str);
|
|
|
|
return &buf[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
ARGVSTR2ARGC(VALUE argv_str)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
char *const *p = ARGVSTR2ARGV(argv_str);
|
|
|
|
while (p[i++])
|
|
|
|
;
|
|
|
|
return i - 1;
|
|
|
|
}
|
|
|
|
|
2020-05-02 09:17:03 -04:00
|
|
|
#ifdef HAVE_WORKING_FORK
|
2020-05-02 08:34:10 -04:00
|
|
|
COMPILER_WARNING_PUSH
|
2020-05-04 02:52:56 -04:00
|
|
|
#if __has_warning("-Wdeprecated-declarations") || RBIMPL_COMPILER_IS(GCC)
|
2020-05-02 08:34:10 -04:00
|
|
|
COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
|
|
|
|
#endif
|
|
|
|
static inline rb_pid_t
|
|
|
|
rb_fork(void)
|
|
|
|
{
|
|
|
|
return fork();
|
|
|
|
}
|
|
|
|
COMPILER_WARNING_POP
|
2020-05-02 09:17:03 -04:00
|
|
|
#endif
|
2020-05-02 08:34:10 -04:00
|
|
|
|
2019-11-29 01:18:34 -05:00
|
|
|
#endif /* INTERNAL_PROCESS_H */
|