1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* internal.h (rb_execarg_new): declared.

(rb_execarg_get): ditto.

* process.c (mark_exec_arg): new function.
  (free_exec_arg): ditto.
  (memsize_exec_arg): ditto.
  (exec_arg_data_type): defined.
  (rb_execarg_new): new function.
  (rb_execarg_get): ditto.
  (rb_f_exec): use rb_execarg_new.
  (rb_spawn_internal): ditto.
  (rb_f_spawn): ditto.

* io.c (pipe_open_v): use rb_execarg_new.
  (pipe_open_s): ditto.

* ext/pty/pty.c (establishShell): use rb_execarg_new.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2012-06-20 10:31:02 +00:00
parent 2741a598ff
commit 826f98e688
5 changed files with 129 additions and 22 deletions

View file

@ -1,3 +1,23 @@
Wed Jun 20 19:13:25 2012 Tanaka Akira <akr@fsij.org>
* internal.h (rb_execarg_new): declared.
(rb_execarg_get): ditto.
* process.c (mark_exec_arg): new function.
(free_exec_arg): ditto.
(memsize_exec_arg): ditto.
(exec_arg_data_type): defined.
(rb_execarg_new): new function.
(rb_execarg_get): ditto.
(rb_f_exec): use rb_execarg_new.
(rb_spawn_internal): ditto.
(rb_f_spawn): ditto.
* io.c (pipe_open_v): use rb_execarg_new.
(pipe_open_s): ditto.
* ext/pty/pty.c (establishShell): use rb_execarg_new.
Wed Jun 20 16:36:14 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* missing/setproctitle.c (environ): use (*_NSGetEnviron()) instead of

View file

@ -78,7 +78,8 @@ static void getDevice(int*, int*, char [DEVICELEN], int);
struct child_info {
int master, slave;
char *slavename;
struct rb_exec_arg earg;
VALUE execarg_obj;
struct rb_exec_arg *earg;
};
static int
@ -142,7 +143,7 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
seteuid(getuid());
#endif
return rb_exec_async_signal_safe(&carg->earg, errbuf, sizeof(errbuf_len));
return rb_exec_async_signal_safe(carg->earg, errbuf, sizeof(errbuf_len));
#undef ERROR_EXIT
}
@ -176,8 +177,9 @@ establishShell(int argc, VALUE *argv, struct pty_info *info,
argv = &v;
}
rb_execarg_init(argc, argv, 1, &carg.earg);
rb_execarg_fixup(&carg.earg);
carg.execarg_obj = rb_execarg_new(argc, argv, 1);
carg.earg = rb_execarg_get(carg.execarg_obj);
rb_execarg_fixup(carg.earg);
getDevice(&master, &slave, SlaveName, 0);
@ -200,6 +202,8 @@ establishShell(int argc, VALUE *argv, struct pty_info *info,
info->child_pid = pid;
info->fd = master;
RB_GC_GUARD(carg.execarg_obj);
}
static int

View file

@ -266,6 +266,8 @@ void rb_maygvl_fd_fix_cloexec(int fd);
/* process.c */
int rb_exec_async_signal_safe(const struct rb_exec_arg *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, VALUE *argv, int accept_shell);
struct rb_exec_arg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e);
int rb_execarg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val);
void rb_execarg_fixup(struct rb_exec_arg *e);

20
io.c
View file

@ -5726,9 +5726,13 @@ pipe_open(struct rb_exec_arg *eargp, const char *modestr, int fmode, convconfig_
static VALUE
pipe_open_v(int argc, VALUE *argv, const char *modestr, int fmode, convconfig_t *convconfig)
{
struct rb_exec_arg earg;
rb_execarg_init(argc, argv, FALSE, &earg);
return pipe_open(&earg, modestr, fmode, convconfig);
VALUE execarg_obj, ret;
struct rb_exec_arg *earg;
execarg_obj = rb_execarg_new(argc, argv, FALSE);
earg = rb_execarg_get(execarg_obj);
ret = pipe_open(earg, modestr, fmode, convconfig);
RB_GC_GUARD(execarg_obj);
return ret;
}
static VALUE
@ -5737,7 +5741,8 @@ pipe_open_s(VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig
const char *cmd = RSTRING_PTR(prog);
int argc = 1;
VALUE *argv = &prog;
struct rb_exec_arg earg;
VALUE execarg_obj, ret;
struct rb_exec_arg *earg;
if (RSTRING_LEN(prog) == 1 && cmd[0] == '-') {
#if !defined(HAVE_FORK)
@ -5747,8 +5752,11 @@ pipe_open_s(VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig
return pipe_open(NULL, modestr, fmode, convconfig);
}
rb_execarg_init(argc, argv, TRUE, &earg);
return pipe_open(&earg, modestr, fmode, convconfig);
execarg_obj = rb_execarg_new(argc, argv, TRUE);
earg = rb_execarg_get(execarg_obj);
ret = pipe_open(earg, modestr, fmode, convconfig);
RB_GC_GUARD(execarg_obj);
return ret;
}
/*

View file

@ -1270,6 +1270,42 @@ enum {
EXEC_OPTION_NEW_PGROUP
};
static void
mark_exec_arg(void *ptr)
{
struct rb_exec_arg *earg = ptr;
if (earg->use_shell)
rb_gc_mark(earg->invoke.sh.shell_script);
else {
rb_gc_mark(earg->invoke.cmd.command_name);
rb_gc_mark(earg->invoke.cmd.command_abspath);
rb_gc_mark(earg->invoke.cmd.argv_str);
rb_gc_mark(earg->invoke.cmd.argv_buf);
}
rb_gc_mark(earg->options);
rb_gc_mark(earg->redirect_fds);
rb_gc_mark(earg->envp_str);
rb_gc_mark(earg->envp_buf);
rb_gc_mark(earg->dup2_tmpbuf);
}
static void
free_exec_arg(void *ptr)
{
xfree(ptr);
}
static size_t
memsize_exec_arg(const void *ptr)
{
return ptr ? sizeof(struct rb_exec_arg) : 0;
}
static const rb_data_type_t exec_arg_data_type = {
"exec_arg",
{mark_exec_arg, free_exec_arg, memsize_exec_arg},
};
#if defined(_WIN32)
#define HAVE_SPAWNV 1
#endif
@ -2019,6 +2055,24 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, str
}
}
VALUE
rb_execarg_new(int argc, VALUE *argv, int accept_shell)
{
VALUE execarg_obj;
struct rb_exec_arg *e;
execarg_obj = TypedData_Make_Struct(rb_cData, struct rb_exec_arg, &exec_arg_data_type, e);
hide_obj(execarg_obj);
rb_execarg_init(argc, argv, accept_shell, e);
return execarg_obj;
}
struct rb_exec_arg *rb_execarg_get(VALUE execarg_obj)
{
struct rb_exec_arg *e;
TypedData_Get_Struct(execarg_obj, struct rb_exec_arg, &exec_arg_data_type, e);
return e;
}
VALUE
rb_execarg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e)
{
@ -2193,20 +2247,25 @@ static int rb_exec_without_timer_thread(const struct rb_exec_arg *e, char *errms
VALUE
rb_f_exec(int argc, VALUE *argv)
{
struct rb_exec_arg earg;
VALUE execarg_obj, fail_str;
struct rb_exec_arg *earg;
#define CHILD_ERRMSG_BUFLEN 80
char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' };
rb_exec_arg_prepare(&earg, argc, argv);
execarg_obj = rb_execarg_new(argc, argv, TRUE);
earg = rb_execarg_get(execarg_obj);
rb_execarg_fixup(earg);
fail_str = earg->use_shell ? earg->invoke.sh.shell_script : earg->invoke.cmd.command_name;
#ifdef __MacOS_X__
rb_exec_without_timer_thread(&earg, errmsg, sizeof(errmsg));
rb_exec_without_timer_thread(earg, errmsg, sizeof(errmsg));
#else
rb_exec_async_signal_safe(&earg, errmsg, sizeof(errmsg));
rb_exec_async_signal_safe(earg, errmsg, sizeof(errmsg));
#endif
RB_GC_GUARD(execarg_obj);
if (errmsg[0])
rb_sys_fail(errmsg);
rb_sys_fail_str(earg.use_shell ? earg.invoke.sh.shell_script : earg.invoke.cmd.command_name);
rb_sys_fail_str(fail_str);
return Qnil; /* dummy */
}
@ -3480,9 +3539,16 @@ rb_spawn_process(struct rb_exec_arg *earg, char *errmsg, size_t errmsg_buflen)
static rb_pid_t
rb_spawn_internal(int argc, VALUE *argv, char *errmsg, size_t errmsg_buflen)
{
struct rb_exec_arg earg;
rb_exec_arg_prepare(&earg, argc, argv);
return rb_spawn_process(&earg, errmsg, errmsg_buflen);
VALUE execarg_obj;
struct rb_exec_arg *earg;
VALUE ret;
execarg_obj = rb_execarg_new(argc, argv, TRUE);
earg = rb_execarg_get(execarg_obj);
rb_execarg_fixup(earg);
ret = rb_spawn_process(earg, errmsg, errmsg_buflen);
RB_GC_GUARD(execarg_obj);
return ret;
}
rb_pid_t
@ -3813,14 +3879,21 @@ rb_f_spawn(int argc, VALUE *argv)
{
rb_pid_t pid;
char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' };
struct rb_exec_arg earg;
VALUE execarg_obj, fail_str;
struct rb_exec_arg *earg;
execarg_obj = rb_execarg_new(argc, argv, TRUE);
earg = rb_execarg_get(execarg_obj);
rb_execarg_fixup(earg);
fail_str = earg->use_shell ? earg->invoke.sh.shell_script : earg->invoke.cmd.command_name;
pid = rb_spawn_process(earg, errmsg, sizeof(errmsg));
RB_GC_GUARD(execarg_obj);
rb_exec_arg_prepare(&earg, argc, argv);
pid = rb_spawn_process(&earg, errmsg, sizeof(errmsg));
if (pid == -1) {
const char *prog = errmsg;
if (!prog[0]) {
rb_sys_fail_str(earg.use_shell ? earg.invoke.sh.shell_script : earg.invoke.cmd.command_name);
rb_sys_fail_str(fail_str);
}
rb_sys_fail(prog);
}