Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 Nov 2012 03:18:32 +0000 (19:18 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 Nov 2012 03:18:32 +0000 (19:18 -0800)
This removes code that has been obsolete since around 1990.
* admin/CPP-DEFINES (HAVE_SETPGID, HAVE_SETSID, SETPGRP_RELEASES_CTTY):
Remove; obsolete.
* configure.ac (setpgid, setsid): Assume their existence.
(AC_FUNC_GETPGRP, SETPGRP_RELEASES_CTTY): Remove; obsolete.
* src/callproc.c (Fcall_process):
* src/emacs.c (main):
* src/process.c (create_process):
* src/term.c (dissociate_if_controlling_tty):
Assume setsid exists.
* src/callproc.c (child_setup): Assume setpgid exists and behaves as
per POSIX.1-1988 or later.
* src/conf_post.h (setpgid) [!HAVE_SETPGID]: Remove.
* src/emacs.c (shut_down_emacs):
* src/sysdep.c (sys_suspend, init_foreground_group):
Assume getpgrp behaves as per POSIX.1-1998 or later.
* src/msdos.c (setpgrp): Remove.
(tcgetpgrp, setpgid, setsid): New functions.
* src/systty.h (EMACS_GETPGRP): Remove.  All callers now use getpgrp.
* src/term.c (no_controlling_tty): Remove; unused.
* src/w32proc.c (setpgrp): Remove.
(setsid, tcgetpgrp): New functions.

Fixes: debbugs:12800

14 files changed:
ChangeLog
admin/CPP-DEFINES
admin/ChangeLog
configure.ac
src/ChangeLog
src/callproc.c
src/conf_post.h
src/emacs.c
src/msdos.c
src/process.c
src/sysdep.c
src/systty.h
src/term.c
src/w32proc.c

index 83026bc..e8bff20 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2012-11-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid (Bug#12800).
+       * configure.ac (setpgid, setsid): Assume their existence.
+       (AC_FUNC_GETPGRP, SETPGRP_RELEASES_CTTY): Remove; obsolete.
+
        Simplify by assuming __fpending.
        Now that Emacs is using the gnulib fpending module,
        there's no need for Emacs to have a separate implementation.
index fb217fc..0a4c14c 100644 (file)
@@ -298,9 +298,7 @@ HAVE_SENDTO
 HAVE_SEQPACKET
 HAVE_SETITIMER
 HAVE_SETLOCALE
-HAVE_SETPGID
 HAVE_SETRLIMIT
-HAVE_SETSID
 HAVE_SHARED_GAME_DIR
 HAVE_SHUTDOWN
 HAVE_SIGNED_${GLTYPE}
@@ -432,7 +430,6 @@ PTY_OPEN
 PTY_TTY_NAME_SPRINTF
 PURESIZE
 RUN_TIME_REMAP
-SETPGRP_RELEASES_CTTY
 SETUP_SLAVE_PTY
 SIGALRM
 SIGCHLD
index c48faad..496e1c1 100644 (file)
@@ -1,5 +1,9 @@
 2012-11-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid (Bug#12800).
+       * CPP-DEFINES (HAVE_SETPGID, HAVE_SETSID, SETPGRP_RELEASES_CTTY):
+       Remove; obsolete.
+
        Simplify by assuming __fpending.
        * CPP-DEFINES (PENDING_OUTPUT_COUNT): Remove.
 
index 9a562a3..9146c66 100644 (file)
@@ -2871,9 +2871,9 @@ AC_SUBST(BLESSMAIL_TARGET)
 
 AC_CHECK_FUNCS(gethostname \
 closedir getrusage get_current_dir_name \
-lrand48 setsid \
+lrand48 \
 fpathconf select euidaccess getpagesize setlocale \
-utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \
+utimes getrlimit setrlimit getcwd shutdown getaddrinfo \
 strsignal setitimer \
 sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
 gai_strerror mkstemp getline getdelim fsync sync \
@@ -2916,8 +2916,6 @@ AC_CHECK_HEADERS_ONCE(sys/un.h)
 
 AC_FUNC_FSEEKO
 
-AC_FUNC_GETPGRP
-
 # UNIX98 PTYs.
 AC_CHECK_FUNCS(grantpt)
 
@@ -3964,8 +3962,6 @@ case $opsys in
   irix6-5)
     AC_DEFINE(PREFER_VSUSP, 1, [Define if process_send_signal should
       use VSUSP instead of VSWTCH.])
-    AC_DEFINE(SETPGRP_RELEASES_CTTY, 1, [Define if process.c:child_setup
-      should not call setpgrp.])
     ;;
 
   sol2-10)
index 29efd9f..6c51527 100644 (file)
@@ -1,5 +1,25 @@
 2012-11-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid (Bug#12800).
+       This removes code that has been obsolete since around 1990.
+       * callproc.c (Fcall_process):
+       * emacs.c (main):
+       * process.c (create_process):
+       * term.c (dissociate_if_controlling_tty):
+       Assume setsid exists.
+       * callproc.c (child_setup): Assume setpgid exists and behaves as
+       per POSIX.1-1988 or later.
+       * conf_post.h (setpgid) [!HAVE_SETPGID]: Remove.
+       * emacs.c (shut_down_emacs):
+       * sysdep.c (sys_suspend, init_foreground_group):
+       Assume getpgrp behaves as per POSIX.1-1998 or later.
+       * msdos.c (setpgrp): Remove.
+       (tcgetpgrp, setpgid, setsid): New functions.
+       * systty.h (EMACS_GETPGRP): Remove.  All callers now use getpgrp.
+       * term.c (no_controlling_tty): Remove; unused.
+       * w32proc.c (setpgrp): Remove.
+       (setsid, tcgetpgrp): New functions.
+
        Simplify by assuming __fpending.
        * dispnew.c: Include <fpending.h>, not <stdio_ext.h>.
        (update_frame_1): Use __fpending, not PENDING_OUTPUT_COUNT.
index c236f22..c7bbe36 100644 (file)
@@ -612,11 +612,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
        if (fd[0] >= 0)
          emacs_close (fd[0]);
 
-#ifdef HAVE_SETSID
        setsid ();
-#else
-       setpgid (0, 0);
-#endif
 
        /* Emacs ignores SIGPIPE, but the child should not.  */
        signal (SIGPIPE, SIG_DFL);
@@ -1286,11 +1282,7 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
   if (err != in && err != out)
     emacs_close (err);
 
-#if defined HAVE_SETPGID || ! (defined USG && defined SETPGRP_RELEASES_CTTY)
-  setpgid (pid, pid);
-#endif
-
-  /* setpgrp_of_tty is incorrect here; it uses input_fd.  */
+  setpgid (0, 0);
   tcsetpgrp (0, pid);
 
   /* execvp does not accept an environment arg so the only way
index da3c3bd..66390dd 100644 (file)
@@ -121,14 +121,6 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */
 
 #define emacs_raise(sig) msdos_fatal_signal (sig)
 
-#ifndef HAVE_SETPGID
-# ifdef USG
-#  define setpgid(pid, pgid) setpgrp ()
-# else
-#  define setpgid(pid, pgid) setpgrp (pid, pgid)
-# endif
-#endif
-
 /* Define one of these for easier conditionals.  */
 #ifdef HAVE_X_WINDOWS
 /* We need a little extra space, see ../../lisp/loadup.el and the
index 061c4b4..f12713b 100644 (file)
@@ -1101,9 +1101,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
         that it is not accessible to programs started from .emacs.  */
       fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC);
 
-#ifdef HAVE_SETSID
       setsid ();
-#endif
 #else /* DOS_NT */
       fprintf (stderr, "This platform does not support the -daemon flag.\n");
       exit (1);
@@ -1915,7 +1913,7 @@ shut_down_emacs (int sig, Lisp_Object stuff)
   /* If we are controlling the terminal, reset terminal modes.  */
 #ifndef DOS_NT
   {
-    pid_t pgrp = EMACS_GETPGRP (0);
+    pid_t pgrp = getpgrp ();
     pid_t tpgrp = tcgetpgrp (0);
     if ((tpgrp != -1) && tpgrp == pgrp)
       {
index 79f0be4..dd05a8b 100644 (file)
@@ -3927,8 +3927,10 @@ croak (char *badfunc)
 /*
  * A few unimplemented functions that we silently ignore.
  */
-int setpgrp (void) {return 0; }
+pid_t tcgetpgrp (int fd) { return 0; }
+int setpgid (int pid, int pgid) { return 0; }
 int setpriority (int x, int y, int z) { return 0; }
+pid_t setsid (void) { return 0; }
 
 #if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4
 ssize_t
index 3c0e53f..16600f9 100644 (file)
@@ -1739,7 +1739,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
       /* Make the pty be the controlling terminal of the process.  */
 #ifdef HAVE_PTYS
       /* First, disconnect its current controlling terminal.  */
-#ifdef HAVE_SETSID
       /* We tried doing setsid only if pty_flag, but it caused
         process_set_signal to fail on SGI when using a pipe.  */
       setsid ();
@@ -1752,12 +1751,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
          ioctl (xforkin, TIOCSCTTY, 0);
 #endif
        }
-#else /* not HAVE_SETSID */
-      /* It's very important to call setpgid here and no time
-        afterwards.  Otherwise, we lose our controlling tty which
-        is set when we open the pty. */
-      setpgid (0, 0);
-#endif /* not HAVE_SETSID */
 #if defined (LDISC1)
       if (pty_flag && xforkin >= 0)
        {
@@ -1790,22 +1783,15 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
              ioctl (j, TIOCNOTTY, 0);
              emacs_close (j);
            }
-#ifndef USG
-         /* In order to get a controlling terminal on some versions
-            of BSD, it is necessary to put the process in pgrp 0
-            before it opens the terminal.  */
-         setpgid (0, 0);
-#endif
        }
 #endif /* TIOCNOTTY */
 
 #if !defined (DONT_REOPEN_PTY)
 /*** There is a suggestion that this ought to be a
-     conditional on TIOCSPGRP,
-     or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
+     conditional on TIOCSPGRP, or !defined TIOCSCTTY.
      Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
      that system does seem to need this code, even though
-     both HAVE_SETSID and TIOCSCTTY are defined.  */
+     both TIOCSCTTY is defined.  */
        /* Now close the pty (if we had it open) and reopen it.
           This makes the pty the controlling terminal of the subprocess.  */
       if (pty_flag)
index 63eac5d..aa9d0f3 100644 (file)
@@ -452,7 +452,7 @@ sys_suspend (void)
 #if defined (SIGTSTP) && !defined (MSDOS)
 
   {
-    pid_t pgrp = EMACS_GETPGRP (0);
+    pid_t pgrp = getpgrp ();
     EMACS_KILLPG (pgrp, SIGTSTP);
   }
 
@@ -709,7 +709,7 @@ static pid_t inherited_pgroup;
 void
 init_foreground_group (void)
 {
-  pid_t pgrp = EMACS_GETPGRP (0);
+  pid_t pgrp = getpgrp ();
   inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
 }
 
index 0611511..80bcaed 100644 (file)
@@ -52,16 +52,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif /* not CDEL */
 #endif /* not _POSIX_VDISABLE */
 \f
-/* Manipulate a terminal's current process group.  */
-
-/* EMACS_GETPGRP (arg) returns the process group of the process.  */
-
-#if defined (GETPGRP_VOID)
-#  define EMACS_GETPGRP(x) getpgrp()
-#else /* !GETPGRP_VOID */
-#  define EMACS_GETPGRP(x) getpgrp(x)
-#endif /* !GETPGRP_VOID */
-\f
 /* Manipulate a TTY's input/output processing parameters.  */
 
 /* struct emacs_tty is a structure used to hold the current tty
index ffc5594..578c701 100644 (file)
@@ -133,10 +133,6 @@ enum no_color_bit
 
 static int max_frame_cols;
 
-/* Non-zero if we have dropped our controlling tty and therefore
-   should not open a frame on stdout. */
-static int no_controlling_tty;
-
 \f
 
 #ifdef HAVE_GPM
@@ -2918,36 +2914,9 @@ set_tty_hooks (struct terminal *terminal)
 static void
 dissociate_if_controlling_tty (int fd)
 {
-#ifndef DOS_NT
   pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */
-  if (pgid != -1)
-    {
-#if defined (USG5)
-      setpgrp ();
-      no_controlling_tty = 1;
-#elif defined (CYGWIN)
-      setsid ();
-      no_controlling_tty = 1;
-#else
-#ifdef TIOCNOTTY                /* Try BSD ioctls. */
-      sigset_t blocked;
-      sigemptyset (&blocked);
-      sigaddset (&blocked, SIGTTOU);
-      pthread_sigmask (SIG_BLOCK, &blocked, 0);
-      fd = emacs_open (DEV_TTY, O_RDWR, 0);
-      if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
-        {
-          no_controlling_tty = 1;
-        }
-      if (fd != -1)
-        emacs_close (fd);
-      pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
-#else
-# error "Unknown system."
-#endif  /* ! TIOCNOTTY */
-#endif  /* ! USG */
-    }
-#endif /* !DOS_NT */
+  if (0 <= pgid)
+    setsid ();
 }
 
 /* Create a termcap display on the tty device with the given name and
index adef765..f35a2da 100644 (file)
@@ -230,14 +230,14 @@ sigismember (const sigset_t *set, int signo)
   return (*set & (1U << signo)) != 0;
 }
 
-int
-setpgrp (int pid, int gid)
+pid_t
+getpgrp (void)
 {
-  return 0;
+  return getpid ();
 }
 
 pid_t
-getpgrp (void)
+tcgetpgrp (int fd)
 {
   return getpid ();
 }
@@ -248,6 +248,12 @@ setpgid (pid_t pid, pid_t pgid)
   return 0;
 }
 
+pid_t
+setsid (void)
+{
+  return getpid ();
+}
+
 /* Emulations of interval timers.
 
    Limitations: only ITIMER_REAL and ITIMER_PROF are supported.