From ab35a4fb0e2d53a36918b515e95ed8c9a79f1da1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cristian=20Rodr=C3=ADguez?= Date: Sun, 15 Jan 2023 01:33:14 +0000 Subject: [PATCH] hardlink: calling putchar is off-limits on a signal handler Using putchar or any stdio function in signal handlers will lead to funny results as they cannot be async signal safe. One can write to stdout instead. --- misc-utils/hardlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index 8cab567685..7e66dfdde1 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -1380,7 +1380,8 @@ static void sighandler(int i) if (last_signal != SIGINT) last_signal = i; if (i == SIGINT) - putchar('\n'); + /* can't use stdio on signal handler */ + ignore_result(write(STDOUT_FILENO, "\n", sizeof("\n")-1)); } int main(int argc, char *argv[]) -- 2.47.3