This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Cygwin: pty: Disable clear screen for ssh sessions with -t option.


On 10/22/19 10:04 AM, Corinna Vinschen wrote:
> On Oct 22 09:20, Michael Haubenwallner wrote:
>> On 10/18/19 1:37 PM, Takashi Yano wrote:

>>> +      const char *term = getenv ("TERM");
>>> +      if (term && strcmp (term, "dumb") && !strstr (term, "emacs") &&
>>> +	  wcsstr (myself->progname, L"\\usr\\sbin\\sshd.exe"))

>> Again, my real problem does not utilize ssh at all, but is some python script
>> using multiple pty.openpty() to spawn commands inside, to allow for herding
>> all the subprocesses started by the commands (Ctrl-C or similar).

> In terms of clearing the screen at all, what's your opinion, Michael?

While I do not fully understand TTY handling, clearing the screen because
just opening a PTY doesn't feel correct.

To start with, attached is some python script where I do not expect to see
the initial clear screen code, but the one from /usr/bin/clear only.

This is what I see with python3 on *Linux*:

$ TERM=dumb python3 ./ptytest1.py 
select read: [3] except: []
read: b'/home/haubi\r\n'
select read: [3] except: []
quit: [Errno 5] Input/output error

$ TERM=xterm python3 ./ptytest1.py 
select read: [3] except: []
read: b'/home/haubi\r\n'
select read: [3] except: []
read: b'\x1b[H\x1b[2J\x1b[3J'
select read: [3] except: []
quit: [Errno 5] Input/output error

$ TERM=screen python3 ./ptytest1.py 
select read: [3] except: []
read: b'/home/haubi\r\n'
select read: [3] except: []
read: b'\x1b[H\x1b[J'
select read: [3] except: []
quit: [Errno 5] Input/output error

Note that the clear screen code does depend on the TERM value, and /usr/bin/clear
does even yell if TERM is empty, unknown or unset.

Also note that Linux select() does not yield the fd as exception when it was closed.

Interesting enough, cygwin-3.0.7 does dump core somewhere in between, so the real
python program probably does some additional setup I've not extracted yet.

/haubi/
#! /usr/bin/env python

import pty
import os
import select
import sys

(masterfd, slavefd) = pty.openpty()

if os.fork() == 0:
  os.close(masterfd)
  os.dup2(slavefd, 0)
  os.dup2(slavefd, 1)
  os.dup2(slavefd, 2)
  os.execv("/bin/sh", ["/bin/sh","-c","/bin/pwd;/usr/bin/clear"])
  sys.exit(0)

os.close(slavefd)

while True:
  (rlist, wlist, xlist) = select.select([masterfd], [], [masterfd], 100)
  print("select read:",rlist,"except:",xlist)
  if rlist:
    try:
      line = os.read(rlist[0], 1024)
      print("read:", line)
    except OSError as e:
      print("quit:",e)
      break
sys.exit(0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]