From 3685f792cbd271ecdc623de2e0b48e1debab6109 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 9 Oct 2001 06:23:26 +0000 Subject: ignore SIGPIPE, as that can be actually get sent when we write to a socket --- lib/url.c | 119 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/lib/url.c b/lib/url.c index ddbdc3b16..f9dc3a7f3 100644 --- a/lib/url.c +++ b/lib/url.c @@ -206,84 +206,89 @@ CURLcode Curl_open(struct SessionHandle **curl) /* Very simple start-up: alloc the struct, init it with zeroes and return */ data = (struct SessionHandle *)malloc(sizeof(struct SessionHandle)); - if(data) { - memset(data, 0, sizeof(struct SessionHandle)); - - /* We do some initial setup here, all those fields that can't be just 0 */ - - data->state.headerbuff=(char*)malloc(HEADERSIZE); - if(!data->state.headerbuff) { - free(data); /* free the memory again */ - return CURLE_OUT_OF_MEMORY; - } - - data->state.headersize=HEADERSIZE; - - data->set.out = stdout; /* default output to stdout */ - data->set.in = stdin; /* default input from stdin */ - data->set.err = stderr; /* default stderr to stderr */ + if(!data) + /* this is a very serious error */ + return CURLE_OUT_OF_MEMORY; + + memset(data, 0, sizeof(struct SessionHandle)); - /* use fwrite as default function to store output */ - data->set.fwrite = (curl_write_callback)fwrite; + /* We do some initial setup here, all those fields that can't be just 0 */ - /* use fread as default function to read input */ - data->set.fread = (curl_read_callback)fread; + data->state.headerbuff=(char*)malloc(HEADERSIZE); + if(!data->state.headerbuff) { + free(data); /* free the memory again */ + return CURLE_OUT_OF_MEMORY; + } - /* set the default passwd function */ - data->set.fpasswd = my_getpass; + data->state.headersize=HEADERSIZE; - data->set.infilesize = -1; /* we don't know any size */ + data->set.out = stdout; /* default output to stdout */ + data->set.in = stdin; /* default input from stdin */ + data->set.err = stderr; /* default stderr to stderr */ + + /* use fwrite as default function to store output */ + data->set.fwrite = (curl_write_callback)fwrite; - data->state.current_speed = -1; /* init to negative == impossible */ + /* use fread as default function to read input */ + data->set.fread = (curl_read_callback)fread; + + /* set the default passwd function */ + data->set.fpasswd = my_getpass; - data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */ + data->set.infilesize = -1; /* we don't know any size */ - /* make libcurl quiet by default: */ - data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ - data->progress.flags |= PGRS_HIDE; + data->state.current_speed = -1; /* init to negative == impossible */ - /* Set the default size of the SSL session ID cache */ - data->set.ssl.numsessions = 5; + data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */ - /* create an array with connection data struct pointers */ - data->state.numconnects = 5; /* hard-coded right now */ - data->state.connects = (struct connectdata **) - malloc(sizeof(struct connectdata *) * data->state.numconnects); + /* make libcurl quiet by default: */ + data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ + data->progress.flags |= PGRS_HIDE; - if(!data->state.connects) { - free(data); - return CURLE_OUT_OF_MEMORY; - } + /* Set the default size of the SSL session ID cache */ + data->set.ssl.numsessions = 5; - memset(data->state.connects, 0, - sizeof(struct connectdata *)*data->state.numconnects); + /* create an array with connection data struct pointers */ + data->state.numconnects = 5; /* hard-coded right now */ + data->state.connects = (struct connectdata **) + malloc(sizeof(struct connectdata *) * data->state.numconnects); + + if(!data->state.connects) { + free(data); + return CURLE_OUT_OF_MEMORY; + } + + memset(data->state.connects, 0, + sizeof(struct connectdata *)*data->state.numconnects); - *curl = data; + *curl = data; - /************************************************************* - * Set signal handler - *************************************************************/ + /************************************************************* + * Set signal handler to catch SIGALRM + *************************************************************/ #ifdef HAVE_SIGACTION - sigaction(SIGALRM, NULL, &sigact); - sigact.sa_handler = alarmfunc; + sigaction(SIGALRM, NULL, &sigact); + sigact.sa_handler = alarmfunc; #ifdef SA_RESTART - /* HPUX doesn't have SA_RESTART but defaults to that behaviour! */ - sigact.sa_flags &= ~SA_RESTART; + /* HPUX doesn't have SA_RESTART but defaults to that behaviour! */ + sigact.sa_flags &= ~SA_RESTART; #endif - sigaction(SIGALRM, &sigact, NULL); + sigaction(SIGALRM, &sigact, NULL); #else - /* no sigaction(), revert to the much lamer signal() */ + /* no sigaction(), revert to the much lamer signal() */ #ifdef HAVE_SIGNAL - signal(SIGALRM, alarmfunc); + signal(SIGALRM, alarmfunc); #endif - #endif - return CURLE_OK; - } - - /* this is a very serious error */ - return CURLE_OUT_OF_MEMORY; + /************************************************************* + * Tell signal handler to ignore SIGPIPE + *************************************************************/ +#if defined(HAVE_SIGNAL) && defined(SIGPIPE) + (void) signal(SIGPIPE, SIG_IGN); +#endif + + return CURLE_OK; } CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) -- cgit v1.2.3