From: Eric Wong <normalperson@yhbt.net>
To: Tarim <sox@mediaplaygrounds.co.uk>, sox-users@lists.sourceforge.net
Cc: sox-devel@lists.sourceforge.net
Subject: [PATCH] use non-blocking stdin for interactive mode
Date: Sat, 3 Oct 2015 22:13:18 +0000 [thread overview]
Message-ID: <20151003221318.GA32546@dcvr.yhbt.net> (raw)
In-Reply-To: <d06a5a840dc9844a8ac389dcba91c7bd.squirrel@mail.mediaplaygrounds.co.uk>
Tarim <sox@mediaplaygrounds.co.uk> wrote:
> I'm now thinking that this is actually a bug in the latest Ubuntu kernel
> 3.13.0-65.105-generic where select's FD_ISSET returns true even when
> there is no data to read!
This is a kernel bug from a performance standpoint, but the select
manpage explicitly documents spurious wakeups as a possibility which
userspace must be prepared for.
The following patch should fix the problem:
------------------8<------------------
Subject: [PATCH] use non-blocking stdin for interactive mode
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.
---
Downloadable patch:
http://80x24.org/spew/1443909787-27821-1-git-send-email-e%4080x24.org/raw
In case upstream prefers a pull request:
The following changes since commit 7e74b254b2a7c963be0bfce751fc5911fe681c12:
Remove hepler script. It's mostly unmaintained, I don't know if anyone but me ever used it. In any case, those who want a custom Debian package should be capable of updating the debian/changelog entry on their own. (2015-02-26 22:48:40 -0500)
are available in the git repository at:
git://bogomips.org/sox nb-stdin
for you to fetch changes up to 62a370a2a01cf1dcc0d5f9b9f49d1515706346cd:
use non-blocking stdin for interactive mode (2015-10-03 22:04:50 +0000)
----------------------------------------------------------------
Eric Wong (1):
use non-blocking stdin for interactive mode
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. */
--
EW
------------------------------------------------------------------------------
next parent reply other threads:[~2015-10-03 22:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <f5d0acadb8966e2192aa5d7c1ca6f6e2.squirrel@mail.mediaplaygrounds.co.uk>
[not found] ` <d06a5a840dc9844a8ac389dcba91c7bd.squirrel@mail.mediaplaygrounds.co.uk>
2015-10-03 22:13 ` Eric Wong [this message]
2015-10-04 9:10 ` [PATCH] use non-blocking stdin for interactive mode Tarim
2015-10-04 11:22 ` Eric Wong
[not found] ` <80d9684bb05ff4318a7a28ccddbcf860.squirrel@mail.mediaplaygrounds.co.uk>
2015-10-07 10:23 ` Eric Wong
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-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.sourceforge.net/lists/listinfo/sox-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151003221318.GA32546@dcvr.yhbt.net \
--to=sox-devel@lists.sourceforge.net \
--cc=sox-users@lists.sourceforge.net \
--cc=sox@mediaplaygrounds.co.uk \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/sox.git
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).