summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2016-11-30 00:28:31 +0000
committerDamien Miller <djm@mindrot.org>2016-11-30 19:44:01 +1100
commit7fc4766ac78abae81ee75b22b7550720bfa28a33 (patch)
tree36cc862d4d493587327dc91f89cf96b22e8230ee /misc.c
parentc9f880c195c65f1dddcbc4ce9d6bfea7747debcc (diff)
upstream commit
On startup, check to see if sshd is already daemonized and if so, skip the call to daemon() and do not rewrite the PidFile. This means that when sshd re-execs itself on SIGHUP the process ID will no longer change. Should address bz#2641. ok djm@ markus@. Upstream-ID: 5ea0355580056fb3b25c1fd6364307d9638a37b9
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index 07d4179e4..65c9222aa 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.106 2016/10/23 22:04:05 dtucker Exp $ */ 1/* $OpenBSD: misc.c,v 1.107 2016/11/30 00:28:31 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -1251,3 +1251,21 @@ bind_permitted(int port, uid_t uid)
1251 return 0; 1251 return 0;
1252 return 1; 1252 return 1;
1253} 1253}
1254
1255/* returns 1 if process is already daemonized, 0 otherwise */
1256int
1257daemonized(void)
1258{
1259 int fd;
1260
1261 if ((fd = open(_PATH_TTY, O_RDONLY | O_NOCTTY)) >= 0) {
1262 close(fd);
1263 return 0; /* have controlling terminal */
1264 }
1265 if (getppid() != 1)
1266 return 0; /* parent is not init */
1267 if (getsid(0) != getpid())
1268 return 0; /* not session leader */
1269 debug3("already daemonized");
1270 return 1;
1271}