From: Andreas Schwab Date: Wed, 30 Jun 2010 23:07:11 +0000 (+0200) Subject: Avoid erroneous syscalls X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~438^2~51^2~86 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ce8f5a9a47d15ff76f33648d2b016fe819d2493f;p=emacs.git Avoid erroneous syscalls * process.c (create_process): Avoid using invalid file descriptors. * callproc.c (child_setup): Avoid closing a file descriptor twice. --- diff --git a/src/ChangeLog b/src/ChangeLog index c86c285e091..0d17a8f21fb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-06-30 Andreas Schwab + + * process.c (create_process): Avoid using invalid file descriptors. + + * callproc.c (child_setup): Avoid closing a file descriptor twice. + 2010-06-30 Jan Djärv * xsettings.c (Ffont_get_system_normal_font, Ffont_get_system_font): diff --git a/src/callproc.c b/src/callproc.c index 82a5ebb90da..cd06ad5c2e8 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1244,8 +1244,10 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) dup2 (out, 1); dup2 (err, 2); emacs_close (in); - emacs_close (out); - emacs_close (err); + if (out != in) + emacs_close (out); + if (err != in && err != out) + emacs_close (err); #endif /* not MSDOS */ #endif /* not WINDOWSNT */ diff --git a/src/process.c b/src/process.c index 22b85ff5910..24f31220d0d 100644 --- a/src/process.c +++ b/src/process.c @@ -2038,7 +2038,7 @@ create_process (process, new_argv, current_dir) 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 @@ create_process (process, new_argv, current_dir) /* 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