diff --git a/configure.ac b/configure.ac index 4df51b415..abe5dafeb 100644 --- a/configure.ac +++ b/configure.ac @@ -417,6 +417,17 @@ fi # features that Autoconf doesn't tell us about # +dnl AC_CHECK_FUNCS uses C linkage, but sometimes (Solaris!) the behaviour is +dnl different with C++. +AC_MSG_CHECKING([if ctermid_r() available]) +AC_TRY_LINK( [ #include ], + [ char buf[L_ctermid]; char *foo = ctermid_r(buf); ], + [ AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_CTERMID_R, 1, Define to 1 if you have the `ctermid_r' function.) + ], + [AC_MSG_RESULT(no)], + ) + # # Check if struct winsize and TIOCGWINSZ exist # diff --git a/src/reader.cpp b/src/reader.cpp index 23edd6f5c..1a84a135a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1520,7 +1520,12 @@ static bool check_for_orphaned_process(unsigned long loop_count, pid_t shell_pgi if (!we_think_we_are_orphaned && loop_count % 128 == 0) { // Try reading from the tty; if we get EIO we are orphaned. This is sort of bad because it // may block. +#ifdef HAVE_CTERMID_R + char buf[L_ctermid]; + char *tty = ctermid_r(buf); +#else char *tty = ctermid(NULL); +#endif if (!tty) { wperror(L"ctermid"); exit_without_destructors(1);