nghttpx: Add error handling for strdup and sigaction

This commit is contained in:
Tatsuhiro Tsujikawa 2015-10-16 22:33:48 +09:00
parent 54bf225692
commit 85bc696c38
2 changed files with 12 additions and 1 deletions

View File

@ -1682,6 +1682,11 @@ int main(int argc, char **argv) {
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
mod_config()->argv[i] = strdup(argv[i]); mod_config()->argv[i] = strdup(argv[i]);
if (mod_config()->argv[i] == nullptr) {
auto error = errno;
LOG(FATAL) << "failed to copy argv: " << strerror(error);
exit(EXIT_FAILURE);
}
} }
mod_config()->cwd = getcwd(nullptr, 0); mod_config()->cwd = getcwd(nullptr, 0);

View File

@ -97,8 +97,14 @@ void signal_set_handler(void (*handler)(int), Signals &&sigs) {
struct sigaction act {}; struct sigaction act {};
act.sa_handler = handler; act.sa_handler = handler;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
int rv;
for (auto sig : sigs) { for (auto sig : sigs) {
sigaction(sig, &act, nullptr); rv = sigaction(sig, &act, nullptr);
if (rv != 0) {
auto error = errno;
LOG(WARN) << "sigaction() with signal " << sig
<< " failed: errno=" << error;
}
} }
} }
} // namespace } // namespace