From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#12800: Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid. Date: Sun, 04 Nov 2012 11:25:55 -0800 Organization: UCLA Computer Science Department Message-ID: <5096C143.8090204@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1352057231 13220 80.91.229.3 (4 Nov 2012 19:27:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Nov 2012 19:27:11 +0000 (UTC) To: 12800@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 04 20:27:20 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TV5qm-0001ds-I6 for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Nov 2012 20:27:16 +0100 Original-Received: from localhost ([::1]:50507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5qd-0003qh-OR for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Nov 2012 14:27:07 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5qZ-0003qN-Pi for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:27:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TV5qX-0004gp-GX for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:27:03 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5qX-0004gj-BD for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:27:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TV5tS-0006CH-4k for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:30:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 04 Nov 2012 19:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12800 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.135205734823732 (code B ref -1); Sun, 04 Nov 2012 19:30:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Nov 2012 19:29:08 +0000 Original-Received: from localhost ([127.0.0.1]:49280 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TV5sZ-0006Ai-Cp for submit@debbugs.gnu.org; Sun, 04 Nov 2012 14:29:08 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57761) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TV5sW-0006Ab-LC for submit@debbugs.gnu.org; Sun, 04 Nov 2012 14:29:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TV5pZ-0004TA-LN for submit@debbugs.gnu.org; Sun, 04 Nov 2012 14:26:03 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:58727) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5pZ-0004T6-HU for submit@debbugs.gnu.org; Sun, 04 Nov 2012 14:26:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5pX-00033m-Om for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:26:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TV5pV-0004SL-M5 for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:25:59 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:34763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV5pV-0004SB-AY for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 14:25:57 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 1B1ED39E810E for ; Sun, 4 Nov 2012 11:25:56 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x3oVdrXOArDI for ; Sun, 4 Nov 2012 11:25:55 -0800 (PST) Original-Received: from [192.168.1.3] (pool-108-23-119-2.lsanca.fios.verizon.net [108.23.119.2]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 0F02339E8106 for ; Sun, 4 Nov 2012 11:25:55 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org 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 Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:66442 Archived-At: Tags: patch This is a proposed code-cleanup patch that arose from a discussion with Eli Zaretskii. Tested on GNU/Linux and on Solaris. === modified file 'ChangeLog' --- ChangeLog 2012-11-03 20:48:03 +0000 +++ ChangeLog 2012-11-04 19:22:04 +0000 @@ -1,3 +1,9 @@ +2012-11-04 Paul Eggert + + Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid. + * configure.ac (setpgid, setsid): Assume their existence. + (AC_FUNC_GETPGRP, SETPGRP_RELEASES_CTTY): Remove; obsolete. + 2012-11-03 Eli Zaretskii * lib/makefile.w32-in (GNULIBOBJS): Add $(BLD)/fpending.$(O) and === modified file 'admin/CPP-DEFINES' --- admin/CPP-DEFINES 2012-09-16 21:43:55 +0000 +++ admin/CPP-DEFINES 2012-11-04 19:22:04 +0000 @@ -298,9 +298,7 @@ HAVE_SEQPACKET HAVE_SETITIMER HAVE_SETLOCALE -HAVE_SETPGID HAVE_SETRLIMIT -HAVE_SETSID HAVE_SHARED_GAME_DIR HAVE_SHUTDOWN HAVE_SIGNED_${GLTYPE} @@ -433,7 +431,6 @@ PTY_TTY_NAME_SPRINTF PURESIZE RUN_TIME_REMAP -SETPGRP_RELEASES_CTTY SETUP_SLAVE_PTY SIGALRM SIGCHLD === modified file 'admin/ChangeLog' --- admin/ChangeLog 2012-11-03 19:19:05 +0000 +++ admin/ChangeLog 2012-11-04 19:22:04 +0000 @@ -1,3 +1,9 @@ +2012-11-04 Paul Eggert + + Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid. + * CPP-DEFINES (HAVE_SETPGID, HAVE_SETSID, SETPGRP_RELEASES_CTTY): + Remove; obsolete. + 2012-11-03 Glenn Morris * admin.el (set-copyright): Add msdos/sed2v2.inp. === modified file 'configure.ac' --- configure.ac 2012-11-02 00:48:12 +0000 +++ configure.ac 2012-11-04 19:22:04 +0000 @@ -2871,9 +2871,9 @@ 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 \ __fpending strsignal setitimer \ sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ gai_strerror mkstemp getline getdelim fsync sync \ @@ -2916,8 +2916,6 @@ AC_FUNC_FSEEKO -AC_FUNC_GETPGRP - # UNIX98 PTYs. AC_CHECK_FUNCS(grantpt) @@ -4058,8 +4056,6 @@ 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) === modified file 'src/ChangeLog' --- src/ChangeLog 2012-11-04 17:29:52 +0000 +++ src/ChangeLog 2012-11-04 19:22:04 +0000 @@ -1,5 +1,23 @@ 2012-11-04 Paul Eggert + Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid. + 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. + (setpgid, setsid): New functions. + * systty.h (EMACS_GETPGRP): Remove. All callers now use getpgrp. + * term.c (no_controlling_tty): Remove; unused. + Fix data-loss with --version (Bug#9574). * emacs.c (close_output_streams): Use strerror, not emacs_strerror, as we can't assume that emacs_strerror is initialized, and strerror === modified file 'src/callproc.c' --- src/callproc.c 2012-10-31 17:27:29 +0000 +++ src/callproc.c 2012-11-04 19:22:04 +0000 @@ -612,11 +612,7 @@ 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 @@ 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 === modified file 'src/conf_post.h' --- src/conf_post.h 2012-11-03 13:48:33 +0000 +++ src/conf_post.h 2012-11-04 19:22:04 +0000 @@ -121,14 +121,6 @@ #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 === modified file 'src/emacs.c' --- src/emacs.c 2012-11-04 17:29:52 +0000 +++ src/emacs.c 2012-11-04 19:22:04 +0000 @@ -1101,9 +1101,7 @@ 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 @@ /* 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) { === modified file 'src/msdos.c' --- src/msdos.c 2012-11-03 13:48:33 +0000 +++ src/msdos.c 2012-11-04 19:22:04 +0000 @@ -3927,8 +3927,9 @@ /* * A few unimplemented functions that we silently ignore. */ -int setpgrp (void) {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 === modified file 'src/process.c' --- src/process.c 2012-11-03 18:32:41 +0000 +++ src/process.c 2012-11-04 19:22:04 +0000 @@ -1739,7 +1739,6 @@ /* 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 @@ 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 @@ 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) === modified file 'src/sysdep.c' --- src/sysdep.c 2012-10-31 17:27:29 +0000 +++ src/sysdep.c 2012-11-04 19:22:04 +0000 @@ -452,7 +452,7 @@ #if defined (SIGTSTP) && !defined (MSDOS) { - pid_t pgrp = EMACS_GETPGRP (0); + pid_t pgrp = getpgrp (); EMACS_KILLPG (pgrp, SIGTSTP); } @@ -709,7 +709,7 @@ void init_foreground_group (void) { - pid_t pgrp = EMACS_GETPGRP (0); + pid_t pgrp = getpgrp (); inherited_pgroup = getpid () == pgrp ? 0 : pgrp; } === modified file 'src/systty.h' --- src/systty.h 2012-09-13 02:21:28 +0000 +++ src/systty.h 2012-11-04 19:22:04 +0000 @@ -63,16 +63,6 @@ #endif -/* 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 */ - /* Manipulate a TTY's input/output processing parameters. */ /* struct emacs_tty is a structure used to hold the current tty === modified file 'src/term.c' --- src/term.c 2012-11-03 05:59:17 +0000 +++ src/term.c 2012-11-04 19:22:04 +0000 @@ -133,10 +133,6 @@ 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; - #ifdef HAVE_GPM @@ -2918,36 +2914,9 @@ 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 === modified file 'src/w32proc.c' --- src/w32proc.c 2012-11-01 14:21:45 +0000 +++ src/w32proc.c 2012-11-04 19:22:04 +0000 @@ -230,12 +230,6 @@ return (*set & (1U << signo)) != 0; } -int -setpgrp (int pid, int gid) -{ - return 0; -} - pid_t getpgrp (void) { @@ -248,6 +242,12 @@ return 0; } +pid_t +setsid (void) +{ + return getpid (); +} + /* Emulations of interval timers. Limitations: only ITIMER_REAL and ITIMER_PROF are supported.