I'm an experienced programmer but new to curl. I have implemented a fuse filesystem that send notifications on open/close mkdir/rmdir events via curl to a web logic server, by emulating a SOAP/XML request, and it gets a response back via the write function callback. My test case is a recursive copy of a filesystem with lots of small files. Using curl 7.29.0, compiled manually for OEL5 (RHEL5), since the dependency list for the binary got complicated. This consistently crashes after while, and I get a SEGV but the stack is somewhat mangled, but is always the same... Is this a known issue that is fixed? Would you like more information? (gdb) where #0 0x00007fd213f452b2 in addbyter () from /usr/local/lib/libcurl.so.4 #1 0x00007fd213f45bac in dprintf_formatf () from /usr/local/lib/libcurl.so.4 #2 0x00007fd213f46bf5 in curl_mvsnprintf () from /usr/local/lib/libcurl.so.4 #3 0x00007fd213f45473 in curl_msnprintf () from /usr/local/lib/libcurl.so.4 #4 0x00007fd213f32eae in Curl_failf () from /usr/local/lib/libcurl.so.4 #5 0x00007fd213f29d91 in Curl_resolv_timeout () from /usr/local/lib/libcurl.so.4 #6 0x00007fd213f39ed8 in resolve_server () from /usr/local/lib/libcurl.so.4 #7 0x00007fd213f3c095 in create_conn () from /usr/local/lib/libcurl.so.4 #8 0x00007fd2043b6a90 in ?? () #9 0x0000000100000000 in ?? () #10 0x00007fd2141751b8 in Curl_cmalloc () from /usr/local/lib/libcurl.so.4 #11 0x0000000100000000 in ?? () #12 0x00007fd204448c20 in ?? () #13 0x0000000100000000 in ?? () #14 0x00007fd2044a6550 in ?? () #15 0x00007fd200000000 in ?? () #16 0x0000000000000015 in ?? () #17 0x0000000100000000 in ?? () #18 0x00007fd204594330 in ?? () #19 0x0000000100000000 in ?? () #20 0x00007fd2044a6550 in ?? () #21 0x0000000000000038 in ?? () #22 0x0000000000000007 in ?? () #23 0x0000000100000000 in ?? () #24 0x00007fd2141751b8 in Curl_cmalloc () from /usr/local/lib/libcurl.so.4 #25 0x00007fd213f16000 in ?? () #26 0x0000000000000020 in ?? () #27 0x0000000000000020 in ?? () #28 0x00007fd204574410 in ?? () #29 0x0000000000000020 in ?? () #30 0x00007fd2141751b8 in Curl_cmalloc () from /usr/local/lib/libcurl.so.4 #31 0x00007fd213f16000 in ?? () #32 0x00007fd204574410 in ?? () #33 0x00007fd2141751b8 in Curl_cmalloc () from /usr/local/lib/libcurl.so.4 #34 0x0000000000000000 in ?? () (gdb) Here is my curl send/receive code: static char *afs_uri_str = NULL; static char *afs_hostname = NULL; static char *afs_port_str = NULL; struct MemoryStruct { char *memory; size_t size; size_t max_size; }; static size_t getWriteDataCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; // -1 because we need room for the null termination. // mem->size can not be greater that mem->max_size -1 if (mem->size >= (mem->max_size - 1)) // if already full { LOG_WARN("Server returned message larger than buffer size!"); return 0; } if ((mem->size + realsize) >= mem->max_size) { LOG_WARN("Server message larger than buffer size!"); realsize = mem->max_size - mem->size - 1; // fill the buffer } memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = '\0'; return realsize; } static void afs_curl_build_payload(char *payload, size_t payload_max_size, const char *msg, const char *action, payload_type_t payload_type) { (void) payload_type; // stop compiler complaining snprintf(payload, payload_max_size, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns1=\"%s\">\n" " <env:Header />\n" " <env:Body>\n" " <ns1:%s>\n" " <arg0>%s</arg0>\n" " </ns1:%s>\n" " </env:Body>\n" "</env:Envelope>\n", AFS_NAME_SPACE, action, msg, action); return; } /* Common init routine between send and send_recieve */ static CURL *afs_curl_send_common(int debug_flag) { CURL *curl = curl_easy_init(); // calls global init if (!curl) { LOG_ERROR("ERROR: Curl library init failed!"); return NULL; } if (afs_uri_str == NULL) { afs_uri_str = calloc(1, AFS_MAX_PATH); if (!afs_uri_str) { return -ENOMEM; } curl_global_init(CURL_GLOBAL_ALL); // do this once... } sprintf(afs_uri_str, "http://%s:%s/%s", afs_hostname, afs_port_str, AFS_CURL_DEFAULT_ENDPOINT); if (debug_flag) { /* The DEBUGFUNCTION has no effect until we enable VERBOSE */ curl_easy_setopt(curl, CURLOPT_HEADER, 1L); // Include header in output curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); } // DEBUG //curl_easy_setopt(curl, CURLOPT_NOPROXY, afs_hostname); // works for 7.29 not 7.15 curl_easy_setopt(curl, CURLOPT_URL, afs_uri_str); return curl; } int afs_curl_send_receive(const char *msg, char *outmsg, size_t outmsg_max_len, char *action) { struct curl_slist * headers=NULL; char payload[PAYLOAD_SIZE]; struct MemoryStruct responseDataChunk; int rc; CURLcode res; CURL *curl = afs_curl_send_common(afs_debug_flag); if (curl == NULL) { return -1; } /* Build the SOAP request message payload */ afs_curl_build_payload(payload, PAYLOAD_SIZE, msg, action, PAYLOAD_TYPE_NO_HTTP_HEADERS); /* Set up response function to collect all return data */ responseDataChunk.memory = outmsg; responseDataChunk.size = 0; // amount of data received responseDataChunk.max_size = outmsg_max_len; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getWriteDataCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseDataChunk); /* pass our list of custom made headers */ //Note: Can't set the POST line using the CURLOPT_HTTPHEADER //headers = curl_slist_append(headers, // "POST http://bluefire:7111/OurayFuseWS/OurayFuseServicePort HTTP/1.1"); headers = curl_slist_append(headers, "Content-Type: application/soap+xml; charset=UTF-8"); headers = curl_slist_append(headers, "SOAPAction: \"\""); headers = curl_slist_append(headers, "Action:"); // remove this, we have soap action (this does not work?) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload); LOG_DEBUG("Performing curl sync send"); //LOG_DEBUG("###Send curl async:\n%s\n###End sent data", payload); res = curl_easy_perform(curl); if (CURLE_OK != res) { LOG_ERROR("ERROR:curl connect failed %s", curl_easy_strerror(res)); rc = -2; } LOG_DEBUG("### Received (%ld, max %ld) bytes:\n%s\n### /Received", responseDataChunk.size, PAYLOAD_SIZE, responseDataChunk.memory); //LOG_DEBUG("curl async send completed, free resources"); curl_slist_free_all(headers); curl_easy_cleanup(curl); return rc; } Ceri Davies | Principal Software Engineer | [email protected] Work: +1 3032727810 x77810 | Home: +1 3035321116 | Cell: +1 3038706743 (Note: Home phone forwards to Cell, so try Home# first)
Oracle Storage | 500 Eldorado Blvd. | Broomfield, CO 80021 |
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
