cURL / Mailing Lists / curl-library / Single Mail

curl-library

SSL error after fork()

From: anon anon <anonemailforward15466_at_gmail.com>
Date: Sun, 17 Mar 2013 12:42:14 -1000

I'm getting an SSL error in the child process after calling fork(). I made
a short program that can reproduce it. Basically, if I make an https
request, call fork and return the parent process, and then make a second
https request, curl_easy_perform returns 35.

Contents of the error buffer:

A PKCS #11 module returned CKR_DEVICE_ERROR, indicating that a problem
has occurred with the token or slot.

main.cpp:

#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;
}

I'm using libcurl version 7.29.0 and openssl version ___. For more details,
see my stackoverflow question:
http://stackoverflow.com/questions/15466809/libcurl-ssl-error-after-fork

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-03-17