From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jim Blandy Newsgroups: gmane.emacs.bugs Subject: PATCH: don't call strsignal in a signal handler Date: 16 Aug 2003 17:12:57 -0500 Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1061071934 26776 80.91.224.253 (16 Aug 2003 22:12:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 16 Aug 2003 22:12:14 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 17 00:12:12 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19o9HQ-000441-00 for ; Sun, 17 Aug 2003 00:12:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19o9HG-0000K2-PU for geb-bug-gnu-emacs@m.gmane.org; Sat, 16 Aug 2003 18:12:02 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19o9HE-0000Jo-0c for bug-gnu-emacs@gnu.org; Sat, 16 Aug 2003 18:12:00 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19o9Gh-0000BR-OT for bug-gnu-emacs@gnu.org; Sat, 16 Aug 2003 18:11:59 -0400 Original-Received: from [12.223.225.216] (helo=zenia.home) by monty-python.gnu.org with esmtp (Exim 4.20) id 19o9Gg-0000BG-TP for bug-gnu-emacs@gnu.org; Sat, 16 Aug 2003 18:11:26 -0400 Original-Received: by zenia.home (Postfix, from userid 5433) id 8F90E202C8; Sat, 16 Aug 2003 17:12:57 -0500 (EST) Original-To: bug-gnu-emacs@gnu.org Original-Lines: 323 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:5552 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:5552 I've posted this patch before, and it was approved in principle. I have a copyright assignment for Emacs on file with the FSF now, so I think this change can go in. 2003-05-30 Jim Blandy It's not safe to call strsignal in a signal handler, so have the SIGCHLD handler just return the signal number, and get the string when we construct Fcall_process's return value. * callproc.c (_GNU_SOURCE): #define this, to get strsignal declaration. (synch_process_death): Delete variable; replaced by... (synch_process_errno, synch_process_signo): ... new variables. (Fcall_process): Clear both of them, instead of just synch_process_death. In both Mac and MS-DOG cases, set either synch_process_errno or synch_process_retcode based on value returned by child_setup. Check all three vars and produce Fcall_process's return value as appropriate. * process.c (sigchld_handler): Don't look up the signal name here; just stash it in synch_process_signo instead. * w32proc.c (sys_wait): Set synch_process_retcode or synch_process_signo, depending on the wait status. * process.h (synch_process_death): Delete declaration. (synch_process_errno, synch_process_signo): New declarations. * sysdep.c (mkdir, rmdir): Check synch_process_errno and synch_process_signo for error returns, instead of synch_process_death. *** ./src/sysdep.c.~1~ 2002-10-18 20:21:14.000000000 -0500 --- ./src/sysdep.c 2003-05-30 18:20:52.000000000 -0500 *************** *** 3767,3773 **** wait_for_termination (cpid); } ! if (synch_process_death != 0 || synch_process_retcode != 0) { errno = EIO; /* We don't know why, but */ return -1; /* /bin/mkdir failed */ --- 3767,3775 ---- wait_for_termination (cpid); } ! if (synch_process_errno != 0 ! || synch_process_signo != 0 ! || synch_process_retcode != 0) { errno = EIO; /* We don't know why, but */ return -1; /* /bin/mkdir failed */ *************** *** 3813,3819 **** wait_for_termination (cpid); } ! if (synch_process_death != 0 || synch_process_retcode != 0) { errno = EIO; /* We don't know why, but */ return -1; /* /bin/rmdir failed */ --- 3815,3823 ---- wait_for_termination (cpid); } ! if (synch_process_signo != 0 ! || synch_process_errno != 0 ! || synch_process_retcode != 0) { errno = EIO; /* We don't know why, but */ return -1; /* /bin/rmdir failed */ *** ./src/process.h.~1~ 1998-04-29 16:47:23.000000000 -0500 --- ./src/process.h 2003-05-30 18:25:08.000000000 -0500 *************** *** 108,121 **** are waiting for it. */ extern int synch_process_alive; ! /* Communicate exit status of sync process to from sigchld_handler ! to Fcall_process. */ ! /* Nonzero => this is a string explaining death of synchronous subprocess. */ ! extern char *synch_process_death; ! /* If synch_process_death is zero, ! this is exit code of synchronous subprocess. */ extern int synch_process_retcode; /* The name of the file open to get a null file, or a data sink. --- 108,129 ---- are waiting for it. */ extern int synch_process_alive; ! /* Communicate exit status of sync process to from sigchld_handler to ! Fcall_process. Only one of synch_process_errno, ! synch_process_signo, and synch_process_retcode may be non-zero; if ! all of them are zero, then that's a successful exit (return code is ! zero). */ ! /* If non-zero, this is the errno code from the failure to run a ! synchronous subprocess. */ ! extern int synch_process_errno; ! /* If non-zero, this is the signal number the synchronous process ! received. */ ! extern int synch_process_signo; ! ! /* If synch_process_errno and synch_process_signo are zero, this is ! exit code of synchronous subprocess. */ extern int synch_process_retcode; /* The name of the file open to get a null file, or a data sink. *** ./src/callproc.c.~1~ 2002-07-08 19:02:36.000000000 -0500 --- ./src/callproc.c 2003-05-30 18:47:19.000000000 -0500 *************** *** 20,25 **** --- 20,26 ---- Boston, MA 02111-1307, USA. */ + #define _GNU_SOURCE /* to get strsignal declared with glibc 2 */ #include #include #include *************** *** 121,131 **** are waiting for it. */ int synch_process_alive; ! /* Nonzero => this is a string explaining death of synchronous subprocess. */ ! char *synch_process_death; ! /* If synch_process_death is zero, ! this is exit code of synchronous subprocess. */ int synch_process_retcode; extern Lisp_Object Vdoc_file_name; --- 122,143 ---- are waiting for it. */ int synch_process_alive; ! /* Communicate exit status of sync process to from sigchld_handler to ! Fcall_process. Only one of synch_process_errno, ! synch_process_signo, and synch_process_retcode may be non-zero; if ! all of them are zero, then that's a successful exit (return code is ! zero). */ ! ! /* If non-zero, this is the errno code from the failure to run a ! synchronous subprocess. */ ! int synch_process_errno; ! ! /* If non-zero, this is the signal number the synchronous process ! received. */ ! int synch_process_signo; ! /* If synch_process_errno and synch_process_signo are zero, this is ! exit code of synchronous subprocess. */ int synch_process_retcode; extern Lisp_Object Vdoc_file_name; *************** *** 496,502 **** /* These vars record information from process termination. Clear them now before process can possibly terminate, to avoid timing error if process terminates soon. */ ! synch_process_death = 0; synch_process_retcode = 0; if (NILP (error_file)) --- 508,515 ---- /* These vars record information from process termination. Clear them now before process can possibly terminate, to avoid timing error if process terminates soon. */ ! synch_process_errno = 0; ! synch_process_signo = 0; synch_process_retcode = 0; if (NILP (error_file)) *************** *** 558,569 **** /* Record that the synchronous process exited and note its termination status. */ synch_process_alive = 0; ! synch_process_retcode = pid; ! if (synch_process_retcode < 0) /* means it couldn't be exec'ed */ ! { ! synchronize_system_messages_locale (); ! synch_process_death = strerror (errno); ! } /* Since CRLF is converted to LF within `decode_coding', we can always open a file with binary mode. */ --- 571,580 ---- /* Record that the synchronous process exited and note its termination status. */ synch_process_alive = 0; ! if (pid < 0) /* means it couldn't be exec'ed */ ! synch_process_errno = errno; ! else ! synch_process_retcode = pid; /* Since CRLF is converted to LF within `decode_coding', we can always open a file with binary mode. */ *************** *** 586,597 **** /* Record that the synchronous process exited and note its termination status. */ synch_process_alive = 0; ! synch_process_retcode = pid; ! if (synch_process_retcode < 0) /* means it couldn't be exec'ed */ ! { ! synchronize_system_messages_locale (); ! synch_process_death = strerror (errno); ! } emacs_close (outfilefd); if (fd_error != outfilefd) --- 597,606 ---- /* Record that the synchronous process exited and note its termination status. */ synch_process_alive = 0; ! if (pid < 0) /* means it couldn't be exec'ed */ ! synch_process_errno = errno; ! else ! synch_process_retcode = pid; emacs_close (outfilefd); if (fd_error != outfilefd) *************** *** 964,973 **** unbind_to (count, Qnil); ! if (synch_process_death) ! return code_convert_string_norecord (build_string (synch_process_death), ! Vlocale_coding_system, 0); ! return make_number (synch_process_retcode); } #endif --- 973,996 ---- unbind_to (count, Qnil); ! if (synch_process_errno) ! { ! synchronize_system_messages_locale (); ! return code_convert_string_norecord (build_string (strerror (errno)), ! Vlocale_coding_system, 0); ! } ! else if (synch_process_signo) ! { ! char *signame; ! synchronize_system_messages_locale (); ! signame = strsignal (errno); ! if (! signame) ! signame = "unknown"; ! return code_convert_string_norecord (build_string (signame), ! Vlocale_coding_system, 0); ! } ! else ! return make_number (synch_process_retcode); } #endif *** ./src/process.c.~1~ 2003-03-16 17:06:56.000000000 -0500 --- ./src/process.c 2003-05-30 18:19:26.000000000 -0500 *************** *** 4275,4292 **** if (WIFEXITED (w)) synch_process_retcode = WRETCODE (w); else if (WIFSIGNALED (w)) ! { ! int code = WTERMSIG (w); ! char *signame; ! ! synchronize_system_messages_locale (); ! signame = strsignal (code); ! ! if (signame == 0) ! signame = "unknown"; ! ! synch_process_death = signame; ! } /* Tell wait_reading_process_input that it needs to wake up and look around. */ --- 4275,4281 ---- if (WIFEXITED (w)) synch_process_retcode = WRETCODE (w); else if (WIFSIGNALED (w)) ! synch_process_signo = WTERMSIG (w); /* Tell wait_reading_process_input that it needs to wake up and look around. */ *** ./src/w32proc.c.~1~ 2001-06-11 06:00:03.000000000 -0500 --- ./src/w32proc.c 2003-05-30 18:22:55.000000000 -0500 *************** *** 549,566 **** if (WIFEXITED (retval)) synch_process_retcode = WRETCODE (retval); else if (WIFSIGNALED (retval)) ! { ! int code = WTERMSIG (retval); ! char *signame; ! ! synchronize_system_messages_locale (); ! signame = strsignal (code); ! ! if (signame == 0) ! signame = "unknown"; ! ! synch_process_death = signame; ! } reap_subprocess (cp); } --- 549,555 ---- if (WIFEXITED (retval)) synch_process_retcode = WRETCODE (retval); else if (WIFSIGNALED (retval)) ! synch_process_signo = WTERMSIG (retval); reap_subprocess (cp); }