From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161029AbcAZRN1 (ORCPT ); Tue, 26 Jan 2016 12:13:27 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:34148 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966812AbcAZRNU (ORCPT ); Tue, 26 Jan 2016 12:13:20 -0500 Subject: Re: stty blocks forever when the line is already opened (and the tx buffer can't be flushed) To: Richard Genoud , Jiri Slaby References: Cc: Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" From: Peter Hurley Message-ID: <56A7A92E.3020407@hurleysoftware.com> Date: Tue, 26 Jan 2016 09:13:18 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: 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 Hi Richard, On 01/26/2016 08:19 AM, Richard Genoud wrote: > [ sorry for the noise, I forgot to Cc the lkml ] > > Hi, > I've found a case were calling > stty -F /dev/ttyS1 clocal > blocks forever. > And I don't know if it's a very old bug or if it's meant to be like that. > > Here is how to reproduce the lock : > NB: there's NO modem on ttyS1 > stty -F /dev/ttyS1 clocal cread crtscts > cat < /dev/ttyS1 > > #on another terminal : > echo "dummy" > /dev/ttyS1 # This call doesn't block > > stty -F /dev/ttyS1 -crtscts # this blocks forever on ioctl(TCSETSW ) > > > looking at tty_port_close_start(), it's pretty clear that nothing is > flushed until the last user, so it explains why the "echo dummy" > returns directly, despite the crtscts flags. > And in tty_mode_ioctl(), there are the lines: > case TCSETSW: > return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD); > That explain why the stty blocks. > > But this behavior seems really strange. > ... Or it's meant to be like that ? Yeah, meant to be like that. When mgetty writes the login prompt but h/w flow control is enabled and nothing's connected, the output is buffered. Since stty uses tcsetattr(TCSADRAIN), the attempt to turn off h/w flow control blocks, waiting for output to empty. In this situation, stopping mgetty will allow the other process to unblock and advance. Hmmm, I could add a -f,--force flag to stty so it uses tcsetattr(TCSANOW)... Regards, Peter Hurley > Regards, > Richard > > NB: This is actually a real life use case with mgetty, a modem losing > its power and another process trying to speak to the modem. >