[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making terminal available for TIOCSCTTY
On Thu, Jan 09, 2003 at 02:13:42PM -0800, Ed Vance wrote:
> On Thu, Jan 09, 2003 at 12:42 PM, Jan Hudec wrote:
> >
> > On Thu, Jan 09, 2003 at 12:29:45PM -0800, Ed Vance wrote:
> > > Hi Jan,
> > >
> > > IIRC, a process must first have no controlling tty to get a
> > > new one assigned on the next open of a tty. Controlling tty
> > > assignments are sticky and are unaffected by closing. Once
> > > assigned, the assignment persists even if the process
> > > closes or redirects all streams open to that tty. For
> > > example, a process still receives signals generated the
> > > keyboard of its controlling tty, even if all streams have
> > > been redirected. By default, a child process inherits the
> > > parent's controlling tty assignment. So, the child process
> > > must use the TIOCNOTTY ioctl on its controlling tty to
> > > remove the controlling tty assignment. It does not matter
> > > that a stream is already open to the previous controlling
> > > tty. Then, the next open of a tty will assign that tty as
> > > the new controlling tty, unless it is opened with the
> > > O_NOCTTY flag or the tty is already the controlling tty of
> > > another process, which it will be if there was a getty on it.
> > >
> > > I hope I got that right ...
> >
> > Thanks, this should help. The trick is, that I have a program
> > that correctly claims controling tty, but I want to redirect
> > it to a different tty. And a terminal can not be a controling
> > terminal of more than one session. So I need something, that
> > will keep the pty (terminal emulator) open, but not a
> > controling terminal of anything.
>
> Do you mean something like the following sequence?
>
> process A has serial port as CTTY.
> process A opens a master pseudo terminal.
> process A forks child process B.
> process B ioctl TIOCNOTTY serial port to remove B's CTTY assignment.
> process B closes serial port streams.
> process B opens corresponding slave pseudo terminal, becomes B's CTTY.
I think, that it's a bit different. It should look like following:
process A has pty/1 as ctty.
process A makes pty/1 available (presumably via TIOCNOTTY)
process B has no ctty (there is something about setsid I don't fully
understand)
process A tells proces B that it can use pty/1
process B opens pty/1 and makes it it's controling terminal (TIOCSCTTY)
The reason behind this: I have a process that logs a LOT to
stdout/stderr, does "setterm" ioctls on it and needs WINCH signal (thus
a controling tty). I want to run it from gdb and have gdb and this
programs output separated. Thus I use gdb's tty commad. But I need to
make a tty available (under X, that is in some terminal emulator).
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/