Project

General

Profile

Bug #9102

ObjectSpace.dump_all creates a FD without close-on-exec flag

Added by akr (Akira Tanaka) almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-11-14 trunk 43675) [x86_64-linux]
[ruby-core:58266]

Description

I found test/objspace/test_objspace.rb creates a file descriptor without
O_CLOEXEC.

Ruby should create all file descriptors with close-on-exec since Ruby 2.0.0.
So, this behavior is a bug (on OS which supports O_CLOEXEC).

% strace -oz -f -e open ./ruby test/objspace/test_objspace.rb

Run options:

Running tests:

Finished tests in 3.411053s, 4.1043 tests/s, 18316.3380 assertions/s.

14 tests, 62478 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.1.0dev (2013-11-11 trunk 43646) [x86_64-linux]
% grep -v O_CLOEXEC z
9832 --- SIGCHLD (Child exited) @ 0 (0) ---
9836 --- SIGCHLD (Child exited) @ 0 (0) ---
9838 open("/tmp/rubyheapAk8lt8", O_RDWR|O_CREAT|O_EXCL, 0600) = 7
9840 --- SIGCHLD (Child exited) @ 0 (0) ---
9843 --- SIGCHLD (Child exited) @ 0 (0) ---
9847 --- SIGCHLD (Child exited) @ 0 (0) ---
% ./ruby -v
ruby 2.1.0dev (2013-11-11 trunk 43646) [x86_64-linux]

I think we cannot use mkstemp().

Associated revisions

Revision 91aa8da5
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Revision 43679
Added by nobu (Nobuyoshi Nakada) almost 6 years ago

objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

History

Updated by akr (Akira Tanaka) almost 6 years ago

  • ruby -v changed from ruby 2.1.0dev (2013-11-11 trunk 43646) [x86_64-linux] to ruby 2.1.0dev (2013-11-14 trunk 43675) [x86_64-linux]

2013/11/11 akr (Akira Tanaka) akr@fsij.org:

Bug #9102: ObjectSpace.dump_all creates a FD without close-on-exec flag
https://bugs.ruby-lang.org/issues/9102

I think we cannot use mkstemp().

Another reason we should avoid mkstemp() is that it doesn't
respect TMPDIR environment variable.

It makes CI difficult to remove temporary files reliably.

It seems test/objspace/test_objspace.rb retains a temporary variable in /tmp.

% ./ruby test/objspace/test_objspace.rb
Run options:

# Running tests:

Finished tests in 0.626708s, 22.3390 tests/s, 101369.4049
assertions/s.
14 tests, 63529 assertions, 0 failures, 0 errors, 0 skips

% ls /tmp/rubyheap*
/tmp/rubyheapIPCDjl

chkbuild (CI used by rubyci.org) sets TMPDIR to a unique directory
for each build to remove temporary files even if a test aborts.

But temporary files created by mkstemp() are not removable because
TMPDIR is not in effect.
--
Tanaka Akira

#2

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43679.
Akira, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


objspace_dump.c: refine output

  • ext/objspace/objspace_dump.c (dump_output): allow IO object as output, and use Tempfile.create and return open file instead of mkstemp() and path name for :file output. [ruby-core:58266] [Bug #9102]
  • test/objspace/test_objspace.rb (TestObjSpace#dump_my_heap_please): remove temporary output file.

Also available in: Atom PDF