From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.3 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7AE5A1F5B7 for ; Fri, 31 Jul 2020 09:38:31 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1k1RUj-0003cu-7N; Fri, 31 Jul 2020 09:38:29 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1RUi-0003cj-NS for sox-devel@lists.sourceforge.net; Fri, 31 Jul 2020 09:38:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kAlalqNZSDAqUE11jbCFJL1BkRwR0HQBsBQnOP1IfsU=; b=iuMcyDyarZBflpAOklIcl1ML9P zqHLjZ4wHrjAkWYiBYvQNjhN8KbJb1XwDtpTVs5o9Mi8VYM9YgjHpHancfVMN5TiL274jjcjIzdVn F1D3dpd53+z02mZL6klGW+oBIPSglnSN/eiJQ1PsmkT/OsO0VeFDcbpnFyK1/UY/TXWE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=kAlalqNZSDAqUE11jbCFJL1BkRwR0HQBsBQnOP1IfsU=; b=UC7/CrAmTaTSdUnm8G/7jPypUv I7cPqWNlHhoUu/8DrsDpyzR9MVCBT3mksSRnqHvDLCEMk+SC6aKdldNuGXWBuqgnka1hiAM0I8PL2 mLnY2vc2Jj+QyQGWggZNWMmsM+8S9K5lD+wiWaAIaP2S8dVeZZs4pn8JLGR/mRkQB6oA=; Received: from dcvr.yhbt.net ([64.71.152.64]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1k1RUg-0084jq-Ez for sox-devel@lists.sourceforge.net; Fri, 31 Jul 2020 09:38:28 +0000 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 94C181F5B7; Fri, 31 Jul 2020 09:38:01 +0000 (UTC) From: Eric Wong To: =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Date: Fri, 31 Jul 2020 09:37:53 +0000 Message-Id: <20200731093801.23548-2-normalperson@yhbt.net> In-Reply-To: <20200731093801.23548-1-normalperson@yhbt.net> References: <20200731093801.23548-1-normalperson@yhbt.net> MIME-Version: 1.0 X-Headers-End: 1k1RUg-0084jq-Ez Subject: [PATCH RESEND 1/9] use non-blocking stdin for interactive mode X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sox-devel@lists.sourceforge.net Cc: Eric Wong , sox-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: sox-devel-bounces@lists.sourceforge.net From: Eric Wong When accepting keyboard input, it is possible for select() to return a false-positive with spurious wakeups from inside the update_status callback. Using the FIONREAD ioctl in place of select is also a possibility, but may be less portable. --- src/sox.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sox.c b/src/sox.c index 9412614e..6b35041b 100644 --- a/src/sox.c +++ b/src/sox.c @@ -1804,6 +1804,18 @@ static int process(void) tcsetattr(fileno(stdin), TCSANOW, &modified_termios); } #endif +#if defined(F_GETFL) && defined(F_SETFL) && defined(O_NONBLOCK) + if (interactive) { + int fd = fileno(stdin); + int flags = fcntl(fd, F_GETFL); + if (flags == -1) { + lsx_warn("error getting flags on stdin descriptor: %s", strerror(errno)); + } else if (!(flags & O_NONBLOCK)) { + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) + lsx_warn("error setting non-blocking on stdin: %s", strerror(errno)); + } + } +#endif setsig(SIGTERM, sigint); /* Stop gracefully, as soon as we possibly can. */ setsig(SIGINT , sigint); /* Either skip current input or behave as SIGTERM. */ _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel