From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] use non-blocking stdin for interactive mode
Date: Sat, 3 Oct 2015 22:03:07 +0000 [thread overview]
Message-ID: <1443909787-27821-1-git-send-email-e@80x24.org> (raw)
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
reply other threads:[~2015-10-03 22:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443909787-27821-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).