diff libinterp/octave.cc @ 17570:1c7d768c3847

don't fork if there is no controlling tty * configure.ac: Check for ctermid. * octave.cc (octave_fork_gui): Check for controlling tty and return false one is not found.
author John W. Eaton <jwe@octave.org>
date Fri, 04 Oct 2013 16:10:22 -0400
parents 1b388d922e6b
children c702371ff6df d63878346099
line wrap: on
line diff
--- a/libinterp/octave.cc
+++ b/libinterp/octave.cc
@@ -33,6 +33,7 @@
 
 #include <iostream>
 
+#include <fcntl.h>
 #include <getopt.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -1085,7 +1086,21 @@
 int
 octave_fork_gui (void)
 {
-  return ! no_fork_option;
+  bool have_ctty = false;
+
+#if ! (defined (__WIN32__) || defined (__APPLE__)) || defined (__CYGWIN__)
+
+#if defined (HAVE_CTERMID)
+  const char *ctty = ctermid (0);
+#else
+  const char *ctty = "/dev/tty";
+#endif
+
+  have_ctty = gnulib::open (ctty, O_RDWR, 0) > 0;
+
+#endif
+
+  return (have_ctty && ! no_fork_option);
 }
 
 DEFUN (isguirunning, args, ,