Project

General

Profile

Actions

Bug #5524

closed

IO.wait_for_single_fd(closed fd) sticks on other than Linux

Added by naruse (Yui NARUSE) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
-
Backport:
[ruby-dev:44726]

Description

r31428 で、test_wait_for_invalid_fd ってテストを追加しており、
IO.wait_for_single_fd(close 済みの fd) が EBADF になることを確認しているのですが、
これ単体で動かすと FreeBSD で戻ってきません。

思うに、このテストって本来ポータブルに刺さる物なんじゃないでしょうか。
test-allだと何かの弾みで通ってしまうだけで。

% cat poll.c
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <errno.h>
int
main(void) {
int pipes[2];
int res = pipe(pipes);
if (res != 0) abort();
int r = pipes[0];
int w = pipes[1];
res = close(w);
if (res != 0) abort();

struct pollfd fds;
fds.fd = w;
fds.events = POLLOUT;
errno = 0;
res = poll(&fds, 1, 1000);
fprintf(stderr, "%d %d %d\n", res, errno, fds.revents);
return 0;

}

というプログラムではポータブルに POLLVAL が返り、

#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
int
main(void) {
int pipes[2];
int res = pipe(pipes);
if (res != 0) abort();
int r = pipes[0];
int w = pipes[1];
res = close(w);
if (res != 0) abort();
fd_set readfds; FD_ZERO(&readfds);
fd_set writefds; FD_ZERO(&writefds);
fd_set exceptfds; FD_ZERO(&exceptfds);
//struct timeval *timeout = NULL;
//FD_SET(r, &readfds);
FD_SET(w, &writefds);
res = select(1, &readfds, &writefds, &exceptfds, NULL);
return 0;
}

はポータブルにブロックされるあたり、このテストってLinux依存なんじゃ無いかという疑惑を持っているんですがどうでしょう。

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

  • ruby -v changed from ruby 2.0.0dev (2011-10-31 trunk 33582) [x86_64-freebsd9.0] to -

小崎です

ええと、なるせさんの論旨がいまいちまだ把握できてない気がするのですが・・・・

r31428 で、test_wait_for_invalid_fd ってテストを追加しており、
IO.wait_for_single_fd(close 済みの fd) が EBADF になることを確認しているのですが、
これ単体で動かすと FreeBSD で戻ってきません。

思うに、このテストって本来ポータブルに刺さる物なんじゃないでしょうか。
test-allだと何かの弾みで通ってしまうだけで。

Macとかでも刺さらないです。

% cat poll.c
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <errno.h>
int
main(void) {
int pipes[2];
int res = pipe(pipes);
if (res != 0) abort();
int r = pipes[0];
int w = pipes[1];
res = close(w);
if (res != 0) abort();

struct pollfd fds;
fds.fd = w;
fds.events = POLLOUT;
errno = 0;
res = poll(&fds, 1, 1000);
fprintf(stderr, "%d %d %d\n", res, errno, fds.revents);
return 0;
}

というプログラムではポータブルに POLLVAL が返り、

POLLVALが返ると思いますが、poll つかうのはLinuxのときだけなんで
今回の件は無関係ではないでしょうか。

#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
int
main(void) {
int pipes[2];
int res = pipe(pipes);
if (res != 0) abort();
int r = pipes[0];
int w = pipes[1];
res = close(w);
if (res != 0) abort();
fd_set readfds; FD_ZERO(&readfds);
fd_set writefds; FD_ZERO(&writefds);
fd_set exceptfds; FD_ZERO(&exceptfds);
//struct timeval *timeout = NULL;
//FD_SET(r, &readfds);
FD_SET(w, &writefds);
res = select(1, &readfds, &writefds, &exceptfds, NULL);
return 0;
}

はポータブルにブロックされるあたり、このテストってLinux依存なんじゃ無いかという疑惑を持っているんですがどうでしょう。

SUSはEBADFを要求しているのでFreeBSDのバグではないでしょうか?

http://pubs.opengroup.org/onlinepubs/7908799/xsh/select.html

FreeBSDのときだけテストスキップじゃだめ?

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

なるせさんのテストプロは selectのmaxfds引数が間違っているので、動かないのは期待通りではないでしょうか。以下の修正をあててFreeBSDで
動かしてもらえませんか

~/projects/test/select_ebadf% diff -u select_badf.c.orig select_badf.c
diff -u select_badf.c.orig select_badf.c
--- select_badf.c.orig 2011-11-08 11:33:44.000000000 -0500
+++ select_badf.c 2011-11-08 11:38:26.000000000 -0500
@@ -3,6 +3,8 @@
#include <sys/select.h>
#include <unistd.h>

+#define max(x,y) ((x > y) ? x : y)
+
int
main(void) {
int pipes[2];
@@ -18,7 +20,8 @@
//struct timeval *timeout = NULL;
//FD_SET(r, &readfds);
FD_SET(w, &writefds);

  • res = select(1, &readfds, &writefds, &exceptfds, NULL);
  • res = select(max(r,w)+1, &readfds, &writefds, &exceptfds, NULL);
  • return 0;
    }

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

  • Status changed from Assigned to Feedback
  • Assignee changed from kosaki (Motohiro KOSAKI) to naruse (Yui NARUSE)

Updated by naruse (Yui NARUSE) over 12 years ago

Motohiro KOSAKI wrote:

なるせさんのテストプロは selectのmaxfds引数が間違っているので、動かないのは期待通りではないでしょうか。以下の修正をあててFreeBSDで
動かしてもらえませんか

おぉ、なるほど、確かにそれだと FreeBSD だけ動きません。
FreeBSD 側のバグとして報告しました、当面 FreeBSD だけスキップするようにします。
http://www.freebsd.org/cgi/query-pr.cgi?pr=162379

Actions #5

Updated by naruse (Yui NARUSE) over 12 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33677.
Yui, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


FreeBSD 8.2 sticks this [ruby-dev:44726] [Bug #5524]
http://redmine.ruby-lang.org/issues/5524

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0