]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: calling putchar is off-limits on a signal handler
authorCristian Rodríguez <crrodriguez@opensuse.org>
Sun, 15 Jan 2023 01:33:14 +0000 (01:33 +0000)
committerCristian Rodríguez <crrodriguez@opensuse.org>
Sun, 15 Jan 2023 01:33:14 +0000 (01:33 +0000)
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

index 8cab5676852a8c44ce91757d946e503a794daea6..7e66dfdde1c5c7914552e36df0fc4f806825ad4c 100644 (file)
@@ -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[])