[#12164] patch for ext/gdbm — Koji Arai <JCA02266@...>

新井です。

24 messages 2001/02/04
[#12168] Re: patch for ext/gdbm — matz@... (Yukihiro Matsumoto) 2001/02/05

まつもと ゆきひろです

[#12176] Re: patch for ext/gdbm — Koji Arai <JCA02266@...> 2001/02/05

新井です。

[#12179] Re: patch for ext/gdbm — matz@... (Yukihiro Matsumoto) 2001/02/06

まつもと ゆきひろです

[#12219] Re: patch for ext/gdbm — Koji Arai <JCA02266@...> 2001/02/12

新井です。

[#12220] Re: patch for ext/gdbm — Koji Arai <JCA02266@...> 2001/02/12

新井です。

[#12256] set_trace_func — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

15 messages 2001/02/17

[#12293] crash on proc without a block — Kenichi Komiya <kom@...1.accsnet.ne.jp>

15 messages 2001/02/25

[#12323] Re: [ruby-list:28364] class definition extension — "K.Kosako" <kosako@...>

ruby-listから移動しました。

13 messages 2001/02/28
[#12324] Re: [ruby-list:28364] class definition extension — matz@... (Yukihiro Matsumoto) 2001/02/28

まつもと ゆきひろです

[ruby-dev:12270] Re: system() problem

From: "Akinori MUSHA" <knu@...>
Date: 2001-02-18 14:15:44 UTC
List: ruby-dev #12270
At Sun, 18 Feb 2001 21:12:58 +0900,
nobu.nakada@nifty.ne.jp wrote:
> 
> なかだです。
> 
> At Sun, 18 Feb 2001 09:57:53 +0900,
> Akinori MUSHA <knu@iDaemons.org> wrote:
> >  Ruby が SIGPIPE でいきなり終了してしまうのが困る場合もあるから
> > SIGPIPE または EPIPE を捕捉したい。しかし一方では
> > 
> > 	ruby -e 'system "yes | ls"'
> > 
> > が動作しないのはとても困る。ジレンマ。。
> 
>   exec する前に SIG_DFL に戻すというのでは解決しないでしょうか。

 できました。パッチを添付します。

 スレッドとのからみがどうかなとも思ったのですが、 Ruby は
MS-DOS や Human68k プラットフォーム以外では system でなくぜんぶ
自前で vfork() & exec[vl]() しているので大丈夫そうですね。

 vfork した子プロセスが exec[vl] に失敗したときは、どうせすぐ
死ぬので SIG_IGN に戻す必要すらないかも。また、 exec[vl] でなく
システムの spawn/system を呼び出す環境では、そもそも SIGPIPE
自体がないんですよね?

 簡単にテストしてみたところ、 system "yes | ls" はちゃんと
帰ってくるし、その後 SIGPIPE が発生しても Errno::EPIPE として
捕捉できています。

knu@archon[2]% ./ruby -e 'system "yes | ls"'
COPYING         config.log      ext             math.c          range.c         st.h
(snip)
config.h        eval.o          marshal.o       random.o        st.c
knu@archon[2]% ./ruby -e 'puts "y" while true' | ls
COPYING         config.log      ext             math.c          range.c         st.h
(snip)
config.h        eval.o          marshal.o       random.o        st.c
-e:1:in `write': Broken pipe (Errno::EPIPE)
        from -e:1:in `puts'
        from -e:1
knu@archon[2]% ./ruby -e 'STDERR.print `yes | echo yes!`; puts "y" while true' | echo yeah!
yeah!
yes!
-e:1:in `write': Broken pipe (Errno::EPIPE)
        from -e:1:in `puts'
        from -e:1

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"We're only at home when we're on the run, on the wing, on the fly"

Index: intern.h
===================================================================
RCS file: /mirror/ruby/src/ruby/intern.h,v
retrieving revision 1.41
diff -u -r1.41 intern.h
--- intern.h	2001/02/16 07:53:19	1.41
+++ intern.h	2001/02/18 13:29:33
@@ -296,6 +296,9 @@
 #ifdef POSIX_SIGNAL
 #define posix_signal ruby_posix_signal
 void posix_signal _((int, void (*)()));
+#define ruby_signal(sig,handle) posix_signal((sig),(handle))
+#else
+#define ruby_signal(sig,handle) signal((sig),(handle))
 #endif
 void rb_trap_exit _((void));
 void rb_trap_exec _((void));
Index: process.c
===================================================================
RCS file: /mirror/ruby/src/ruby/process.c,v
retrieving revision 1.30
diff -u -r1.30 process.c
--- process.c	2001/02/16 07:53:19	1.30
+++ process.c	2001/02/18 13:54:09
@@ -450,13 +450,24 @@
 char *strtok();
 #endif
 
+#ifdef SIGPIPE
+#define __unhook_sigpipe() ruby_signal(SIGPIPE, SIG_DFL)
+#define __hook_sigpipe() ruby_signal(SIGPIPE, SIG_IGN)
+#else
+#define __unhook_sigpipe()
+#define __hook_sigpipe()
+#endif
+
 #ifdef HAVE_SETITIMER
-#define before_exec() rb_thread_stop_timer()
-#define after_exec() rb_thread_start_timer()
+#define __thread_stop_timer() rb_thread_stop_timer()
+#define __thread_start_timer() rb_thread_start_timer()
 #else
-#define before_exec()
-#define after_exec()
+#define __thread_stop_timer()
+#define __thread_start_timer()
 #endif
+
+#define before_exec() do { __thread_stop_timer(); __unhook_sigpipe(); } while (0)
+#define after_exec() do { __hook_sigpipe(); __thread_start_timer(); } while (0)
 
 extern char *dln_find_exe();
 
Index: signal.c
===================================================================
RCS file: /mirror/ruby/src/ruby/signal.c,v
retrieving revision 1.17
diff -u -r1.17 signal.c
--- signal.c	2001/02/14 05:51:58	1.17
+++ signal.c	2001/02/18 13:28:23
@@ -298,9 +298,6 @@
 #endif
     sigaction(signum, &sigact, 0);
 }
-#define ruby_signal(sig,handle) posix_signal((sig),(handle))
-#else
-#define ruby_signal(sig,handle) signal((sig),(handle))
 #endif
 
 static void signal_exec _((int sig));

In This Thread