From: Maria Matejka Date: Mon, 26 Aug 2024 15:54:59 +0000 (+0200) Subject: Displaced bird_name to log.c where it rightfully belongs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08f4e2a04cf095bc1696d35c0058ddecb2222680;p=thirdparty%2Fbird.git Displaced bird_name to log.c where it rightfully belongs --- diff --git a/lib/birdlib.h b/lib/birdlib.h index bc7c334cb..eac0fc4d8 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -216,6 +216,9 @@ void die(const char *msg, ...) NORET; void bug(const char *msg, ...) NORET; void vlog(int class, const char *msg, va_list args); +void set_daemon_name(char *path, char *def); + + #define L_DEBUG "\001" /* Debugging messages */ #define L_TRACE "\002" /* Protocol tracing */ #define L_INFO "\003" /* Informational messages */ diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 384da303d..5dbc0e2d5 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -36,6 +36,7 @@ static pool *log_pool; static struct rfile *dbg_rf; static char *current_syslog_name = NULL; /* NULL -> syslog closed */ +const char *bird_name = NULL; _Atomic uint max_thread_id = 1; _Thread_local uint this_thread_id; @@ -837,6 +838,7 @@ resolve_fail: void log_init_debug(char *f) { + ASSERT_DIE(bird_name); clock_gettime(CLOCK_MONOTONIC, &dbg_time_start); if (dbg_rf && dbg_rf != &rf_stderr) @@ -853,3 +855,26 @@ log_init_debug(char *f) 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); +} diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 2e5987f97..4c38cf0f2 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -836,7 +836,6 @@ signal_init(void) static char *opt_list = "bc:dD:ps:P:u:g:flRh"; int parse_and_exit; -char *bird_name; static char *use_user; static char *use_group; static int run_in_foreground = 0; @@ -881,20 +880,6 @@ display_version(void) 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 get_uid(const char *s) { @@ -948,7 +933,8 @@ parse_args(int argc, char **argv) int socket_changed = 0; int c; - bird_name = get_bird_name(argv[0], "bird"); + set_daemon_name(argv[0], "bird"); + if (argc == 2) { if (!strcmp(argv[1], "--version")) diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h index c4130edf6..4132c6333 100644 --- a/sysdep/unix/unix.h +++ b/sysdep/unix/unix.h @@ -25,7 +25,7 @@ struct config; /* main.c */ -extern char *bird_name; +extern const char *bird_name; extern int parse_and_exit; void async_config(void); void async_dump(void); diff --git a/test/birdtest.c b/test/birdtest.c index 76bae76d5..a8b87fc20 100644 --- a/test/birdtest.c +++ b/test/birdtest.c @@ -76,6 +76,8 @@ bt_init(int argc, char *argv[]) bt_test_id = NULL; is_terminal = isatty(fileno(stdout)); + set_daemon_name(argv[0], "birdtest"); + while ((c = getopt(argc, argv, "lcdftv")) >= 0) switch (c) { @@ -539,7 +541,6 @@ bt_is_char(byte c) */ int parse_and_exit; -char *bird_name; void async_config(void) {} void async_dump(void) {} void async_shutdown(void) {}