|
|
d830a4 |
diff --git a/src/cli.c b/src/cli.c
|
|
|
d830a4 |
index 8e788f9..5761dde 100644
|
|
|
d830a4 |
--- a/src/cli.c
|
|
|
d830a4 |
+++ b/src/cli.c
|
|
|
d830a4 |
@@ -38,6 +38,7 @@ gchar **opt_log_path = NULL;
|
|
|
d830a4 |
char *opt_exit_dir = NULL;
|
|
|
d830a4 |
int opt_timeout = 0;
|
|
|
d830a4 |
int64_t opt_log_size_max = -1;
|
|
|
d830a4 |
+int64_t opt_log_global_size_max = -1;
|
|
|
d830a4 |
char *opt_socket_path = DEFAULT_SOCKET_PATH;
|
|
|
d830a4 |
gboolean opt_no_new_keyring = FALSE;
|
|
|
d830a4 |
char *opt_exit_command = NULL;
|
|
|
d830a4 |
@@ -70,6 +71,7 @@ GOptionEntry opt_entries[] = {
|
|
|
d830a4 |
{"log-level", 0, 0, G_OPTION_ARG_STRING, &opt_log_level, "Print debug logs based on log level", NULL},
|
|
|
d830a4 |
{"log-path", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &opt_log_path, "Log file path", NULL},
|
|
|
d830a4 |
{"log-size-max", 0, 0, G_OPTION_ARG_INT64, &opt_log_size_max, "Maximum size of log file", NULL},
|
|
|
d830a4 |
+ {"log-global-size-max", 0, 0, G_OPTION_ARG_INT64, &opt_log_global_size_max, "Maximum size of all log files", NULL},
|
|
|
d830a4 |
{"log-tag", 0, 0, G_OPTION_ARG_STRING, &opt_log_tag, "Additional tag to use for logging", NULL},
|
|
|
d830a4 |
{"name", 'n', 0, G_OPTION_ARG_STRING, &opt_name, "Container name", NULL},
|
|
|
d830a4 |
{"no-new-keyring", 0, 0, G_OPTION_ARG_NONE, &opt_no_new_keyring, "Do not create a new session keyring for the container", NULL},
|
|
|
d830a4 |
@@ -180,5 +182,5 @@ void process_cli()
|
|
|
d830a4 |
if (opt_container_pid_file == NULL)
|
|
|
d830a4 |
opt_container_pid_file = g_strdup_printf("%s/pidfile-%s", cwd, opt_cid);
|
|
|
d830a4 |
|
|
|
d830a4 |
- configure_log_drivers(opt_log_path, opt_log_size_max, opt_cid, opt_name, opt_log_tag);
|
|
|
d830a4 |
+ configure_log_drivers(opt_log_path, opt_log_size_max, opt_log_global_size_max, opt_cid, opt_name, opt_log_tag);
|
|
|
d830a4 |
}
|
|
|
d830a4 |
diff --git a/src/ctr_logging.c b/src/ctr_logging.c
|
|
|
d830a4 |
index c3fd5d2..8581783 100644
|
|
|
d830a4 |
--- a/src/ctr_logging.c
|
|
|
d830a4 |
+++ b/src/ctr_logging.c
|
|
|
d830a4 |
@@ -32,6 +32,9 @@ static const char *const JOURNALD_FILE_STRING = "journald";
|
|
|
d830a4 |
/* Max log size for any log file types */
|
|
|
d830a4 |
static int64_t log_size_max = -1;
|
|
|
d830a4 |
|
|
|
d830a4 |
+/* Max total log size for any log file types */
|
|
|
d830a4 |
+static int64_t log_global_size_max = -1;
|
|
|
d830a4 |
+
|
|
|
d830a4 |
/* k8s log file parameters */
|
|
|
d830a4 |
static int k8s_log_fd = -1;
|
|
|
d830a4 |
static char *k8s_log_path = NULL;
|
|
|
d830a4 |
@@ -77,9 +80,10 @@ static void reopen_k8s_file(void);
|
|
|
d830a4 |
* (currently just k8s log file), it will also open the log_fd for that specific
|
|
|
d830a4 |
* log file.
|
|
|
d830a4 |
*/
|
|
|
d830a4 |
-void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_, char *tag)
|
|
|
d830a4 |
+void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, int64_t log_global_size_max_, char *cuuid_, char *name_, char *tag)
|
|
|
d830a4 |
{
|
|
|
d830a4 |
log_size_max = log_size_max_;
|
|
|
d830a4 |
+ log_global_size_max = log_global_size_max_;
|
|
|
d830a4 |
if (log_drivers == NULL)
|
|
|
d830a4 |
nexit("Log driver not provided. Use --log-path");
|
|
|
d830a4 |
for (int driver = 0; log_drivers[driver]; ++driver) {
|
|
|
d830a4 |
@@ -284,6 +288,7 @@ static int write_k8s_log(stdpipe_t pipe, const char *buf, ssize_t buflen)
|
|
|
d830a4 |
writev_buffer_t bufv = {0};
|
|
|
d830a4 |
static int64_t bytes_written = 0;
|
|
|
d830a4 |
int64_t bytes_to_be_written = 0;
|
|
|
d830a4 |
+ static int64_t total_bytes_written = 0;
|
|
|
d830a4 |
|
|
|
d830a4 |
/*
|
|
|
d830a4 |
* Use the same timestamp for every line of the log in this buffer.
|
|
|
d830a4 |
@@ -307,6 +312,10 @@ static int write_k8s_log(stdpipe_t pipe, const char *buf, ssize_t buflen)
|
|
|
d830a4 |
bytes_to_be_written += 1;
|
|
|
d830a4 |
}
|
|
|
d830a4 |
|
|
|
d830a4 |
+ /* If the caller specified a global max, enforce it before writing */
|
|
|
d830a4 |
+ if (log_global_size_max > 0 && total_bytes_written >= log_global_size_max)
|
|
|
d830a4 |
+ break;
|
|
|
d830a4 |
+
|
|
|
d830a4 |
/*
|
|
|
d830a4 |
* We re-open the log file if writing out the bytes will exceed the max
|
|
|
d830a4 |
* log size. We also reset the state so that the new file is started with
|
|
|
d830a4 |
@@ -360,6 +369,7 @@ static int write_k8s_log(stdpipe_t pipe, const char *buf, ssize_t buflen)
|
|
|
d830a4 |
}
|
|
|
d830a4 |
|
|
|
d830a4 |
bytes_written += bytes_to_be_written;
|
|
|
d830a4 |
+ total_bytes_written += bytes_to_be_written;
|
|
|
d830a4 |
next:
|
|
|
d830a4 |
/* Update the head of the buffer remaining to output. */
|
|
|
d830a4 |
buf += line_len;
|
|
|
d830a4 |
diff --git a/src/ctr_logging.h b/src/ctr_logging.h
|
|
|
d830a4 |
index 1b63cd7..9b1f693 100644
|
|
|
d830a4 |
--- a/src/ctr_logging.h
|
|
|
d830a4 |
+++ b/src/ctr_logging.h
|
|
|
d830a4 |
@@ -7,7 +7,7 @@
|
|
|
d830a4 |
|
|
|
d830a4 |
void reopen_log_files(void);
|
|
|
d830a4 |
bool write_to_logs(stdpipe_t pipe, char *buf, ssize_t num_read);
|
|
|
d830a4 |
-void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_, char *tag);
|
|
|
d830a4 |
+void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, int64_t log_global_size_max_, char *cuuid_, char *name_, char *tag);
|
|
|
d830a4 |
void sync_logs(void);
|
|
|
d830a4 |
|
|
|
d830a4 |
#endif /* !defined(CTR_LOGGING_H) */
|