diff options
-rw-r--r-- | ruby.c | 14 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 7 |
2 files changed, 17 insertions, 4 deletions
@@ -2052,6 +2052,8 @@ proc_argv0(VALUE process) return rb_orig_progname; } +static VALUE ruby_setproctitle(VALUE title); + /* * call-seq: * Process.setproctitle(string) -> string @@ -2072,10 +2074,14 @@ proc_argv0(VALUE process) static VALUE proc_setproctitle(VALUE process, VALUE title) { - StringValue(title); - - setproctitle("%.*s", RSTRING_LENINT(title), RSTRING_PTR(title)); + return ruby_setproctitle(title); +} +static VALUE +ruby_setproctitle(VALUE title) +{ + const char *ptr = StringValueCStr(title); + setproctitle("%.*s", RSTRING_LENINT(title), ptr); return title; } @@ -2085,7 +2091,7 @@ set_arg0(VALUE val, ID id) if (origarg.argv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized"); - rb_progname = rb_str_new_frozen(proc_setproctitle(rb_mProcess, val)); + rb_progname = rb_str_new_frozen(ruby_setproctitle(val)); } static inline VALUE diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index f927af2f2d..beb6a24e93 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -549,6 +549,13 @@ class TestRubyOptions < Test::Unit::TestCase def test_setproctitle skip "platform dependent feature" unless defined?(PSCMD) and PSCMD + assert_separately([], "#{<<-"{#"}\n#{<<-'};'}") + {# + assert_raise(ArgumentError) do + Process.setproctitle("hello\0") + end + }; + with_tmpchdir do write_file("test-script", "$_0 = $0.dup; Process.setproctitle('hello world'); $0 == $_0 or Process.setproctitle('$0 changed!'); sleep 60") |