[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing a terminal's fd



The problem is that once you've passed the descriptor, if the 
session owner exits, the tty will revoke() the descriptor.

The only way to get around this is to arrange that the original owner 
hangs around 'till the new owner is finished with the descriptor.  
There's no facility for passing session ownership to an arbitrary 
process.

ppp(8) (in MP mode) handles this by fork()ing itself after passing 
the ctty descriptor to another process, pause()ing the parent and 
getting rid of the session in the child (with a setsid() and another 
fork()).

>  Hello,
> 
>    I realize it's not OpenBSD specific, but I run OpenBSD and somebody
>    in here must know.
> 
>    Basically, what I want to do is that a client passes a file
>    descriptor of its terminal to a server so the server has further
>    access on this terminal, even after the client quits.  I realize
>    this has multiple problems, notably that the terminal will stay open
>    as long as the daemon stays on (well, I _think_ so), and blah blah
>    blah.  But I still want to do it.
> 
>    What I tried is :
>     
> ---
>    connect(destfd, [... to server's unix socket ...]);
>    fd = open("/dev/tty", O_RDWR);	/* get my own tty */
>    send_fd(destfd, fd);			/* FD passing using sendmsg() ... */
>    (and send_fd(destfd, fileno(stdout)), with the same result)
> ---
>    
>    But it doesn't work.  What I think is that they share the same file
>    descriptor entry, but it points to /dev/tty's vnode, which is
>    dynamic and always is the process' own console. (anyways, that's
>    what reading the code in /sys make me think).
> 
>    Anybody has an idea of what I could try next?  Even just a pointer
>    to where I could look...
> 
>    I _could_ keep the clients in the background, writing on the
>    terminal and reading data from the server on a socket, but for
>    multiple reasons I would prefer not to. 
> 
>   Note: I'm not subscribed on misc@, so please CC answers to me.
> 
>         Vincent Labrecque                            ASCII Ribbon  /~\
>                                                  Campaign Against  \ /
>         limitln@cooptel.qc.ca                         HTML Email!   X
>     http://www.cooptel.qc.ca/~limitln                              / \

-- 
Brian <brian@freebsd-services.com>                <brian@Awfulhak.org>
      http://www.freebsd-services.com/        <brian@[uk.]FreeBSD.org>
Don't _EVER_ lose your sense of humour !      <brian@[uk.]OpenBSD.org>