From fe3a78ab1997f650dd6e76a7a0ba51b72546221e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2001 14:13:29 +0000 Subject: we use signal() to ignore signals only as long as we have to, and we now restore the previous (if any) signal handler properly on return. --- lib/url.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib/url.c') diff --git a/lib/url.c b/lib/url.c index 31e1459ca..079e9575a 100644 --- a/lib/url.c +++ b/lib/url.c @@ -143,13 +143,23 @@ RETSIGTYPE alarmfunc(int signal) } #endif + +/* + * This is the internal function curl_easy_cleanup() calls. This should + * cleanup and free all resources associated with this sessionhandle. + * + * NOTE: if we ever add something that attempts to write to a socket or + * similar here, we must ignore SIGPIPE first. It is currently only done + * when curl_easy_perform() is invoked. + */ + CURLcode Curl_close(struct SessionHandle *data) { /* Loop through all open connections and kill them one by one */ while(-1 != ConnectionKillOne(data)); #ifdef USE_SSLEAY - /* Close down all open info open SSL and sessions */ + /* Close down all open SSL info and sessions */ Curl_SSL_Close_All(data); #endif @@ -258,13 +268,6 @@ CURLcode Curl_open(struct SessionHandle **curl) *curl = data; - /************************************************************* - * Tell signal handler to ignore SIGPIPE - *************************************************************/ -#if defined(HAVE_SIGNAL) && defined(SIGPIPE) - (void) signal(SIGPIPE, SIG_IGN); -#endif - return CURLE_OK; } @@ -1141,7 +1144,7 @@ static CURLcode CreateConnection(struct SessionHandle *data, { char *tmp; char *buf; - CURLcode result; + CURLcode result=CURLE_OK; char resumerange[40]=""; struct connectdata *conn; struct connectdata *conn_temp; @@ -1154,6 +1157,10 @@ static CURLcode CreateConnection(struct SessionHandle *data, #ifdef HAVE_SIGACTION struct sigaction keep_sigact; /* store the old struct here */ bool keep_copysig; /* did copy it? */ +#else +#ifdef HAVE_SIGNAL + void *keep_sigact; /* store the old handler here */ +#endif #endif /************************************************************* @@ -1941,7 +1948,7 @@ static CURLcode CreateConnection(struct SessionHandle *data, #else /* no sigaction(), revert to the much lamer signal() */ #ifdef HAVE_SIGNAL - signal(SIGALRM, alarmfunc); + keep_sigact = signal(SIGALRM, alarmfunc); #endif #endif @@ -2006,6 +2013,11 @@ static CURLcode CreateConnection(struct SessionHandle *data, and clean */ sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */ } +#else +#ifdef HAVE_SIGNAL + /* restore the previous SIGALRM handler */ + signal(SIGALRM, keep_sigact); +#endif #endif /* switch back the alarm() to either zero or to what it was before minus the time we spent until now! */ -- cgit v1.2.3