PR #24333 opened by Thomas Devoogdt (ThomasDevoogdt)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24333
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24333.patch

sigterm_handler() called exit(123) directly, bypassing
avformat_close_input() and therefore any protocol level shutdown, such as
the RTSP TEARDOWN.  Set a flag instead and let the event loop leave
through do_exit(), which keeps the 123 exit status.

Based on sigterm_handler logic from fftools/ffmpeg.c

Signed-off-by: Thomas Devoogdt <[email protected]>
____________

Based on this suggestion: 
https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23406#issuecomment-59750


>From 14730199c0070dd6ec218eb156a70a9c42d92179 Mon Sep 17 00:00:00 2001
From: Thomas Devoogdt <[email protected]>
Date: Sun, 19 Jul 2026 19:23:45 +0200
Subject: [PATCH] fftools/ffplay: exit via do_exit() on termination signal

sigterm_handler() called exit(123) directly, bypassing
avformat_close_input() and therefore any protocol level shutdown, such as
the RTSP TEARDOWN.  Set a flag instead and let the event loop leave
through do_exit(), which keeps the 123 exit status.

Based on sigterm_handler logic from fftools/ffmpeg.c

Signed-off-by: Thomas Devoogdt <[email protected]>
---
 fftools/ffplay.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 31dca9a7fa..358fdac260 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -362,6 +362,10 @@ static int64_t audio_callback_time;
 
 #define FF_QUIT_EVENT    (SDL_USEREVENT + 2)
 
+static volatile int received_sigterm = 0;
+static volatile int received_nb_signals = 0;
+static int exit_status = 0;
+
 static SDL_Window *window;
 static SDL_Renderer *renderer;
 static SDL_RendererInfo renderer_info = {0};
@@ -1368,12 +1372,20 @@ static void do_exit(VideoState *is)
         printf("\n");
     SDL_Quit();
     av_log(NULL, AV_LOG_QUIET, "%s", "");
-    exit(0);
+    exit(exit_status);
 }
 
 static void sigterm_handler(int sig)
 {
-    exit(123);
+    int ret;
+    received_sigterm = sig;
+    received_nb_signals++;
+    if(received_nb_signals > 3) {
+        ret = write(2 /* STDERR_FILENO */, "Received > 3 system signals, hard 
exiting\n",
+                    strlen("Received > 3 system signals, hard exiting\n"));
+        if (ret < 0) { /* Do nothing */ };
+        exit(123);
+    }
 }
 
 static void set_default_window_size(int width, int height, AVRational sar)
@@ -3404,6 +3416,10 @@ static void refresh_loop_wait_event(VideoState *is, 
SDL_Event *event) {
     double remaining_time = 0.0;
     SDL_PumpEvents();
     while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, 
SDL_LASTEVENT)) {
+        if (received_sigterm) {
+            exit_status = 123;
+            do_exit(is);
+        }
         if (!cursor_hidden && av_gettime_relative() - cursor_last_shown > 
CURSOR_HIDE_DELAY) {
             SDL_ShowCursor(0);
             cursor_hidden = 1;
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to