[#30549] [ANN] Ruby 1.8.6 has been released — "Akinori MUSHA" <knu@...>

 Ruby 1.8.6 をリリースしました。

14 messages 2007/03/12

[#30553] help: lib/shell for ruby 1.9 — keiju@... (Keiju ISHITSUKA)

けいじゅ@いしつかです.

13 messages 2007/03/13
[#30585] Re: help: lib/shell for ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/03/15

まつもと ゆきひろです

[#30587] Re: help: lib/shell for ruby 1.9 — keiju@... (石塚圭樹) 2007/03/15

けいじゅ@いしつかです.

[#30588] Re: help: lib/shell for ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/03/15

まつもと ゆきひろです

[ruby-dev:30618] possible bug in rb_detach_process()

From: "KUBO Takehiro" <kubo@...>
Date: 2007-03-17 09:36:07 UTC
List: ruby-dev #30618
久保です。

waitpid 関係でちらほらソースを見ていたのですが、以下の部分は問題ではな
いでしょうか?

static VALUE
detach_process_watcher(int *pid_p)
{
    rb_pid_t cpid;
    int status;

    for (;;) {
        cpid = rb_waitpid(*pid_p, &status, WNOHANG);
        if (cpid != 0) return rb_last_status_get();
        rb_thread_sleep(1);
    }
}

VALUE
rb_detach_process(rb_pid_t pid)
{
    return rb_thread_create(detach_process_watcher, (void*)&pid);
}

detach_process_watcher() に渡される引数は、rb_detach_process のスレッ
ドのスタック上の値になっています。rb_waitpid() が実行される前に
rb_detach_process のスレッドが動いてスタック上の値が書き変わったら、
rb_waitpid() に渡される pid はわけのわからない値になります。

正しくはこう?

static VALUE
detach_process_watcher(void *arg)  <- int *pid_p を void *arg に
{
    rb_pid_t pid = (int)arg;       <- void* を rb_pid_t に戻す。
    rb_pid_t cpid;
    int status;

    for (;;) {
        cpid = rb_waitpid(pid, &status, WNOHANG);  <- *pid_p を pid に
        if (cpid != 0) return rb_last_status_get();
        rb_thread_sleep(1);
    }
}

VALUE
rb_detach_process(rb_pid_t pid)
{
    return rb_thread_create(detach_process_watcher, (void*)pid); <- &pid を pid に
}

In This Thread

Prev Next