From 3978ead184e81157c61181066b08ce93c0dd81d2 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Tue, 21 Jan 2014 15:51:33 +0100 Subject: [PATCH] use a second fork to avoid a terminal after the setsid() we are the process leader. And as a process leader we are able to open a new terminal, even if we currently don't own one. So we do another fork and do not call setsid() and not become a process leader to avoid that. --- repmgrd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/repmgrd.c b/repmgrd.c index 6858996c..c16575fe 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -230,6 +230,24 @@ main(int argc, char **argv) log_err("Error in setsid(): %s\n", strerror(errno)); exit(ERR_SYS_FAILURE); } + + /* ensure that we are no longer able to open a terminal */ + pid = fork(); + + if(pid == -1) /* error case */ + { + log_err("Error in fork(): %s\n", strerror(errno)); + exit(ERR_SYS_FAILURE); + break; + } + + if (pid != 0) /* parent process */ + { + exit(0); + } + + /* a child just flows along */ + break; default: /* parent process */