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#20555: Emacs 24.2 vs 24.4 on Solaris: M-x shell and "tty => not a tty" Date: Thu, 11 Jun 2015 16:48:10 -0700 Organization: UCLA Computer Science Department Message-ID: <557A1E3A.3050509@cs.ucla.edu> References: <555198E2.30809@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030105060604000901030807" X-Trace: ger.gmane.org 1434066565 1475 80.91.229.3 (11 Jun 2015 23:49:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Jun 2015 23:49:25 +0000 (UTC) Cc: Georges Ko , 20555-done@debbugs.gnu.org, "Warren, John W CIV \(US\)" To: Akira Shirai Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 12 01:49:13 2015 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 1Z3CDf-0004be-LP for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Jun 2015 01:49:11 +0200 Original-Received: from localhost ([::1]:49062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3CDe-0005vW-TA for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Jun 2015 19:49:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3CDb-0005u2-9z for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2015 19:49:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3CDX-0007Nr-7e for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2015 19:49:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36667) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3CDX-0007Nj-3b for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2015 19:49:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z3CDW-00031K-NH for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2015 19:49:02 -0400 In-Reply-To: <555198E2.30809@cs.ucla.edu> Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Jun 2015 23:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 20555 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 20555@debbugs.gnu.org, eggert@cs.ucla.edu, eggert@cs.ucla.edu Original-Received: via spool by 20555-done@debbugs.gnu.org id=D20555.143406650711563 (code D ref 20555); Thu, 11 Jun 2015 23:49:02 +0000 Original-Received: (at 20555-done) by debbugs.gnu.org; 11 Jun 2015 23:48:27 +0000 Original-Received: from localhost ([127.0.0.1]:51127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z3CCw-00030Q-2X for submit@debbugs.gnu.org; Thu, 11 Jun 2015 19:48:27 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55985) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z3CCs-00030A-DH for 20555-done@debbugs.gnu.org; Thu, 11 Jun 2015 19:48:23 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 74349160781; Thu, 11 Jun 2015 16:48:16 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id cF0EC-9Z5r7u; Thu, 11 Jun 2015 16:48:13 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C20C1160782; Thu, 11 Jun 2015 16:48:13 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id KTXbsjGm8o2v; Thu, 11 Jun 2015 16:48:13 -0700 (PDT) Original-Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 9B15E160781; Thu, 11 Jun 2015 16:48:13 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.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:103848 Archived-At: This is a multi-part message in MIME format. --------------030105060604000901030807 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Akira Shirai, thanks for the info about grantpt and its internal setuid program; that made the problem obvious. I installed the attached patch into the Emacs master sources and am (perhaps optimistically) marking this bug as done. --------------030105060604000901030807 Content-Type: text/x-diff; name="0001-Fix-not-a-tty-bug-on-Solaris-10.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-not-a-tty-bug-on-Solaris-10.patch" >From 099cb9f7b8b1d00293298d947fc77b8c96120820 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 11 Jun 2015 16:41:36 -0700 Subject: [PATCH] Fix "not a tty" bug on Solaris 10 * configure.ac (PTY_OPEN): Define to plain 'open' on SVR4-derived hosts, so that the O_CLOEXEC flag isn't set. * src/process.c (allocate_pty): Set the O_CLOEXEC flag after calling PTY_TTY_NAME_SPRINTF, for the benefit of SVR4-derived hosts that call grantpt which does its work via a setuid subcommand (Bug#19191, Bug#19927, Bug#20555, Bug#20686). Also, set O_CLOEXEC even if PTY_OPEN is not defined, since it seems relevant in that case too. --- configure.ac | 5 ++++- src/process.c | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 9c6a74a..070b061 100644 --- a/configure.ac +++ b/configure.ac @@ -4397,14 +4397,17 @@ case $opsys in ;; sol2* ) - dnl On SysVr4, grantpt(3) forks a subprocess, so keep sigchld_handler() + dnl On SysVr4, grantpt(3) forks a subprocess, so do not use + dnl O_CLOEXEC when opening the pty, and keep the SIGCHLD handler dnl from intercepting that death. If any child but grantpt's should die dnl within, it should be caught after sigrelse(2). + AC_DEFINE(PTY_OPEN, [fd = open (pty_name, O_RDWR | O_NONBLOCK)]) AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptsname (int), *ptyname; int grantpt_result; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); grantpt_result = grantpt (fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (grantpt_result == -1 || unlockpt (fd) == -1 || !(ptyname = ptsname (fd))) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }]) ;; unixware ) dnl Comments are as per sol2*. + AC_DEFINE(PTY_OPEN, [fd = open (pty_name, O_RDWR | O_NONBLOCK)]) AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptsname (int), *ptyname; int grantpt_result; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); grantpt_result = grantpt (fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (grantpt_result == -1) fatal("could not grant slave pty"); if (unlockpt(fd) == -1) fatal("could not unlock slave pty"); if (!(ptyname = ptsname(fd))) fatal ("could not enable slave pty"); snprintf (pty_name, PTY_NAME_SIZE, "%s", ptyname); }]) ;; esac diff --git a/src/process.c b/src/process.c index 17fe708..b4f979f 100644 --- a/src/process.c +++ b/src/process.c @@ -658,22 +658,24 @@ allocate_pty (char pty_name[PTY_NAME_SIZE]) if (fd >= 0) { -#ifdef PTY_OPEN +#ifdef PTY_TTY_NAME_SPRINTF + PTY_TTY_NAME_SPRINTF +#else + sprintf (pty_name, "/dev/tty%c%x", c, i); +#endif /* no PTY_TTY_NAME_SPRINTF */ + /* Set FD's close-on-exec flag. This is needed even if PT_OPEN calls posix_openpt with O_CLOEXEC, since POSIX doesn't require support for that combination. + Do this after PTY_TTY_NAME_SPRINTF, which on some platforms + doesn't work if the close-on-exec flag is set (Bug#20555). Multithreaded platforms where posix_openpt ignores O_CLOEXEC (or where PTY_OPEN doesn't call posix_openpt) have a race condition between the PTY_OPEN and here. */ fcntl (fd, F_SETFD, FD_CLOEXEC); -#endif - /* Check to make certain that both sides are available - this avoids a nasty yet stupid bug in rlogins. */ -#ifdef PTY_TTY_NAME_SPRINTF - PTY_TTY_NAME_SPRINTF -#else - sprintf (pty_name, "/dev/tty%c%x", c, i); -#endif /* no PTY_TTY_NAME_SPRINTF */ + + /* Check to make certain that both sides are available. + This avoids a nasty yet stupid bug in rlogins. */ if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) { emacs_close (fd); -- 2.1.0 --------------030105060604000901030807--