From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: michael.cadilhac@lrde.org (=?iso-8859-1?Q?Micha=EBl?= Cadilhac) Newsgroups: gmane.emacs.devel Subject: Re: delete-process bug Date: Sun, 28 May 2006 18:01:34 +0200 Organization: Epita/LRDE Message-ID: <87pshyqgtd.fsf@lrde.org> References: <87k69eyddj.fsf@lrde.org> <87fyj0r41g.fsf@lrde.org> <20060524112846.GA12046@agmartin.aq.upm.es> <87bqtmjrsh.fsf_-_@lrde.org> <87odxjakox.fsf@lrde.org> <8764jrlewm.fsf@lrde.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0404748499==" X-Trace: sea.gmane.org 1148832236 30725 80.91.229.2 (28 May 2006 16:03:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 28 May 2006 16:03:56 +0000 (UTC) Cc: Michael Mauger , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 28 18:03:48 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FkNk3-0003XN-EJ for ged-emacs-devel@m.gmane.org; Sun, 28 May 2006 18:03:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkNk2-000686-UV for ged-emacs-devel@m.gmane.org; Sun, 28 May 2006 12:03:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FkNhU-0005Xs-Ky for emacs-devel@gnu.org; Sun, 28 May 2006 12:01:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FkNhS-0005XH-MR for emacs-devel@gnu.org; Sun, 28 May 2006 12:01:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkNhS-0005XC-Dv for emacs-devel@gnu.org; Sun, 28 May 2006 12:01:06 -0400 Original-Received: from [62.39.139.2] (helo=kualalumpur.lrde.epita.fr) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FkNmp-00051a-3D for emacs-devel@gnu.org; Sun, 28 May 2006 12:06:39 -0400 Original-Received: from mahaena.lrde.epita.fr ([192.168.101.66] helo=mahaena.lrde) by kualalumpur.lrde.epita.fr with esmtp (Exim 4.50) id 1FkNhL-0005MR-OG; Sun, 28 May 2006 18:00:59 +0200 Original-To: Stefan Monnier Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEVWPh+Tai+5r5YKBAEU CQQzGAtiq7gjAAACR0lEQVQ4jW2UzW7lIAyFzVW8BzTZX5DmCZLuU2H2pMXv/ypzbK7aSh2kRCRf /HNsE0q7Sg+RQ7JFKaqtrRNAl5AIIKe6D5DBqgbmUAe5hBI1wIRFAHjeM0RKtZi7XVVEpb0BSNfA IddChChT5DildSLWOWhY5IEItMnncZgFcUAc/5jjwCMsDosRNdfKPDTFEdVBW8C+RebDb4N5Orio RhM1+11IJyx0ng2+LryFHBMPDQDYHrY6IfGuU3ouiXTQNE8LIJDKOWpNxERTFrggQwRPd7USUsTW fJ0XbR3bdj5KgBYy4SACpxDeUYEUAzLmtJ1iIrD2gczPq8Qomjhsh/RjGIgKIO8p7NITjwlx7WID nsnQe5NeuTvoBpi8LX6vLLOh5icjOHqBypgnuSp7M+RE1agbQKHQr5E2z1WObhYW4gMqeGQL7joM jCf2DxSk5ApADSYHfFF4igNfJZL1z0GKP0FN02s4XiDXr7V5P94W6I9v8MfBOQDmfwAaVYt+x8Da v4DJvX8BAdin3Knm5yMZYAO4ABDkDniZLLfi4P40gP1F0TPGZOu0CGwA1lcowxwlGy6A9705mD0V jHCxwVZT/hYdRJVUGZNlx6l7ScQBTluof6Wj6bsPYlvpwoTvXFD9gHPn2TZPF3ntI2ecxVrW5MrV XiCie5EeNa7BlWu/HNSkprDUva163PHxAv5jyGV7gVzyAghSKOTnat85UIYFICXbD2NV9rRiv0BS tKQsg6OHH4A15F1WW+UHKHHa32h6aPnAm3/pUcWp+WYnTQAAAABJRU5ErkJggg== User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55375 Archived-At: --===============0404748499== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable michael.cadilhac@lrde.org (Micha=EBl Cadilhac) writes: > Stefan Monnier writes: > >> BTW, did anyone actually test my code to make sure that it does indeed w= ork >> and fix the problem? >> >> Stefan > > As far as I tested, it doesn't work and freeze my Emacs. I'll > investigate today. I fixed what we discussed here. I found two bugs in your proposal: =2D the list was set to Qnil at the wrong place (wrong init) =2D `return' was used in the handler, but it could still have some process to treat (a continue would have been better but still wrong). A patch is attached. However, the whole thing still doesn't work ; Emacs freezes or prints this kind of error message:=20 Error in post-command-hook: (wrong-type-argument listp (nil DEAD . 18764377= )) I thought that the race condition could be the following: =2D delq makes some change on the list but not all, =2D It is interrupted by the handler, =2D The handler now has to deal with a malformed list. It's certainly a bug too, as with the delq I had some Abort in the handler of the form: #0 0xb7a45951 in kill () from /lib/libc.so.6 #1 0x080eb75c in abort () at emacs.c:464 #2 0x081536b2 in Fsignal (error_symbol=3D137610425, data=3D137557813) at e= val.c:1616 #3 0x081402ce in wrong_type_argument (predicate=3D137622913, value=3D14928= 2605) at data.c:124 #4 0x0815c175 in Fmember (elt=3D71112, list=3D149282605) at fns.c:1468 #5 0x0818577c in sigchld_handler (signo=3D17) at process.c:6390 Which I think I don't have without, however, it is not the only error, as with this line deleted, I still have the previous error and problems. For example, I don't think it's normal for emacs to receive a SIGPIPE #0 0xb7ba62b8 in write () from /lib/libpthread.so.0 #1 0x00000002 in ?? () #2 0x0810561e in emacs_write (fildes=3D12, buf=3D0x8d26178 "!\n", nbyte=3D= 12) at sysdep.c:3370 #3 0x08187afb in send_process (proc=3D150054228, buf=3D0x8d26178 "!\n", le= n=3D2, object=3D149437363) at process.c:5489 #4 0x08188274 in Fprocess_send_string (process=3D150054228, string=3D14943= 7363) at process.c:5643 #5 0x081534cb in Ffuncall (nargs=3D3, args=3D0xbfea69b4) at eval.c:2905 ... Alas, most of the backtraces only show Emacs blocked in select,=20 pthread things or wait_for_termination. If any hacker can help :-) Maybe it's not the good solution to keep traces of these. The other possibility (if we don't consider the wait_for_termination solution), is to store the PID of the synchronous process ; but I'm confused with compatibilities with DOS and Mac :-/ If we have the PID of the synchronous process, we can explicitly test it in sigchld_handler. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=process.patch Content-Transfer-Encoding: quoted-printable Index: src/process.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/process.c,v retrieving revision 1.481 diff -c -r1.481 process.c *** src/process.c 8 May 2006 05:19:42 -0000 1.481 =2D-- src/process.c 28 May 2006 15:29:27 -0000 *************** *** 778,783 **** =2D-- 778,792 ---- return proc; } =20=20 +=20 + /* Fdelete_process promises to immediately forget about the process, but = in + reality, Emacs needs to remember those processes until they have been + treated by sigchld_handler; otherwise this handler would consider the + process as being synchronous and say that the synchronous process is + dead. */ + static Lisp_Object deleted_pid_list; +=20 +=20 DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0, doc: /* Delete PROCESS: kill it and forget about it immediately. PROCESS may be a process, a buffer, the name of a process or buffer, or *************** *** 800,805 **** =2D-- 809,818 ---- else if (XINT (p->infd) >=3D 0) { Fkill_process (process, Qnil); + /* No problem storing the pid here, as it is still in Vprocess_alis= t. */ + deleted_pid_list =3D Fcons (make_fixnum_or_float (p->pid), + /* GC handled elements set to nil. */ + Fdelq (Qnil, deleted_pid_list)); /* Do this now, since remove_process will make sigchld_handler do n= othing. */ p->status =3D Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil)); *************** *** 6373,6445 **** =20=20 /* Find the process that signaled us, and record its status. */ =20=20 ! p =3D 0; ! for (tail =3D Vprocess_alist; GC_CONSP (tail); tail =3D XCDR (tail)) ! { ! proc =3D XCDR (XCAR (tail)); ! p =3D XPROCESS (proc); ! if (GC_EQ (p->childp, Qt) && p->pid =3D=3D pid) ! break; p =3D 0; ! } =20=20 ! /* Look for an asynchronous process whose pid hasn't been filled ! in yet. */ ! if (p =3D=3D 0) ! for (tail =3D Vprocess_alist; GC_CONSP (tail); tail =3D XCDR (tail)) ! { ! proc =3D XCDR (XCAR (tail)); ! p =3D XPROCESS (proc); ! if (p->pid =3D=3D -1) ! break; ! p =3D 0; ! } =20=20 ! /* Change the status of the process that was found. */ ! if (p !=3D 0) ! { ! union { int i; WAITTYPE wt; } u; ! int clear_desc_flag =3D 0; =20=20 ! XSETINT (p->tick, ++process_tick); ! u.wt =3D w; ! p->raw_status =3D u.i; ! p->raw_status_new =3D 1; !=20 ! /* If process has terminated, stop waiting for its output. */ ! if ((WIFSIGNALED (w) || WIFEXITED (w)) ! && XINT (p->infd) >=3D 0) ! clear_desc_flag =3D 1; =20=20 ! /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */ ! if (clear_desc_flag) ! { ! FD_CLR (XINT (p->infd), &input_wait_mask); ! FD_CLR (XINT (p->infd), &non_keyboard_wait_mask); ! } =20=20 ! /* Tell wait_reading_process_output that it needs to wake up and ! look around. */ ! if (input_available_clear_time) ! EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); ! } =20=20 ! /* There was no asynchronous process found for that id. Check ! if we have a synchronous process. */ ! else ! { ! synch_process_alive =3D 0; =20=20 ! /* Report the status of the synchronous process. */ ! if (WIFEXITED (w)) ! synch_process_retcode =3D WRETCODE (w); ! else if (WIFSIGNALED (w)) ! synch_process_termsig =3D WTERMSIG (w); !=20 ! /* Tell wait_reading_process_output that it needs to wake up and ! look around. */ ! if (input_available_clear_time) ! EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); } =20=20 /* On some systems, we must return right away. =2D-- 6386,6466 ---- =20=20 /* Find the process that signaled us, and record its status. */ =20=20 ! /* The process can have been deleted by Fdelete_process. */ ! tail =3D Fmember (make_fixnum_or_float (pid), deleted_pid_list); ! if (!NILP (tail)) ! Fsetcar (tail, Qnil); ! else ! { ! /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ p =3D 0; ! for (tail =3D Vprocess_alist; GC_CONSP (tail); tail =3D XCDR (tail)) ! { ! proc =3D XCDR (XCAR (tail)); ! p =3D XPROCESS (proc); ! if (GC_EQ (p->childp, Qt) && p->pid =3D=3D pid) ! break; ! p =3D 0; ! } =20=20 ! /* Look for an asynchronous process whose pid hasn't been filled ! in yet. */ ! if (p =3D=3D 0) ! for (tail =3D Vprocess_alist; GC_CONSP (tail); tail =3D XCDR (tail)) ! { ! proc =3D XCDR (XCAR (tail)); ! p =3D XPROCESS (proc); ! if (p->pid =3D=3D -1) ! break; ! p =3D 0; ! } =20=20 ! /* Change the status of the process that was found. */ ! if (p !=3D 0) ! { ! union { int i; WAITTYPE wt; } u; ! int clear_desc_flag =3D 0; =20=20 ! XSETINT (p->tick, ++process_tick); ! u.wt =3D w; ! p->raw_status =3D u.i; ! p->raw_status_new =3D 1; !=20 ! /* If process has terminated, stop waiting for its output. */ ! if ((WIFSIGNALED (w) || WIFEXITED (w)) ! && XINT (p->infd) >=3D 0) ! clear_desc_flag =3D 1; =20=20 ! /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. = */ ! if (clear_desc_flag) ! { ! FD_CLR (XINT (p->infd), &input_wait_mask); ! FD_CLR (XINT (p->infd), &non_keyboard_wait_mask); ! } =20=20 ! /* Tell wait_reading_process_output that it needs to wake up and ! look around. */ ! if (input_available_clear_time) ! EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); ! } =20=20 ! /* There was no asynchronous process found for that id. Check ! if we have a synchronous process. */ ! else ! { ! synch_process_alive =3D 0; =20=20 ! /* Report the status of the synchronous process. */ ! if (WIFEXITED (w)) ! synch_process_retcode =3D WRETCODE (w); ! else if (WIFSIGNALED (w)) ! synch_process_termsig =3D WTERMSIG (w); !=20 ! /* Tell wait_reading_process_output that it needs to wake up and ! look around. */ ! if (input_available_clear_time) ! EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); ! } } =20=20 /* On some systems, we must return right away. *************** *** 6843,6848 **** =2D-- 6864,6870 ---- FD_SET (0, &input_wait_mask); =20=20 Vprocess_alist =3D Qnil; + deleted_pid_list =3D Qnil; for (i =3D 0; i < MAXDESC; i++) { chan_process[i] =3D Qnil; --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable =20=20 =2D-=20 | Micha=EBl `Micha' Cadilhac | Mieux vaut se taire = | | Epita/LRDE Promo 2007 | Que de parler trop fort. = | | http://www.lrde.org/~cadilh_m | -- As de tr=E8fle = | `-- - JID: micha@amessage.be --' - -= -' --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFEeclgZYNf4qobZ7kRAmuTAJ0RJ8bFtq5lP1p7Sod3s0nbOpwxmACgy8Kx BuNdiQU6ZwU2WzovZaV5aP0= =2DVa -----END PGP SIGNATURE----- --==-=-=-- --===============0404748499== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============0404748499==--