Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752345AbbBRO6R (ORCPT ); Wed, 18 Feb 2015 09:58:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57814 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751726AbbBRO6Q (ORCPT ); Wed, 18 Feb 2015 09:58:16 -0500 Date: Wed, 18 Feb 2015 09:58:06 -0500 From: Aristeu Rozanski To: Peter Hurley 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 Message-ID: <20150218145805.GD13666@redhat.com> References: <20150217210609.GA13666@redhat.com> <54E3B27E.9020506@hurleysoftware.com> <20150217215046.GC13666@redhat.com> <54E3C21E.3000301@hurleysoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54E3C21E.3000301@hurleysoftware.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2253 Lines: 99 Hi Peter, On Tue, Feb 17, 2015 at 05:35:10PM -0500, Peter Hurley wrote: > I realize that. But hanging up the tty that is /dev/console only affects > open descriptors that are not /dev/console. > > So readers using the /dev/ttyS0 file descriptor will see a hungup fops, > but readers using /dev/console will not, and /dev/ttyS0 will _not_ > be closed or released because of the still-open descriptor on /dev/console. I see. > Ok, so the process sleeping on /dev/console read() should have received > SIGHUP, which would wake the process and cause it to exit the > n_tty_read() loop, thus dropping the ldisc reference it holds. > Did it ignore the signal or perhaps the signal is masked? Not masked on the test case (attached). Sent sighup manually and it did receive it. -- Aristeu #include #include #include #include #include #include #include #include #include #include #include static char *default_console = "/dev/console"; static char *default_tty = "/dev/ttyS0"; struct data { char *console; char *tty; }; static void *reader(void *d) { struct data *data = (struct data *)d; struct termios old_termio; char buff[512]; int fd = -1, rc; while (1) { if (fd == -1) { fd = open(data->console, O_RDWR); if (fd < 0) exit(1); if (tcgetattr(fd, &old_termio) == -1) exit(1); old_termio.c_lflag = ICANON; if (tcsetattr(fd, 0, &old_termio) == -1) exit(1); } rc = read(fd, buff, sizeof(buff)); if (rc < 0 && errno == EAGAIN) continue; close(fd); fd = -1; } } void launch(void *(*fn)(void *), struct data *data) { if (fork() == 0) fn(data); } int main(int argc, char *argv[]) { struct data data; int fd; fd = open("/dev/ttyS0", O_RDWR); close(0); close(1); close(2); ioctl(fd, TIOCSCTTY, 1); data.console = default_console; data.tty = default_tty; launch(reader, &data); waitpid(-1, NULL, 0); return 0; } -- 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/