From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS16276 92.222.0.0/16 X-Spam-Status: No, score=-1.1 required=3.0 tests=AWL,BAYES_40,RCVD_IN_XBL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: spew@80x24.org Received: from 80x24.org (relay2.tor.maximilian-jacobsen.com [92.222.113.177]) by dcvr.yhbt.net (Postfix) with ESMTP id 05FE8633849 for ; Sat, 3 Oct 2015 22:03:11 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] use non-blocking stdin for interactive mode Date: Sat, 3 Oct 2015 22:03:07 +0000 Message-Id: <1443909787-27821-1-git-send-email-e@80x24.org> List-Id: 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 bab0f45..fdb7616 100644 --- a/src/sox.c +++ b/src/sox.c @@ -1789,6 +1789,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 signal(SIGTERM, sigint); /* Stop gracefully, as soon as we possibly can. */ signal(SIGINT , sigint); /* Either skip current input or behave as SIGTERM. */ -- 2.5.0.rc1.33.g9b79a96