MEDIUM: initcall: use initcalls for a few initialization functions
signal_init(), init_log(), init_stream(), and init_task() all used to
only preset some values and lists. This needs to be done very early to
provide a reliable interface to all other users. The calls used to be
explicit in haproxy.c:init(). Now they're placed in initcalls at the
STG_PREPARE stage. The functions are not exported anymore.
diff --git a/include/proto/log.h b/include/proto/log.h
index e127431..b05ab3e 100644
--- a/include/proto/log.h
+++ b/include/proto/log.h
@@ -54,12 +54,6 @@
extern THREAD_LOCAL char *logline_rfc5424;
-/*
- * Initializes some log data.
- */
-void init_log();
-
-
/* Initialize/Deinitialize log buffers used for syslog messages */
int init_log_buffers();
void deinit_log_buffers();
diff --git a/include/proto/signal.h b/include/proto/signal.h
index ff6976d..ef2892a 100644
--- a/include/proto/signal.h
+++ b/include/proto/signal.h
@@ -25,7 +25,6 @@
void signal_handler(int sig);
void __signal_process_queue();
-int signal_init();
void deinit_signals();
struct sig_handler *signal_register_fct(int sig, void (*fct)(struct sig_handler *), int arg);
struct sig_handler *signal_register_task(int sig, struct task *task, int reason);
diff --git a/include/proto/stream.h b/include/proto/stream.h
index 8c6773e..f448209 100644
--- a/include/proto/stream.h
+++ b/include/proto/stream.h
@@ -39,9 +39,6 @@
struct stream *stream_new(struct session *sess, enum obj_type *origin);
int stream_create_from_cs(struct conn_stream *cs);
-/* perform minimal intializations, report 0 in case of error, 1 if OK. */
-int init_stream();
-
/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
void stream_shutdown(struct stream *stream, int why);
diff --git a/include/proto/task.h b/include/proto/task.h
index 264899e..111a0cf 100644
--- a/include/proto/task.h
+++ b/include/proto/task.h
@@ -553,9 +553,6 @@
*/
int wake_expired_tasks();
-/* Perform minimal initializations, report 0 in case of error, 1 if OK. */
-int init_task();
-
#endif /* _PROTO_TASK_H */
/*
diff --git a/src/haproxy.c b/src/haproxy.c
index 96715ee..6567b43 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1426,12 +1426,9 @@
srandom(now_ms - getpid());
- init_log();
- signal_init();
if (init_acl() != 0)
exit(1);
- init_task();
- init_stream();
+
/* warning, we init buffers later */
if (!init_http(&err_msg)) {
ha_alert("%s. Aborting.\n", err_msg);
diff --git a/src/log.c b/src/log.c
index 77d58e2..3093cce 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1581,9 +1581,8 @@
} while(0)
-/* Initializes some log data.
- */
-void init_log()
+/* Initializes some log data at boot */
+static void init_log()
{
char *tmp;
int i;
@@ -1656,6 +1655,8 @@
FD_SET(0x7f, http_encode_map);
}
+INITCALL0(STG_PREPARE, init_log);
+
static int init_log_buffers_per_thread()
{
return init_log_buffers();
diff --git a/src/signal.c b/src/signal.c
index b6ed1a6..2484a44 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -100,8 +100,8 @@
ha_sigmask(SIG_SETMASK, &old_sig, NULL);
}
-/* perform minimal intializations, report 0 in case of error, 1 if OK. */
-int signal_init()
+/* perform minimal intializations */
+static void signal_init()
{
int sig;
@@ -121,8 +121,6 @@
sigdelset(&blocked_sig, SIGSEGV);
for (sig = 0; sig < MAX_SIGNAL; sig++)
LIST_INIT(&signal_state[sig].handlers);
-
- return 1;
}
/*
@@ -273,3 +271,5 @@
signal(sig, SIG_IGN);
}
+
+INITCALL0(STG_PREPARE, signal_init);
diff --git a/src/stream.c b/src/stream.c
index da59cf1..bba3f67 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -65,7 +65,7 @@
DECLARE_POOL(pool_head_stream, "stream", sizeof(struct stream));
-struct list streams;
+struct list streams = LIST_HEAD_INIT(streams);
__decl_spinlock(streams_lock);
/* List of all use-service keywords. */
@@ -512,14 +512,6 @@
offer_buffers(s, tasks_run_queue);
}
-/* perform minimal intializations, report 0 in case of error, 1 if OK. */
-int init_stream()
-{
- LIST_INIT(&streams);
-
- return 1;
-}
-
void stream_process_counters(struct stream *s)
{
struct session *sess = s->sess;
diff --git a/src/task.c b/src/task.c
index aeb3e4e..1f09f13 100644
--- a/src/task.c
+++ b/src/task.c
@@ -469,8 +469,8 @@
}
}
-/* perform minimal intializations, report 0 in case of error, 1 if OK. */
-int init_task()
+/* perform minimal intializations */
+static void init_task()
{
int i;
@@ -482,9 +482,10 @@
for (i = 0; i < MAX_THREADS; i++) {
LIST_INIT(&task_per_thread[i].task_list);
}
- return 1;
}
+INITCALL0(STG_PREPARE, init_task);
+
/*
* Local variables:
* c-indent-level: 8