Process.daemon() 失敗時ã®æŒ™å‹•ãŒã€ HAVE_DAEMON 定義時ã¨éžå®šç¾©æ™‚
ã¨ã§ç•°ãªã£ã¦ã„ã¾ã™ã€‚後者ã®å ´åˆã‚‚〠-1 ã‚’è¿”ã™ã®ã§ã¯ãªã errno ã«
基ã¥ã„ãŸä¾‹å¤–を上ã’ã‚‹ã¹ãã ã¨æ€ã„ã¾ã™ãŒã©ã†ã§ã—ょã†ã€‚
–
Akinori MUSHA / http://akinori.org/
Mon Mar 29 19:08:10 2010 Akinori MUSHA [email protected]
- process.c (proc_daemon): Process.daemon should raise an error on
failure regardless of whether the implementation uses daemon(3)
or not.
Index: process.c
— process.c (revision 27080)
+++ process.c (working copy)
@@ -4531,8 +4531,8 @@ proc_setmaxgroups(VALUE obj, VALUE val)
#if defined(HAVE_DAEMON) || defined(HAVE_FORK)
/*
-
-
-
- Return zero on success, or raise one of Errno::*.
*/
static VALUE
@@ -4561,7 +4562,7 @@ proc_daemon(int argc, VALUE *argv)
#elif defined(HAVE_FORK)
switch (rb_fork(0, 0, 0, Qnil)) {
case -1:
- rb_sys_fail(“daemon”);
case 0:
break;
default:
@@ -4573,7 +4574,7 @@ proc_daemon(int argc, VALUE argv)
/ must not be process-leader */
switch (rb_fork(0, 0, 0, Qnil)) {
case -1:
- rb_sys_fail(“daemon”);
case 0:
break;
default:
2010e$BG/e(B3e$B7ne(B29e$BF|e(B19:52 Akinori MUSHA [email protected]:
e$B!!e(BProcess.daemon() e$B<:GT;~$N5sF0$,!"e(B HAVE_DAEMON e$BDj5A;~$HHsDj5A;~e(B
e$B$H$G0[$J$C$F$$$^$9!#8e<T$N>l9g$b!"e(B -1 e$B$rJV$9$N$G$O$J$/e(B errno e$B$Ke(B
e$B4p$E$$$?Nc30$r>e$2$k$Y$-$@$H;W$$$^$9$,$I$&$G$7$g$&!#e(B
e$B<:GT;~$N5sF0$r9g$o$;$k$H$$$&%3%s%;%W%H$O;?@.$G$9$,!"e(Brb_fork()e$B$N$h$&$KJ#?t$Ne(B
e$B%7%9%F%`%3!<%k$r8F$V4X?t$KBP$7$Fe(Brb_sys_fail()e$B$r;H$&$N$O7y$+$b!#e(B
e$BM}M3$Oe(Berrnoe$B$r8+$F$b<:GT$7$F$$$k860x$r$^$C$?$/EA$($F$$$J$$$H9M$($k$+$i$G$9!#e(B
e$B0l$D<ALd$J$N$G$9$,!"$3$NNc30$O%9%/%j%W%HB&$G$I$&$$$&=hM}$r4|BT$7$F$$$^$9$+!)e(B
e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:40832] Process.daemon() returns -1 on failure
ifndef HAVE_DAEMON”
on Mon, 29 Mar 2010 19:52:00 +0900, “Akinori MUSHA”
[email protected] writes:
|e$B!!e(BProcess.daemon() e$B<:GT;~$N5sF0$,!"e(B HAVE_DAEMON e$BDj5A;~$HHsDj5A;~e(B
|e$B$H$G0[$J$C$F$$$^$9!#8e<T$N>l9g$b!"e(B -1 e$B$rJV$9$N$G$O$J$/e(B errno e$B$Ke(B
|e$B4p$E$$$?Nc30$r>e$2$k$Y$-$@$H;W$$$^$9$,$I$&$G$7$g$&!#e(B
e$BF10U$7$^$9!#e(B
2010e$BG/e(B3e$B7ne(B29e$BF|e(B19:52 Akinori MUSHA [email protected]:
e$B!!e(BProcess.daemon() e$B<:GT;~$N5sF0$,!"e(B HAVE_DAEMON e$BDj5A;~$HHsDj5A;~e(B
e$B$H$G0[$J$C$F$$$^$9!#8e<T$N>l9g$b!"e(B -1 e$B$rJV$9$N$G$O$J$/e(B errno e$B$Ke(B
e$B4p$E$$$?Nc30$r>e$2$k$Y$-$@$H;W$$$^$9$,$I$&$G$7$g$&!#e(B
e$B<:GT;~$N5sF0$r9g$o$;$k$H$$$&%3%s%;%W%H$O;?@.$G$9$,!"e(Brb_fork()e$B$N$h$&$KJ#?t$Ne(B
e$B%7%9%F%`%3!<%k$r8F$V4X?t$KBP$7$Fe(Brb_sys_fail()e$B$r;H$&$N$O7y$+$b!#e(B
e$BM}M3$Oe(Berrnoe$B$r8+$F$b<:GT$7$F$$$k860x$r$^$C$?$/EA$($F$$$J$$$H9M$($k$+$i$G$9!#e(B
e$B<+8J%l%9e(B
e$B8+D>$7$?$H$3$m!“e(Bprocess.ce$B$K;w$?$h$&$J=hM}$O$9$G$KBt;3$”$k$N$G!“$$$^$5$ie(B
e$B$H$$$&46$N$”$k;XE&$G$7$?!#<h$j>C$7$^$9!#$9$$$^$;$s!#e(B
At Tue, 30 Mar 2010 08:53:22 +0900,
KOSAKI Motohiro wrote:
見直ã—ãŸã¨ã“ã‚ã€process.cã«ä¼¼ãŸã‚ˆã†ãªå‡¦ç†ã¯ã™ã§ã«æ²¢å±±ã‚ã‚‹ã®ã§ã€ã„ã¾ã•ã‚‰
ã¨ã„ã†æ„Ÿã®ã‚る指摘ã§ã—ãŸã€‚å–り消ã—ã¾ã™ã€‚ã™ã„ã¾ã›ã‚“。
 ãã†ãªã‚“ã§ã™ã€‚rb_f_fork(Process.fork)ãŒãã†ãªã£ã¦ã„ã¾ã™ã€‚
 エミュレートã—ã¦ã„ã‚‹ *BSD 系㮠daemon(3) ã‚‚ã€å¤±æ•—時ã¯ä¸€å¾‹ã«
-1 ã‚’è¿”ã™ã®ã§ errno を見よã€ã«æ¢ã¾ã£ã¦ã„ã¾ã™ã€‚
一ã¤è³ªå•ãªã®ã§ã™ãŒã€ã“ã®ä¾‹å¤–ã¯ã‚¹ã‚¯ãƒªãƒ—トå´ã§ã©ã†ã„ã†å‡¦ç†ã‚’期待ã—ã¦ã„ã¾ã™ã‹ï¼Ÿ
 ã¡ã‚‡ã†ã©æ˜¨æ—¥ã€Twitter㧠popen(3) ã¯æ§˜ã€…ãªç†ç”±ã§å¤±æ•—ã™ã‚‹ã®ã«
相互ã«åŒºåˆ¥ã§ããªã„エラーã®çµ„ãŒè¤‡æ•°ã‚ã‚‹ã¨ã„ã†è©±ã‚’ã—ã¦ã„ã¾ã—ãŸã€‚
本件ã¯ã€æ°—ã«ãªã£ã¦ io.c ã‚„ process.c 㧠rb_sys_fail() ã—ã¦ã„ã‚‹
箇所を調ã¹ã¦ã„ã¦ãŸã¾ãŸã¾è¦‹ã¤ã‘ãŸã‚‚ã®ã§ã™ã€‚
 今ã®ã¨ã“ã‚ã¯ã€ Errno::* ã«ã¤ã„ã¦ã¯ errno を発生ã—ãŸã‚·ã‚¹ãƒ†ãƒ
コールãŒç‰¹å®šã§ãã¦ãªãŠã‹ã¤å„値ã«ã¤ã„ã¦ã®å¯¾å‡¦æ³•ãŒï¼ˆPOSIX çš„ã«ï¼‰
明確ãªã‚‚ã®ã‚’除ã„ã¦ã¯ã€ãã®ã¾ã¾ãƒ¦ãƒ¼ã‚¶ã«ä¼ãˆã¦ã‚ãらã‚ã‚‹ã‹ä»£æ›¿
手段をå–ã‚‹ãらã„ã§ã™ã。
 Ruby(CRuby)ã¨ã—ã¦ã¯ã€POSIX やメジャー㪠libc 実装ç‰ã§ã‚ˆã‚Š
é©åˆ‡ãªã‚¨ãƒ©ãƒ¼å‡¦ç†ãŒå¯èƒ½ãªæ–°ã—ã„APIãŒå‡ºã¦ããŸã‚‰å¯¾å¿œã‚’考ãˆã‚‹ã€ã¨
ã„ã†ã®ãŒå¦¥å½“ãªã¨ã“ã‚ã‹ã‚‚。
e$B<jCJ$r<h$k$/$i$$$G$9$M!#e(B
Rubye$B!Je(BCRubye$B!K$H$7$F$O!“e(BPOSIX e$B$d%a%8%c!<$Je(B libc e$B<BAuEy$G$h$je(B
e$BE,@Z$J%(%i!<=hM}$,2DG=$J?7$7$$e(BAPIe$B$,=P$F$-$?$iBP1~$r9M$($k!”$He(B
e$B$$$&$N$,BEEv$J$H$3$m$+$b!#e(B
e$B$J$k$[$I!#e(B
e$B<+J,$O%f!<%6%i%s%I$NG:$_$rJY6/$7$?$/$F!"$3$Ne(BMLe$B$r9XFI$5$;$F$b$i$C$F$$$kLL$,$"$j$^$9$N$Ge(B
e$B$3$&$$$&OC$OHs>o$K6=L#?<$$$G$9!#e(B