diff src/process.c @ 109087:a089fae47976

Avoid erroneous syscalls * process.c (create_process): Avoid using invalid file descriptors. * callproc.c (child_setup): Avoid closing a file descriptor twice.
author Andreas Schwab <schwab@linux-m68k.org>
date Thu, 01 Jul 2010 01:07:11 +0200
parents d418516def73
children 2bc9a0c04c87
line wrap: on
line diff
--- a/src/process.c	Thu Jul 01 01:07:00 2010 +0200
+++ b/src/process.c	Thu Jul 01 01:07:11 2010 +0200
@@ -2038,7 +2038,7 @@
 	   process_set_signal to fail on SGI when using a pipe.  */
 	setsid ();
 	/* Make the pty's terminal the controlling terminal.  */
-	if (pty_flag)
+	if (pty_flag && xforkin >= 0)
 	  {
 #ifdef TIOCSCTTY
 	    /* We ignore the return value
@@ -2081,8 +2081,11 @@
 	    /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
 	       I can't test it since I don't have 4.3.  */
 	    int j = emacs_open ("/dev/tty", O_RDWR, 0);
-	    ioctl (j, TIOCNOTTY, 0);
-	    emacs_close (j);
+	    if (j >= 0)
+	      {
+		ioctl (j, TIOCNOTTY, 0);
+		emacs_close (j);
+	      }
 #ifndef USG
 	    /* In order to get a controlling terminal on some versions
 	       of BSD, it is necessary to put the process in pgrp 0