From d4605ce5a455f02f2422189dea72a00b8f1f1d55 Mon Sep 17 00:00:00 2001 From: des Date: Sun, 16 Jul 2000 00:47:00 +0000 Subject: Better signal handling. Submitted by: green --- usr.bin/fetch/fetch.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'usr.bin/fetch') diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index d6aa1fb..02a0cd5 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -345,13 +346,15 @@ fetch(char *URL, char *path) if (sigint) warnx("transfer interrupted"); - /* check the status of our files */ - if (ferror(f)) - warn("%s", URL); - if (ferror(of)) - warn("%s", path); - if (ferror(f) || ferror(of)) - goto failure; + if (!sigalrm && !sigint) { + /* check the status of our files */ + if (ferror(f)) + warn("%s", URL); + if (ferror(of)) + warn("%s", path); + if (ferror(f) || ferror(of)) + goto failure; + } /* did the transfer complete normally? */ if (us.size != -1 && count < us.size) { @@ -412,6 +415,7 @@ int main(int argc, char *argv[]) { struct stat sb; + struct sigaction sa; char *p, *q, *s; int c, e, r; @@ -542,8 +546,7 @@ main(int argc, char *argv[]) if ((buf = malloc(B_size)) == NULL) errx(1, strerror(ENOMEM)); - /* timeout handling */ - signal(SIGALRM, sig_handler); + /* timeouts */ if ((s = getenv("FTP_TIMEOUT")) != NULL) { if (parseint(s, &ftp_timeout) == -1) { warnx("FTP_TIMEOUT is not a positive integer"); @@ -557,8 +560,12 @@ main(int argc, char *argv[]) } } - /* interrupt handling */ - signal(SIGINT, sig_handler); + /* signal handling */ + sa.sa_flags = 0; + sa.sa_handler = sig_handler; + sigemptyset(&sa.sa_mask); + (void)sigaction(SIGALRM, &sa, NULL); + (void)sigaction(SIGINT, &sa, NULL); /* output file */ if (o_flag) { -- cgit v1.1