From 81130a6e3f778a9e3a9a54258d952eed6393f87c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 28 Oct 2022 14:57:19 +0100 Subject: [PATCH] gstdio: Document async-signal-safety of g_clear_fd and g_autofd g_clear_fd wraps g_close and is async-signal-safe under essentially the same circumstances. If fd_ptr already pointed to a negative number, then g_clear_fd doesn't call g_close, and is still async-signal-safe. g_autofd passes a NULL error pointer to g_clear_fd, so it is async-signal-safe, as long as no programming error occurs. Signed-off-by: Simon McVittie --- glib/gstdio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glib/gstdio.c b/glib/gstdio.c index 673ed92a7..cd3c8b405 100644 --- a/glib/gstdio.c +++ b/glib/gstdio.c @@ -1849,6 +1849,9 @@ g_close (gint fd, * stored in both %errno and @error. If this function succeeds, * %errno is undefined. * + * This function is async-signal-safe if @error is %NULL and @fd_ptr + * points to either a negative number or a valid file descriptor. + * * It is a programming error for @fd_ptr to point to a non-negative * number that is not a valid file descriptor. * @@ -1902,6 +1905,9 @@ g_close (gint fd, * only supported on GCC and clang, and the variable must be initialized * (to either a valid file descriptor or a negative number). * + * Using this macro is async-signal-safe if the constraints described above + * are met, so it can be used in a signal handler or after `fork()`. + * * Any error from closing the file descriptor when it goes out of scope * is ignored. Use g_clear_fd() if error-checking is required. *