summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sshd.c b/sshd.c
index ce4a493ef..fafcd3400 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.477 2016/11/29 03:54:50 dtucker Exp $ */ 1/* $OpenBSD: sshd.c,v 1.478 2016/11/30 00:28:31 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1343,7 +1343,7 @@ main(int ac, char **av)
1343 struct ssh *ssh = NULL; 1343 struct ssh *ssh = NULL;
1344 extern char *optarg; 1344 extern char *optarg;
1345 extern int optind; 1345 extern int optind;
1346 int r, opt, i, j, on = 1; 1346 int r, opt, i, j, on = 1, already_daemon;
1347 int sock_in = -1, sock_out = -1, newsock = -1; 1347 int sock_in = -1, sock_out = -1, newsock = -1;
1348 const char *remote_ip; 1348 const char *remote_ip;
1349 int remote_port; 1349 int remote_port;
@@ -1802,11 +1802,12 @@ main(int ac, char **av)
1802 log_init(__progname, options.log_level, options.log_facility, log_stderr); 1802 log_init(__progname, options.log_level, options.log_facility, log_stderr);
1803 1803
1804 /* 1804 /*
1805 * If not in debugging mode, and not started from inetd, disconnect 1805 * If not in debugging mode, not started from inetd and not already
1806 * from the controlling terminal, and fork. The original process 1806 * daemonized (eg re-exec via SIGHUP), disconnect from the controlling
1807 * exits. 1807 * terminal, and fork. The original process exits.
1808 */ 1808 */
1809 if (!(debug_flag || inetd_flag || no_daemon_flag)) { 1809 already_daemon = daemonized();
1810 if (!(debug_flag || inetd_flag || no_daemon_flag || already_daemon)) {
1810 1811
1811 if (daemon(0, 0) < 0) 1812 if (daemon(0, 0) < 0)
1812 fatal("daemon() failed: %.200s", strerror(errno)); 1813 fatal("daemon() failed: %.200s", strerror(errno));
@@ -1840,7 +1841,7 @@ main(int ac, char **av)
1840 * Write out the pid file after the sigterm handler 1841 * Write out the pid file after the sigterm handler
1841 * is setup and the listen sockets are bound 1842 * is setup and the listen sockets are bound
1842 */ 1843 */
1843 if (options.pid_file != NULL && !debug_flag) { 1844 if (options.pid_file != NULL && !debug_flag && !already_daemon) {
1844 FILE *f = fopen(options.pid_file, "w"); 1845 FILE *f = fopen(options.pid_file, "w");
1845 1846
1846 if (f == NULL) { 1847 if (f == NULL) {