[ruby-trunk - Bug #5475][Open] r33507以降SolarisでPTYが使えない

Issue #5475 has been reported by Naohisa G…


Bug #5475: r33507以降SolarisでPTYが使えない
http://redmine.ruby-lang.org/issues/5475

Author: Naohisa G.
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0dev (2011-10-24) [sparc-solaris2.10]

r33507以降、SolarisでPTYがまともに使えません。
% ruby -rpty -e ‘PTY.spawn("/bin/cat") { |r,w,id| p r; p w; p id }’
を実行すると、
-e:1:in spawn': can't get Master/Slave device (RuntimeError) from -e:1:in
のようになります。

make test-all では、TestIO_ConsoleはほとんどのテストがSkipされてしまいます。
TestPTYも同様に多数のSkipおよび以下のErrorが出ます。一部を抜粋します。

  1. Skipped:
    test_echo(TestIO_Console)
    [/XXX/test/io/console/test_io_console.rb:171]:
    can’t get Master/Slave device
    (中略)

  2. Skipped:
    test_winsize(TestIO_Console)
    [/XXX/test/io/console/test_io_console.rb:171]:
    can’t get Master/Slave device

  3. Skipped:
    test_argv0(TestPTY) [/XXX/test/test_pty.rb:49]:
    can’t get Master/Slave device
    (中略)

  4. Error:
    test_pty_check_default(TestPTY):
    RuntimeError: can’t get Master/Slave device
    /XXX/test/test_pty.rb:170:in spawn' /XXX/test/test_pty.rb:170:intest_pty_check_default’
    (以下略)

デバッガで追ってみると、ext/pty/pty.c:296 の grantpt(masterfd) が -1 となり、
errno は EACCES (Solaris10では13) でした。
そして、r33507で新規に導入された ext/pty/pty.c:294 の rb_fd_set_cloexec(masterfd); で
masterfd に FD_CLOEXEC フラグを設定しているのが原因のようです。

Solarisでは、grantpt(3) 内部で /usr/lib/pt_chmod という setuid root
されたヘルパープログラムを呼んでデバイスファイルのパーミッション設定を行っていますが、FD_CLOEXECをptyのmasterfdに設定すると、ヘルパープログラムを呼ぶ際に自動でcloseされてしまうため、ヘルパープログラムにclose済みのファイルデスクリプタが渡され、エラーになるのだろうと推測します。

2011$BG/(B10$B7n(B24$BF|(B16:56 Naohisa G. [email protected]:

Bug #5475: r33507$B0J9_(BSolaris$B$G(BPTY$B$,;H$($J$$(B
http://redmine.ruby-lang.org/issues/5475

$B%G%P%C%,$GDI$C$F$_$k$H!"(Bext/pty/pty.c:296 $B$N(B grantpt(masterfd) $B$,(B -1
$B$H$J$j!"(B
errno $B$O(B EACCES (Solaris10$B$G$O(B13) $B$G$7$?!#(B
$B$=$7$F!"(Br33507$B$G?75,$KF3F~$5$l$?(B ext/pty/pty.c:294 $B$N(B
rb_fd_set_cloexec(masterfd); $B$G(B masterfd $B$K(B FD_CLOEXEC
$B%U%i%[email protected]_Dj$7$F$$$k$N$,860x$N$h$&$G$9!#(B

Solaris$B$G$O!"(Bgrantpt(3) $BFbIt$G(B /usr/lib/pt_chmod $B$H$$$&(B setuid root
$B$5$l$?%X%k%Q!<%W%m%0%i%$r8F$s$G%G%P%$%9%U%!%$%k$N%Q!<%_%C%7%g%[email protected]_Dj$r9T$C$F$$$^$9$,!"(BFD_CLOEXEC$B$r(Bpty$B$N([email protected]_Dj$9$k$H!"%X%k%Q!<%W%m%0%i%$r8F$V:]$K<+F0$G(Bclose$B$5$l$F$7$^$&$?$a!"%X%k%Q!<%W%m%0%i%`$K(Bclose$B:Q$_$N%U%!%$%k%G%9%/%j%W%?$,EO$5$l!"%(%i!<[email protected]$m$&$H?dB,$7$^$9!#(B

$B$J$k$[$I!#(B

$B$H$j$"$($:%o!<%/%"%i%s%I$H$7$F0J2<$N$h$&$K$9$k$HHr$1$i$l$k$G$7$g$&$+!#(B

$B$=$N$&$A(B Solaris $B$N(B grandpt() $B$,(B FD_CLOEXEC
$B$r$D$1$F$"$C$F$bF0$/$h$&$K(B
$BJQ$o$k$s$8$c$J$$$+$H$$$&5$$b$7$^$9$,!#(B

Index: ext/pty/pty.c

— ext/pty/pty.c (revision 33517)
+++ ext/pty/pty.c (working copy)
@@ -290,10 +290,18 @@ get_device_once(int *master, int *slave,
dfl.sa_flags = 0;
sigemptyset(&dfl.sa_mask);

+#if defined(sun)

  • /* Solaris 10 needs FD_CLOEXEC bit clear to work with grantpt().
    [ruby-dev:44688] */
  • if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
  • if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
  • if (grantpt(masterfd) == -1) goto grantpt_error;
  • rb_fd_set_cloexec(masterfd);
    +#else
    if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
    rb_fd_set_cloexec(masterfd);
    if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
    if (grantpt(masterfd) == -1) goto grantpt_error;
    +#endif
    if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
    if (unlockpt(masterfd) == -1) goto error;
    if ((slavedevice = ptsname(masterfd)) == NULL) goto error;

On Mon, 24 Oct 2011 18:43:39 +0900
Tanaka A. [email protected] wrote:

$B$H$j$"$($:%o!<%/%"%i%s%I$H$7$F0J2<$N$h$&$K$9$k$HHr$1$i$l$k$G$7$g$&$+!#(B

$B2sHr$G$-$^$7$?!#0J2$N$h$&[email protected]o=*N;$7$^$9!#(B
% ruby -rpty -e ‘PTY.spawn("/bin/cat") { |r,w,id| p r; p w; p id }’
#<File:/dev/pts/28>
#<File:/dev/pts/28>
16125
$B$^$?!"(Btest_pty.rb, test_io_console.rb
$B6&$K(BSkip$B$d(BError$B$,>C$($^$7$?!#(B

$B$J$!"(BSolaris 9 $B$$h$S$=$l0JA0$G$O(B posix_openpt
$B$,B8:_$7$J$$$i$7$$$?$a!"(B
defined(HAVE_PTSNAME)
$B$N$H$3$m$bF1MM$KBP:v$9$kI,MW$,$"$k5$$,$7$^$9$,!"(B
[email protected]$K(BSolaris9$B$r;H$C$F$$$k?M$,?7$7$$(BRuby$B$r5a$a$k$3$H$OL5$$$H?.$8$?$$!#(B

$B$=$l$H!"(BSolaris$B$r<1JL$9$k%^%/%m$O(B __sun
$B$N$[$&$,$h$$$N$+$b$7$l$^$;$s!#(B
OpenCSW$B$G$O(B #if defined(__sun) || defined(sun) $B?d>)!"(B
http://wiki.opencsw.org/porting-faq#toc18
pkgsrc developer’s guide $B$G$O(B sun $B?d>)$N$h$&$G$9!#(B
http://www.netbsd.org/docs/pkgsrc/fixes.html#fixes.build
$B$b$C$H$b!"(Bsun $B$b;d$N<j85$N(B Sun cc, Fujitsu fcc, gcc
$B$G$O$9$Y$F(B
$BDj5A$5$l$F$$$^$7$?!#(B__sun
$B$O(BGCC$B$7$+Dj5A$7$J$$$h$&$G$9!#(B

2011$BG/(B10$B7n(B24$BF|(B22:26 Naohisa GOTO
[email protected]:

$B$J$!"(BSolaris 9 $B$$h$S$=$l0JA0$G$O(B posix_openpt
$B$,B8:_$7$J$$$i$7$$$?$a!"(B
defined(HAVE_PTSNAME) $B$N$H$3$m$bF1MM$KBP:v$9$kI,MW$,$"$k5$$,$7$^$9$,!"(B

[email protected]$K(BSolaris9$B$r;H$C$F$$$k?M$,?7$7$$(BRuby$B$r5a$a$k$3$H$OL5$$$H?.$8$?$$!#(B

$B$^$!!"J,$+$C$F$$$k$N$KD>$5$J$$$N$b2?$J$N$G$d$C$F$*$-$^$7$?!#(B

$B$=$l$H!"(BSolaris$B$r<1JL$9$k%^%/%m$O(B __sun
$B$N$[$&$,$h$$$N$+$b$7$l$^$;$s!#(B
OpenCSW$B$G$O(B #if defined(__sun) || defined(sun) $B?d>)!"(B
http://wiki.opencsw.org/porting-faq#toc18
pkgsrc developer’s guide $B$G$O(B sun $B?d>)$N$h$&$G$9!#(B
http://www.netbsd.org/docs/pkgsrc/fixes.html#fixes.build
$B$b$C$H$b!"(Bsun $B$b;d$N<j85$N(B Sun cc, Fujitsu fcc, gcc $B$G$O$9$Y$F(B
$BDj5A$5$l$F$$$^$7$?!#(B__sun
$B$O(BGCC$B$7$+Dj5A$7$J$$$h$&$G$9!#(B

$B$3$l$b$d$C$F$*$-$^$7$?!#(B

$B$D$$$G$K!"(Bdln.c $B$K(B
#if defined(sun) && defined(sparc)
$B$H$$$&$N$,$"$C$F5$$,$D$$$?$s$G$9$,!"$b$7$+$7$F(B sparc $B$b(B __sparc
$B$H$+$N$[$&$,(B
$B$$$$$G$9$+$M!#(B
($B$&$%$`!#(BSPARC $B$N(B ABI $B$r8+$F$b:$C$F$$$J$+$C$?(B…)

On Mon, 24 Oct 2011 22:59:20 +0900
Tanaka A. [email protected] wrote:

$B$D$$$G$K!"(Bdln.c $B$K(B
#if defined(sun) && defined(sparc)
$B$H$$$&$N$,$"$C$F5$$,$D$$$?$s$G$9$,!"$b$7$+$7$F(B sparc $B$b(B __sparc
$B$H$+$N$[$&$,(B
$B$$$$$G$9$+$M!#(B
($B$&$%$`!#(BSPARC $B$N(B ABI $B$r8+$F$b:$C$F$$$J$+$C$?(B…)

Sun(Oracle) $B$N(B cc $B$G$O(B sparc $B$H(B __sparc
$BN>J}Dj5A$,$"$j$^$9$,!"(B
$B%I%-%e%a%s%H$G$O(B __sparc $B$r;H$&$h$&$K;X<($,$5$l$F$$$^$9!#(B
http://developers.sun.com/sunstudio/documentation/ss12u1/mr/READMEs/c++_faq.html#Vers6

ISO C$B87L)=`5r%b!<%I(B(-Xc)$B$G$N$_(B sparc $B$d(B sun $B$O>C$($^$9!#(B
[email protected]$7!"$3$N%b!<%I$G$O(BRuby$B$N%3%s%Q%$%k$ODL$i$J$$$H;W$$$^$9!#(B
http://download.oracle.com/docs/cd/E19205-01/820-1209/bjaii/index.html

$B;d$N<j85$K$"$kB>$N%3%s%Q%$%i(B(fcc, gcc)$B$G$bF1MM$K(B
sparc $B$H(B __sparc $B$NN>J}$,Dj5A$5$l$F$$$^$9!#(B
OpenSolaris, Illumos $B$O$*$=$i$/(BSun$B$HF1MM$H;W$$$^$9!#(B

$B$7$+$7!"(BSparc Linux (Debian$B$J$I(B), NetBSD, FreeBSD, OpenBSD
$B$J$I!"B>$N(Bsparc$B>e$N(BUNIX$B7O(BOS$B$G$N>u67$O$o$+$j$^$;$s$G$7$?!#(B
__sparcv9 $B$N$3$H$b9M$($k$H$5$i$KLLE]!#(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs