Professional Web Applications Themes

1.8.0, fcgi and $stdout/$stderr - Ruby

--gBBFr7Ir9EOA20Yy Content-Type: text/plain; cht=us-ascii Content-Disposition: inline I have just been trying to get fcgi to run under 1.8.0, and I have found a problem: /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476: warning: assignment to $stdout is deprecated; use STDOUT.reopen() instead /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476:in `each_cgi': $stdout is a read-only variable (NameError) from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each' from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each_cgi' (One problem is that Ruby gives both a warning and an error; either assignment should be allowed with a warning, or disallowed, not both :-) This is caused by the following code: $stdout, $defout, $stderr = request.out, request.out, request.err Now, 'request.out' and 'request.err' are objects which respond to IO-like calls, but are ...

  1. #1

    Default 1.8.0, fcgi and $stdout/$stderr


    --gBBFr7Ir9EOA20Yy
    Content-Type: text/plain; cht=us-ascii
    Content-Disposition: inline

    I have just been trying to get fcgi to run under 1.8.0, and I have found a
    problem:

    /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476: warning: assignment to $stdout is deprecated; use STDOUT.reopen() instead
    /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476:in `each_cgi': $stdout is a read-only variable (NameError)
    from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each'
    from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each_cgi'

    (One problem is that Ruby gives both a warning and an error; either
    assignment should be allowed with a warning, or disallowed, not both :-)

    This is caused by the following code:

    $stdout, $defout, $stderr = request.out, request.out, request.err

    Now, 'request.out' and 'request.err' are objects which respond to IO-like
    calls, but are not actually IO objects (following the Ruby principle of Duck
    Typing).

    However, I now can't change $stdout/$stderr, and nor can I reopen them since
    the new objects are not IO:

    /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:475:in `reopen': cannot convert FCGI::Stream into IO (TypeError)

    I guess this makes sense, since $stdout/$stderr are supposed to refer to the
    actual system standard input/standard output channels attached to the
    process.

    So it looks like the best I can do now is:

    $defout, $deferr = request.out, request.err

    although in that case, any existing programs which do

    $stderr.puts "Some warning message"

    are now going to send to the system stderr rather than the fastcgi "stderr".

    Anyway, I think the attached patch does the job for ruby-fcgi, although I've
    not actually tested it under 1.6.8

    Cheers,

    Brian.

    --gBBFr7Ir9EOA20Yy
    Content-Type: text/plain; cht=us-ascii
    Content-Disposition: attachment; filename=ruby-fcgi-180patch

    --- ruby-fcgi-0.8.3/README.orig Mon Jul 28 00:09:32 2003
    +++ ruby-fcgi-0.8.3/README Mon Jul 28 00:09:40 2003
    -14,7 +14,7

    $ ruby install.rb config
    (Pure Ruby Version: ruby install.rb config --without-ext)
    - (Some systems need: ruby install.rb config --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib)
    + (Some systems need: ruby install.rb config -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib)
    $ ruby install.rb setup
    # ruby install.rb install

    --- ruby-fcgi-0.8.3/lib/fcgi.rb.orig Mon Jul 28 00:09:48 2003
    +++ ruby-fcgi-0.8.3/lib/fcgi.rb Mon Jul 28 00:21:33 2003
    -468,15 +468,20
    else
    exit_requested = false
    trap('SIGPIPE','IGNORE')
    - o_stdout, o_defout, o_stderr = $stdout, $defout, $stderr
    + rb16 = RUBY_VERSION < "1.8.0"
    + $deferr ||= $stderr if rb16
    + o_defout, o_deferr = $defout, $deferr
    + o_stdout, o_stderr = $stdout, $stderr if rb16

    FCGI::each {|request|
    trap('SIGUSR1') { exit_requested = true }
    - $stdout, $defout, $stderr = request.out, request.out, request.err
    + $defout, $deferr = request.out, request.err
    + $stdout, $stderr = request.out, request.err if rb16

    yield CGI.new(request, *args)

    - $stdout, $defout, $stderr = o_stdout, o_defout, o_stderr
    + $defout, $deferr = o_defout, o_deferr
    + $stdout, $stderr = o_stdout, o_stderr if rb16
    request.finish
    trap('SIGUSR1','DEFAULT')
    raise SignalException, 'SIGUSR1' if exit_requested

    --gBBFr7Ir9EOA20Yy--

    Brian Candler Guest

  2. #2

    Default Re: 1.8.0, fcgi and $stdout/$stderr

    On Mon, Jul 28, 2003 at 05:28:56PM +0900, Yukihiro Matsumoto wrote:
    > Hi,
    >
    > In message "1.8.0, fcgi and $stdout/$stderr"
    > on 03/07/28, Brian Candler <B.Candlerpobox.com> writes:
    >
    > |/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476: warning: assignment to $stdout is deprecated; use STDOUT.reopen() instead
    > |/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:476:in `each_cgi': $stdout is a read-only variable (NameError)
    > | from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each'
    > | from /usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each_cgi'
    > |
    > |(One problem is that Ruby gives both a warning and an error; either
    > |assignment should be allowed with a warning, or disallowed, not both :-)
    >
    > Fortunately for you, $stdin etc. now become assignable again in
    > preview5.
    Thank you. I hope it wasn't just for me :-)

    Cheers,

    Brian.

    Brian Candler Guest

Similar Threads

  1. Redirect stdout, stderr to file and stdout
    By Larry Guest in forum PERL Beginners
    Replies: 8
    Last Post: January 20th, 10:42 AM
  2. Run one process and get the stdout and stderr
    By Marcos Rebelo in forum PERL Beginners
    Replies: 2
    Last Post: October 16th, 12:01 PM
  3. [PHP-DEV] STDOUT, STDERR not defined in CLI mode
    By Alex Kiesel in forum PHP Development
    Replies: 0
    Last Post: August 8th, 11:36 AM
  4. redirecting stdout/stderr on execl
    By shea martin in forum UNIX Programming
    Replies: 3
    Last Post: July 21st, 11:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139