https://bugzilla.mindrot.org/show_bug.cgi?id=2641

--- Comment #5 from Jakub Jelen <[email protected]> ---
The test if the process is daemon passes for every process that is run
as a systemd service so it does not solve the problem for us. As the
result with the pushed change the 7.4p1 will not write PID file when
running as a systemd service.

I would consider a bit different approach. We can remember if we
already called daemon() using environment variable and prevent the
repeated calls if this variable is already set. This finally made it
working for me. The patch can look somehow like this:

diff -up openssh-7.4p1/misc.c.daemon openssh-7.4p1/misc.c
--- openssh-7.4p1/misc.c.daemon 2017-02-03 13:08:14.751282516 +0100
+++ openssh-7.4p1/misc.c        2017-02-03 13:08:14.778282474 +0100
@@ -1273,6 +1273,9 @@ daemonized(void)
                return 0;       /* parent is not init */
        if (getsid(0) != getpid())
                return 0;       /* not session leader */
+       if (getenv("_SSH_DAEMONIZED") == NULL)
+               return 0;       /* already reexeced */
+
        debug3("already daemonized");
        return 1;
 }
diff -up openssh-7.4p1/sshd.c.daemon openssh-7.4p1/sshd.c
--- openssh-7.4p1/sshd.c.daemon 2017-02-03 13:08:14.755282510 +0100
+++ openssh-7.4p1/sshd.c        2017-02-03 13:09:29.765164356 +0100
@@ -1866,6 +1866,7 @@ main(int ac, char **av)
                if (daemon(0, 0) < 0)
                        fatal("daemon() failed: %.200s",
strerror(errno));

+               setenv("_SSH_DAEMONIZED", "1", 1);
                disconnect_controlling_tty();
        }
        /* Reinitialize the log (because of the fork above). */

-- 
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
[email protected]
https://lists.mindrot.org/mailman/listinfo/openssh-bugs

Reply via email to