]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: initcall: use initcalls for a few initialization functions
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 15:31:20 +0000 (16:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
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.

include/proto/log.h
include/proto/signal.h
include/proto/stream.h
include/proto/task.h
src/haproxy.c
src/log.c
src/signal.c
src/stream.c
src/task.c

index e12743165630c155db4152f5906e4f7d0519925a..b05ab3efc40f9bea1dfd83123f8c602cd752c434 100644 (file)
@@ -54,12 +54,6 @@ extern THREAD_LOCAL char *logline;
 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();
index ff6976d35c27677e84d4953b317be65bf7d4de69..ef2892a1c41faf61735cad01156d84f0bdf74041 100644 (file)
@@ -25,7 +25,6 @@ __decl_hathreads(extern HA_SPINLOCK_T signals_lock);
 
 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);
index 8c6773eeb44e160f390585f35fd10b05114ad07f..f44820977055642f897a0e7feaa5f4771bdd68b6 100644 (file)
@@ -39,9 +39,6 @@ extern struct data_cb sess_conn_cb;
 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);
 
index 264899e5d13da4fc0345ce6c22899aa43836be3f..111a0cfef1336fc374be34402d19e9e8b80d4b02 100644 (file)
@@ -553,9 +553,6 @@ void process_runnable_tasks();
  */
 int wake_expired_tasks();
 
-/* Perform minimal initializations, report 0 in case of error, 1 if OK. */
-int init_task();
-
 #endif /* _PROTO_TASK_H */
 
 /*
index 96715ee274e0cb16d34eaf1e79fdc751ad0c75d4..6567b43553582c76e6dd8ded57ba4cd63cc53978 100644 (file)
@@ -1426,12 +1426,9 @@ static void init(int argc, char **argv)
 
        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);
index 77d58e2fee10effdde4201247f34408747c683f7..3093ccea3b7e8a631a801c56095491a280d6b2c3 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1581,9 +1581,8 @@ const char sess_set_cookie[8] = "NPDIRU67";       /* No set-cookie, Set-cookie found a
                } 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 @@ void init_log()
        FD_SET(0x7f, http_encode_map);
 }
 
+INITCALL0(STG_PREPARE, init_log);
+
 static int init_log_buffers_per_thread()
 {
        return init_log_buffers();
index b6ed1a60e0c61296f4cf0b3aaf4844f66007a871..2484a44418088ae349b6f05de75fbdb6489c526e 100644 (file)
@@ -100,8 +100,8 @@ void __signal_process_queue()
        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 @@ int signal_init()
        sigdelset(&blocked_sig, SIGSEGV);
        for (sig = 0; sig < MAX_SIGNAL; sig++)
                LIST_INIT(&signal_state[sig].handlers);
-
-       return 1;
 }
 
 /*
@@ -273,3 +271,5 @@ void signal_unregister(int sig)
 
        signal(sig, SIG_IGN);
 }
+
+INITCALL0(STG_PREPARE, signal_init);
index da59cf127f2cdcebef00b12055912bb177b72f33..bba3f674ab553f75db7ff1d2f7e67719b9dab0a5 100644 (file)
@@ -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 @@ void stream_release_buffers(struct stream *s)
                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;
index aeb3e4e2c665fe024b17725d38ec9548e8e78bb9..1f09f131c994d1ad0380ede9152424e29cff2c41 100644 (file)
@@ -469,8 +469,8 @@ void process_runnable_tasks()
        }
 }
 
-/* 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 @@ int init_task()
        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