process.c: avoid EINTR from Process.spawn

* process.c (send_child_error): retry write on EINTR to fix
  occasional Errno::EINTR from Process.spawn.
* process.c (recv_child_error): retry read on EINTR to fix
  occasional Errno::EINTR from Process.spawn.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-01-25 05:50:44 +00:00
Родитель 27dfc398a8
Коммит 7336d8c899
2 изменённых файлов: 37 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Jan 25 14:50:42 2014 Eric Wong <normalperson@yhbt.net>
* process.c (send_child_error): retry write on EINTR to fix
occasional Errno::EINTR from Process.spawn.
* process.c (recv_child_error): retry read on EINTR to fix
occasional Errno::EINTR from Process.spawn.
Sat Jan 25 14:21:06 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (iseq_compile_each): result of assignment should be

Просмотреть файл

@ -3296,6 +3296,30 @@ retry_fork(int *status, int *ep, int chfunc_is_async_signal_safe)
}
}
static ssize_t
write_retry(int fd, const void *buf, size_t len)
{
ssize_t w;
do {
w = write(fd, buf, len);
} while (w < 0 && errno == EINTR);
return w;
}
static ssize_t
read_retry(int fd, void *buf, size_t len)
{
ssize_t r;
do {
r = read(fd, buf, len);
} while (r < 0 && errno == EINTR);
return r;
}
static void
send_child_error(int fd, int state, char *errmsg, size_t errmsg_buflen, int chfunc_is_async_signal_safe)
{
@ -3303,7 +3327,7 @@ send_child_error(int fd, int state, char *errmsg, size_t errmsg_buflen, int chfu
int err;
if (!chfunc_is_async_signal_safe) {
if (write(fd, &state, sizeof(state)) == sizeof(state) && state) {
if (write_retry(fd, &state, sizeof(state)) == sizeof(state) && state) {
VALUE errinfo = rb_errinfo();
io = rb_io_fdopen(fd, O_WRONLY|O_BINARY, NULL);
rb_marshal_dump(errinfo, io);
@ -3311,11 +3335,11 @@ send_child_error(int fd, int state, char *errmsg, size_t errmsg_buflen, int chfu
}
}
err = errno;
if (write(fd, &err, sizeof(err)) < 0) err = errno;
if (write_retry(fd, &err, sizeof(err)) < 0) err = errno;
if (errmsg && 0 < errmsg_buflen) {
errmsg[errmsg_buflen-1] = '\0';
errmsg_buflen = strlen(errmsg);
if (errmsg_buflen > 0 && write(fd, errmsg, errmsg_buflen) < 0)
if (errmsg_buflen > 0 && write_retry(fd, errmsg, errmsg_buflen) < 0)
err = errno;
}
if (!NIL_P(io)) rb_io_close(io);
@ -3329,7 +3353,7 @@ recv_child_error(int fd, int *statep, VALUE *excp, int *errp, char *errmsg, size
ssize_t size;
VALUE exc = Qnil;
if (!chfunc_is_async_signal_safe) {
if ((read(fd, &state, sizeof(state))) == sizeof(state) && state) {
if ((read_retry(fd, &state, sizeof(state))) == sizeof(state) && state) {
io = rb_io_fdopen(fd, O_RDONLY|O_BINARY, NULL);
exc = rb_marshal_load(io);
rb_set_errinfo(exc);
@ -3339,11 +3363,8 @@ recv_child_error(int fd, int *statep, VALUE *excp, int *errp, char *errmsg, size
}
#define READ_FROM_CHILD(ptr, len) \
(NIL_P(io) ? read(fd, (ptr), (len)) : rb_io_bufread(io, (ptr), (len)))
while ((size = READ_FROM_CHILD(&err, sizeof(err))) < 0) {
if ((size = READ_FROM_CHILD(&err, sizeof(err))) < 0) {
err = errno;
if (err != EINTR) {
break;
}
}
*errp = err;
if (size == sizeof(err) &&