is it necessary to be a session leader to attach psuedo terminal as a controlling terminal of a process

  • Follow


To attach controlling terminal (CT) to a process:
I have following code similar in OpenSSH

1. disconnect from old CT
2. become a session leader setsid()
3. attach psuedo tty to process calling ioctl(fd, TIOCSCTTY, NULL)

I dont want my process being a session leader to avoid SIGHUP for child
process.

But if I comment out setsid, I get error in ioctl and subsequent open
calls for terminals-
ioctl - (Input/output error)
/dev/pts/4: No such file or directory
open /dev/tty failed

(fd is associated with /dev/pts/4)

Is there any mechanism to attach psuedo terminal to process as its
Controlling Terminal without being a session leader?

OR can a process give up session leadership after attaching CT ?

0
Reply pankaj.takawale (23) 7/20/2006 1:40:12 PM

ioctl(fd, TIOCSCTTY, NULL) gives following error
ioctl(TIOCSCTTY):  Operation not permitted


pankajtakawale wrote:

> To attach controlling terminal (CT) to a process:
> I have following code similar in OpenSSH
>
> 1. disconnect from old CT
> 2. become a session leader setsid()
> 3. attach psuedo tty to process calling ioctl(fd, TIOCSCTTY, NULL)
>
> I dont want my process being a session leader to avoid SIGHUP for child
> process.
>
> But if I comment out setsid, I get error in ioctl and subsequent open
> calls for terminals-
> ioctl - (Input/output error)
> /dev/pts/4: No such file or directory
> open /dev/tty failed
>
> (fd is associated with /dev/pts/4)
>
> Is there any mechanism to attach psuedo terminal to process as its
> Controlling Terminal without being a session leader?
> 
> OR can a process give up session leadership after attaching CT ?

0
Reply pankajtakawale 7/20/2006 1:55:05 PM


pankajtakawale wrote:
> To attach controlling terminal (CT) to a process:
> I have following code similar in OpenSSH
>
> 1. disconnect from old CT
> 2. become a session leader setsid()
> 3. attach psuedo tty to process calling ioctl(fd, TIOCSCTTY, NULL)
>
> I dont want my process being a session leader to avoid SIGHUP for child
> process.

Is there a reason why you can't block SIGHUP before spawning a child?
This way children would not receive SIGHUP since the signal mask is
inherited by child processed.

http://www.opengroup.org/onlinepubs/009695399/functions/sigprocmask.html

P.S. If you are using Solaris 8, it's broken in this regard. The signal
mask on this operating system is only inherited by threads, not child
processes.

0
Reply Maxim 7/21/2006 10:55:33 AM

Maxim Yegorushkin wrote:

> pankajtakawale wrote:
> > To attach controlling terminal (CT) to a process:
> > I have following code similar in OpenSSH
> >
> > 1. disconnect from old CT
> > 2. become a session leader setsid()
> > 3. attach psuedo tty to process calling ioctl(fd, TIOCSCTTY, NULL)
> >
> > I dont want my process being a session leader to avoid SIGHUP for child
> > process.
>
> Is there a reason why you can't block SIGHUP before spawning a child?
> This way children would not receive SIGHUP since the signal mask is
> inherited by child processed.
>
Yes blocking SIGHUP is one way. I dont want block SIGHUP in all cases.
foreground process wouldnt receive SIGHUP if I close the session. I
think I have to cpmpromise somewhere.

> http://www.opengroup.org/onlinepubs/009695399/functions/sigprocmask.html
>
> P.S. If you are using Solaris 8, it's broken in this regard. The signal
> mask on this operating system is only inherited by threads, not child
> processes.

Thanks

0
Reply pankajtakawale 7/24/2006 10:37:04 AM

3 Replies
420 Views

(page loaded in 0.239 seconds)

Similiar Articles:




7/25/2012 3:18:05 AM


Reply: