Ruby bug reading from /dev/urandom after failed require?

I’ve been trying to track down a bug that surfaced when trying to
generate a Rails 2.0.2 app in Cygwin. Reading from /dev/urandom fails
with “No such file or directory - /dev/urandom” if a failed require
has been made previously.

The Rails code looks OK, so I thought it might be Cygwin. I came up
with a simple snippet that fails in Cygwin (see below). Corinna
Vinschen over at Cygwin ran strace on it and thought it might be a
Ruby bug…see her thoughts here:
http://cygwin.com/ml/cygwin/2007-12/msg00502.html

I’m not well versed on the low level strace stuff, but I thought I’d
try to see this through. I’d appreciate any comments from someone
knowledgeable about the Ruby source.

Demonstration code:

Test failure of reading /dev/urandom after failed require

this method is from the Rails’ source secret_key_generator.rb

def generate_secret_with_urandom
return File.read("/dev/urandom", 64).unpack(“H*”)[0]
end

cause_failure = true

begin
require ‘nonexistent_file’
rescue LoadError
puts ‘’ unless cause_failure
end

puts generate_secret_with_urandom

Thanks,
Mike B.
http://boonedocks.net/mike/

Hi,

In message “Re: Ruby bug reading from /dev/urandom after failed
require?”
on Sun, 23 Dec 2007 00:20:05 +0900, Mike B.
[email protected] writes:
|
|I’ve been trying to track down a bug that surfaced when trying to
|generate a Rails 2.0.2 app in Cygwin. Reading from /dev/urandom fails
|with “No such file or directory - /dev/urandom” if a failed require
|has been made previously.

Could you describe how it fails for those who don’t use Cygwin
platform, like myself?

|The Rails code looks OK, so I thought it might be Cygwin. I came up
|with a simple snippet that fails in Cygwin (see below). Corinna
|Vinschen over at Cygwin ran strace on it and thought it might be a
|Ruby bug…see her thoughts here:
|http://cygwin.com/ml/cygwin/2007-12/msg00502.html
|
|I’m not well versed on the low level strace stuff, but I thought I’d
|try to see this through. I’d appreciate any comments from someone
|knowledgeable about the Ruby source.

The bug must lie between Cygwin and Ruby. We don’t call lseek
explicitly. You can clearly see this by doing strace on Linux (or
other platforms), which don’t call lseek at all. So, someone (in the
library, I guess) must call lseek weirdly on Cygwin.

I have no clue right now to identify “someone”.

          matz.

On Dec 22 2007, 10:47 am, Yukihiro M. [email protected]
wrote:

The bug must lie between Cygwin and Ruby. We don’t call lseek
explicitly. You can clearly see this by doing strace on Linux (or
other platforms), which don’t call lseek at all. So, someone (in the
library, I guess) must call lseek weirdly on Cygwin.

I have no clue right now to identify “someone”.

Sorry for the late reply. I have done some more experimentation with
the Ruby source in Cygwin.

The current Ruby 1.8.6 does not make in Cygwin, giving an error about
strftime.o. However, the stable-snapshot does make correctly, but my
test script still gives the /dev/urandom error. Interestingly,
compiling Ruby 1.9.0 works fine and the /dev/urandom error goes away.

I have GDB on my Cygwin system, but I am not sure where to begin
tracing the problem. Where would be the best place to set a breakpoint
for tracking the error “No such file or directory - /dev/urandom”?

Thanks,
Mike B.
http://boonedocks.net/mike/

On Jan 2, 9:39 pm, Nobuyoshi N. [email protected] wrote:

Sorry that I missed your post. Fixed it just now.

Excellent! Thank you.

Mike B…

Hi,

At Thu, 3 Jan 2008 06:00:03 +0900,
Mike B. wrote in [ruby-talk:285706]:

The current Ruby 1.8.6 does not make in Cygwin, giving an error about
strftime.o. However, the stable-snapshot does make correctly, but my
test script still gives the /dev/urandom error. Interestingly,
compiling Ruby 1.9.0 works fine and the /dev/urandom error goes away.

Sorry that I missed your post. Fixed it just now.

And the make failure is bacause of the change of Cygwin since
1.8.6 has been released.