error SSL de libCurl después de la bifurcación ()
Estoy desarrollando un controlador FUSE y cuando lo ejecuto como un demonio (sin las marcas -f o -d) todas las solicitudes https realizadas a través de libcurl fallan. Pude reproducir el error haciendo una solicitud https, bifurcando y devolviendo el proceso principal, y luego realizando una segunda solicitud del nuevo proceso. Si quito elfork
llamar o hacer una solicitud http no hay errores.
Estoy haciendo un informe oficial de errores ahora mismo, pero ¿alguien sabe cómo puedo hacer que funcione?
Aquí está mi código y la salida (archivo de registro):
Nota: si ejecuta mi programa, canalice a / dev / null porque libcurl envía el búfer recibido a la salida estándar de forma predeterminada.
#include <curl/curl.h>
#include <string>
#include <unistd.h>
#include <iostream>
using namespace std;
void log(string str)
{ //TODO: remove
static const char logfile[] = "/home/austin/megalog";
FILE *f = fopen(logfile, "a");
fwrite(str.data(), str.size(), 1, f);
fclose(f);
cout << str;
}
int main(int argc, char *argv[])
{
string url = "https://www.google.com/";
char errBuf[1024];
CURLcode err;
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL *handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf);
if ((err = curl_easy_perform(handle)))
{
log("first request failed\n");
return 1;
}
curl_easy_cleanup(handle);
if(fork())
return 0;
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf);
if ((err = curl_easy_perform(handle)))
{
log(string("curl error while sending: (") + to_string(err) + ") " + curl_easy_strerror(err) + "\n");
log(errBuf);
}
else
log("no error\n");
return 0;
}
... y la salida:
$ g++ -std=c++11 main.cpp -lcurl
$ rm -f log
$ ./a.out > /dev/null
$ cat log
curl error while sending: (35) SSL connect error
A PKCS #11 module returned CKR_DEVICE_ERROR, indicating that a problem has occurred with the token or slot.
Estoy usando (la última) libcurl versión 7.29.0, (la última) openssl versión 1.0.1e, y estoy ejecutando Fedora 18 con la versión del kernel 3.7.4.