Skip to content

Commit b0899ee

Browse files
daztuckerdjmdjm
authored andcommitted
upstream commit
Factor out code to disconnect from controlling terminal into its own function. ok djm@ Upstream-ID: 39fd9e8ebd7222615a837312face5cc7ae962885
1 parent 54d0220 commit b0899ee

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

sshd.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshd.c,v 1.476 2016/09/28 16:33:07 djm Exp $ */
1+
/* $OpenBSD: sshd.c,v 1.477 2016/11/29 03:54:50 dtucker Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -123,10 +123,6 @@
123123
#include "version.h"
124124
#include "ssherr.h"
125125

126-
#ifndef O_NOCTTY
127-
#define O_NOCTTY 0
128-
#endif
129-
130126
/* Re-exec fds */
131127
#define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
132128
#define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
@@ -1807,20 +1803,11 @@ main(int ac, char **av)
18071803
* exits.
18081804
*/
18091805
if (!(debug_flag || inetd_flag || no_daemon_flag)) {
1810-
#ifdef TIOCNOTTY
1811-
int fd;
1812-
#endif /* TIOCNOTTY */
1806+
18131807
if (daemon(0, 0) < 0)
18141808
fatal("daemon() failed: %.200s", strerror(errno));
18151809

1816-
/* Disconnect from the controlling tty. */
1817-
#ifdef TIOCNOTTY
1818-
fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);
1819-
if (fd >= 0) {
1820-
(void) ioctl(fd, TIOCNOTTY, NULL);
1821-
close(fd);
1822-
}
1823-
#endif /* TIOCNOTTY */
1810+
disconnect_controlling_tty();
18241811
}
18251812
/* Reinitialize the log (because of the fork above). */
18261813
log_init(__progname, options.log_level, options.log_facility, log_stderr);

sshpty.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshpty.c,v 1.30 2015/07/30 23:09:15 djm Exp $ */
1+
/* $OpenBSD: sshpty.c,v 1.31 2016/11/29 03:54:50 dtucker Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -238,3 +238,17 @@ pty_setowner(struct passwd *pw, const char *tty)
238238
}
239239
}
240240
}
241+
242+
/* Disconnect from the controlling tty. */
243+
void
244+
disconnect_controlling_tty(void)
245+
{
246+
#ifdef TIOCNOTTY
247+
int fd;
248+
249+
if ((fd = open(_PATH_TTY, O_RDWR | O_NOCTTY)) >= 0) {
250+
(void) ioctl(fd, TIOCNOTTY, NULL);
251+
close(fd);
252+
}
253+
#endif /* TIOCNOTTY */
254+
}

sshpty.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshpty.h,v 1.12 2010/01/09 05:04:24 djm Exp $ */
1+
/* $OpenBSD: sshpty.h,v 1.13 2016/11/29 03:54:50 dtucker Exp $ */
22

33
/*
44
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -25,3 +25,4 @@ void pty_release(const char *);
2525
void pty_make_controlling_tty(int *, const char *);
2626
void pty_change_window_size(int, u_int, u_int, u_int, u_int);
2727
void pty_setowner(struct passwd *, const char *);
28+
void disconnect_controlling_tty(void);

0 commit comments

Comments
 (0)