Subject: Re: Emacs can forget processes

From: Jorgen Schaefer <[email-masked]>
Date: Wed, 28 May 2014 22:53:46 +0200

On Tue, 27 May 2014 17:47:41 -0700
Paul Eggert <[email-masked]> wrote:

> I'm still suspicious of the interaction between pthread_sigmask and 
> vfork, though.  What happens if you do the following shell session, 
> where "$" is the shell prompt and "(gdb)" is the GDB prompt?

Assuming you meant in an Emacs with vfork enabled (i.e. the default):

> $ grep -i pthread src/config.h

/* Define to 1 if you have pthread (-lpthread). */
#define HAVE_PTHREAD 1
/* Define to 1 if you have the <pthread.h> header file. */
#define HAVE_PTHREAD_H 1
/* Define to 1 if the pthread_sigmask function can be used (despite bugs). */
/* #undef HAVE_PTHREAD_SIGMASK */
/* Define to 1 if pthread_sigmask(), when it fails, returns -1 and sets errno.
/* #undef PTHREAD_SIGMASK_FAILS_WITH_ERRNO */
/* Define to 1 if pthread_sigmask() may returns 0 and have no effect. */
/* #undef PTHREAD_SIGMASK_INEFFECTIVE */
/* Define to 1 if pthread_sigmask() unblocks signals incorrectly. */
/* #undef PTHREAD_SIGMASK_UNBLOCK_BUG */
#define PTY_TTY_NAME_SPRINTF { char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }
#ifndef _POSIX_PTHREAD_SEMANTICS
# define _POSIX_PTHREAD_SEMANTICS 1

> $ ldd src/bootstrap-emacs | grep -i pthread

        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
        (0x00007f0c1cf79000)

> $ gdb src/bootstrap-emacs
> (gdb) disas rpl_pthread_sigmask

No symbol "rpl_pthread_sigmask" in current context.

> (gdb) disas pthread_sigmask

Dump of assembler code for function pthread_sigmask:
   0x00000000005642c0 <+0>:     sub    $0x8,%rsp
   0x00000000005642c4 <+4>:     callq  0x405790 <sigprocmask@plt>
   0x00000000005642c9 <+9>:     xor    %edx,%edx
   0x00000000005642cb <+11>:    test   %eax,%eax
   0x00000000005642cd <+13>:    jns    0x5642d6 <pthread_sigmask+22>
   0x00000000005642cf <+15>:    callq  0x405a10 <__errno_location@plt>
   0x00000000005642d4 <+20>:    mov    (%rax),%edx
   0x00000000005642d6 <+22>:    mov    %edx,%eax
   0x00000000005642d8 <+24>:    add    $0x8,%rsp
   0x00000000005642dc <+28>:    retq   
End of assembler dump.

> (gdb) disas rpl_vfork

No symbol "rpl_vfork" in current context.

> (gdb) disas vfork

Dump of assembler code for function vfork@plt:
   0x0000000000405ed0 <+0>:     jmpq   *0x39e662(%rip)        # 0x7a4538 <[email-masked]>
   0x0000000000405ed6 <+6>:     pushq  $0xfc
   0x0000000000405edb <+11>:    jmpq   0x404f00
End of assembler dump.

> (gdb) disas rpl_fork

No symbol "rpl_fork" in current context.

> (gdb) disas fork

Dump of assembler code for function fork@plt:
   0x0000000000405cb0 <+0>:     jmpq   *0x39e772(%rip)        # 0x7a4428 <[email-masked]>
   0x0000000000405cb6 <+6>:     pushq  $0xda
   0x0000000000405cbb <+11>:    jmpq   0x404f00
End of assembler dump.

Regards,
Jorgen