Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752222AbbBRQjD (ORCPT ); Wed, 18 Feb 2015 11:39:03 -0500 Received: from mail-qc0-f170.google.com ([209.85.216.170]:46154 "EHLO mail-qc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbbBRQjA (ORCPT ); Wed, 18 Feb 2015 11:39:00 -0500 Message-ID: <54E4C01F.4090905@hurleysoftware.com> Date: Wed, 18 Feb 2015 11:38:55 -0500 From: Peter Hurley User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Aristeu Rozanski CC: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: Re: [PATCH] n_tty_read: check for hanging tty while waiting for input References: <20150217210609.GA13666@redhat.com> <54E3B27E.9020506@hurleysoftware.com> <20150217215046.GC13666@redhat.com> <54E3C21E.3000301@hurleysoftware.com> <20150218145805.GD13666@redhat.com> <54E4B25A.3040001@hurleysoftware.com> <20150218155627.GF13666@redhat.com> In-Reply-To: <20150218155627.GF13666@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2021 Lines: 47 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/