Bug 245571

Summary: editors/emacs does not give a tty to sub-shells
Product: Ports & Packages Reporter: Bertrand Petit <bsdpr>
Component: Individual Port(s)Assignee: emacs (Nobody) <emacs>
Status: Closed Overcome By Events    
Severity: Affects Only Me CC: ashish, bsdpr, jrm
Priority: --- Flags: bugzilla: maintainer-feedback? (emacs)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
test that attempts to become the foreground process none

Description Bertrand Petit 2020-04-12 15:04:45 UTC
After upgrading emacs to emacs-26.3_3,3 (12.1-STABLE) from emacs-25.3_4,3 (11.2-STABLE), shells running under the control of shell-mode are no longer given a tty as their standard input, this prevents the shells to perform job control.

Bash complains as follows:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

sh is more terse but the effect is the same:
sh: can't access tty; job control turned off
Comment 1 Ashish SHUKLA freebsd_committer freebsd_triage 2020-04-13 04:33:26 UTC
(In reply to Bertrand Petit from comment #0)

I'm not able to reproduce it. This is what I did:

1. M-x shell RET

2. hostname!abbe:~ % lsof -n -p $$
lsof -n -p $$
COMMAND   PID USER   FD   TYPE                DEVICE SIZE/OFF NODE NAME
zsh     44814 abbe  cwd   VDIR 4148061892,1756814850      181    4 /usr/home/abbe
zsh     44814 abbe  rtd   VDIR  2317175353,554032710       25    4 /
zsh     44814 abbe    0u  VCHR                 0,116      0t6  116 /dev/pts/7
zsh     44814 abbe    1u  VCHR                 0,116      0t6  116 /dev/pts/7
zsh     44814 abbe    2u  VCHR                 0,116      0t6  116 /dev/pts/7
zsh     44814 abbe   10u  VCHR                 0,116    0t520  116 /dev/pts/7
zsh     44814 abbe   12r  VREG 1313969477,1458822731   182144  959 /usr/local/share/zsh/5.6.2/functions/Completion.zwc
zsh     44814 abbe   13r  VREG 1313969477,1458822731   194784 2055 /usr/local/share/zsh/5.6.2/functions/Misc.zwc
zsh     44814 abbe   14r  VREG 1313969477,1458822731   269528 1014 /usr/local/share/zsh/5.6.2/functions/Completion/Base.zwc


Could you describe in exact steps how to reproduce your problem ?

Thanks!
Comment 2 Bertrand Petit 2020-04-17 05:21:11 UTC
I use an emacs configured as shown bellow:

cd /usr/ports/editors/emacs ; make showconfig
===> The following configuration options are available for emacs-26.3_3,3:
     ACL=off: Access control list support
     DBUS=off: D-Bus IPC system support
     FCITXPATCH=off: Patch to pass C-Space to Fcitx input method
     GCONF=off: GConf configuration backend support
     GNUTLS=on: SSL/TLS support via GnuTLS
     GSETTINGS=off: GSettings API for application settings
     LCMS2=off: Little CMS 2.x support
     M17N=off: M17N support for text-shaping [implies XFT]
     MAILUTILS=off: Mail framework via GNU Mailutils
     MODULES=on: Dynamic modules support
     OTF=on: Opentype fonts [implies XFT]
     SCROLLBARS=off: Toolkit scroll-bars
     SOURCES=on: Install sources
     THREADS=on: Threading support
     XFT=on: Xft font library support
     XIM=off: X Input Method
     XML=on: XML format or parser support
     XWIDGETS=off: Experimental GTK widgets [implies GTK3]
====> Graphics support
     CAIRO=off: Experimental Cairo library support [implies PNG, XFT]
     GIF=on: GIF image format support
     JPEG=on: JPEG image format support
     MAGICK=off: ImageMagick image processing library support
     PNG=on: PNG image format support
     SVG=on: Scalable vector graphics support [implies PNG]
     TIFF=on: TIFF image format support
     XPM=on: XPM pixmap image format support
====> File notification support: you can only select none or one of them
     GFILE=off: File notification via gfile
     KQUEUE=on: File notification via kqueue
====> Sound (audio) support: you can only select none or one of them
     ALSA=off: ALSA audio architecture support
     OSS=on: Open Sound System support
====> X11 toolkit: you can only select none or one of them
     GTK2=off: GTK+ 2 GUI toolkit support
     GTK3=off: GTK+ 3 GUI toolkit support
     MOTIF=off: Motif widget library support
     XAW=on: Athena widgets
     XAW3D=off: Athena3D widgets
===> Use 'make config' to modify these settings

Then for testing I run it as:
emacs -q -f shell

In the shell buffer, I get this:

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
[/tmp]$ lsof -n -p $$
lsof: WARNING: device cache mismatch: /dev/random
COMMAND  PID   USER   FD   TYPE                DEVICE SIZE/OFF NODE NAME
bash    9443 elrond  cwd   VDIR 1999562137,1302847080       88    3 /tmp
bash    9443 elrond  rtd   VDIR 1953227420,2260328126       40    4 /
bash    9443 elrond    0u  VCHR                 0,176    0t194  176 /dev/pts/3
bash    9443 elrond    1u  VCHR                 0,176    0t194  176 /dev/pts/3
bash    9443 elrond    2u  VCHR                 0,176    0t194  176 /dev/pts/3
bash    9443 elrond  255u  VCHR                 0,176    0t194  176 /dev/pts/3
lsof: WARNING: /home/elrond/.lsof_memo3 was updated.
[/tmp]$ stty
speed 9600 baud;
lflags: -echo echoe echoke echoctl
oflags: -onlcr tab0
cflags: cs8 -parenb
erase   kill    
<undef> <undef> 

(emacs-version)
"GNU Emacs 26.3 (build 1, amd64-portbld-freebsd12.1, X toolkit)"
Comment 3 Ashish SHUKLA freebsd_committer freebsd_triage 2020-04-17 19:00:13 UTC
(In reply to Bertrand Petit from comment #2)

I'm not sure where that message from bash comes from. I tried it in a pristine bash shell (no ~/.bash* files), and am not able to reproduce it:

[abbe@host ~]$ yes >/dev/null
  C-c C-c
[abbe@host ~]$ yes >/dev/null &
[1] 68485
[abbe@host ~]$
[abbe@host ~]$
[abbe@host ~]$ yes >/dev/null&
[2] 68486
[abbe@host ~]$
[abbe@host ~]$
[abbe@host ~]$kill %1
[abbe@host ~]$ kill %2
[1]-  Terminated              yes > /dev/null
[abbe@host ~]$
[2]+  Terminated              yes > /dev/null
[abbe@host ~]$ yes | grep no &
[1] 68504
[abbe@host ~]$
[abbe@host ~]$
[abbe@host ~]$ kill %1
[abbe@host ~]$
[1]+  Terminated              yes | grep no
[abbe@host ~]$
-UUU:**--F1  *shell*        Bot L174767  (Shell:run) ----------


I can perform job control operations as you can see. Could you elaborate exactly the problem you are facing, like not able to kill child processes, or something ?

Thanks!
Comment 4 Bertrand Petit 2020-04-21 09:24:00 UTC
(In reply to Ashish SHUKLA from comment #3)
The problem is not related to bash or any other shell, /bin/sh is affected as well. To illustrate this further here is the output of a (attached) test command, first when executed by a shell in shell-mode, then directly run by comint, and eventually from an xterm


== using /bin/sh in shell-mode ==
$ ./ttytest 
/dev/pts/0 is a tty
tcsetpgrp fail, Inappropriate ioctl for device


== using comint ==
M-x comint-run ttytest
/dev/pts/8 is a tty
setpgid fail, Operation not permitted

Process ttytest exited abnormally with code 1


== using a /bin/sh running under an xterm ==
$ ./ttytest 
/dev/pts/1 is a tty
no error


I currently have no more ideas to explore this issue further.
Comment 5 Bertrand Petit 2020-04-21 09:26:17 UTC
Created attachment 213629 [details]
test that attempts to become the foreground process
Comment 6 Bertrand Petit 2020-04-21 13:17:12 UTC
The same emacs version running on an older 12.1-STABLE version does not exhibit the incorrect behavior. The bug could lie in the kernel or any library (base or ports) on which emacs depends.
Affected systems run svn rev 359586 (amd64).
The unaffected system run svn rev 354128 (armv7).
Comment 7 Joseph Mingrone freebsd_committer freebsd_triage 2020-05-03 01:34:42 UTC
Hello Bertrand,

Thanks for your report.

I also cannot reproduce on 12.1 and I do not have a 12-STABLE system available to test on.

If you have the time and motivation you could help us out by testing the following.

- We are preparing for the upcoming 27.1 release.  Could you test our WIP update?  https://reviews.freebsd.org/D23966

- Could you try editors/emacs-devel?

- Could you bisect commits from the STABLE branch to try and identify which change caused the problem for you?

Regards,

Joseph
Comment 8 Bertrand Petit 2020-05-05 03:01:21 UTC
(In reply to Joseph Mingrone from comment #7)

I did install emacs-27.0.91,3 after applying the diff you provided against the ports tree. I used the same 12-1 STABLE revision as before. Aside from incompatibilities in my .emacs, that version fully restored job control in shell mode when it is running either /bin/sh or /usr/local/bin/bash.

Likewise, from the same patched ports tree, I installed emacs-devel-28.0.50.20200416,2. This version also provide a properly configured tty to shell mode sub-processes. In both cases no other port was upgraded since the original report.

Since I may be the only one affected it is surely not worth examining this issue further.
Comment 9 Joseph Mingrone freebsd_committer freebsd_triage 2020-05-23 16:45:53 UTC
Thanks.  We'll close this then.  Of course, please re-open if necessary.