Skip to content

Commit 35eb5ee

Browse files
committed
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 <[email protected]> Signed-off-by: Andriy Gelman <[email protected]>
1 parent 4ae2dfd commit 35eb5ee

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

fftools/ffmpeg.c

+26-4
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,30 @@ static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
394394
}
395395
#endif
396396

397+
#ifdef __linux__
398+
#define SIGNAL(sig, func) \
399+
do { \
400+
action.sa_handler = func; \
401+
sigaction(sig, &action, NULL); \
402+
} while (0)
403+
#else
404+
#define SIGNAL(sig, func) \
405+
signal(sig, func)
406+
#endif
407+
397408
void term_init(void)
398409
{
410+
#if defined __linux__
411+
struct sigaction action = {0};
412+
action.sa_handler = sigterm_handler;
413+
414+
/* block other interrupts while processing this one */
415+
sigfillset(&action.sa_mask);
416+
417+
/* restart interruptible functions (i.e. don't fail with EINTR) */
418+
action.sa_flags = SA_RESTART;
419+
#endif
420+
399421
#if HAVE_TERMIOS_H
400422
if (!run_as_daemon && stdin_interaction) {
401423
struct termios tty;
@@ -414,14 +436,14 @@ void term_init(void)
414436

415437
tcsetattr (0, TCSANOW, &tty);
416438
}
417-
signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
439+
SIGNAL(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
418440
}
419441
#endif
420442

421-
signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
422-
signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
443+
SIGNAL(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
444+
SIGNAL(SIGTERM, sigterm_handler); /* Termination (ANSI). */
423445
#ifdef SIGXCPU
424-
signal(SIGXCPU, sigterm_handler);
446+
SIGNAL(SIGXCPU, sigterm_handler);
425447
#endif
426448
#ifdef SIGPIPE
427449
signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */

0 commit comments

Comments
 (0)