If two processes were both configured to bootstrap the CA certificate, then
one of them would succeed in writing it to a file and use it, and the other
one would fail to use it because the file was created behind its back.
This commit fixes the problem by making the bootstrap code accept a CA
certificate file that exists at the time that bootstrapping tries to create
it.
fd = open(ca_cert_file, O_CREAT | O_EXCL | O_WRONLY, 0444);
if (fd < 0) {
- VLOG_ERR("could not bootstrap CA cert: creating %s failed: %s",
- ca_cert_file, strerror(errno));
- return errno;
+ if (errno == EEXIST) {
+ VLOG_INFO("reading CA cert %s created by another process",
+ ca_cert_file);
+ stream_ssl_set_ca_cert_file(ca_cert_file, true);
+ return EPROTO;
+ } else {
+ VLOG_ERR("could not bootstrap CA cert: creating %s failed: %s",
+ ca_cert_file, strerror(errno));
+ return errno;
+ }
}
file = fdopen(fd, "w");