Hello community, here is the log from the commit of package conmon for openSUSE:Factory checked in at 2019-11-18 20:04:56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/conmon (Old) and /work/SRC/openSUSE:Factory/.conmon.new.26869 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "conmon" Mon Nov 18 20:04:56 2019 rev:5 rq:748702 version:2.0.3 Changes: -------- --- /work/SRC/openSUSE:Factory/conmon/conmon.changes 2019-11-06 13:47:44.959612878 +0100 +++ /work/SRC/openSUSE:Factory/.conmon.new.26869/conmon.changes 2019-11-18 20:05:34.393738046 +0100 @@ -1,0 +2,6 @@ +Thu Nov 14 14:25:29 UTC 2019 - Sascha Grunert <sgrun...@suse.com> + +- Add log level trace +- Separate handling of log reopen events and terminal resize events + +------------------------------------------------------------------- Old: ---- conmon-2.0.2.tar.xz New: ---- conmon-2.0.3.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ conmon.spec ++++++ --- /var/tmp/diff_new_pack.WVtch0/_old 2019-11-18 20:05:36.257737109 +0100 +++ /var/tmp/diff_new_pack.WVtch0/_new 2019-11-18 20:05:36.261737108 +0100 @@ -1,7 +1,7 @@ # # spec file for package conmon # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LLC. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,12 +17,12 @@ Name: conmon -Version: 2.0.2 +Version: 2.0.3 Release: 0 Summary: An OCI container runtime monitor License: Apache-2.0 Group: System/Management -Url: https://github.com/containers/conmon +URL: https://github.com/containers/conmon Source0: %{name}-%{version}.tar.xz BuildRequires: glib2-devel ++++++ _service ++++++ --- /var/tmp/diff_new_pack.WVtch0/_old 2019-11-18 20:05:36.281737098 +0100 +++ /var/tmp/diff_new_pack.WVtch0/_new 2019-11-18 20:05:36.281737098 +0100 @@ -2,8 +2,8 @@ <service name="tar_scm" mode="disabled"> <param name="url">https://github.com/containers/conmon</param> <param name="scm">git</param> -<param name="versionformat">2.0.2</param> -<param name="revision">v2.0.2</param> +<param name="versionformat">2.0.3</param> +<param name="revision">v2.0.3</param> </service> <service name="recompress" mode="disabled"> <param name="file">conmon-*.tar</param> ++++++ conmon-2.0.2.tar.xz -> conmon-2.0.3.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/VERSION new/conmon-2.0.3/VERSION --- old/conmon-2.0.2/VERSION 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/VERSION 2019-11-11 16:16:23.000000000 +0100 @@ -1 +1 @@ -2.0.2 +2.0.3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/cmd/conmon-config/conmon-config.go new/conmon-2.0.3/cmd/conmon-config/conmon-config.go --- old/conmon-2.0.2/cmd/conmon-config/conmon-config.go 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/cmd/conmon-config/conmon-config.go 2019-11-11 16:16:23.000000000 +0100 @@ -16,10 +16,20 @@ #define STDIO_BUF_SIZE %d #define CONN_SOCK_BUF_SIZE %d #define DEFAULT_SOCKET_PATH "%s" +#define WIN_RESIZE_EVENT %d +#define REOPEN_LOGS_EVENT %d #endif // CONFIG_H ` - if err := ioutil.WriteFile("config.h", []byte(fmt.Sprintf(output, config.BufSize, config.BufSize, config.ConnSockBufSize, config.ContainerAttachSocketDir)), 0644); err != nil { - fmt.Errorf(err.Error()) + if err := ioutil.WriteFile("config.h", []byte(fmt.Sprintf( + output, + config.BufSize, + config.BufSize, + config.ConnSockBufSize, + config.ContainerAttachSocketDir, + config.WinResizeEvent, + config.ReopenLogsEvent)), + 0644); err != nil { + fmt.Errorf(err.Error()) } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/runner/config/config.go new/conmon-2.0.3/runner/config/config.go --- old/conmon-2.0.2/runner/config/config.go 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/runner/config/config.go 2019-11-11 16:16:23.000000000 +0100 @@ -6,4 +6,11 @@ // ConnSockBufSize is the size of the socket used for // to attach to the container ConnSockBufSize = 32768 + // WinResizeEvent is the event code the caller program will + // send along the ctrl fd to signal conmon to resize + // the pty window + WinResizeEvent = 1 + // ReopenLogsEvent is the event code the caller program will + // send along the ctrl fd to signal conmon to reopen the log files + ReopenLogsEvent = 2 ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/config.h new/conmon-2.0.3/src/config.h --- old/conmon-2.0.2/src/config.h 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/config.h 2019-11-11 16:16:23.000000000 +0100 @@ -6,5 +6,7 @@ #define STDIO_BUF_SIZE 8192 #define CONN_SOCK_BUF_SIZE 32768 #define DEFAULT_SOCKET_PATH "/var/run/crio" +#define WIN_RESIZE_EVENT 1 +#define REOPEN_LOGS_EVENT 2 #endif // CONFIG_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/conmon.c new/conmon-2.0.3/src/conmon.c --- old/conmon-2.0.2/src/conmon.c 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/conmon.c 2019-11-11 16:16:23.000000000 +0100 @@ -78,6 +78,7 @@ static gchar **opt_exit_args = NULL; static gboolean opt_replace_listen_pid = FALSE; static char *opt_log_level = NULL; +static char *opt_log_tag = NULL; static GOptionEntry opt_entries[] = { {"terminal", 't', 0, G_OPTION_ARG_NONE, &opt_terminal, "Terminal", NULL}, {"stdin", 'i', 0, G_OPTION_ARG_NONE, &opt_stdin, "Stdin", NULL}, @@ -117,6 +118,7 @@ {"version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print the version and exit", NULL}, {"syslog", 0, 0, G_OPTION_ARG_NONE, &opt_syslog, "Log to syslog (use with cgroupfs cgroup manager)", NULL}, {"log-level", 0, 0, G_OPTION_ARG_STRING, &opt_log_level, "Print debug logs based on log level", NULL}, + {"log-tag", 0, 0, G_OPTION_ARG_STRING, &opt_log_tag, "Additional tag to use for logging", NULL}, {NULL, 0, 0, 0, NULL, NULL, NULL}}; #define CGROUP_ROOT "/sys/fs/cgroup" @@ -143,7 +145,6 @@ return count; } - /* * Returns the path for specified controller name for a pid. * Returns NULL on error. @@ -290,6 +291,8 @@ static int console_socket_fd = -1; static int terminal_ctrl_fd = -1; static int inotify_fd = -1; +static int winsz_fd_w = -1; +static int winsz_fd_r = -1; static gboolean timed_out = FALSE; @@ -681,48 +684,35 @@ } #define CTLBUFSZ 200 -static gboolean ctrl_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer user_data) +/* + * read_from_ctrl_buffer reads a line (of no more than CTLBUFSZ) from an fd, + * and calls line_process_func. It is a generic way to handle input on an fd + * line_process_func should return TRUE if it succeeds, and FALSE if it fails + * to process the line. + */ +static gboolean read_from_ctrl_buffer(int fd, gboolean(*line_process_func)(char*)) { static char ctlbuf[CTLBUFSZ]; static int readsz = CTLBUFSZ - 1; static char *readptr = ctlbuf; ssize_t num_read = 0; - int ctl_msg_type = -1; - int height = -1; - int width = -1; - int ret; num_read = read(fd, readptr, readsz); if (num_read <= 0) { - nwarn("Failed to read from control fd"); + nwarnf("Failed to read from fd %d", fd); return G_SOURCE_CONTINUE; } readptr[num_read] = '\0'; - ninfof("Got ctl message: %s", ctlbuf); + ninfof("Got ctl message: %s on fd %d", ctlbuf, fd); char *beg = ctlbuf; char *newline = strchrnul(beg, '\n'); /* Process each message which ends with a line */ while (*newline != '\0') { - ret = sscanf(ctlbuf, "%d %d %d\n", &ctl_msg_type, &height, &width); - if (ret != 3) { - nwarn("Failed to sscanf message"); + if (!line_process_func(ctlbuf)) { return G_SOURCE_CONTINUE; } - ninfof("Message type: %d, Height: %d, Width: %d", ctl_msg_type, height, width); - switch (ctl_msg_type) { - // This matches what we write from container_attach.go - case 1: - resize_winsz(height, width); - break; - case 2: - reopen_log_files(); - break; - default: - ninfof("Unknown message type: %d", ctl_msg_type); - break; - } beg = newline + 1; newline = strchrnul(beg, '\n'); } @@ -753,6 +743,78 @@ return G_SOURCE_CONTINUE; } +/* + * process_terminal_ctrl_line takes a line from the + * caller program (received through the terminal ctrl fd) + * and either writes to the winsz fd (to handle terminal resize events) + * or reopens log files. + */ +static gboolean process_terminal_ctrl_line(char* line) +{ + int ctl_msg_type, height, width, ret = -1; + _cleanup_free_ char *hw_str = NULL; + + // while the height and width won't be used in this function, + // we want to remove them from the buffer anyway + ret = sscanf(line, "%d %d %d\n", &ctl_msg_type, &height, &width); + if (ret != 3) { + nwarn("Failed to sscanf message"); + return FALSE; + } + + ninfof("Message type: %d", ctl_msg_type); + switch (ctl_msg_type) { + case WIN_RESIZE_EVENT: + hw_str = g_strdup_printf("%d %d\n", height, width); + if (write(winsz_fd_w, hw_str, strlen(hw_str)) < 0) { + nwarn("Failed to write to window resizing fd. A resize event may have been dropped"); + return FALSE; + } + break; + case REOPEN_LOGS_EVENT: + reopen_log_files(); + break; + default: + ninfof("Unknown message type: %d", ctl_msg_type); + break; + } + return TRUE; +} + +/* + * ctrl_cb is a callback for handling events directly from the caller + */ +static gboolean ctrl_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer user_data) +{ + return read_from_ctrl_buffer(fd, process_terminal_ctrl_line); +} + +/* + * process_winsz_ctrl_line processes a line passed to the winsz fd + * after the terminal_ctrl fd receives a winsz event. + * It reads a height and length, and resizes the pty with it. + */ +static gboolean process_winsz_ctrl_line(char * line) +{ + int height, width, ret = -1; + ret = sscanf(line, "%d %d\n", &height, &width); + ninfof("Height: %d, Width: %d", height, width); + if (ret != 2) { + nwarn("Failed to sscanf message"); + return FALSE; + } + resize_winsz(height, width); + return TRUE; +} + +/* + * ctrl_winsz_cb is a callback after a window resize event is sent along the winsz fd. + */ +static gboolean ctrl_winsz_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer user_data) +{ + return read_from_ctrl_buffer(fd, process_winsz_ctrl_line); +} + static gboolean terminal_accept_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer user_data) { const char *csname = user_data; @@ -795,10 +857,10 @@ masterfd_stdin = console.fd; masterfd_stdout = console.fd; - /* now that we've set masterfd_stdout, we can register the ctrl_cb + /* now that we've set masterfd_stdout, we can register the ctrl_winsz_cb * if we didn't set it here, we'd risk attempting to run ioctl on * a negative fd, and fail to resize the window */ - g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); + g_unix_fd_add(winsz_fd_r, G_IO_IN, ctrl_winsz_cb, NULL); /* Clean up everything */ close(connfd); @@ -972,29 +1034,38 @@ return attach_symlink_dir_path; } -static int setup_terminal_control_fifo() -{ - _cleanup_free_ char *ctl_fifo_path = g_build_filename(opt_bundle_path, "ctl", NULL); - ninfof("ctl fifo path: %s", ctl_fifo_path); +static void setup_fifo(int *fifo_r, int *fifo_w, char * filename, char* error_var_name) { + _cleanup_free_ char *fifo_path = g_build_filename(opt_bundle_path, filename, NULL); + + if (!fifo_r || !fifo_w) + pexitf("setup fifo was passed a NULL pointer"); - /* Setup fifo for reading in terminal resize and other stdio control messages */ + if (mkfifo(fifo_path, 0666) == -1) + pexitf("Failed to mkfifo at %s", fifo_path); - if (mkfifo(ctl_fifo_path, 0666) == -1) - pexitf("Failed to mkfifo at %s", ctl_fifo_path); + if ((*fifo_r = open(fifo_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1) + pexitf("Failed to open %s read half", error_var_name); - terminal_ctrl_fd = open(ctl_fifo_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); - if (terminal_ctrl_fd == -1) - pexit("Failed to open control fifo"); + if ((*fifo_w = open(fifo_path, O_WRONLY | O_CLOEXEC)) == -1) + pexitf("Failed to open %s write half", error_var_name); +} + +static void setup_console_fifo() { + setup_fifo(&winsz_fd_r, &winsz_fd_w, "winsz", "window resize control fifo"); + ninfof("winsz read side: %d, winsz write side: %d", winsz_fd_r, winsz_fd_r); +} +static int setup_terminal_control_fifo() +{ /* * Open a dummy writer to prevent getting flood of POLLHUPs when * last writer closes. */ - int dummyfd = open(ctl_fifo_path, O_WRONLY | O_CLOEXEC); - if (dummyfd == -1) - pexit("Failed to open dummy writer for fifo"); - + int dummyfd = -1; + setup_fifo(&terminal_ctrl_fd, &dummyfd, "ctl", "terminal control fifo"); ninfof("terminal_ctrl_fd: %d", terminal_ctrl_fd); + g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); + return dummyfd; } @@ -1172,7 +1243,7 @@ exit(EXIT_FAILURE); } - set_conmon_logs(opt_log_level, opt_cid, opt_syslog); + set_conmon_logs(opt_log_level, opt_cid, opt_syslog, opt_log_tag); oom_score_fd = open("/proc/self/oom_score_adj", O_WRONLY); if (oom_score_fd < 0) { @@ -1230,7 +1301,7 @@ opt_container_pid_file = default_pid_file; } - configure_log_drivers(opt_log_path, opt_log_size_max, opt_cid, opt_name); + configure_log_drivers(opt_log_path, opt_log_size_max, opt_cid, opt_name, opt_log_tag); start_pipe_fd = get_pipe_fd_from_env("_OCI_STARTPIPE"); if (start_pipe_fd > 0) { @@ -1324,10 +1395,10 @@ masterfd_stdout = fds[0]; slavefd_stdout = fds[1]; - /* now that we've set masterfd_stdout, we can register the ctrl_cb + /* now that we've set masterfd_stdout, we can register the ctrl_winsz_cb * if we didn't set it here, we'd risk attempting to run ioctl on * a negative fd, and fail to resize the window */ - g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); + g_unix_fd_add(winsz_fd_r, G_IO_IN, ctrl_winsz_cb, NULL); } /* We always create a stderr pipe, because that way we can capture @@ -1522,6 +1593,7 @@ if (opt_bundle_path != NULL) { attach_symlink_dir_path = setup_attach_socket(); dummyfd = setup_terminal_control_fifo(); + setup_console_fifo(); if (opt_attach) { ndebug("sending attach message to parent"); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/ctr_logging.c new/conmon-2.0.3/src/ctr_logging.c --- old/conmon-2.0.2/src/ctr_logging.c 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/ctr_logging.c 2019-11-11 16:16:23.000000000 +0100 @@ -51,6 +51,8 @@ static char *container_id_full = NULL; static char *container_id = NULL; static char *container_name = NULL; +static char *container_tag = NULL; +static size_t container_tag_len; static void parse_log_path(char *log_config); static const char *stdpipe_name(stdpipe_t pipe); @@ -68,7 +70,7 @@ * (currently just k8s log file), it will also open the log_fd for that specific * log file. */ -void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_) +void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_, char *tag) { log_size_max = log_size_max_; if (log_drivers == NULL) @@ -102,6 +104,10 @@ /* Setup some sd_journal_sendv arguments that won't change */ container_id_full = g_strdup_printf("CONTAINER_ID_FULL=%s", cuuid); container_id = g_strdup_printf("CONTAINER_ID=%s", short_cuuid); + if (tag) { + container_tag = g_strdup_printf("CONTAINER_TAG=%s", tag); + container_tag_len = strlen (container_tag); + } /* To maintain backwards compatibility with older versions of conmon, we need to skip setting * the name value if it isn't present @@ -202,6 +208,9 @@ if (writev_buffer_append_segment(-1, &bufv, container_id, TRUNC_ID_LEN + CID_EQ_LEN) < 0) return -1; + if (container_tag && writev_buffer_append_segment(-1, &bufv, container_tag, container_tag_len) < 0) + return -1; + /* only print the name if we have a name to print */ if (name && writev_buffer_append_segment(-1, &bufv, container_name, name_len + CID_FULL_EQ_LEN) < 0) return -1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/ctr_logging.h new/conmon-2.0.3/src/ctr_logging.h --- old/conmon-2.0.2/src/ctr_logging.h 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/ctr_logging.h 2019-11-11 16:16:23.000000000 +0100 @@ -7,7 +7,7 @@ void reopen_log_files(void); bool write_to_logs(stdpipe_t pipe, char *buf, ssize_t num_read); -void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_); +void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuuid_, char *name_, char *tag); void sync_logs(void); #endif /* !defined(CTR_LOGGING_H) */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/utils.c new/conmon-2.0.3/src/utils.c --- old/conmon-2.0.2/src/utils.c 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/utils.c 2019-11-11 16:16:23.000000000 +0100 @@ -1,5 +1,6 @@ #include "utils.h" #include <string.h> +#include <strings.h> log_level_t log_level = WARN_LEVEL; char *log_cid = NULL; @@ -7,25 +8,32 @@ /* Set the log level for this call. log level defaults to warning. parse the string value of level_name to the appropriate log_level_t enum value */ -void set_conmon_logs(char *level_name, char *cid_, gboolean syslog_) +void set_conmon_logs(char *level_name, char *cid_, gboolean syslog_, char *tag) { - log_cid = cid_; + if (tag == NULL) + log_cid = cid_; + else + log_cid = g_strdup_printf("%s: %s", cid_, tag); use_syslog = syslog_; // log_level is initialized as Warning, no need to set anything if (level_name == NULL) return; - if (!strcmp(level_name, "error") || !strcmp(level_name, "fatal") || !strcmp(level_name, "panic")) { + if (!strcasecmp(level_name, "error") || !strcasecmp(level_name, "fatal") || !strcasecmp(level_name, "panic")) { log_level = EXIT_LEVEL; return; - } else if (!strcmp(level_name, "warn") || !strcmp(level_name, "warning")) { + } else if (!strcasecmp(level_name, "warn") || !strcasecmp(level_name, "warning")) { log_level = WARN_LEVEL; return; - } else if (!strcmp(level_name, "info")) { + } else if (!strcasecmp(level_name, "info")) { log_level = INFO_LEVEL; return; - } else if (!strcmp(level_name, "debug")) { + } else if (!strcasecmp(level_name, "debug")) { log_level = DEBUG_LEVEL; return; + } else if (!strcasecmp(level_name, "trace")) { + log_level = TRACE_LEVEL; + return; } + ntracef("set log level to %s", level_name); nexitf("No such log level %s", level_name); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/conmon-2.0.2/src/utils.h new/conmon-2.0.3/src/utils.h --- old/conmon-2.0.2/src/utils.h 2019-10-10 14:41:45.000000000 +0200 +++ new/conmon-2.0.3/src/utils.h 2019-11-11 16:16:23.000000000 +0100 @@ -25,6 +25,7 @@ WARN_LEVEL, INFO_LEVEL, DEBUG_LEVEL, + TRACE_LEVEL, } log_level_t; // Default log level is Warning, This will be configured before any logging @@ -134,10 +135,28 @@ } while (0); \ } +#define ntrace(s) \ + if (log_level >= TRACE_LEVEL) { \ + do { \ + fprintf(stderr, "[conmon:d]: %s\n", s); \ + if (use_syslog) \ + syslog(LOG_INFO, "conmon %.20s <ntrace>: %s\n", log_cid, s); \ + } while (0); \ + } + +#define ntracef(fmt, ...) \ + if (log_level >= TRACE_LEVEL) { \ + do { \ + fprintf(stderr, "[conmon:d]: " fmt "\n", ##__VA_ARGS__); \ + if (use_syslog) \ + syslog(LOG_INFO, "conmon %.20s <ntrace>: " fmt " \n", log_cid, ##__VA_ARGS__); \ + } while (0); \ + } + /* Set the log level for this call. log level defaults to warning. parse the string value of level_name to the appropriate log_level_t enum value */ -void set_conmon_logs(char *level_name, char *cid_, gboolean syslog_); +void set_conmon_logs(char *level_name, char *cid_, gboolean syslog_, char *tag); #define _cleanup_(x) __attribute__((cleanup(x)))