void protocol_unregister(struct protocol *proto);
/* binds all listeners of all registered protocols. Returns a composition
- * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
+ * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
*/
-int protocol_bind_all(char *errmsg, int errlen);
+int protocol_bind_all(int verbose);
/* unbinds all listeners of all registered protocols. They are also closed.
* This must be performed before calling exit() in order to get a chance to
extern const struct cfg_opt cfg_opts[];
extern const struct cfg_opt cfg_opts2[];
-int start_proxies(int verbose);
+void start_proxies(void);
struct task *manage_proxy(struct task *t, void *context, unsigned short state);
void soft_stop(void);
int pause_proxy(struct proxy *p);
{
int err, retry;
struct rlimit limit;
- char errmsg[100];
int pidfd = -1;
setvbuf(stdout, NULL, _IONBF, 0);
err = ERR_NONE;
while (retry >= 0) {
struct timeval w;
- err = start_proxies(retry == 0 || nb_oldpids == 0);
+ err = protocol_bind_all(retry == 0 || nb_oldpids == 0);
/* exit the loop on no error or fatal error */
if ((err & (ERR_RETRYABLE|ERR_FATAL)) != ERR_RETRYABLE)
break;
retry--;
}
- /* Note: start_proxies() sends an alert when it fails. */
+ /* Note: protocol_bind_all() sends an alert when it fails. */
if ((err & ~ERR_WARN) != ERR_NONE) {
+ ha_alert("[%s.main()] Some protocols failed to start their listeners! Exiting.\n", argv[0]);
if (retry != MAX_START_RETRIES && nb_oldpids) {
protocol_unbind_all(); /* cleanup everything we can */
tell_old_pids(SIGTTIN);
exit(1);
}
+ start_proxies();
+
if (!(global.mode & MODE_MWORKER_WAIT) && listeners == 0) {
ha_alert("[%s.main()] No enabled listener found (check for 'bind' directives) ! Exiting.\n", argv[0]);
/* Note: we don't have to send anything to the old pids because we
exit(1);
}
- err = protocol_bind_all(errmsg, sizeof(errmsg));
- if ((err & ~ERR_WARN) != ERR_NONE) {
- if ((err & ERR_ALERT) || (err & ERR_WARN))
- ha_alert("[%s.main()] %s.\n", argv[0], errmsg);
-
- ha_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) {
- ha_alert("[%s.main()] %s.\n", argv[0], errmsg);
- }
- /* Ok, all listener should now be bound, close any leftover sockets
+ /* Ok, all listeners should now be bound, close any leftover sockets
* the previous process gave us, we don't need them anymore
*/
while (xfer_sock_list != NULL) {
#include <haproxy/list.h>
#include <haproxy/listener.h>
#include <haproxy/protocol.h>
+#include <haproxy/proxy.h>
#include <haproxy/tools.h>
/* binds all listeners of all registered protocols. Returns a composition
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
*/
-int protocol_bind_all(char *errmsg, int errlen)
+int protocol_bind_all(int verbose)
{
struct protocol *proto;
struct listener *listener;
- int err;
+ char msg[100];
+ int err, lerr;
err = 0;
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
list_for_each_entry(proto, &protocols, list) {
list_for_each_entry(listener, &proto->listeners, proto_list) {
- err |= proto->bind(listener, errmsg, errlen);
- if (err & ERR_ABORT)
+ lerr = proto->bind(listener, msg, sizeof(msg));
+
+ /* errors are reported if <verbose> is set or if they are fatal */
+ if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) {
+ struct proxy *px = listener->bind_conf->frontend;
+
+ if (lerr & ERR_ALERT)
+ ha_alert("Starting %s %s: %s\n",
+ proxy_type_str(px), px->id, msg);
+ else if (lerr & ERR_WARN)
+ ha_warning("Starting %s %s: %s\n",
+ proxy_type_str(px), px->id, msg);
+ }
+
+ err |= lerr;
+ if (lerr & ERR_ABORT)
break;
}
+ if (err & ERR_ABORT)
+ break;
}
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
return err;
}
/*
- * This function creates all proxy sockets. It should be done very early,
- * typically before privileges are dropped. The sockets will be registered
- * but not added to any fd_set, in order not to loose them across the fork().
- * The proxies also start in READY state because they all have their listeners
- * bound.
- *
- * Its return value is composed from ERR_NONE, ERR_RETRYABLE and ERR_FATAL.
- * Retryable errors will only be printed if <verbose> is not zero.
- */
-int start_proxies(int verbose)
+ * This function finishes the startup of proxies by marking them ready. */
+void start_proxies(void)
{
struct proxy *curproxy;
- struct listener *listener;
- int lerr, err = ERR_NONE;
- int pxerr;
- char msg[100];
for (curproxy = proxies_list; curproxy != NULL; curproxy = curproxy->next) {
if (curproxy->state != PR_STNEW)
continue; /* already initialized */
- pxerr = 0;
- list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
- if (listener->state != LI_ASSIGNED)
- continue; /* already started */
-
- lerr = listener->proto->bind(listener, msg, sizeof(msg));
-
- /* errors are reported if <verbose> is set or if they are fatal */
- if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) {
- if (lerr & ERR_ALERT)
- ha_alert("Starting %s %s: %s\n",
- proxy_type_str(curproxy), curproxy->id, msg);
- else if (lerr & ERR_WARN)
- ha_warning("Starting %s %s: %s\n",
- proxy_type_str(curproxy), curproxy->id, msg);
- }
-
- err |= lerr;
- if (lerr & (ERR_ABORT | ERR_FATAL)) {
- pxerr |= 1;
- break;
- }
- else if (lerr & ERR_CODE) {
- pxerr |= 1;
- continue;
- }
- }
-
- if (!pxerr) {
- curproxy->state = PR_STREADY;
- send_log(curproxy, LOG_NOTICE, "Proxy %s started.\n", curproxy->id);
- }
-
- if (err & ERR_ABORT)
- break;
+ curproxy->state = PR_STREADY;
+ send_log(curproxy, LOG_NOTICE, "Proxy %s started.\n", curproxy->id);
}
-
- return err;
}