[前][次][番号順一覧][スレッド一覧]

ruby-changes:25768

From: kosaki <ko1@a...>
Date: Sat, 24 Nov 2012 11:52:33 +0900 (JST)
Subject: [ruby-changes:25768] kosaki:r37825 (trunk): * process.c (proc_getsid): adds new method for getting session id.

kosaki	2012-11-24 11:51:24 +0900 (Sat, 24 Nov 2012)

  New Revision: 37825

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37825

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/configure.in
    trunk/process.c
    trunk/test/ruby/test_process.rb

Index: configure.in
===================================================================
--- configure.in	(revision 37824)
+++ configure.in	(revision 37825)
@@ -1554,7 +1554,7 @@
 	      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\
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37824)
+++ ChangeLog	(revision 37825)
@@ -1,3 +1,13 @@
+Sat Nov 24 11:47:14 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* 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@g...>
 
 	* thread.c (thread_create_core): don't use th->thread_id before
Index: process.c
===================================================================
--- process.c	(revision 37824)
+++ process.c	(revision 37825)
@@ -4219,6 +4219,40 @@
 #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 @@
     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);
Index: NEWS
===================================================================
--- NEWS	(revision 37824)
+++ NEWS	(revision 37825)
@@ -109,6 +109,10 @@
     * 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.
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 37824)
+++ test/ruby/test_process.rb	(revision 37825)
@@ -1558,4 +1558,19 @@
     }
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]