Code review comment for ~vpa1977/ubuntu/+source/jruby:jruby-ftbfs

Revision history for this message
Vladimir Petko (vpa1977) wrote :

captureRuby.rb
---
require 'open3'
require 'fcntl'

if defined? JRUBY_VERSION
  puts "JRuby #{JRUBY_VERSION}, Java #{java.lang.System.getProperty('java.version')}"
else
  puts "CRuby #{RUBY_VERSION}"
end

read, write = IO.pipe
flags = write.fcntl(Fcntl::F_GETFL)
# set nonblocking flag so that ruby knows about it
write.fcntl(Fcntl::F_SETFL, flags | (Fcntl::O_NONBLOCK)) # actually clears
# clear nonblocking flag
write.fcntl(Fcntl::F_SETFL, flags & (~Fcntl::O_NONBLOCK)) # set nonblock flag

pid = spawn("./printFlags.py", :out => write)

write.close
puts "Manual spawn: #{read.read}"
Process.wait pid
---

printFlags.py
------
#!/usr/bin/env python3

import fcntl
import os
import sys

def decode_flags(flags):
    flags_to_check = {
        "O_RDONLY": os.O_RDONLY,
        "O_WRONLY": os.O_WRONLY,
        "O_RDWR": os.O_RDWR,
        "O_APPEND": os.O_APPEND,
        "O_NONBLOCK": os.O_NONBLOCK,
    }

    result = []
    for name, flag in flags_to_check.items():
        if flags & flag:
            result.append(name)
            flags &= ~flag

    if flags:
        result.append(str(flags))

    return "+".join(result)

stdout_io_flags = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
print(f"stdout io flags: {stdout_io_flags} == {decode_flags(stdout_io_flags)}")
----

$jruby capturePython.rb
JRuby 9.4.5.0, Java 21.0.2
Manual spawn: stdout io flags: 1 == O_WRONLY

The output shows that the flag was successfully cleared.

« Back to merge proposal