Revise usage of print_{error,fatal}()

Let's limit print_fatal() to unexpected conditions.

Also added exit_fatal() to save a few lines of code.
This commit is contained in:
2014-07-16 23:23:03 +02:00
parent e00d2079b5
commit 1842fa90dd
3 changed files with 28 additions and 50 deletions

View File

@@ -65,10 +65,7 @@ static void
setup_signal_handlers (void)
{
if (pipe (g_signal_pipe) == -1)
{
print_fatal ("pipe: %s", strerror (errno));
exit (EXIT_FAILURE);
}
exit_fatal ("%s: %s", "pipe", strerror (errno));
set_cloexec (g_signal_pipe[0]);
set_cloexec (g_signal_pipe[1]);
@@ -87,10 +84,7 @@ setup_signal_handlers (void)
sa.sa_handler = sigterm_handler;
if (sigaction (SIGINT, &sa, NULL) == -1
|| sigaction (SIGTERM, &sa, NULL) == -1)
{
print_error ("sigaction: %s", strerror (errno));
exit (EXIT_FAILURE);
}
exit_fatal ("%s: %s", "sigaction", strerror (errno));
}
// --- IRC token validation ----------------------------------------------------
@@ -1011,10 +1005,8 @@ on_irc_client_available (const struct pollfd *pfd, void *user_data)
// TODO: handle resource exhaustion (EMFILE, ENFILE) specially
// (stop accepting new connections and wait until we close some).
print_fatal ("%s: %s", "accept", strerror (errno));
// FIXME: handle this better, bring the server down cleanly.
exit (EXIT_FAILURE);
exit_fatal ("%s: %s", "accept", strerror (errno));
}
char host[NI_MAXHOST] = "unknown", port[NI_MAXSERV] = "unknown";
@@ -1363,7 +1355,7 @@ main (int argc, char *argv[])
call_write_default_config (optarg, g_config_table);
exit (EXIT_SUCCESS);
default:
print_fatal ("error in options");
print_error ("wrong options");
exit (EXIT_FAILURE);
}
}
@@ -1384,7 +1376,7 @@ main (int argc, char *argv[])
struct error *e = NULL;
if (!read_config_file (&ctx.config, &e))
{
print_fatal ("error loading configuration: %s", e->message);
print_error ("error loading configuration: %s", e->message);
error_free (e);
exit (EXIT_FAILURE);
}