summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg.c
diff options
context:
space:
mode:
authorAndriy Gelman <andriy.gelman@gmail.com>2020-11-28 14:46:53 -0500
committerAndriy Gelman <andriy.gelman@gmail.com>2021-01-16 16:21:09 -0500
commit35eb5eeca809bc48463302dc29b5d46cd66e4a72 (patch)
tree1d06d3d6ee1a25f6947c34518bbb847d8658e50e /fftools/ffmpeg.c
parent4ae2dfd7ea2f95deaa91c6072ac9d36c4810d36e (diff)
ffmpeg: use sigaction() instead of signal() on linux
As per signal() help (man 2 signal) the semantics of using signal may vary across platforms. It is suggested to use sigaction() instead. Reviewed-by: Zane van Iperen <zane@zanevaniperen.com> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Diffstat (limited to 'fftools/ffmpeg.c')
-rw-r--r--fftools/ffmpeg.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 84a60f944a..4419c68d11 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -394,8 +394,30 @@ static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
}
#endif
+#ifdef __linux__
+#define SIGNAL(sig, func) \
+ do { \
+ action.sa_handler = func; \
+ sigaction(sig, &action, NULL); \
+ } while (0)
+#else
+#define SIGNAL(sig, func) \
+ signal(sig, func)
+#endif
+
void term_init(void)
{
+#if defined __linux__
+ struct sigaction action = {0};
+ action.sa_handler = sigterm_handler;
+
+ /* block other interrupts while processing this one */
+ sigfillset(&action.sa_mask);
+
+ /* restart interruptible functions (i.e. don't fail with EINTR) */
+ action.sa_flags = SA_RESTART;
+#endif
+
#if HAVE_TERMIOS_H
if (!run_as_daemon && stdin_interaction) {
struct termios tty;
@@ -414,14 +436,14 @@ void term_init(void)
tcsetattr (0, TCSANOW, &tty);
}
- signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
+ SIGNAL(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
}
#endif
- signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
- signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
+ SIGNAL(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
+ SIGNAL(SIGTERM, sigterm_handler); /* Termination (ANSI). */
#ifdef SIGXCPU
- signal(SIGXCPU, sigterm_handler);
+ SIGNAL(SIGXCPU, sigterm_handler);
#endif
#ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */