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

ruby-changes:73614

From: Nobuyoshi <ko1@a...>
Date: Mon, 19 Sep 2022 15:34:31 +0900 (JST)
Subject: [ruby-changes:73614] ae07336529 (master): Reduce fork calls in daemon

https://git.ruby-lang.org/ruby.git/commit/?id=ae07336529

From ae07336529ee0955bb08b12eb69a90aa9ab4b9f9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 19 Sep 2022 00:46:52 +0900
Subject: Reduce fork calls in daemon

The forked child process is a grandchild process from the viewpoint of
the process which invoked the caller process.  That means the child is
detached at that point, and it does not need to fork twice.
---
 process.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/process.c b/process.c
index 4465b36c51..a3d3bcbb78 100644
--- a/process.c
+++ b/process.c
@@ -7109,20 +7109,14 @@ rb_daemon(int nochdir, int noclose) https://github.com/ruby/ruby/blob/trunk/process.c#L7109
 #else
     int n;
 
-#define fork_daemon() \
-    switch (rb_fork_ruby(NULL)) { \
-      case -1: return -1; \
-      case 0:  break; \
-      default: _exit(EXIT_SUCCESS); \
+    switch (rb_fork_ruby(NULL)) {
+      case -1: return -1;
+      case 0:  break;
+      default: _exit(EXIT_SUCCESS);
     }
 
-    fork_daemon();
-
     if (setsid() < 0) return -1;
 
-    /* must not be process-leader */
-    fork_daemon();
-
     if (!nochdir)
         err = chdir("/");
 
-- 
cgit v1.2.1


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

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