Project

General

Profile

Actions

Bug #6249

closed

Process.exec doesn't restore the environment if it fails

Added by john_firebaugh (John Firebaugh) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Backport:
[ruby-core:44093]

Description

ENV["foo"]
=> nil
Process.exec({"foo" => "bar"}, "nonexistent")
Errno::ENOENT: No such file or directory - nonexistent
from (irb):2:in exec' from (irb):2 from /Users/john/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in '
ENV["foo"]
=> "bar"

I expected that Process.exec would either use execle or execve, or (if it implements environment modification itself), to manually restore the existing environment upon failure.

Updated by akr (Akira Tanaka) over 12 years ago

2012/4/3 john_firebaugh (John Firebaugh) :

ENV["foo"]
=> nil
Process.exec({"foo" => "bar"}, "nonexistent")
Errno::ENOENT: No such file or directory - nonexistent
from (irb):2:in exec' from (irb):2 from /Users/john/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in '
ENV["foo"]
=> "bar"

I expected that Process.exec would either use execle or execve, or (if it implements environment modification itself), to manually restore the existing environment upon failure.

I see.

I think Process.exec should use execve.

Tanaka Akira

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)
Actions #3

Updated by akr (Akira Tanaka) over 12 years ago

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

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


  • use execve() to preserve environment variables when exec method is
    failed. [ruby-core:44093] [ruby-trunk - Bug #6249]

  • include/ruby/intern.h (rb_exec_arg): add envp_str and envp_buf field
    to store envp of execve().

  • process.c (proc_exec_v): takes envp_str as an argument and use it
    for execve().
    (rb_proc_exec_ne): extended version of rb_proc_exec_n().
    (rb_proc_exec_n): use rb_proc_exec_ne().
    (rb_proc_exec): follow proc_exec_v() change.
    (fill_envp_buf_i): new function.
    (rb_exec_arg_fixup): set up envp_str and envp_buf.
    (save_env_i): removed.
    (save_env): removed.
    (rb_run_exec_options_err): don't modify environment variables.
    (rb_exec_err): use rb_proc_exec_ne().

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0