зеркало из https://github.com/github/ruby.git
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.
This commit is contained in:
Родитель
1c9381283e
Коммит
ae07336529
14
process.c
14
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("/");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче