1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (proc_getsid): adds new method for getting session id.

Contributed from fumiyas (Fumiyasu SATOH). Thank you!
  [Feature #6757] [ruby-dev:45977]
* configure.in: adds getsid check.
* test/ruby/test_process.rb (TestProcess#test_setsid): new test
  for the above.
* NEWS: news for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2012-11-24 02:51:24 +00:00
parent 82b33551a4
commit 5611df706e
5 changed files with 65 additions and 1 deletions

View file

@ -1,3 +1,13 @@
Sat Nov 24 11:47:14 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* process.c (proc_getsid): adds new method for getting session id.
Contributed from fumiyas (Fumiyasu SATOH). Thank you!
[Feature #6757] [ruby-dev:45977]
* configure.in: adds getsid check.
* test/ruby/test_process.rb (TestProcess#test_setsid): new test
for the above.
* NEWS: news for the above.
Sat Nov 24 10:59:14 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (thread_create_core): don't use th->thread_id before

4
NEWS
View file

@ -109,6 +109,10 @@ with all sufficient information, see the ChangeLog file.
* added method:
* added nil.to_h which returns {}
* Process
* added method:
* added getsid for getting sessin id (unix only).
* Range
* added method:
* added Range#size for lazy size evaluation.

View file

@ -1554,7 +1554,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit setrlimit sysconf close getpwnam_r getgrnam_r\
dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
setsid telldir seekdir fchmod cosh sinh tanh log2 round llabs\
getsid setsid telldir seekdir fchmod cosh sinh tanh log2 round llabs\
setuid setgid daemon select_large_fdset setenv unsetenv\
mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
pread sendfile shutdown sigaltstack dl_iterate_phdr\

View file

@ -4219,6 +4219,40 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
#endif
#ifdef HAVE_GETSID
/*
* call-seq:
* Process.getsid() -> integer
* Process.getsid(pid) -> integer
*
* Returns the session ID for for the given process id. If not give,
* return current process sid. Not available on all platforms.
*
* Process.getsid() #=> 27422
* Process.getsid(0) #=> 27422
* Process.getsid(Process.pid()) #=> 27422
*/
static VALUE
proc_getsid(int argc, VALUE *argv)
{
rb_pid_t sid;
VALUE pid;
rb_secure(2);
rb_scan_args(argc, argv, "01", &pid);
if (NIL_P(pid))
pid = INT2NUM(0);
sid = getsid(NUM2PIDT(pid));
if (sid < 0) rb_sys_fail(0);
return PIDT2NUM(sid);
}
#else
#define proc_getsid rb_f_notimplement
#endif
#if defined(HAVE_SETSID) || (defined(HAVE_SETPGRP) && defined(TIOCNOTTY))
#if !defined(HAVE_SETSID)
static rb_pid_t ruby_setsid(void);
@ -6609,6 +6643,7 @@ Init_process(void)
rb_define_module_function(rb_mProcess, "getpgid", proc_getpgid, 1);
rb_define_module_function(rb_mProcess, "setpgid", proc_setpgid, 2);
rb_define_module_function(rb_mProcess, "getsid", proc_getsid, -1);
rb_define_module_function(rb_mProcess, "setsid", proc_setsid, 0);
rb_define_module_function(rb_mProcess, "getpriority", proc_getpriority, 2);

View file

@ -1558,4 +1558,19 @@ class TestProcess < Test::Unit::TestCase
}
end if File.executable?("/bin/sh")
def test_setsid
return unless Process.respond_to?(:setsid)
return unless Process.respond_to?(:getsid)
IO.popen(["./ruby-trunk", "-e", <<EOS]) do|io|
Marshal.dump(Process.getsid, STDOUT)
newsid = Process.setsid
Marshal.dump(newsid, STDOUT)
STDOUT.flush
EOS
assert_equal(Marshal.load(io), Process.getsid)
assert_equal(Marshal.load(io), Process.getsid(io.pid))
end
end
end