Skip to content

Commit

Permalink
Merge pull request rubinius#1858 from eregon/program_name
Browse files Browse the repository at this point in the history
Avoid changing the process title when initializing $0
  • Loading branch information
dbussink committed Aug 13, 2012
2 parents 7f06b88 + 2e6e0ea commit 49fcc23
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions kernel/loader.rb
Expand Up @@ -235,7 +235,7 @@ def options(argv=ARGV)
options.doc "\nRuby options"
options.on "-", "Read and evaluate code from STDIN" do
@run_irb = false
$0 = "-"
set_program_name "-"
CodeLoader.execute_script STDIN.read
end

Expand Down Expand Up @@ -269,7 +269,7 @@ def options(argv=ARGV)

options.on "-e", "CODE", "Compile and execute CODE" do |code|
@run_irb = false
$0 = "(eval)"
set_program_name "(eval)"
@evals << code
end

Expand Down Expand Up @@ -363,7 +363,7 @@ def options(argv=ARGV)
end
end

$0 = script if file
set_program_name script if file

# if missing, let it die a natural death
@script = file ? file : script
Expand Down Expand Up @@ -471,6 +471,12 @@ def options(argv=ARGV)
end
end

# Sets $0 ($PROGRAM_NAME) without changing the process title
def set_program_name(name)
Rubinius::Globals.set! :$0, name
end
private :set_program_name

def set_default_internal_encoding(encoding)
if @default_internal_encoding_set && Encoding.default_internal.name != encoding
raise RuntimeError, "Default internal encoding already set to '#{Encoding.default_internal.name}'."
Expand Down Expand Up @@ -616,7 +622,7 @@ def script
end
end

$0 = @script
set_program_name @script
CodeLoader.load_script @script, @debugging
end

Expand Down Expand Up @@ -677,7 +683,7 @@ def irb

if Terminal
repr = ENV['RBX_REPR'] || "bin/irb"
$0 = repr
set_program_name repr
prog = File.join @main_lib, repr
begin
# HACK: this was load but load raises LoadError
Expand All @@ -691,7 +697,7 @@ def irb
exit 1
end
else
$0 = "(eval)"
set_program_name "(eval)"
CodeLoader.execute_script "p #{STDIN.read}"
end
end
Expand Down

0 comments on commit 49fcc23

Please sign in to comment.