[lxc-devel] [lxcfs/master] macro: add and use lxcfs_info()
brauner on Github
lxc-bot at linuxcontainers.org
Wed Mar 4 11:04:57 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200304/ded765ab/attachment.bin>
-------------- next part --------------
From cc42d0c79cf40a066101321a5c06710215597dad Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 4 Mar 2020 12:03:36 +0100
Subject: [PATCH] macro: add and use lxcfs_info()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
bindings.c | 22 ++++++++++++++--------
macro.h | 5 +++++
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/bindings.c b/bindings.c
index 45a3e57..b805f13 100644
--- a/bindings.c
+++ b/bindings.c
@@ -708,6 +708,8 @@ static void __attribute__((constructor)) lxcfs_init(void)
char *cret;
char cwd[MAXPATHLEN];
+ lxcfs_info("Running constructor %s", __func__);
+
cgroup_ops = cgroup_init();
if (!cgroup_ops)
log_exit("Failed to initialize cgroup support");
@@ -736,28 +738,32 @@ static void __attribute__((constructor)) lxcfs_init(void)
if (!init_cpuview())
log_exit("Failed to init CPU view");
- fprintf(stderr, "mount namespace: %d\n", cgroup_ops->mntns_fd);
- fprintf(stderr, "hierarchies:\n");
+ lxcfs_info("mount namespace: %d", cgroup_ops->mntns_fd);
+ lxcfs_info("hierarchies:");
for (struct hierarchy **h = cgroup_ops->hierarchies; h && *h; h++, i++) {
- __do_free char *controllers = lxc_string_join(",", (const char **)(*h)->controllers, false);
- fprintf(stderr, " %2d: fd: %3d: %s\n", i, (*h)->fd, controllers ?: "");
+ char **controller_list = (*h)->controllers;
+ __do_free char *controllers = NULL;
+ if (controller_list && *controller_list)
+ controllers = lxc_string_join(",", (const char **)controller_list, false);
+ lxcfs_info(" %2d: fd: %3d: %s", i, (*h)->fd, controllers ?: "");
}
pidfd = pidfd_open(pid, 0);
if (pidfd >= 0 && pidfd_send_signal(pidfd, 0, NULL, 0) == 0) {
can_use_pidfd = true;
- fprintf(stderr, "Kernel supports pidfds\n");
+ lxcfs_info("Kernel supports pidfds");
}
- fprintf(stderr, "api_extensions:\n");
+ lxcfs_info("api_extensions:");
for (i = 0; i < nr_api_extensions; i++)
- fprintf(stderr, "- %s\n", api_extensions[i]);
+ lxcfs_info("- %s", api_extensions[i]);
}
static void __attribute__((destructor)) lxcfs_exit(void)
{
- lxcfs_debug("%s\n", "Running destructor for liblxcfs");
+ lxcfs_info("Running destructor %s", __func__);
+
free_cpuview();
cgroup_exit(cgroup_ops);
}
diff --git a/macro.h b/macro.h
index 6b1c996..52b442d 100644
--- a/macro.h
+++ b/macro.h
@@ -48,6 +48,11 @@
#define lxcfs_v(format, ...)
#endif /* VERBOSE */
+#define lxcfs_info(format, ...) \
+ do { \
+ fprintf(stderr, format "\n", ##__VA_ARGS__); \
+ } while (false)
+
#define log_error_errno(__ret__, __errno__, format, ...) \
({ \
errno = __errno__; \
More information about the lxc-devel
mailing list