… | |
… | |
25 | #include "config.h" |
25 | #include "config.h" |
26 | |
26 | |
27 | #include "ptytty.h" |
27 | #include "ptytty.h" |
28 | |
28 | |
29 | #include <stdlib.h> |
29 | #include <stdlib.h> |
30 | #include <cstdio> |
30 | #include <stdio.h> |
31 | #include <cstring> |
31 | #include <string.h> |
32 | |
32 | |
33 | #include <sys/types.h> |
33 | #include <sys/types.h> |
34 | #include <sys/stat.h> |
34 | #include <sys/stat.h> |
35 | #include <unistd.h> |
35 | #include <unistd.h> |
36 | #include <fcntl.h> |
36 | #include <fcntl.h> |
37 | |
37 | |
38 | #ifdef HAVE_SYS_IOCTL_H |
38 | #ifdef HAVE_SYS_IOCTL_H |
39 | # include <sys/ioctl.h> |
39 | # include <sys/ioctl.h> |
40 | #endif |
40 | #endif |
41 | #if defined(HAVE_SYS_STROPTS_H) |
41 | #ifdef HAVE_STROPTS_H |
42 | # include <sys/stropts.h> /* for I_PUSH */ |
|
|
43 | #endif |
|
|
44 | #if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H) |
|
|
45 | # include <stropts.h> |
42 | # include <stropts.h> |
46 | #endif |
43 | #endif |
47 | #if defined(HAVE_PTY_H) |
44 | #if defined(HAVE_PTY_H) |
48 | # include <pty.h> |
45 | # include <pty.h> |
49 | #elif defined(HAVE_LIBUTIL_H) |
46 | #elif defined(HAVE_LIBUTIL_H) |
… | |
… | |
353 | * Push STREAMS modules: |
350 | * Push STREAMS modules: |
354 | * ptem: pseudo-terminal hardware emulation module. |
351 | * ptem: pseudo-terminal hardware emulation module. |
355 | * ldterm: standard terminal line discipline. |
352 | * ldterm: standard terminal line discipline. |
356 | * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. |
353 | * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. |
357 | * |
354 | * |
358 | * After we push the STREAMS modules, the first open () on the slave side |
355 | * On Solaris, a process can acquire a controlling terminal in the |
359 | * should make the "ptem" (or "ldterm" depending upon either which OS |
356 | * following ways: |
360 | * version or which set of manual pages you have) module give us a |
357 | * - open() of /dev/ptmx or of a slave device without O_NOCTTY |
361 | * controlling terminal. We must already have close ()d the master side |
358 | * - I_PUSH ioctl() of the "ptem" or "ldterm" module on a slave device |
362 | * fd in this child process before we push STREAMS modules on because the |
359 | * The second case is problematic, because it cannot be disabled. |
363 | * documentation is really unclear about whether it is any close () on |
360 | * Fortunately, Solaris (10 and 11 at least) provides an undocumented |
364 | * the master side or the last close () - i.e. a proper STREAMS dismantling |
361 | * __IPUSH_NOCTTY ioctl which does not have this side-effect, so we |
365 | * close () - on the master side which causes a hang up to be sent |
362 | * use it if defined. See |
366 | * through - Geoff Wing |
363 | * https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/os/streamio.c#L3755 |
|
|
364 | * https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/ptem.c#L203 |
|
|
365 | * https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/io/ldterm.c#L794 |
|
|
366 | * Note that an open() of a slave device autoloads the modules, |
|
|
367 | * with __I_PUSH_NOCTTY, if xpg[46] mode is enabled (which requires |
|
|
368 | * linking /usr/lib/values-xpg[46].o). |
|
|
369 | * https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/sys/open.c#L173 |
367 | */ |
370 | */ |
|
|
371 | |
|
|
372 | #ifdef __I_PUSH_NOCTTY |
|
|
373 | # define PT_I_PUSH __I_PUSH_NOCTTY |
|
|
374 | #else |
|
|
375 | # define PT_I_PUSH I_PUSH |
|
|
376 | #endif |
|
|
377 | |
368 | #if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H) |
378 | #if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H) |
369 | if (isastream (tty) == 1) |
379 | if (isastream (tty) == 1) |
370 | # endif |
380 | # endif |
371 | { |
381 | { |
372 | ioctl (tty, I_PUSH, "ptem"); |
382 | ioctl (tty, PT_I_PUSH, "ptem"); |
373 | ioctl (tty, I_PUSH, "ldterm"); |
383 | ioctl (tty, PT_I_PUSH, "ldterm"); |
374 | ioctl (tty, I_PUSH, "ttcompat"); |
384 | ioctl (tty, PT_I_PUSH, "ttcompat"); |
375 | } |
385 | } |
376 | #endif |
386 | #endif |
377 | |
387 | |
378 | #if UTMP_SUPPORT |
388 | #if UTMP_SUPPORT |
379 | # if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
389 | # if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |