cURL / Mailing Lists / curl-library / Single Mail

curl-library

Segmentation fault when ethernet cable is disconnected during a curl_easy_perform

From: Ison <ison.thomas_at_mindteck.com>
Date: Sat, 05 Nov 2016 20:02:21 +0530

Hi,

I use the following code section to upload a file to ftp. I am using
BeagleBone Black with debian OS. curl library version is 7.45.

{
/uint8 ret_val = g_FAILURE_c;//
// struct stat file_info;//
// FILE *p_file;//
// uint8 ftp_url[64];//
// uint8 server_len = 0;//
// struct myprogress prog;//
// long ftp_port;//
//
// /* get the file size of the local file *///
// if(stat((const char*)get_tx_file_name(), &file_info))//
// {//
// printf("Couldnt open temporary pdf file\n");//
// set_rcrdtrnsfr_eth_status(g_FILE_DETECT_ERROR_c);//
// }//
// else//
// {//
// file_size = (curl_off_t)file_info.st_size;//
//
// printf("Local file size: %" CURL_FORMAT_CURL_OFF_T "
bytes.\n", file_size);//
//
// /* get a FILE * of the same file *///
// p_file = fopen((const char*)get_tx_file_name(), "rb");//
//
// /* we want to use our own read function *///
//// curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);//
//
// curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo);//
// /* pass the struct pointer into the xferinfo function, note
that this is//
// an alias to CURLOPT_PROGRESSDATA *///
// curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog);//
//
// curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);//
//
// /* enable uploading *///
// curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);//
//
// /* Connection establishment timeout *///
// curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,
g_FTP_CONNECTION_TIMEOUT_c);// //30seconds
//
// /* File Transfer timeout *///
// curl_easy_setopt(curl, CURLOPT_TIMEOUT,
g_FTP_TRANSFER_TIMEOUT_c);// // 60 seconds
//
// /** Update User name and Password, if any *///
// if( (g_NONE_c < get_eth_config_param_len(g_FTP_USERNAME_c)) &&//
// (g_NONE_c <
get_eth_config_param_len(g_FTP_PASSWORD_c)) )//
// {//
// get_ftp_username(ftp_url);//
// curl_easy_setopt(curl, CURLOPT_USERNAME, ftp_url);//
// printf("Username : %s\n", ftp_url);//
//
// get_ftp_password(ftp_url);//
// curl_easy_setopt(curl, CURLOPT_PASSWORD, ftp_url);//
// printf("Password : %s\n", ftp_url);//
//
// get_ftp_server_port(ftp_url);//
// ftp_port = atoi(ftp_url);//
// printf("FTP Port : %ld\n", ftp_port);//
// // if(990 != ftp_port || 21 != ftp_port)//
// curl_easy_setopt(curl, CURLOPT_PORT, ftp_port);//
// }//
//
// /** Update ftp url *///
// server_len = get_ftp_server_address((char*)ftp_url);//
//
// strcat((char*)&ftp_url[server_len], "/");//
// server_len++;//
//
// strcat((char*)&ftp_url[server_len], (const
char*)get_tx_file_name());//
// printf("Server Address : %s\n", ftp_url);//
//
// curl_easy_setopt(curl, CURLOPT_URL, ftp_url);//
//
// curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_NONE);//
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);//
//
// /* specify which file to upload *///
// curl_easy_setopt(curl, CURLOPT_READDATA, p_file);//
//
// curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_size);//
//
// /* Upload file *///
// if(CURLE_OK != (ret_val = curl_easy_perform(curl)))//
// {//
// //printf("Curl Perform Upload Failed...\n");//
// printf("Curl Perform Upload Failed...%d...%s\n", ret_val,
curl_easy_strerror(ret_val));//
//*sleep(20);*//
// }//
// else//
// {//
// printf("Curl Perform Upload Success...\n");//
// ret_val = g_SUCCESS_c;//
// }//
//
// fclose(p_file);//
// }
}

/Now, if I disconnect my ethernet cable after the file upload has
started, i.e, I am able to see the following prints in console

/UP: 0 of 0 DOWN: 0 of 0//
//UP: 0 of 0 DOWN: 0 of 0//
//UP: 0 of 0 DOWN: 0 of 0//
//UP: 0 of 0 DOWN: 0 of 0//
//UP: 0 of 0 DOWN: 0 of 0//
//UP: 0 of 0 DOWN: 0 of 0/

*Disconnect ethernet cable here*

/Curl Perform Upload Failed...28...Timeout was reached//

/I am able to continue with the rest of the operations after this/
/
But if I disconnect the cable before this prints starts, i.e when the
library is trying to resolve the host name, I get the following output
on console and a seg fault after some time

/Curl Perform Upload Failed...6...Couldn't resolve host name//
/
My application is simply waits at this print for 20 seconds. In this
case I observe a segmentation fault occurring after around 10seconds
every time.

The only difference between the two case is the time at which the
ethernet cable was pulled out which gave two different errors. Do we
have to do any other settings to handle an ethernet cable disconnection
when host name resolving does not happen?

Regards

Ison Thomas

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-05