From a9f974b4951a261063187f0536c01c7f84e5fe56 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Sun, 15 Sep 2019 06:58:15 +0100 Subject: [PATCH] Introduce flush_early_log_to_stderr destructor Prior log initialisation CRIU preserves all (early) log messages in a buffer. In case of error the content of the content of this buffer needs to be printed out (flushed). Suggested-by: Dmitry Safonov <0x7f454c46@gmail.com> Signed-off-by: Radostin Stoyanov --- criu/crtools.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/criu/crtools.c b/criu/crtools.c index 0799a564c..4625446ad 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -47,6 +47,13 @@ #include "setproctitle.h" #include "sysctl.h" +void flush_early_log_to_stderr() __attribute__((destructor)); + +void flush_early_log_to_stderr(void) +{ + flush_early_log_buffer(STDERR_FILENO); +} + int main(int argc, char *argv[], char *envp[]) { int ret = -1; @@ -95,10 +102,8 @@ int main(int argc, char *argv[], char *envp[]) return cr_service_work(atoi(argv[2])); } - if (check_options()) { - flush_early_log_buffer(STDERR_FILENO); + if (check_options()) return 1; - } if (opts.imgs_dir == NULL) SET_CHAR_OPTS(imgs_dir, ".");