(init_subshell): use openpty() to open master/slave devices for subshell.

Thanks Jesse R. Gorzinski <jgorzins@us.ibm.com> for the original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2018-09-04 13:52:10 +03:00
parent 3909ef1bc5
commit a7ff88d24c
2 changed files with 33 additions and 0 deletions

View File

@ -24,6 +24,15 @@ AC_DEFUN([mc_SUBSHELL], [
if test "x$result" != xno; then if test "x$result" != xno; then
AC_DEFINE(ENABLE_SUBSHELL, 1, [Define to enable subshell support]) AC_DEFINE(ENABLE_SUBSHELL, 1, [Define to enable subshell support])
dnl openpty() can simplify opening of master/slave devices for subshell
AC_CHECK_HEADERS([pty.h libutil.h util.h])
AC_CHECK_FUNCS(openpty,,
AC_CHECK_LIB(util,openpty,
[AC_DEFINE(HAVE_OPENPTY)
LIBS="$LIBS -lutil"]
)
)
fi fi
AC_MSG_RESULT([$result]) AC_MSG_RESULT([$result])

View File

@ -74,6 +74,20 @@
#include <stropts.h> /* For I_PUSH */ #include <stropts.h> /* For I_PUSH */
#endif /* HAVE_STROPTS_H */ #endif /* HAVE_STROPTS_H */
#ifdef HAVE_OPENPTY
/* includes for openpty() */
#if HAVE_PTY_H
#include <pty.h>
#endif
#if HAVE_UTIL_H
#include <util.h>
#endif
/* <sys/types.h> is a prerequisite of <libutil.h> on FreeBSD 8.0. */
#if HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#endif /* HAVE_OPENPTY */
#include "lib/global.h" #include "lib/global.h"
#include "lib/unixcompat.h" #include "lib/unixcompat.h"
@ -1026,6 +1040,15 @@ init_subshell (void)
/* FIXME: We may need to open a fresh pty each time on SVR4 */ /* FIXME: We may need to open a fresh pty each time on SVR4 */
#ifdef HAVE_OPENPTY
if (openpty (&mc_global.tty.subshell_pty, &subshell_pty_slave, NULL, NULL, NULL))
{
fprintf (stderr, "Cannot open master and slave sides of pty: %s\n",
unix_error_string (errno));
mc_global.tty.use_subshell = FALSE;
return;
}
#else
mc_global.tty.subshell_pty = pty_open_master (pty_name); mc_global.tty.subshell_pty = pty_open_master (pty_name);
if (mc_global.tty.subshell_pty == -1) if (mc_global.tty.subshell_pty == -1)
{ {
@ -1041,6 +1064,7 @@ init_subshell (void)
mc_global.tty.use_subshell = FALSE; mc_global.tty.use_subshell = FALSE;
return; return;
} }
#endif /* HAVE_OPENPTY */
/* Create a pipe for receiving the subshell's CWD */ /* Create a pipe for receiving the subshell's CWD */