All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Aristeu Rozanski <aris@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.cz>
Subject: Re: [PATCH] n_tty_read: check for hanging tty while waiting for input
Date: Wed, 18 Feb 2015 11:38:55 -0500	[thread overview]
Message-ID: <54E4C01F.4090905@hurleysoftware.com> (raw)
In-Reply-To: <20150218155627.GF13666@redhat.com>

On 02/18/2015 10:56 AM, Aristeu Rozanski wrote:
> Hi Peter,
> On Wed, Feb 18, 2015 at 10:40:10AM -0500, Peter Hurley wrote:
>> The child is not receiving SIGHUP because /dev/ttyS0 was not set as the
>> controlling terminal by ioctl(TIOCSCTTY), which is failing (probably
>> with errno == EPERM). You need to check the return value and errno.
>>
>> To set the controlling tty, the calling process must be a session leader;
>> ie., have called setsid() before ioctl(TIOCSCTTY). Check the return value
>> for that too.
>>
>> FWIW, the idiom for starting a session leader is for the parent to
>> fork a child and exit and for the child to become the session leader with
>> setsid() and establish its controlling tty either with ioctl(TIOCSCTTY)
>> or simply opening the first tty.
>>
>> The reason for this idiom is that setsid() will fail for an existing
>> group leader (because otherwise a group leader could abandon existing
>> members of its process group, leaving them without a group leader in
>> a different session).
>>
>> I highly recommend Ch 34 of Michael Kerrisk's book, "The Linux Programming
>> Interface", especially if this is not a toy project.
> 
> Actually wrote this trying to reproduce a problem a customer is seeing
> in a commercial application, but clearly I need to read it. Specifically
> about the console behavior, would you recommend the same book?

Ch 34 is about controlling ttys and job control, so it covers the two-tier
process hierarchy, foreground and background process groups, and job control
signals. Personally, I think the book is invaluable.

Unfortunately, consoles are not well documented anywhere.

> Every time I need details like this I fail to find any reference online.
> Thanks for your help

No problem.

Regards,
Peter Hurley


      reply	other threads:[~2015-02-18 16:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-17 21:06 [PATCH] n_tty_read: check for hanging tty while waiting for input Aristeu Rozanski
2015-02-17 21:28 ` Peter Hurley
2015-02-17 21:50   ` Aristeu Rozanski
2015-02-17 22:35     ` Peter Hurley
2015-02-18 14:58       ` Aristeu Rozanski
2015-02-18 15:40         ` Peter Hurley
2015-02-18 15:56           ` Aristeu Rozanski
2015-02-18 16:38             ` Peter Hurley [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54E4C01F.4090905@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=aris@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.