0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

Displaced bird_name to log.c where it rightfully belongs

This commit is contained in:
Maria Matejka 2024-08-26 17:54:59 +02:00
parent bb183c9d0c
commit e70207b281
5 changed files with 33 additions and 18 deletions

View File

@ -201,6 +201,9 @@ void log_rl(struct tbf *rl, const char *msg, ...);
void die(const char *msg, ...) NORET; void die(const char *msg, ...) NORET;
void bug(const char *msg, ...) NORET; void bug(const char *msg, ...) NORET;
void set_daemon_name(char *path, char *def);
#define L_DEBUG "\001" /* Debugging messages */ #define L_DEBUG "\001" /* Debugging messages */
#define L_TRACE "\002" /* Protocol tracing */ #define L_TRACE "\002" /* Protocol tracing */
#define L_INFO "\003" /* Informational messages */ #define L_INFO "\003" /* Informational messages */

View File

@ -36,6 +36,7 @@ static pool *log_pool;
static struct rfile *dbg_rf; static struct rfile *dbg_rf;
static char *current_syslog_name = NULL; /* NULL -> syslog closed */ static char *current_syslog_name = NULL; /* NULL -> syslog closed */
const char *bird_name = NULL;
_Atomic uint max_thread_id = 1; _Atomic uint max_thread_id = 1;
_Thread_local uint this_thread_id; _Thread_local uint this_thread_id;
@ -826,6 +827,7 @@ resolve_fail:
void void
log_init_debug(char *f) log_init_debug(char *f)
{ {
ASSERT_DIE(bird_name);
clock_gettime(CLOCK_MONOTONIC, &dbg_time_start); clock_gettime(CLOCK_MONOTONIC, &dbg_time_start);
if (dbg_rf && dbg_rf != &rf_stderr) if (dbg_rf && dbg_rf != &rf_stderr)
@ -842,3 +844,26 @@ log_init_debug(char *f)
exit(1); exit(1);
} }
} }
/*
* Setting BIRD name
*/
static inline char *
get_bird_name(char *s, char *def)
{
char *t;
if (!s)
return def;
t = strrchr(s, '/');
if (!t)
return s;
if (!t[1])
return def;
return t+1;
}
void set_daemon_name(char *path, char *def)
{
bird_name = get_bird_name(path, def);
}

View File

@ -709,7 +709,6 @@ signal_init(void)
static char *opt_list = "bc:dD:ps:P:u:g:flRh"; static char *opt_list = "bc:dD:ps:P:u:g:flRh";
int parse_and_exit; int parse_and_exit;
char *bird_name;
static char *use_user; static char *use_user;
static char *use_group; static char *use_group;
static int run_in_foreground = 0; static int run_in_foreground = 0;
@ -754,20 +753,6 @@ display_version(void)
exit(0); exit(0);
} }
static inline char *
get_bird_name(char *s, char *def)
{
char *t;
if (!s)
return def;
t = strrchr(s, '/');
if (!t)
return s;
if (!t[1])
return def;
return t+1;
}
static inline uid_t static inline uid_t
get_uid(const char *s) get_uid(const char *s)
{ {
@ -821,7 +806,8 @@ parse_args(int argc, char **argv)
int socket_changed = 0; int socket_changed = 0;
int c; int c;
bird_name = get_bird_name(argv[0], "bird"); set_daemon_name(argv[0], "bird");
if (argc == 2) if (argc == 2)
{ {
if (!strcmp(argv[1], "--version")) if (!strcmp(argv[1], "--version"))

View File

@ -24,7 +24,7 @@ struct config;
/* main.c */ /* main.c */
extern char *bird_name; extern const char *bird_name;
extern int parse_and_exit; extern int parse_and_exit;
void async_config(void); void async_config(void);
void async_dump(void); void async_dump(void);

View File

@ -76,6 +76,8 @@ bt_init(int argc, char *argv[])
bt_test_id = NULL; bt_test_id = NULL;
is_terminal = isatty(fileno(stdout)); is_terminal = isatty(fileno(stdout));
set_daemon_name(argv[0], "birdtest");
while ((c = getopt(argc, argv, "lcdftv")) >= 0) while ((c = getopt(argc, argv, "lcdftv")) >= 0)
switch (c) switch (c)
{ {
@ -539,7 +541,6 @@ bt_is_char(byte c)
*/ */
int parse_and_exit; int parse_and_exit;
char *bird_name;
void async_config(void) {} void async_config(void) {}
void async_dump(void) {} void async_dump(void) {}
void async_shutdown(void) {} void async_shutdown(void) {}