Skip to content

Commit 56665b7

Browse files
lebinzhanglebinzhang
authored andcommitted
process return EIO instead of exit
1 parent 7bbb936 commit 56665b7

File tree

1 file changed

+71
-50
lines changed

1 file changed

+71
-50
lines changed

src/curl.cpp

Lines changed: 71 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -617,51 +617,75 @@ string S3fsCurl::LookupMimeType(string name)
617617

618618
bool S3fsCurl::LocateBundle(void)
619619
{
620-
// See if environment variable CURL_CA_BUNDLE is set
621-
// if so, check it, if it is a good path, then set the
622-
// curl_ca_bundle variable to it
623-
char *CURL_CA_BUNDLE;
624-
625-
if(0 == S3fsCurl::curl_ca_bundle.size()){
626-
CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
627-
if(CURL_CA_BUNDLE != NULL) {
628-
// check for existence and readability of the file
629-
ifstream BF(CURL_CA_BUNDLE);
630-
if(!BF.good()){
631-
S3FS_PRN_ERR("%s: file specified by CURL_CA_BUNDLE environment variable is not readable", program_name.c_str());
632-
return false;
633-
}
634-
BF.close();
635-
S3fsCurl::curl_ca_bundle.assign(CURL_CA_BUNDLE);
636-
return true;
620+
// See if environment variable CURL_CA_BUNDLE is set
621+
// if so, check it, if it is a good path, then set the
622+
// curl_ca_bundle variable to it
623+
if(S3fsCurl::curl_ca_bundle.empty()){
624+
char* CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
625+
if(CURL_CA_BUNDLE != NULL) {
626+
// check for existence and readability of the file
627+
std::ifstream BF(CURL_CA_BUNDLE);
628+
if(!BF.good()){
629+
S3FS_PRN_ERR("%s: file specified by CURL_CA_BUNDLE environment variable is not readable", program_name.c_str());
630+
return false;
631+
}
632+
BF.close();
633+
S3fsCurl::curl_ca_bundle = CURL_CA_BUNDLE;
634+
return true;
635+
}
636+
}else{
637+
// Already set ca bundle variable
638+
return true;
637639
}
638-
}
639640

640-
// not set via environment variable, look in likely locations
641-
642-
///////////////////////////////////////////
643-
// from curl's (7.21.2) acinclude.m4 file
644-
///////////////////////////////////////////
645-
// dnl CURL_CHECK_CA_BUNDLE
646-
// dnl -------------------------------------------------
647-
// dnl Check if a default ca-bundle should be used
648-
// dnl
649-
// dnl regarding the paths this will scan:
650-
// dnl /etc/ssl/certs/ca-certificates.crt Debian systems
651-
// dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
652-
// dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
653-
// dnl /usr/local/share/certs/ca-root.crt FreeBSD
654-
// dnl /etc/ssl/cert.pem OpenBSD
655-
// dnl /etc/ssl/certs/ (ca path) SUSE
656-
ifstream BF("/etc/pki/tls/certs/ca-bundle.crt");
657-
if(BF.good()){
658-
BF.close();
659-
S3fsCurl::curl_ca_bundle.assign("/etc/pki/tls/certs/ca-bundle.crt");
660-
}else{
661-
S3FS_PRN_ERR("%s: /etc/pki/tls/certs/ca-bundle.crt is not readable", program_name.c_str());
662-
return false;
663-
}
664-
return true;
641+
// not set via environment variable, look in likely locations
642+
643+
///////////////////////////////////////////
644+
// following comment from curl's (7.21.2) acinclude.m4 file
645+
///////////////////////////////////////////
646+
// dnl CURL_CHECK_CA_BUNDLE
647+
// dnl -------------------------------------------------
648+
// dnl Check if a default ca-bundle should be used
649+
// dnl
650+
// dnl regarding the paths this will scan:
651+
// dnl /etc/ssl/certs/ca-certificates.crt Debian systems
652+
// dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
653+
// dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
654+
// dnl /usr/local/share/certs/ca-root.crt FreeBSD
655+
// dnl /etc/ssl/cert.pem OpenBSD
656+
// dnl /etc/ssl/certs/ (ca path) SUSE
657+
///////////////////////////////////////////
658+
// Within CURL the above path should have been checked
659+
// according to the OS. Thus, although we do not need
660+
// to check files here, we will only examine some files.
661+
//
662+
std::ifstream BF("/etc/pki/tls/certs/ca-bundle.crt");
663+
if(BF.good()){
664+
BF.close();
665+
S3fsCurl::curl_ca_bundle = "/etc/pki/tls/certs/ca-bundle.crt";
666+
}else{
667+
BF.open("/etc/ssl/certs/ca-certificates.crt");
668+
if(BF.good()){
669+
BF.close();
670+
S3fsCurl::curl_ca_bundle = "/etc/ssl/certs/ca-certificates.crt";
671+
}else{
672+
BF.open("/usr/share/ssl/certs/ca-bundle.crt");
673+
if(BF.good()){
674+
BF.close();
675+
S3fsCurl::curl_ca_bundle = "/usr/share/ssl/certs/ca-bundle.crt";
676+
}else{
677+
BF.open("/usr/local/share/certs/ca-root.crt");
678+
if(BF.good()){
679+
BF.close();
680+
S3fsCurl::curl_ca_bundle = "/usr/share/ssl/certs/ca-bundle.crt";
681+
}else{
682+
S3FS_PRN_ERR("%s: /.../ca-bundle.crt is not readable", program_name.c_str());
683+
return false;
684+
}
685+
}
686+
}
687+
}
688+
return true;
665689
}
666690

667691
size_t S3fsCurl::WriteMemoryCallback(void* ptr, size_t blockSize, size_t numBlocks, void* data)
@@ -1935,13 +1959,12 @@ int S3fsCurl::RequestPerform(void)
19351959
if(0 == S3fsCurl::curl_ca_bundle.size()){
19361960
if(!S3fsCurl::LocateBundle()){
19371961
S3FS_PRN_CRIT("could not get CURL_CA_BUNDLE.");
1938-
exit(EXIT_FAILURE);
1962+
return -EIO;
19391963
}
19401964
break; // retry with CAINFO
19411965
}
19421966
S3FS_PRN_CRIT("curlCode: %d msg: %s", curlCode, curl_easy_strerror(curlCode));
1943-
exit(EXIT_FAILURE);
1944-
break;
1967+
return -EIO;
19451968

19461969
#ifdef CURLE_PEER_FAILED_VERIFICATION
19471970
case CURLE_PEER_FAILED_VERIFICATION:
@@ -1957,8 +1980,7 @@ int S3fsCurl::RequestPerform(void)
19571980
}else{
19581981
S3FS_PRN_INFO("my_curl_easy_perform: curlCode: %d -- %s", curlCode, curl_easy_strerror(curlCode));
19591982
}
1960-
exit(EXIT_FAILURE);
1961-
break;
1983+
return -EIO;
19621984
#endif
19631985

19641986
// This should be invalid since curl option HTTP FAILONERROR is now off
@@ -1982,8 +2004,7 @@ int S3fsCurl::RequestPerform(void)
19822004
// Unknown CURL return code
19832005
default:
19842006
S3FS_PRN_CRIT("###curlCode: %d msg: %s", curlCode, curl_easy_strerror(curlCode));
1985-
exit(EXIT_FAILURE);
1986-
break;
2007+
return -EIO;
19872008
}
19882009
S3FS_PRN_INFO("### retrying...");
19892010

0 commit comments

Comments
 (0)