]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
log: add lxc_log_get_fd()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 30 Jan 2021 10:07:43 +0000 (11:07 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 30 Jan 2021 11:02:09 +0000 (12:02 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/log.c
src/lxc/log.h

index 522a576adfd12f9b0c637103f30abcc3d8ee89b4..bc60083fe30ea5a1b91ea11e06389f4c9e8da14a 100644 (file)
@@ -46,7 +46,7 @@
 int lxc_log_fd = -EBADF;
 static bool wants_syslog = false;
 static int lxc_quiet_specified;
-int lxc_log_use_global_fd;
+bool lxc_log_use_global_fd = false;
 static int lxc_loglevel_specified;
 
 static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
@@ -92,6 +92,20 @@ static const char *lxc_log_get_container_name(void)
        return log_vmname;
 }
 
+int lxc_log_get_fd(void)
+{
+       int fd_log = -EBADF;
+
+#ifndef NO_LXC_CONF
+       if (current_config && !lxc_log_use_global_fd)
+               fd_log = current_config->logfd;
+#endif
+       if (fd_log < 0)
+               fd_log = lxc_log_fd;
+
+       return fd_log;
+}
+
 static char *lxc_log_get_va_msg(struct lxc_log_event *event)
 {
        __do_free char *msg = NULL;
@@ -659,7 +673,7 @@ int lxc_log_init(struct lxc_log *log)
                if (ret < 0)
                        return log_error_errno(-1, errno, "Failed to enable logfile");
 
-               lxc_log_use_global_fd = 1;
+               lxc_log_use_global_fd = true;
        } else {
                /* if no name was specified, there nothing to do */
                if (!log->name)
index 0361db40fadeb3b20164c70a88c3706d492f790c..68e87eb06e739fc3bbdf12f0ddad39851ef641dc 100644 (file)
@@ -85,7 +85,7 @@ struct lxc_log_category {
 };
 
 #ifndef NO_LXC_CONF
-extern int lxc_log_use_global_fd;
+extern bool lxc_log_use_global_fd;
 #endif
 
 /*
@@ -574,5 +574,6 @@ __hidden extern const char *lxc_log_get_file(void);
 __hidden extern void lxc_log_set_prefix(const char *prefix);
 __hidden extern const char *lxc_log_get_prefix(void);
 __hidden extern void lxc_log_options_no_override(void);
+__hidden extern int lxc_log_get_fd(void);
 
 #endif /* __LXC_LOG_H */