From 7e649856bce883738622cc3533ad808c6ea1a73f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 12 Jul 2013 07:31:42 -0700 Subject: [PATCH] Minor EBADF fixes. * process.c (create_process, wait_reading_process_output) [AIX]: Remove obsolete SIGHUP-related code, as Emacs no longer disables SIGHUP, so EBADF is no longer acceptable here (it wouldn't work in a multithreaded environment anyway). * sysdep.c (emacs_close): It's not dangerous to invoke emacs_close (-1). --- src/ChangeLog | 9 +++++++++ src/keyboard.c | 2 +- src/process.c | 21 +-------------------- src/sysdep.c | 6 +++--- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 75031274694..dfc74d7bb39 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-07-12 Paul Eggert + + Minor EBADF fixes. + * process.c (create_process, wait_reading_process_output) [AIX]: + Remove obsolete SIGHUP-related code, as Emacs no longer disables + SIGHUP, so EBADF is no longer acceptable here (it wouldn't work in + a multithreaded environment anyway). + * sysdep.c (emacs_close): It's not dangerous to invoke emacs_close (-1). + 2013-07-12 Andreas Schwab * image.c (x_find_image_file): Don't close a remote file handle. diff --git a/src/keyboard.c b/src/keyboard.c index 39535f5cd71..b6eb9e6ad15 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -7008,7 +7008,7 @@ tty_read_avail_input (struct terminal *terminal, { nread = emacs_read (fileno (tty->input), (char *) cbuf, n_to_read); /* POSIX infers that processes which are not in the session leader's - process group won't get SIGHUP's at logout time. BSDI adheres to + process group won't get SIGHUPs at logout time. BSDI adheres to this part standard and returns -1 from read (0) with errno==EIO when the control tty is taken away. Jeffrey Honig says this is generally safe. */ diff --git a/src/process.c b/src/process.c index bdab1f8cb8a..81be29082fc 100644 --- a/src/process.c +++ b/src/process.c @@ -1812,12 +1812,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) SETUP_SLAVE_PTY; } #endif /* SETUP_SLAVE_PTY */ -#ifdef AIX - /* On AIX, we've disabled SIGHUP above once we start a child on a pty. - Now reenable it in the child, so it will die when we want it to. */ - if (pty_flag) - signal (SIGHUP, SIG_DFL); -#endif #endif /* HAVE_PTYS */ signal (SIGINT, SIG_DFL); @@ -4632,20 +4626,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, if (xerrno == EINTR) no_avail = 1; else if (xerrno == EBADF) - { -#ifdef AIX - /* AIX doesn't handle PTY closure the same way BSD does. On AIX, - the child's closure of the pts gives the parent a SIGHUP, and - the ptc file descriptor is automatically closed, - yielding EBADF here or at select() call above. - So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF - in m/ibmrt-aix.h), and here we just ignore the select error. - Cleanup occurs c/o status_notify after SIGCHLD. */ - no_avail = 1; /* Cannot depend on values returned */ -#else - emacs_abort (); -#endif - } + emacs_abort (); else error ("select error: %s", emacs_strerror (xerrno)); } diff --git a/src/sysdep.c b/src/sysdep.c index a1f217b39a6..f614d8bc557 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2237,8 +2237,8 @@ posix_close (int fd, int flag) arriving. FD is always closed when this function returns, even when it returns -1. - Do not call this function if FD might already be closed, as that - might close an innocent victim opened by some other thread. */ + Do not call this function if FD is nonnegative and might already be closed, + as that might close an innocent victim opened by some other thread. */ int emacs_close (int fd) @@ -2250,7 +2250,7 @@ emacs_close (int fd) return r; if (!POSIX_CLOSE_RESTART || errno != EINTR) { - eassert (errno != EBADF); + eassert (errno != EBADF || fd < 0); return errno == EINPROGRESS ? 0 : r; } } -- 2.39.2