Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LIBEXECDIR ?= ${PREFIX}/libexec
PKG_CONFIG ?= pkg-config
HEADERS := $(wildcard src/*.h)

OBJS := src/conmon.o src/cmsg.o src/ctr_logging.o src/utils.o src/cli.o src/globals.o src/cgroup.o src/conn_sock.o src/oom.o src/ctrl.o src/ctr_stdio.o src/parent_pipe_fd.o src/ctr_exit.o src/runtime_args.o src/close_fds.o src/seccomp_notify.o
OBJS := src/conmon.o src/cmsg.o src/ctr_logging.o src/ctr_logging_buffer.o src/utils.o src/cli.o src/globals.o src/cgroup.o src/conn_sock.o src/oom.o src/ctrl.o src/ctr_stdio.o src/parent_pipe_fd.o src/ctr_exit.o src/runtime_args.o src/close_fds.o src/seccomp_notify.o

MAKEFILE_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

Expand Down
2 changes: 1 addition & 1 deletion nix/derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ with pkgs; stdenv.mkDerivation rec {
# Static builds will use PKG_CONFIG_PATH approach instead
];
prePatch = ''
export CFLAGS='-static -pthread'
export CFLAGS='-static'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the last 4 years this reference to -pthread has been there without the need for it?

If so, perhaps this is worthy of pulling out into a separate commit.

export LDFLAGS='-s -w -static-libgcc -static'
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
${lib.optionalString (!enableSystemd) "export DISABLE_SYSTEMD=1"}
Expand Down
9 changes: 9 additions & 0 deletions src/cli.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cli.h"
#include "globals.h"
#include "ctr_logging.h"
#include "ctr_logging_buffer.h"
#include "config.h"
#include "utils.h"

Expand Down Expand Up @@ -224,6 +225,14 @@ void process_cli()

configure_log_drivers(opt_log_path, opt_log_size_max, opt_log_global_size_max, opt_cid, opt_name, opt_log_tag, opt_log_labels);

/* Initialize async logging for improved log performance */
if (!init_async_logging()) {
nwarn("Failed to initialize async logging, falling back to direct logging");
} else {
/* Register cleanup handler for async logging */
atexit(shutdown_async_logging);
}

/* Warn if --no-container-partial-message is used without journald logging */
if (opt_no_container_partial_message && !logging_is_journald_enabled()) {
nwarnf("--no-container-partial-message has no effect without journald log driver");
Expand Down
3 changes: 3 additions & 0 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "conn_sock.h"
#include "ctrl.h"
#include "ctr_stdio.h"
#include "ctr_logging_buffer.h"
#include "config.h"
#include "parent_pipe_fd.h"
#include "ctr_exit.h"
Expand Down Expand Up @@ -418,6 +419,8 @@ int main(int argc, char *argv[])
if (mainfd_stderr >= 0) {
g_unix_fd_add(mainfd_stderr, G_IO_IN, stdio_cb, GINT_TO_POINTER(STDERR_PIPE));
}
/* Setup log buffer timer for async flushing */
setup_log_timer_in_main_loop();

if (opt_timeout > 0) {
g_timeout_add_seconds(opt_timeout, timeout_cb, NULL);
Expand Down
9 changes: 9 additions & 0 deletions src/ctr_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "parent_pipe_fd.h"
#include "globals.h"
#include "ctr_logging.h"
#include "ctr_logging_buffer.h"
#include "close_fds.h"
#include "oom.h"

Expand Down Expand Up @@ -129,6 +130,8 @@ void runtime_exit_cb(G_GNUC_UNUSED GPid pid, int status, G_GNUC_UNUSED gpointer
{
runtime_status = status;
create_pid = -1;
/* Flush logs before runtime exit to ensure CRI-O sees all logs */
flush_log_buffer();
g_main_loop_quit(main_loop);
}

Expand All @@ -137,6 +140,10 @@ void container_exit_cb(G_GNUC_UNUSED GPid pid, int status, G_GNUC_UNUSED gpointe
if (get_exit_status(status) != 0) {
ninfof("container %d exited with status %d", pid, get_exit_status(status));
}

/* Force flush async log buffer before container exit to ensure CRI-O sees all logs */
flush_log_buffer();

container_status = status;
container_pid = -1;
/* In the case of a quickly exiting exec command, the container exit callback
Expand All @@ -149,6 +156,8 @@ void container_exit_cb(G_GNUC_UNUSED GPid pid, int status, G_GNUC_UNUSED gpointe
return;
}

/* Final flush before main loop quits */
flush_log_buffer();
g_main_loop_quit(main_loop);
}

Expand Down
7 changes: 7 additions & 0 deletions src/ctr_logging.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define _GNU_SOURCE
#include "ctr_logging.h"
#include "ctr_logging_buffer.h"
#include "cli.h"
#include "config.h"
#include <ctype.h>
Expand Down Expand Up @@ -761,6 +762,9 @@ static void set_k8s_timestamp(char *buf, ssize_t buflen, const char *pipename)
/* Force closing any open FD. */
void close_logging_fds(void)
{
/* Shutdown async logging system */
shutdown_async_logging();

if (k8s_log_fd >= 0)
close(k8s_log_fd);
k8s_log_fd = -1;
Expand Down Expand Up @@ -1243,6 +1247,9 @@ static void reopen_k8s_file(void)

void sync_logs(void)
{
/* Flush any buffered logs before syncing */
flush_log_buffer();

/* Sync the logs to disk */
if (k8s_log_fd > 0)
if (fsync(k8s_log_fd) < 0)
Expand Down
Loading
Loading