This patch replace
Alert(...); exit(1);
with
Alert(1, ...)
when it's possible.
---
src/haproxy.c | 176 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 87 insertions(+), 89 deletions(-)
diff --git a/src/haproxy.c b/src/haproxy.c
index 0c223e5..c1acea6 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -698,10 +698,9 @@ void init(int argc, char **argv)
while (argc > 1 && argv[1][0] != '-') {
oldpids = realloc(oldpids, (nb_oldpids
+ 1) * sizeof(int));
- if (!oldpids) {
- Alert("Cannot allocate old pid
: out of memory.\n");
- exit(1);
- }
+ if (!oldpids)
+ Alert_exit(1, "Cannot allocate
old pid : out of memory.\n");
+
argc--; argv++;
oldpids[nb_oldpids] = atol(*argv);
if (oldpids[nb_oldpids] <= 0)
@@ -714,10 +713,11 @@ void init(int argc, char **argv)
argv++; argc--;
while (argc > 0) {
wl = calloc(1, sizeof(*wl));
- if (!wl) {
- Alert("Cannot load
configuration file %s : out of memory.\n", *argv);
- exit(1);
- }
+ if (!wl)
+ Alert_exit(1,
+ "Cannot load
configuration file %s : out of memory.\n",
+ *argv);
+
wl->s = *argv;
LIST_ADDQ(&cfg_cfgfiles, &wl->list);
argv++; argc--;
@@ -737,10 +737,11 @@ void init(int argc, char **argv)
case 'L' : strncpy(localpeer, *argv,
sizeof(localpeer) - 1); break;
case 'f' :
wl = calloc(1, sizeof(*wl));
- if (!wl) {
- Alert("Cannot load
configuration file %s : out of memory.\n", *argv);
- exit(1);
- }
+ if (!wl)
+ Alert_exit(1,
+ "Cannot load
configuration file %s : out of memory.\n",
+ *argv);
+
wl->s = *argv;
LIST_ADDQ(&cfg_cfgfiles, &wl->list);
break;
@@ -761,10 +762,11 @@ void init(int argc, char **argv)
if (LIST_ISEMPTY(&cfg_cfgfiles))
usage(progname);
- if (change_dir && chdir(change_dir) < 0) {
- Alert("Could not change to directory %s : %s\n", change_dir,
strerror(errno));
- exit(1);
- }
+ if (change_dir && chdir(change_dir) < 0)
+ Alert_exit(1,
+ "Could not change to directory %s : %s\n",
+ change_dir,
+ strerror(errno));
global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket
eaters */
@@ -774,13 +776,15 @@ void init(int argc, char **argv)
int ret;
ret = readcfgfile(wl->s);
- if (ret == -1) {
- Alert("Could not open configuration file %s : %s\n",
- wl->s, strerror(errno));
- exit(1);
- }
+ if (ret == -1)
+ Alert_exit(1,
+ "Could not open configuration file %s :
%s\n",
+ wl->s,
+ strerror(errno));
+
if (ret & (ERR_ABORT|ERR_FATAL))
Alert("Error(s) found in configuration file : %s\n",
wl->s);
+
err_code |= ret;
if (err_code & ERR_ABORT)
exit(1);
@@ -792,10 +796,8 @@ void init(int argc, char **argv)
#endif
err_code |= check_config_validity();
- if (err_code & (ERR_ABORT|ERR_FATAL)) {
- Alert("Fatal errors found in configuration.\n");
- exit(1);
- }
+ if (err_code & (ERR_ABORT|ERR_FATAL))
+ Alert_exit(1, "Fatal errors found in configuration.\n");
/* recompute the amount of per-process memory depending on nbproc and
* the shared SSL cache size (allowed to exist in all processes).
@@ -815,10 +817,8 @@ void init(int argc, char **argv)
#ifdef CONFIG_HAP_NS
err_code |= netns_init();
- if (err_code & (ERR_ABORT|ERR_FATAL)) {
- Alert("Failed to initialize namespace support.\n");
- exit(1);
- }
+ if (err_code & (ERR_ABORT|ERR_FATAL))
+ Alert_exit(1, "Failed to initialize namespace support.\n");
#endif
if (global.mode & MODE_CHECK) {
@@ -846,10 +846,9 @@ void init(int argc, char **argv)
apply_server_state();
global_listener_queue_task = task_new();
- if (!global_listener_queue_task) {
- Alert("Out of memory when initializing global task\n");
- exit(1);
- }
+ if (!global_listener_queue_task)
+ Alert_exit(1, "Out of memory when initializing global task\n");
+
/* very simple initialization, users will queue the task if needed */
global_listener_queue_task->context = NULL; /* not even a context! */
global_listener_queue_task->process = manage_global_listener_queue;
@@ -866,11 +865,10 @@ void init(int argc, char **argv)
for (px = proxy; px; px = px->next) {
err_code |= flt_init(px);
- if (err_code & (ERR_ABORT|ERR_FATAL)) {
- Alert("Failed to initialize filters for proxy '%s'.\n",
- px->id);
- exit(1);
- }
+ if (err_code & (ERR_ABORT|ERR_FATAL))
+ Alert_exit(1,
+ "Failed to initialize filters for proxy
'%s'.\n",
+ px->id);
}
if (start_checks() < 0)
@@ -965,15 +963,14 @@ void init(int argc, char **argv)
global.maxsslconn = sslmem / (global.ssl_session_max_cost +
global.ssl_handshake_max_cost);
global.maxsslconn = round_2dig(global.maxsslconn);
- if (sslmem <= 0 || global.maxsslconn < sides) {
- Alert("Cannot compute the automatic maxsslconn because
global.maxconn is already too "
- "high for the global.memmax value (%d MB). The
absolute maximum possible value "
- "without SSL is %d, but %d was found and SSL is
in use.\n",
- global.rlimit_memmax,
- (int)(mem / (STREAM_MAX_COST + 2 *
global.tune.bufsize)),
- global.maxconn);
- exit(1);
- }
+ if (sslmem <= 0 || global.maxsslconn < sides)
+ Alert_exit(1,
+ "Cannot compute the automatic maxsslconn
because global.maxconn is already too "
+ "high for the global.memmax value (%d MB).
The absolute maximum possible value "
+ "without SSL is %d, but %d was found and SSL
is in use.\n",
+ global.rlimit_memmax,
+ (int)(mem / (STREAM_MAX_COST + 2 *
global.tune.bufsize)),
+ global.maxconn);
if (global.maxsslconn > sides * global.maxconn)
global.maxsslconn = sides * global.maxconn;
@@ -1005,15 +1002,14 @@ void init(int argc, char **argv)
global.maxconn = DEFAULT_MAXCONN;
#endif /* SYSTEM_MAXCONN */
- if (clearmem <= 0 || !global.maxconn) {
- Alert("Cannot compute the automatic maxconn because
global.maxsslconn is already too "
- "high for the global.memmax value (%d MB). The
absolute maximum possible value "
- "is %d, but %d was found.\n",
- global.rlimit_memmax,
- (int)(mem / (global.ssl_session_max_cost +
global.ssl_handshake_max_cost)),
- global.maxsslconn);
- exit(1);
- }
+ if (clearmem <= 0 || !global.maxconn)
+ Alert_exit(1,
+ "Cannot compute the automatic maxconn
because global.maxsslconn is already too "
+ "high for the global.memmax value (%d MB).
The absolute maximum possible value "
+ "is %d, but %d was found.\n",
+ global.rlimit_memmax,
+ (int)(mem / (global.ssl_session_max_cost +
global.ssl_handshake_max_cost)),
+ global.maxsslconn);
if (global.mode & (MODE_VERBOSE|MODE_DEBUG)) {
if (sides && global.maxsslconn > sides *
global.maxconn) {
@@ -1134,19 +1130,19 @@ void init(int argc, char **argv)
list_filters(stderr);
}
- if (!init_pollers()) {
- Alert("No polling mechanism available.\n"
- " It is likely that haproxy was built with
TARGET=generic and that FD_SETSIZE\n"
- " is too low on this platform to support maxconn and the
number of listeners\n"
- " and servers. You should rebuild haproxy specifying
your system using TARGET=\n"
- " in order to support other polling systems (poll,
epoll, kqueue) or reduce the\n"
- " global maxconn setting to accommodate the system's
limitation. For reference,\n"
- " FD_SETSIZE=%d on this system, global.maxconn=%d
resulting in a maximum of\n"
- " %d file descriptors. You should thus reduce
global.maxconn by %d. Also,\n"
- " check build settings using 'haproxy -vv'.\n\n",
- FD_SETSIZE, global.maxconn, global.maxsock,
(global.maxsock + 1 - FD_SETSIZE) / 2);
- exit(1);
- }
+ if (!init_pollers())
+ Alert_exit(1,
+ "No polling mechanism available.\n"
+ " It is likely that haproxy was built with
TARGET=generic and that FD_SETSIZE\n"
+ " is too low on this platform to support maxconn
and the number of listeners\n"
+ " and servers. You should rebuild haproxy
specifying your system using TARGET=\n"
+ " in order to support other polling systems (poll,
epoll, kqueue) or reduce the\n"
+ " global maxconn setting to accommodate the
system's limitation. For reference,\n"
+ " FD_SETSIZE=%d on this system, global.maxconn=%d
resulting in a maximum of\n"
+ " %d file descriptors. You should thus reduce
global.maxconn by %d. Also,\n"
+ " check build settings using 'haproxy -vv'.\n\n",
+ FD_SETSIZE, global.maxconn, global.maxsock,
(global.maxsock + 1 - FD_SETSIZE) / 2);
+
if (global.mode & (MODE_VERBOSE|MODE_DEBUG)) {
printf("Using %s() as the polling mechanism.\n",
cur_poller.name);
}
@@ -1729,24 +1725,27 @@ int main(int argc, char **argv)
exit(1);
}
- if (listeners == 0) {
- Alert("[%s.main()] No enabled listener found (check for 'bind'
directives) ! Exiting.\n", argv[0]);
+ if (listeners == 0)
/* Note: we don't have to send anything to the old pids because
we
* never stopped them. */
- exit(1);
- }
+ Alert_exit(1,
+ "[%s.main()] No enabled listener found (check for
'bind' directives) ! Exiting.\n",
+ argv[0]);
err = protocol_bind_all(errmsg, sizeof(errmsg));
if ((err & ~ERR_WARN) != ERR_NONE) {
if ((err & ERR_ALERT) || (err & ERR_WARN))
Alert("[%s.main()] %s.\n", argv[0], errmsg);
- Alert("[%s.main()] Some protocols failed to start their
listeners! Exiting.\n", argv[0]);
protocol_unbind_all(); /* cleanup everything we can */
if (nb_oldpids)
tell_old_pids(SIGTTIN);
- exit(1);
- } else if (err & ERR_WARN) {
+
+ Alert_exit(1,
+ "[%s.main()] Some protocols failed to start their
listeners! Exiting.\n",
+ argv[0]);
+ }
+ else if (err & ERR_WARN) {
Alert("[%s.main()] %s.\n", argv[0], errmsg);
}
@@ -1767,19 +1766,21 @@ int main(int argc, char **argv)
unlink(global.pidfile);
pidfd = open(global.pidfile, O_CREAT | O_WRONLY | O_TRUNC,
0644);
if (pidfd < 0) {
- Alert("[%s.main()] Cannot create pidfile %s\n",
argv[0], global.pidfile);
if (nb_oldpids)
tell_old_pids(SIGTTIN);
protocol_unbind_all();
- exit(1);
+ Alert_exit(1,
+ "[%s.main()] Cannot create pidfile %s\n",
+ argv[0],
+ global.pidfile);
}
}
if ((global.last_checks & LSTCHK_NETADM) && global.uid) {
- Alert("[%s.main()] Some configuration options require full
privileges, so global.uid cannot be changed.\n"
- "", argv[0]);
protocol_unbind_all();
- exit(1);
+ Alert_exit(1,
+ "[%s.main()] Some configuration options require full
privileges, so global.uid cannot be changed.\n",
+ argv[0]);
}
/* If the user is not root, we'll still let him try the configuration
@@ -1793,11 +1794,10 @@ int main(int argc, char **argv)
/* chroot if needed */
if (global.chroot != NULL) {
if (chroot(global.chroot) == -1 || chdir("/") == -1) {
- Alert("[%s.main()] Cannot chroot(%s).\n", argv[0],
global.chroot);
if (nb_oldpids)
tell_old_pids(SIGTTIN);
protocol_unbind_all();
- exit(1);
+ Alert_exit(1, "[%s.main()] Cannot chroot(%s).\n",
argv[0], global.chroot);
}
}
@@ -1815,16 +1815,14 @@ int main(int argc, char **argv)
" without 'uid'/'user' is generally
useless.\n", argv[0]);
if (setgid(global.gid) == -1) {
- Alert("[%s.main()] Cannot set gid %d.\n", argv[0],
global.gid);
protocol_unbind_all();
- exit(1);
+ Alert_exit(1, "[%s.main()] Cannot set gid %d.\n",
argv[0], global.gid);
}
}
if (global.uid && setuid(global.uid) == -1) {
- Alert("[%s.main()] Cannot set uid %d.\n", argv[0], global.uid);
protocol_unbind_all();
- exit(1);
+ Alert_exit(1, "[%s.main()] Cannot set uid %d.\n", argv[0],
global.uid);
}
/* check ulimits */
@@ -1846,9 +1844,9 @@ int main(int argc, char **argv)
for (proc = 0; proc < global.nbproc; proc++) {
ret = fork();
if (ret < 0) {
- Alert("[%s.main()] Cannot fork.\n", argv[0]);
+ /* there has been an error */
protocol_unbind_all();
- exit(1); /* there has been an error */
+ Alert_exit(1, "[%s.main()] Cannot fork.\n",
argv[0]);
}
else if (ret == 0) /* child breaks here */
break;
--
2.8.2