all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: michael.cadilhac@lrde.org (Michaël Cadilhac)
Cc: Agustin Martin <agustin.martin@hispalinux.es>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel@gnu.org
Subject: Re: delete-process bug
Date: Sun, 28 May 2006 23:36:54 +0200	[thread overview]
Message-ID: <87odxhq1ah.fsf@lrde.org> (raw)
In-Reply-To: <m3bqthg8a9.fsf@kfs-l.imdomain.dk> (Kim F. Storm's message of "Sun, 28 May 2006 23:15:58 +0200")


[-- Attachment #1.1.1: Type: text/plain, Size: 1498 bytes --]

storm@cua.dk (Kim F. Storm) writes:

> michael.cadilhac@lrde.org (Michaël Cadilhac) writes:
>
>> (Final ?) patch attached.
>
> Looks good to me!
>
> I wonder whether the pid should be added to deleted_pid_list if SIGCHLD is
> not defined?  In that case, it would be a memory leak...

Oh, hmm... About memory leaks hrm...

In fact, there is already a configuration that would lead to the non
deletion of the PID from the list:

- Call to delete_process,
- Interrupted by a signal before inserting  in deleted_processes_list ,
- Deletion from  process_alist,
- Then delete_process continues by... inserting the dead PID in the
    deleted_processes_list.

I forgot to tell about it in my previous post. Sorry.

Any idea for fixing this ? Putting the insertion in
deleted_processes_list BEFORE the Kill would limit this leak, but not
completely avoid it.


> But I also wonder if any of the async process stuff actually works
> without SIGCHLD ?!?   Are there any systems which support async processes
> but don't have SIGCHLD?

Indeed, I  don't know any system  in which SIGCHLD is  not defined and
that  can  use sub  processes  (are  we  talking about  a  one-process
system ?!).

But it would be cleaner, indeed, to define the whole thing iff SIGCHLD
is defined.

I modified the patch for that (including in sigchld_handler and so
because the list is not defined if SIGCHLD is not), and to make the
insertion in deleted_processes_list before the kill.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: process.patch --]
[-- Type: text/x-patch, Size: 3541 bytes --]

Index: src/process.c
===================================================================
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
--- src/process.c	28 May 2006 21:35:32 -0000
***************
*** 778,783 ****
--- 778,793 ----
    return proc;
  }
  
+ 
+ #ifdef SIGCHLD
+ /* 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;
+ #endif
+ 
  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
***************
*** 799,804 ****
--- 809,820 ----
      }
    else if (XINT (p->infd) >= 0)
      {
+ #ifdef SIGCHLD
+       /* No problem storing the pid here, as it is still in Vprocess_alist.  */
+       deleted_pid_list = Fcons (make_fixnum_or_float (p->pid),
+ 				/* GC treated elements set to nil.  */
+ 				Fdelq (Qnil, deleted_pid_list));
+ #end
        Fkill_process (process, Qnil);
        /* Do this now, since remove_process will make sigchld_handler do nothing.  */
        p->status
***************
*** 6373,6378 ****
--- 6389,6405 ----
  
        /* Find the process that signaled us, and record its status.  */
  
+ #ifdef SIGCHLD
+       /* The process can have been deleted by Fdelete_process.  */
+       tail = Fmember (make_fixnum_or_float (pid), deleted_pid_list);
+       if (!NILP (tail))
+ 	{
+ 	  Fsetcar (tail, Qnil);
+ 	  goto sigchld_end_of_loop;
+ 	}
+ #endif
+ 
+       /* Otherwise, if it is asynchronous, it is in Vprocess_alist.  */
        p = 0;
        for (tail = Vprocess_alist; GC_CONSP (tail); tail = XCDR (tail))
  	{
***************
*** 6424,6431 ****
  	    EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
  	}
  
! 	/* There was no asynchronous process found for that id.  Check
! 	   if we have a synchronous process.  */
        else
  	{
  	  synch_process_alive = 0;
--- 6451,6458 ----
  	    EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
  	}
  
!       /* There was no asynchronous process found for that pid: we have
! 	 a synchronous process.  */
        else
  	{
  	  synch_process_alive = 0;
***************
*** 6442,6447 ****
--- 6469,6478 ----
  	    EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
  	}
  
+ 
+     sigchld_end_of_loop:
+       ;
+ 
        /* On some systems, we must return right away.
  	 If any more processes want to signal us, we will
  	 get another signal.
***************
*** 6843,6848 ****
--- 6874,6882 ----
    FD_SET (0, &input_wait_mask);
  
    Vprocess_alist = Qnil;
+ #ifdef SIGCHLD
+   deleted_pid_list = Qnil;
+ #endif
    for (i = 0; i < MAXDESC; i++)
      {
        chan_process[i] = Qnil;
***************
*** 6981,6986 ****
--- 7015,7023 ----
    staticpro (&Qlast_nonmenu_event);
  
    staticpro (&Vprocess_alist);
+ #ifdef SIGCHLD
+   staticpro (&deleted_pid_list);
+ #endif
  
    DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
  	       doc: /* *Non-nil means delete processes immediately when they exit.

[-- Attachment #1.1.3: Type: text/plain, Size: 325 bytes --]



-- 
 |      Michaël `Micha' Cadilhac   |   Pour les 35-40 ans, l'humour         |
 |         Epita/LRDE Promo 2007   |        c'est une plus-value.           |
 | http://www.lrde.org/~cadilh_m   |           -- Guillaume L.              |
 `--  -   JID: micha@amessage.be --'                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2006-05-28 21:36 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-24 19:36 Ispell loads dict twice Michaël Cadilhac
2006-04-26 10:14 ` Agustin Martin
2006-04-26 21:58   ` Michaël Cadilhac
2006-05-23 18:26 ` Michaël Cadilhac
2006-05-24 11:28   ` Agustin Martin
2006-05-25 10:57     ` delete-process bug (was: Ispell loads dict twice.) Michaël Cadilhac
2006-05-25 12:19       ` Agustin Martin
2006-05-25 14:55       ` delete-process bug Stefan Monnier
2006-05-25 14:59         ` David Kastrup
2006-05-25 15:17         ` Michaël Cadilhac
2006-05-25 15:26           ` David Kastrup
2006-05-25 19:40           ` Stefan Monnier
2006-05-25 23:51         ` Kim F. Storm
2006-05-26  4:49           ` Richard Stallman
2006-05-26 13:03           ` Stefan Monnier
2006-05-26  2:22         ` Richard Stallman
2006-05-26 11:29           ` Michaël Cadilhac
2006-05-27  3:36             ` Richard Stallman
2006-05-26 13:10           ` Stefan Monnier
2006-05-26 17:27             ` Michael Mauger
2006-05-27  9:19               ` Michaël Cadilhac
2006-05-27 14:16                 ` Stefan Monnier
2006-05-27 14:29                   ` Michaël Cadilhac
2006-05-28 16:01                     ` Michaël Cadilhac
2006-05-28 18:00                       ` Stefan Monnier
2006-05-28 18:32                         ` Michaël Cadilhac
2006-05-28 19:48                           ` Stefan Monnier
2006-05-28 20:26                             ` Michaël Cadilhac
2006-05-28 21:15                               ` Kim F. Storm
2006-05-28 21:36                                 ` Michaël Cadilhac [this message]
2006-05-28 23:54                                   ` Stefan Monnier
2006-05-29 11:39                                     ` Michaël Cadilhac
2006-05-29  8:22                                   ` Kim F. Storm
2006-05-29  8:50                                     ` David Kastrup
2006-05-29 19:04                                       ` Eli Zaretskii
2006-05-29 19:27                                     ` Eli Zaretskii
2006-05-29 21:42                                       ` Kim F. Storm
2006-05-29 22:08                                         ` Eli Zaretskii
2006-05-29  3:32                                 ` Eli Zaretskii
2006-05-29  8:14                                   ` Kim F. Storm
2006-05-29 10:59                                     ` Michaël Cadilhac
2006-05-29 19:25                                     ` Eli Zaretskii
2006-05-29 20:04                                       ` Michaël Cadilhac
2006-05-29 21:24                                         ` Eli Zaretskii
2006-05-29 21:42                                           ` Michaël Cadilhac
2006-05-29 22:11                                             ` Eli Zaretskii
2006-05-29 22:32                                               ` Michaël Cadilhac
2006-05-30 12:11                                         ` Kim F. Storm
2006-05-30 12:42                                           ` Michaël Cadilhac
2006-05-30 14:26                                             ` Kim F. Storm
2006-05-30 15:13                                               ` Michaël Cadilhac
2006-06-01 14:06                                                 ` Kim F. Storm
2006-06-01 14:20                                                   ` Michaël Cadilhac
2006-06-01 14:29                                                     ` Kim F. Storm
2006-06-01 16:05                                                       ` Michaël Cadilhac
2006-06-02  7:46                                                         ` Kim F. Storm
2006-06-01 16:41                                                     ` Agustin Martin
2006-06-01 16:55                                                       ` Michaël Cadilhac
2006-05-29 23:07                               ` Agustin Martin
2006-05-25 23:52       ` delete-process bug (was: Ispell loads dict twice.) Kim F. Storm
2006-06-06 20:45   ` Ispell loads dict twice Michaël Cadilhac
2006-06-09 13:02     ` Kim F. Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87odxhq1ah.fsf@lrde.org \
    --to=michael.cadilhac@lrde.org \
    --cc=agustin.martin@hispalinux.es \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.