nghttpx: Don't exit from save_pid and set_alpn_prefs

This commit is contained in:
Tatsuhiro Tsujikawa 2016-07-31 20:35:10 +09:00
parent 9a8e9815c9
commit e2906025c8
3 changed files with 18 additions and 16 deletions

View File

@ -294,7 +294,7 @@ int chown_to_running_user(const char *path) {
} // namespace
namespace {
void save_pid() {
int save_pid() {
constexpr auto SUFFIX = StringRef::from_lit(".XXXXXX");
auto &pid_file = get_config()->pid_file;
@ -313,7 +313,7 @@ void save_pid() {
auto error = errno;
LOG(ERROR) << "Could not save PID to file " << pid_file << ": "
<< strerror(error);
exit(EXIT_FAILURE);
return -1;
}
auto content = util::utos(get_config()->pid) + '\n';
@ -322,14 +322,14 @@ void save_pid() {
auto error = errno;
LOG(ERROR) << "Could not save PID to file " << pid_file << ": "
<< strerror(error);
exit(EXIT_FAILURE);
return -1;
}
if (fsync(fd) == -1) {
auto error = errno;
LOG(ERROR) << "Could not save PID to file " << pid_file << ": "
<< strerror(error);
exit(EXIT_FAILURE);
return -1;
}
close(fd);
@ -341,7 +341,7 @@ void save_pid() {
unlink(temp_path);
exit(EXIT_FAILURE);
return -1;
}
if (get_config()->uid != 0) {
@ -351,6 +351,8 @@ void save_pid() {
<< " failed: " << strerror(error);
}
}
return 0;
}
} // namespace
@ -2379,7 +2381,9 @@ int process_options(Config *config,
tlsconf.tls_proto_mask = ssl::create_tls_proto_mask(tlsconf.tls_proto_list);
tlsconf.alpn_prefs = ssl::set_alpn_prefs(tlsconf.npn_list);
if (ssl::set_alpn_prefs(tlsconf.alpn_prefs, tlsconf.npn_list) != 0) {
return -1;
}
tlsconf.bio_method = create_bio_method();

View File

@ -94,16 +94,14 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
}
} // namespace
// This function is meant be called from master process, hence the
// call exit(3).
std::vector<unsigned char>
set_alpn_prefs(const std::vector<std::string> &protos) {
int set_alpn_prefs(std::vector<unsigned char> &out,
const std::vector<std::string> &protos) {
size_t len = 0;
for (const auto &proto : protos) {
if (proto.size() > 255) {
LOG(FATAL) << "Too long ALPN identifier: " << proto.size();
exit(EXIT_FAILURE);
return -1;
}
len += 1 + proto.size();
@ -111,10 +109,10 @@ set_alpn_prefs(const std::vector<std::string> &protos) {
if (len > (1 << 16) - 1) {
LOG(FATAL) << "Too long ALPN identifier list: " << len;
exit(EXIT_FAILURE);
return -1;
}
auto out = std::vector<unsigned char>(len);
out.resize(len);
auto ptr = out.data();
for (const auto &proto : protos) {
@ -123,7 +121,7 @@ set_alpn_prefs(const std::vector<std::string> &protos) {
ptr += proto.size();
}
return out;
return 0;
}
namespace {

View File

@ -181,8 +181,8 @@ bool check_http2_requirement(SSL *ssl);
// passed to SSL_CTX_set_options().
long int create_tls_proto_mask(const std::vector<std::string> &tls_proto_list);
std::vector<unsigned char>
set_alpn_prefs(const std::vector<std::string> &protos);
int set_alpn_prefs(std::vector<unsigned char> &out,
const std::vector<std::string> &protos);
// Setups server side SSL_CTX. This function inspects get_config()
// and if upstream_no_tls is true, returns nullptr. Otherwise