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.
This commit is contained in:
Willy Tarreau 2018-11-26 16:31:20 +01:00
parent 2455cebe00
commit b6b3df3ed3
9 changed files with 14 additions and 36 deletions

View 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();

View 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);

View 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);

View 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 */
/*

View 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);

View File

@ -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();

View 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);

View 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;

View 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