cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: crash of libcurl on FreeBSD 6.0

From: GOD GOD <nusflying_at_yahoo.com.sg>
Date: Mon, 15 May 2006 20:52:39 +0800 (CST)

i have cut only the related code from c code
   
   
  
// bank related variable
bool DBSContLastSession = false;
  int main(int argc, char **argv) {
   //
 // start routine
 //
 while (true) {
    // check timing condition for further actions
  // Monday to Friday: 8:00 AM - 11:00PM 300 seconds
  // Saturday: 8:00 AM - 11:00PM 600 seconds
  // Sudany: 8:00 AM - 11:00PM 900 seconds
  
  IBCheckStatus = DBSIBCheck(HandledIB, NewIB);
  if (IBCheckStatus) {
   ERR << "[" << EventDateBuffer << "] fatal DBS IB error @ Step " << IBCheckStatus << "." << std::endl;
  }
  
  if (TimeStruct->tm_hour < 8 ||
   (TimeStruct->tm_hour == 23 && TimeStruct->tm_min > 20)) {
   // between 11:20 PM and 8:00 AM
     // to do
   // 1. update date string
   // 2. determine a big time interval to sleep
     // task 2
   if (TimeStruct->tm_hour == 23) {
    ToSleepTime = 8 * 3600 + (60 - TimeStruct->tm_min) * 60;
    TimeStruct->tm_mday += 1;
   } else {
    ToSleepTime = (8 - TimeStruct->tm_hour) * 3600 - TimeStruct->tm_min * 60;
   }
     // bank session halts
   DBSContLastSession = false;
    } else {
   if (TimeStruct->tm_wday == SUNDAY) {
    ToSleepTime = 600; // 10 minutes
   } else if (TimeStruct->tm_wday == SATURDAY) {
    ToSleepTime = 300; // 5 minutes
   } else {
    ToSleepTime = 180; // 3 minutes
   }
  }
    sleep(ToSleepTime);
 }
   return 0;
}
  
void DBSCurlInitialize() {
   if (DBSCurlHandle) {
  // cleanup curl stuff
  curl_easy_cleanup(DBSCurlHandle);
 }
 
 curl_global_init(CURL_GLOBAL_ALL);
   // init the curl session
 DBSCurlHandle = curl_easy_init();
   // some servers don't like requests that are made without a user-agent
 // field, so we provide one
 curl_easy_setopt(DBSCurlHandle, CURLOPT_USERAGENT, BROWSER_AGENT);
   // send all data to this function
 curl_easy_setopt(DBSCurlHandle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
   // DBSCurlResponse struct to the callback function
 curl_easy_setopt(DBSCurlHandle, CURLOPT_WRITEDATA, (void *)& DBSCurlResponse);
 
 // POST variable & HTTP URL
 curl_easy_setopt(DBSCurlHandle, CURLOPT_POSTFIELDS, DBSFormPOSTVariable);
 curl_easy_setopt(DBSCurlHandle, CURLOPT_URL, DBSHTTPURLBuffer);
}
  /*
check dbs ibanking procedure
*/
int DBSIBCheck(std::vector <IBInfo *> & HandledIB, std::vector <IBInfo *> & NewIB) {
   // return immediately whenever anything is wrong.
 // due to abnormal exit, we need to clear memory
 if (DBSCurlResponse.memory) {
  
  free(DBSCurlResponse.memory);
    DBSCurlResponse.memory = NULL;
  DBSCurlResponse.size = 0;
 }
   
 //
 // STEP 0
 // check whether to continue last session
 //
   if (DBSContLastSession) {
  
  //std::cout << "continue last session" << std::endl;
  
  DBSContLastSession = false;
  goto DBS_CONT_LAST_SESSION;
   } else {
    //std::cout << "use new session" << std::endl;
  
  DBSCurlInitialize();
   }
   //
 // STEP 1
 // GET DBS Login Page
 //
   // specify URL & POST content variables
 strcpy(DBSHTTPURLBuffer, "https://SOMEHTTPSURL");
 strcpy(DBSFormPOSTVariable, "FROM_IB=TRUE");
   // fetch DBS web page
 // ============> the bug is found here <====================
 // after long time sleep, e.g. 8 hours.
 curl_easy_perform(DBSCurlHandle);
 sleep(2);
   if (DBSCurlResponse.memory == NULL) {
  return 100;
 }
 
 /// A LOT OF STEPS
 // BLAH BLAH BLAH BLAH BLAH BLAH
  
DBS_CONT_LAST_SESSION:
   // fetch DBS web page
 curl_easy_perform(DBSCurlHandle);
 sleep(2);
   if (DBSCurlResponse.memory == NULL) {
  return 104;
 }
   // no error till now, so to
 // continue this session next time
 DBSContLastSession = true;
   return 0;
}

cremes.devlist_at_mac.com wrote:
  
On May 15, 2006, at 7:07 AM, GOD GOD wrote:

> I have tried to write a programme based on libcurl to regularly
> retrieve a HTTPS web page. This programme sleeps regular at night
> time, and wake up at 8 sharp morning.
>
> The programme i completed works well on Redhat Linux 9.0. When i
> tried to port to FreeBSD 6.0 . I found the programme crashes, when
> waking up. I have tried to locate the bugs to
>
> this line "curl_easy_perform(SomeCurlHandle);"
>
> Is this an OS related problem?
> What i guess, upon the problem, is FreeBSD regularly clean up the
> socket resource, which happens to touch the data struct of the curl
> handle, becuase the programme sleeps for 8 hours. This does not
> cause a problem on Red Hat Linux, and it does happen on FreeBSD.
> When the programme (on FreeBSD) gets back to run again, the data
> structure is ruined. It Crashes.
>
> Can anyone help me to figure out? I have already tried to GOOGLE,
> no much information out.

Post your code. No one can help you based on what you've written
above. Also, tell us what version of libcurl you are using.

Send instant messages to your online friends http://asia.messenger.yahoo.com
Received on 2006-05-15