summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-19 00:46:52 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-19 15:34:16 +0900
commitae07336529ee0955bb08b12eb69a90aa9ab4b9f9 (patch)
tree2f3ef64af9b1872272239371fd2d7df5f7b8629f
parent1c9381283e68b9021df2509fb64d663998d8cb5a (diff)
downloadruby-ae07336529ee0955bb08b12eb69a90aa9ab4b9f9.tar.gz
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.
-rw-r--r--process.c14
1 files 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)
#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("/");