ref: 638e16ba26635d85c7a3f4a806963557c10063cd
parent: ee847e85c9bc170288ea8f129f8aee0b9234eacd
author: Eric Wong <e@80x24.org>
date: Sat Oct 3 18:03:07 EDT 2015
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.
--- a/src/sox.c
+++ b/src/sox.c
@@ -1804,6 +1804,18 @@
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. */