From: watson1978@gmail.com
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50861] [Ruby master Bug#16342] macOS + Ruby 2.6.0 以降で拡張ライブラリ内での waitpid() コールに失敗する
Date: Tue, 12 Nov 2019 04:52:00 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-82632.20191112045159.49ecb673d1d030c7@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-16342.20191111155954@ruby-lang.org>
Issue #16342 has been updated by watson1978 (Shizuo Fujita).
書き忘れていたのですが、 https://github.com/ruby/ruby/commit/48b6bd74e2febde095ac85d818e94c0e58677647 の変更を境にエラーになるようになり、それ以前ですと問題なく動いておりました。
----------------------------------------
Bug #16342: macOS + Ruby 2.6.0 以降で拡張ライブラリ内での waitpid() コールに失敗する
https://bugs.ruby-lang.org/issues/16342#change-82632
* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
## 再現環境
* Ruby 2.6.0 以降
* macOS 10.15 (試した環境)
## 問題の説明
macOS 上で Ruby 2.6.0 以降を使用した際に、拡張ライブラリ内で `fork()/exec()` で外部コマンドを実行したあと `waitpid()` をコールすると失敗するようになりました。
私がメンテナンスしている RMagick 利用している ImageMagick が PDF を処理する際にこのような処理を行っており、macOS + Ruby 2.6.0 以降で処理に失敗するようになり困っております。
https://github.com/rmagick/rmagick/issues/483
https://github.com/Watson1978/rmagick-issue483 に再現コードを用意しており、以下の様に実行していただくと macOS + Ruby 2.6.0 以降でエラー終了します。
```
$ ./setup.sh
$ ruby sample.rb
$ ruby sample.rb
Ruby v2.6.0
Error waitpid(): Interrupted system call
```
```
$ ./setup.sh
$ ruby ./sample.rb
Ruby v2.6.5
Error waitpid(): Interrupted system call
```
Ruby 2.5.x 以下ですと期待通りに `WIFEXITED` のパスを通り正常に終了します。
```
$ ./setup.sh
$ ruby sample.rb
Ruby v2.5.7
(1) WIFEXITED : status = 0
```
```
$ ./setup.sh
$ ruby sample.rb
Ruby v2.3.8
(1) WIFEXITED : status = 0
```
確認した限り、macOS 上だけでこの現象が発生します。
## 再現コード
https://github.com/Watson1978/rmagick-issue483 のレポジトリに以下と同様の再現コードをコミットしており、すぐに確認できるかと思います。
```
#include <ruby.h>
#include <unistd.h>
VALUE
sample_test(VALUE self)
{
int status = 0;
int child_status = 0;
pid_t child_pid = fork();
if (child_pid == 0) {
char *const args[] = {
"/bin/sleep",
"1",
NULL
};
status = execvp(args[0], args);
exit(0);
}
else {
pid_t pid;
pid = waitpid(child_pid, &child_status, 0);
if (pid == -1) {
status = -1;
perror("Error waitpid()");
}
else {
if (WIFEXITED(child_status)) {
// Expected path
status = WEXITSTATUS(child_status);
printf("(1) WIFEXITED : status = %d\n", status);
}
else if (WIFSIGNALED(child_status)) {
status = -1;
printf("(2) WIFSIGNALED : status = %d\n", status);
}
}
}
return INT2FIX(status);
}
void Init_sample(void)
{
VALUE rb_cSample = rb_define_class("Sample", rb_cObject);
rb_define_method(rb_cSample, "test", sample_test, 0);
}
```
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2019-11-12 4:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-16342.20191111155954@ruby-lang.org>
2019-11-11 15:59 ` [ruby-dev:50858] " watson1978
2019-11-11 16:45 ` [ruby-dev:50859] " mame
2019-11-12 4:52 ` watson1978 [this message]
2019-12-16 8:03 ` [ruby-dev:50891] " mame
2019-12-16 10:29 ` [ruby-dev:50892] " taca
2020-01-29 15:16 ` [ruby-dev:50913] " watson1978
2020-01-29 21:13 ` [ruby-dev:50914] " naruse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-82632.20191112045159.49ecb673d1d030c7@ruby-lang.org \
--to=watson1978@gmail.com \
--cc=ruby-dev@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).