summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2020-10-25 08:36:57 +0100
committerDaiki Ueno <ueno@gnu.org>2020-10-30 09:29:39 +0100
commitff2a662482a21b0369a6e1aac6e3c36f6d58c024 (patch)
tree479e3249659a675dfdbf3ae9230017734b2abf45
parent8d84c6d7b04bafebb43ecfd268677a180a3c9233 (diff)
downloadgnutls-ff2a662482a21b0369a6e1aac6e3c36f6d58c024.tar.gz
mini-record-timing: use only async-signal-safe functions in handler
Signed-off-by: Daiki Ueno <ueno@gnu.org>
-rw-r--r--tests/suite/mini-record-timing.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/suite/mini-record-timing.c b/tests/suite/mini-record-timing.c
index 093f3d5d32..4cdd78f472 100644
--- a/tests/suite/mini-record-timing.c
+++ b/tests/suite/mini-record-timing.c
@@ -495,11 +495,30 @@ static void ch_handler(int sig)
wait(&status);
if (WEXITSTATUS(status) != 0 ||
(WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)) {
- if (WIFSIGNALED(status))
- fprintf(stderr, "Child died with sigsegv\n");
- else
- fprintf(stderr, "Child died with status %d\n",
- WEXITSTATUS(status));
+ /* This code must be async-signal-safe. */
+ if (WIFSIGNALED(status)) {
+ const char msg[] = "Child died with sigsegv\n";
+ write(STDERR_FILENO, "Child died with sigsegv\n", sizeof(msg));
+ } else {
+ char buf[64] = { 0 };
+ char *p;
+
+ p = stpcpy(buf, "Child died with status ");
+
+ status = WEXITSTATUS(status) & 0377;
+ if (status > 100) {
+ *p++ = '0' + status / 100;
+ status %= 100;
+ }
+ if (status > 10) {
+ *p++ = '0' + status / 10;
+ status %= 10;
+ }
+ *p++ = '0' + status;
+ *p++ = '\n';
+
+ write(STDERR_FILENO, buf, p - buf);
+ }
}
return;
}