hurl

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e5399e327f21a6033de0decb3c8588a17a63eea8
parent e0b2498d20b2082339ac02a098b40a11bdbe3ab7
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 22 May 2020 21:32:48 +0200

add alarm timer in case connection hangs without triggering a connect timeout

Noticed on a (broken?) snapshot version on OpenBSD -current with libtls.

Should make the time-out behaviour more reliable regardless.

Diffstat:
Mhurl.c | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/hurl.c b/hurl.c @@ -6,6 +6,7 @@ #include <errno.h> #include <netdb.h> #include <locale.h> +#include <signal.h> #include <stdarg.h> #include <stdio.h> #include <stdint.h> @@ -54,6 +55,13 @@ static char *url; /* TLS config */ static struct tls_config *tls_config; +void +sighandler(int signo) +{ + if (signo == SIGALRM) + _exit(2); +} + int parseuri(const char *s, struct uri *u) { @@ -525,6 +533,10 @@ main(int argc, char **argv) if (parseuri(url, &u) == -1) errx(1, "invalid url: %s", url); + signal(SIGALRM, sighandler); + if (alarm(config_timeout) == -1) + err(1, "alarm"); + if (!strcmp(u.proto, "https")) { if (tls_init()) errx(1, "tls_init failed");